Sign in to follow this  
Followers 0
mastrboy

batch packer gui for 7zip

3 posts in this topic

putting it here so i don't loose it.

v0.1 written with a hangover :whistle:

#include <GUIConstants.au3>
#NoTrayIcon
Opt("RunErrorsFatal", 0)

;batch packer gui for 7zip written by mastrboy with a hangover ;)

;default 7-zip location
$7zip = @ProgramFilesDir & "\7-Zip\7zG.exe"

;if 7-zip not found at programfilesdir check registry for path
If Not FileExists($7zip) Then
    $7zipreg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip", "Path")
    If FileExists($7zipreg & "\7zG.exe") Then
        $7zip = $7zipreg & "\7zG.exe"
    Else
        MsgBox(0, "Can't locate 7-zip", "7-zip required files not found")
        Exit
    EndIf
EndIf

$form = GUICreate("Batch compression for 7-zip", 385, 658, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Label2 = GUICtrlCreateLabel("Folder:", 8, 8, 36, 17)
$folder = GUICtrlCreateInput(@ScriptDir, 8, 25, 321, 21)
$bfolder = GUICtrlCreateButton("...", 332, 24, 30, 22, 0)
$Label3 = GUICtrlCreateLabel("Output folder:", 8, 55, 70, 17)
$outputfolder = GUICtrlCreateInput(@ScriptDir, 8, 74, 321, 21)
$boutputfolder = GUICtrlCreateButton("...", 332, 73, 30, 22, 0)
$Label4 = GUICtrlCreateLabel("Archive format:", 48, 144, 75, 17)
$Label1 = GUICtrlCreateLabel("Compression Level:", 32, 176, 96, 17)
$Group1 = GUICtrlCreateGroup("Options", 8, 112, 361, 209)
$Label5 = GUICtrlCreateLabel("Filetype:", 80, 264, 43, 17)
$ifileext = GUICtrlCreateInput("*.*", 136, 264, 153, 21)
$bsearch = GUICtrlCreateButton("Search", 295, 262, 55, 25, 0)
$format = GUICtrlCreateCombo("", 136, 144, 153, 25)
$level = GUICtrlCreateCombo("", 136, 176, 153, 25)
$delete = GUICtrlCreateCheckbox("Delete files", 136, 208, 161, 17)
$recycle = GUICtrlCreateCheckbox("Move files to Recycle bin", 136, 232, 135, 17)
$status = GUICtrlCreateList("", 16, 368, 345, 214, BitOR($WS_BORDER,$WS_VSCROLL))
$start = GUICtrlCreateButton("Start", 8, 608, 81, 33, 0)
$exit = GUICtrlCreateButton("Exit", 208, 608, 81, 33, 0)
$Group2 = GUICtrlCreateGroup("Status", 8, 328, 361, 273)
$help = GUICtrlCreateButton("Help", 296, 608, 73, 33, 0)
$progress = GUICtrlCreateProgress(16, 344, 337, 17)
GUICtrlSetTip($help, "Help")
GUICtrlSetState($start, $GUI_DISABLE)
GUICtrlSetState($delete, $GUI_DISABLE)
GUICtrlSetState($recycle, $GUI_DISABLE)
GUICtrlSetData($format, "7z|Gzip|Zip", "Zip")
GUICtrlSetData($level, "Normal|Maximum|Ultra", "Maximum")

GUISetState(@SW_SHOW)
While 1
    ;check to make sure delete and recycle is not selected at the same time
    $del = GUICtrlRead($delete)
    $rec = GUICtrlRead($recycle)
    If $del = "1" And $rec = "1" Then
        MsgBox(48, "Wrong options", "You can't both delete and move to recycle bin")
        GUICtrlSetState($delete, $GUI_UNCHECKED)
        GUICtrlSetState($recycle, $GUI_UNCHECKED)
    EndIf
    
    ;make some variables from gui
    $fileext = GUICtrlRead($ifileext)
    $gfolder = GUICtrlRead($folder)
    ;folder \ fix
    If StringRight($gfolder, 1) = "\" Then
        ;
    Else
        $gfolder = $gfolder & "\"
    EndIf
    
    $goutputfolder = GUICtrlRead($outputfolder)
    ;folder \ fix
    If StringRight($goutputfolder, 1) = "\" Then
        ;
    Else
        $goutputfolder = $goutputfolder & "\"
    EndIf
    
    ;look for actions
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $bfolder
            ;display folder select dialog
            $folderselect = FileSelectFolder("Choose folder to search for files", "", 4, @ScriptDir)
            If $folderselect Then GUICtrlSetData($folder, $folderselect)
        Case $boutputfolder
            ;display folder select dialog
            $outfolderselect = FileSelectFolder("Choose output folder", "", 5, @ScriptDir)
            If $outfolderselect Then GUICtrlSetData($outputfolder, $outfolderselect)
        Case $bsearch
            ;check for valid folder to search in
            If StringInStr(FileGetAttrib($gfolder), "D") Then
                ;search for files
                $search = FileFindFirstFile($gfolder & $fileext)

                ;check to see if there is any nds files in the folder previusly selected
                If $search = -1 Then
                    MsgBox(48, "Error", "No files matching " & $fileext & " found in " & $gfolder)
                    GUICtrlSetState($start, $GUI_DISABLE)
                    ; Close the search handle
                    FileClose($search)
                Else
                    $i = "0"
                    While 1
                        $file = FileFindNextFile($search)
                        If @error Then ExitLoop
                        If Not StringInStr(FileGetAttrib($gfolder & $file), "D", 1) Then
                            $i = $i + 1
                        EndIf
                    WEnd
                    GUICtrlSetData($status, "Found " & $i & " File(s)|")
                    GUICtrlSetState($start, $GUI_ENABLE)
                    $progressmax = $i
                EndIf
                FileClose($search)
            Else
                MsgBox(48, "Invalid folder", "Folder is invalid, or does not exist")
            EndIf
        Case $start
            ;compression level variable check
            $glevel = GUICtrlRead($level)
            Switch $glevel
                Case "Normal"
                    $clevel = "5"
                Case "Maximum"
                    $clevel = "7"
                Case "Ultra"
                    $clevel = "9"
            EndSwitch
            
            ;command processing
            $gformat = GUICtrlRead($format)
            
            Switch $gformat
                Case "7z"
                    $ext = ".7z"
                Case "Gzip"
                    $ext = ".gz"
                Case "Zip"
                    $ext = ".zip"
            EndSwitch
            
            ;check output folder
            If FileExists($goutputfolder) And StringInStr(FileGetAttrib($goutputfolder), "D") Then
                $search = FileFindFirstFile($gfolder & $fileext)
                $i = 0
                While 1
                    $file = FileFindNextFile($search)
                    If @error Then ExitLoop
                    If Not StringInStr(FileGetAttrib($gfolder & $file), "D", 1) Then
                        $fullfile = $gfolder & $file
                        ;grr, took me ages to figure out this ugly regexp.. i hate regexp!!
                        $outfile = StringRegExpReplace($file, "\.(.*)", $ext)
                        $fulloutfile = $goutputfolder & $outfile
                        Switch $gformat
                            Case "7z"
                                $command = $7zip & " a -mx" & $clevel & " -t7z """ & $fulloutfile & """" & " """ & $fullfile & """"
                            Case "Gzip"
                                $command = $7zip & " a -mx" & $clevel & " -tgzip """ & $fulloutfile & """" & " """ & $fullfile & """"
                            Case "Zip"
                                $command = $7zip & " a -mx" & $clevel & " -tzip """ & $fulloutfile & """" & " """ & $fullfile & """"
                        EndSwitch
                        GUICtrlSetState($start, $GUI_DISABLE)
                        $i = $i + 1
                        $progressset = $i / $progressmax * 100
                        GUICtrlSetData($progress,int($progressset))
                        $run = RunWait($command)
                        Switch $run
                            Case 0
                                GUICtrlSetData($status, "Compressed - "&$file & "|")
                            Case 1
                                GUICtrlSetState($start, $GUI_ENABLE)
                                GUICtrlSetData($status, "Warning (Non fatal error(s)). For example, some files were locked by other application during compressing. So they were not compressed.|")
                                ExitLoop
                            Case 2
                                GUICtrlSetState($start, $GUI_ENABLE)
                                GUICtrlSetData($status, "Fatal error|")
                                ExitLoop
                            Case 7
                                GUICtrlSetState($start, $GUI_ENABLE)
                                GUICtrlSetData($status, "Command line error|")
                                ExitLoop
                            Case 8
                                GUICtrlSetState($start, $GUI_ENABLE)
                                GUICtrlSetData($status, "Not enough memory for operation|")
                                ExitLoop
                            Case 255
                                GUICtrlSetState($start, $GUI_ENABLE)
                                GUICtrlSetData($status, "canceled|")
                                ExitLoop
                            Case Else
                                GUICtrlSetState($start, $GUI_ENABLE)
                                GUICtrlSetData($status, "unknown error|")
                                ExitLoop
                        EndSwitch
                        GUICtrlSetState($start, $GUI_ENABLE)
                    EndIf
                WEnd
                FileClose($search)
            Else
                MsgBox(48, "Invalid output folder", "Output folder does not exist or is not a folder!")
            EndIf
        Case $help
            MsgBox(64,"hmm","There should be some help here, but my head hurts to much to write it right now :P")
        Case $exit
            Exit
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

se attachement for compiled

batchpacker_gui.exe


 -

Share this post


Link to post
Share on other sites



Looks good but a few suggestions.

1) Try using 7za.exe (Command line version)

2) Change

;folder \ fix
    If StringRight($goutputfolder, 1) = "\" Then
        ;
    Else
        $goutputfolder = $goutputfolder & "\"
    EndIfoÝ÷ Ù:ºÚ"µÍYÝ[ÔYÚ
    ÌÍÙÛÝ]]ÛJH    ÉÝÈ  ][ÝÉÌLÉ][ÝÈ[  ÌÍÙÛÝ]]Û  [ÏH    ][ÝÉÌLÉ][ÝoÝ÷ Ûp¡jxjëh×6    ;check to make sure delete and recycle is not selected at the same time
    $del = GUICtrlRead($delete)
    $rec = GUICtrlRead($recycle)
    If $del = "1" And $rec = "1" Then
        MsgBox(48, "Wrong options", "You can't both delete and move to recycle bin")
        GUICtrlSetState($delete, $GUI_UNCHECKED)
        GUICtrlSetState($recycle, $GUI_UNCHECKED)
    EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Looks good but a few suggestions.

1) Try using 7za.exe (Command line version)

2) Change

;folder \ fix
    If StringRight($goutputfolder, 1) = "\" Then
        ;
    Else
        $goutputfolder = $goutputfolder & "\"
    EndIfoÝ÷ Ûp¡jxjëh×6    ;check to make sure delete and recycle is not selected at the same time
    $del = GUICtrlRead($delete)
    $rec = GUICtrlRead($recycle)
    If $del = "1" And $rec = "1" Then
        MsgBox(48, "Wrong options", "You can't both delete and move to recycle bin")
        GUICtrlSetState($delete, $GUI_UNCHECKED)
        GUICtrlSetState($recycle, $GUI_UNCHECKED)
    EndIf
 oÝ÷ Ù:ºÚ"µÍ ÌÍÙ[HÕRPÝXY
    ÌÍÙ[]JB  ÌÍÜXÈHÕRPÝXY
    ÌÍÜXÞXÛJBY ÌÍÙ[HH[ÕRPÝÙ]Ý]J ÌÍÜXÞXÛK   ÌÍÑÕRWÕSÒPÒÑQ
B[ÙBÕRPÝÙ]Ý]J  ÌÍÙ[]K   ÌÍÑÕRWÕSÒPÒÑQ
B[Y

looks like you also find it fun to write programs when you drunk lol

Share this post


Link to post
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
Sign in to follow this  
Followers 0