Jump to content

Disk Manager - V2 with source code!


James
 Share

Recommended Posts

  • Replies 130
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

To-do:

  • Re-make the GUI: Menu, Size, Colours
  • Add more information about the drives
  • More functions: Auto update (I need to add it in), Copy data to clipboard
  • Allow you to select different types of drives
  • Minimize to tray
  • Show in tooltip on hover (regards to above)
  • Save data in a config file
  • Bug reporting
  • New icon (There is one for the compiled version)
Link to comment
Share on other sites

Hi JamesB,

I would add the option to remove cdrom and other drives which are not ready.. further i would remove the floppy drive.. because checking the space on a floppy drive will slow down the complete computer and causes the computer to make noise while checking it..

and if i were you .. i would spell my name correct Emiel instead om Emeil :)

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

Infact here:

You can try it now, unfinished and lots to do, you can also ask me things to add or remove.

; Includes
#include <GUIConstantsEx.au3>
#include <GUIStatusBar.au3>
#include <GUIListView.au3>
#include <GuiEdit.au3>
#include <Constants.au3>
#include <File.au3>
#include <Array.au3>

; Display no Tray Icon
#NoTrayIcon

; Options for the program
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "Minimize")

; Retrieve all drive types
Global $_AllD = DriveGetDrive("ALL")
; Set the default parameters for the console
Global $Warnings = True, $NR_Drives = False
; Location of the config file
Global $Config_File = @ScriptDir & '\config.ini'
; Allow the creation of the data from the 1-Dimensional array ~ Martin
Global $Data[$_AllD[0]]
; Set the parts for the status bar
Local $Parts[2] = [175, 150]
; Allow multi control creation of controls ~ Nahuel
Dim $Labels[$_AllD[0] + 1]
Dim $Progress[$_AllD[0] + 1]

#region GUI
; Create the GUI and the controls inside it
$GUI = GUICreate("Disk Manager - James Brooks", 520, 400 + $_AllD[0] * 2)

; Create the menu
#region Menu
$M_File = GUICtrlCreateMenu("File")
$M_Export = GUICtrlCreateMenuItem("Export Data", $M_File)
$M_Import = GUICtrlCreateMenuItem("Import Data", $M_File)
GUICtrlCreateMenuItem("", $M_File)
$M_Copy = GUICtrlCreateMenuItem("Copy Data to Clipboard", $M_File)
GUICtrlCreateMenuItem("", $M_File)
$M_Exit = GUICtrlCreateMenuItem("Exit", $M_File)
$M_Options = GUICtrlCreateMenu("Options")
$M_Colours = GUICtrlCreateMenu("Colour Scheme", $M_Options)
$M_Colours_Sea = GUICtrlCreateMenuItem("Sea", $M_Colours)
$M_Colours_Mystic = GUICtrlCreateMenuItem("Mystic", $M_Colours)
$M_Colours_HinSun = GUICtrlCreateMenuItem("Hindered Sun", $M_Colours)
$M_Colours_Grass = GUICtrlCreateMenuItem("Grass", $M_Colours)
$M_Colours_Simple = GUICtrlCreateMenuItem("Simple", $M_Colours)
$M_Progress = GUICtrlCreateMenu("Progress Styles", $M_Options)
$M_Progress_Solid = GUICtrlCreateMenuItem("Solid", $M_Progress)
$M_Progress_Block = GUICtrlCreateMenuItem("Block", $M_Progress)
$M_Help = GUICtrlCreateMenu("Help")
$M_About = GUICtrlCreateMenuItem("About", $M_Help)
$M_BugReport = GUICtrlCreateMenuItem("Report Bug", $M_Help)
$M_HelpTopic = GUICtrlCreateMenuItem("Help Me", $M_Help)
#endregion Menu

; Create the Statusbar
$StatusBar = _GUICtrlStatusBar_Create($GUI)
_GUICtrlStatusBar_SetParts($StatusBar, $Parts)
_GUICtrlStatusBar_SetText($StatusBar, "Loading Drive Data...")

; Create the listview to display the drives ~ Saunders Edited by Me
$DriveList = _GUICtrlListView_Create($GUI, "Drive|Label|Type|Status|File System|Serial Number|Free Space|Used Space|Total Space", 10, 10, 500, 120)

; Create a group to hold the progress bars
GUICtrlCreateGroup("Information", 10, 140, 160, ($_AllD * 2))
For $i = 1 To $_AllD[0]
    $Labels[$i] = GUICtrlCreateLabel(StringUpper($_AllD[$i]), 20, ($i * 20) + 140, 121, 17)
    $Progress[$i] = GUICtrlCreateProgress(40, ($i * 20) + 140, 121, 17, 1)
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Progress[$i]), "wstr", "", "wstr", "")
    If Not FileExists($Config_File) Then
        GUICtrlSetColor($Progress[$i], 0x94FF00)
        GUICtrlSetBkColor($Progress[$i], 0xFFFFFF)
    ElseIf FileExists($Config_File) Then
        GUICtrlSetColor($Progress[$i], IniRead($Config_File, "Scheme", "Front", ""))
        GUICtrlSetBkColor($Progress[$i], IniRead($Config_File, "Scheme", "Back", ""))
    EndIf
Next
GUICtrlCreateGroup("", -99, -99, 1, 1)

; Create a group for the console
GUICtrlCreateGroup("Console", 180, 140, 330, 220)
$ConsoleBox = GUICtrlCreateEdit("Welcome to Disk Manager by James Brooks" & @CRLF & "Commands:" & @CRLF & _
        @TAB & "warn [-t = Show -f = Hide]" & @CRLF & @TAB & "clear" & @CRLF & @TAB & "export" & _
        @CRLF & @TAB & "help" & @CRLF, 190, 160, 310, 170, $WS_VSCROLL)
GUICtrlSetFont(-1, 8.5, 400, Default, "Courier New")
GUICtrlSetColor(-1, IniRead($Config_File, "Scheme", "Console", ""))
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($ConsoleBox), "wstr", "", "wstr", "")
$Console = GUICtrlCreateInput("", 190, 340, 310, 17)
GUICtrlSetFont(-1, 8.5, 400, Default, "Courier New")
GUICtrlCreateGroup("", -99, -99, 1, 1)

; We have to show the GUI
GUISetState(@SW_SHOW)
#endregion Menu

; Insert data into the listview made above
_Drives()

While 1
    $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            Exit
            ; If you press X then close the window
        Case $iMsg = $GUI_EVENT_MINIMIZE
            GUISetState(@SW_HIDE)
            TraySetState(1)
            ; Minimize the GUI to the tray
        Case $iMsg = $M_Export
            _ExportData()
            ; Export the data NOT WORKING YET
        Case $iMsg = $Console
            $Com = StringLower(GUICtrlRead($Console))
            If $Com = "warn -t" Then
                $Warnings = True
                _GUICtrlEdit_AppendText($ConsoleBox, "Warnings on" & @CRLF)
                GUICtrlSetData($Console, "")
            EndIf
            If $Com = "warn -f" Then
                $Warnings = False
                _GUICtrlEdit_AppendText($ConsoleBox, "Warnings off" & @CRLF)
                GUICtrlSetData($Console, "")
            EndIf
            If $Com = "clear" Then
                GUICtrlSetData($ConsoleBox, "")
                GUICtrlSetData($Console, "")
            EndIf
            If $Com = "help" Then
                _GUICtrlEdit_AppendText($ConsoleBox, "Commands:" & @CRLF)
                GUICtrlSetData($Console, "")
            EndIf
            If $Com = "about" Then
                _GUICtrlEdit_AppendText($ConsoleBox, "Disk Manager by James Brooks" & @CRLF & "Thanks to the AutoIt " & _
                        "Community for helping me with this project. Special thanks to, Nahuel, Saunders, Gary Frost, Valuater, " & _
                        "Martin & Emiel Wieldraaijer for their help, support and contribution to it!" & @CRLF)
                GUICtrlSetData($Console, "")
            EndIf
            If $Com = "export" Then
                $Info = _ExportData()
                _ArrayDisplay($Info)
                GUICtrlSetData($Console, "")
            EndIf
            If $Com = "update" Then
                _Drives()
                GUICtrlSetData($Console, "")
                _GUICtrlEdit_AppendText($ConsoleBox, "Retrieved devices")
            EndIf
            ; Read through the console
        Case $iMsg = $M_About
            About()
            ; Display the about box
        Case $iMsg = $M_BugReport
            BugReport()
        Case $iMsg = $M_Import
            Import()
        Case $iMsg = $M_Colours_Simple
            If Not FileExists($Config_File) Then
                _FileCreate($Config_File)
            Else
                IniWrite($Config_File, "Scheme", "Back", "0x8BD1E0")
                IniWrite($Config_File, "Scheme", "Front", "0xC1C1C1")
                IniWrite($Config_File, "Scheme", "Console", "0x000000")
                _GUICtrlStatusBar_SetText($StatusBar, "Config file was created!")
                For $z = 1 To $_AllD[0]
                    GUICtrlSetColor($Progress[$z], IniRead($Config_File, "Scheme", "Front", ""))
                    GUICtrlSetBkColor($Progress[$z], IniRead($Config_File, "Scheme", "Back", ""))
                    GUICtrlSetColor($ConsoleBox, IniRead($Config_File, "Scheme", "Console", ""))
                Next
            EndIf
            ; Set the colour scheme to a simple blue and grey
        Case $iMsg = $M_Colours_Mystic
            If Not FileExists($Config_File) Then
                _FileCreate($Config_File)
            Else
                IniWrite($Config_File, "Scheme", "Back", "0x6F6F6F")
                IniWrite($Config_File, "Scheme", "Front", "0xCC3300")
                IniWrite($Config_File, "Scheme", "Console", "0xCC3300")
                _GUICtrlStatusBar_SetText($StatusBar, "Config file was created!")
                For $z = 1 To $_AllD[0]
                    GUICtrlSetColor($Progress[$z], IniRead($Config_File, "Scheme", "Front", ""))
                    GUICtrlSetBkColor($Progress[$z], IniRead($Config_File, "Scheme", "Back", ""))
                    GUICtrlSetColor($ConsoleBox, IniRead($Config_File, "Scheme", "Console", ""))
                Next
            EndIf
            ; Set the colour scheme to Grey and Red
        Case $iMsg = $M_Colours_Sea
            If Not FileExists($Config_File) Then
                _FileCreate($Config_File)
            Else
                IniWrite($Config_File, "Scheme", "Back", "0x96B6E5")
                IniWrite($Config_File, "Scheme", "Front", "0xC4E596")
                IniWrite($Config_File, "Scheme", "Console", "0x508238")
                _GUICtrlStatusBar_SetText($StatusBar, "Config file was created!")
                For $z = 1 To $_AllD[0]
                    GUICtrlSetColor($Progress[$z], IniRead($Config_File, "Scheme", "Front", ""))
                    GUICtrlSetBkColor($Progress[$z], IniRead($Config_File, "Scheme", "Back", ""))
                    GUICtrlSetColor($ConsoleBox, IniRead($Config_File, "Scheme", "Console", ""))
                Next
            EndIf
            ; Set the colour scheme to Blue and Green
        Case $iMsg = $M_Colours_HinSun
            If Not FileExists($Config_File) Then
                _FileCreate($Config_File)
            Else
                IniWrite($Config_File, "Scheme", "Back", "0xCC3300")
                IniWrite($Config_File, "Scheme", "Front", "0xE8A03A")
                IniWrite($Config_File, "Scheme", "Console", "0xCC3300")
                _GUICtrlStatusBar_SetText($StatusBar, "Config file was created!")
                For $z = 1 To $_AllD[0]
                    GUICtrlSetColor($Progress[$z], IniRead($Config_File, "Scheme", "Front", ""))
                    GUICtrlSetBkColor($Progress[$z], IniRead($Config_File, "Scheme", "Back", ""))
                    GUICtrlSetColor($ConsoleBox, IniRead($Config_File, "Scheme", "Console", ""))
                Next
            EndIf
        Case $iMsg = $M_Colours_Grass
            If Not FileExists($Config_File) Then
                _FileCreate($Config_File)
            Else
                IniWrite($Config_File, "Scheme", "Back", "0x89d464")
                IniWrite($Config_File, "Scheme", "Front", "0xC5D464")
                IniWrite($Config_File, "Scheme", "Console", "0x508238")
                _GUICtrlStatusBar_SetText($StatusBar, "Config file was created!")
                For $z = 1 To $_AllD[0]
                    GUICtrlSetColor($Progress[$z], IniRead($Config_File, "Scheme", "Front", ""))
                    GUICtrlSetBkColor($Progress[$z], IniRead($Config_File, "Scheme", "Back", ""))
                    GUICtrlSetColor($ConsoleBox, IniRead($Config_File, "Scheme", "Console", ""))
                Next
            EndIf
    EndSelect
WEnd

Func _Drives()
    For $a = 1 To $_AllD[0]
        $Total = DriveSpaceTotal($_AllD[$a])
        $Free = Round(DriveSpaceFree($_AllD[$a]))
        $Used = Round($Total - $Free)
        $Letter = StringUpper($_AllD[$a])
        $Label = DriveGetLabel($_AllD[$a])
        If $Label = '' Then $Label = "[None]"
        $Type = DriveGetType($_AllD[$a])
        If $Type = 'UNKNOWN' Then $Type = "[Unknown]"
        $Status = DriveStatus($_AllD[$a])
        $FSys = DriveGetFileSystem($_AllD[$a])
        If $FSys = '' Then $FSys = "[None]"
        $Serial = DriveGetSerial($_AllD[$a])
        If $Serial = '' Then $Serial = "[None]"
        
        $sItem = $Letter & "|" & $Label & "|" & $Type & "|" & $Status & "|" & $FSys & "|" & $Serial & "|" & $Free & "|" & _
                $Used & "|" & $Total
        $iItem = _GUICtrlListView_InsertItem($DriveList, "", -1, 1)
        _GUICtrlListView_SetItemText($DriveList, $iItem, $sItem, -1)
        GUICtrlSetData($Progress[$a], $Used / 1024); not precise ~ Valuater edited my Me
        $Data[$a - 1] = StringSplit($sItem, "|")
    Next
    TrayTip("Disk Manager", "Drive data was loaded!", 10, 1)
    If @error Then
        If $Warnings = True Then _GUICtrlEdit_AppendText($ConsoleBox, "There was an error reading disk data!" & @CRLF)
    EndIf
    _GUICtrlStatusBar_SetText($StatusBar, "Drive Data was loaded!")
    ; Retrieve all device data
EndFunc   ;==>_Drives

Func _CopyToClipBoard()
    ; Copies all data to the clipboard for further analysis
EndFunc   ;==>_CopyToClipBoard

Func Minimize()
    TraySetState(2)
    GUISetState(@SW_SHOW)
    TraySetToolTip("Disk Manager")
    ; Minimize function
EndFunc   ;==>Minimize

Func About()
    $About = GUICreate("About Disk Manager", 300, 200)
    GUICtrlCreateLabel("Disk Manager by James Brooks" & @CRLF & @CRLF & "Thanks to the AutoIt " & _
            "Community for helping me with this" & @CRLF & "project. Special thanks to, Nahuel, Saunders, " & _
            @CRLF & "Gary Frost, Valuater, Martin and" & @CRLF & "Emiel Wieldraaijer for their help, support and contribution to it!", 10, 10)
    $Link = GUICtrlCreateLabel("Please visit my site for more programs!", 10, 100, 280)
    GUICtrlSetColor(-1, 0x0000FF)
    GUICtrlSetFont(-1, Default, Default, 4)
    GUICtrlSetCursor(-1, 2)
    
    GUISetState(@SW_SHOW, $About)
    
    While WinActive($About)
        $aMsg = GUIGetMsg()
        Switch $aMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($About)
            Case $Link
                ShellExecute("http://www.james-brooks.net")
        EndSwitch
    WEnd
    ; About window
EndFunc   ;==>About

Func BugReport()
    MsgBox(0, "Disk Manager", "Bug reporting is only installed in the Compiled Version!")
EndFunc   ;==>BugReport

Func Help()
    ; ShellExecute("http://www.james-brooks.net/help/prog-man/index.php")
    ; Pages not setup yet
EndFunc   ;==>Help

Func Import()
    $File = FileOpenDialog("Disk Manager", @ScriptDir, "DMan Files (*.dma)", 1 + 2)
    If @error Then
        MsgBox(4096, "", "No File chosen")
        _GUICtrlStatusBar_SetText($StatusBar, "Error importing external deivce data")
    Else
        _GUICtrlListView_DeleteAllItems($DriveList)
        MsgBox(0, "Disk Manager", "Import soon")
    EndIf
EndFunc   ;==>Import

Func _ExportData()
    For $n = 0 To UBound($Data) - 1
        _ArrayDisplay($Data[$n]);each element is an array so specify the element
    Next

    If @error Then
        _GUICtrlEdit_AppendText($ConsoleBox, "Error exporting data!" & @CRLF)
    Else
        _GUICtrlStatusBar_SetText($StatusBar, "Data was exported" & @CRLF)
    EndIf
    ; Export the data into a specified file ~ Martin
EndFunc   ;==>_ExportData

Lots of improvements.

Martin has sped up the array and made it smaller! If you haven't already copy the code again! I have just fixed the problem that if there is no config file the progress bar will set a "default" colour. Please get yet again!

Edited by JamesB
Link to comment
Share on other sites

Update:

At the moment, I am working on the export function :) Unfortunatley it's not so easy. Martin provided me with some code:

Func _ExportData()
    $io_file = FileOpen(@ScriptDir & '\Export.DMA', 2)
    If FileExists(@ScriptDir & '\Export.DMA') Then FileDelete(@ScriptDir & '\Export.DMA') ; Delete the file if it exists
    FileWrite($io_file, "// Export data for computer: " & @ComputerName & @CRLF)
    FileWrite($io_file, "// Exported on: " & @MDAY & "/" & @MON & "/" & @YEAR & @CRLF)
    FileWrite($io_file, "// Exported by: " & @UserName & @CRLF)
    For $n = 0 To UBound($Data) - 1
        FileWrite($io_file, $Data[$n] & @CRLF)
        ;_ArrayDisplay($Data[$n]);each element is an array so specify the element
    Next
    FileClose($io_file)

    If @error Then
        _GUICtrlEdit_AppendText($ConsoleBox, "Error exporting data!" & @CRLF)
    Else
        _GUICtrlStatusBar_SetText($StatusBar, "Data was exported" & @CRLF)
    EndIf
    ; Export the data into a specified file ~ Martin edited by Me
EndFunc   ;==>_ExportData

Yet, it doesn't work how I need it to, which is, to write all the data in a "list" for each drive. Well if anyone can make it work please tell me :P

After the export function I will start work on an Import function so that you can import other peoples drive data into the program. Once the export is done, this will be really simple!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...