careca

Archiver

1 post in this topic

#1 ·  Posted (edited)

Hi there, my aim was to be able to pack files, even inside folders, into a .dat file (just because) and then extract the files from it, while retaining the path structure.

Run the script as normal, drag files and or folders into the listview, when all files you want to pack are there, press "go" button.

Doesn't work if you drag from multiple sources, only admits drag and drop from the same folder.

SFX.dat is created, to extract them back run the script with '/ext' parameter, it extracts the .ini which is what holds the filenames, then it extracts the file one by one efectivelly splitting .dat into pieces and writing those pieces into new files. There you go.

This is a proof of concept, not sure it will be of use to anyone, but there you go.

#Region ;Wrapper
;#RequireAdmin ;Disables Console
#pragma compile(UPX, false)
#pragma compile(CompanyName, '')
#pragma compile(ProductVersion, 1.0)
#pragma compile(FileVersion, 1.0)
#pragma compile(x64, false)
#pragma compile(Icon, 'Archive1.ico')
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_ShowProgress=y
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Fileversion=1.0
#AutoIt3Wrapper_Icon='Archive1.ico'
#AutoIt3Wrapper_Res_Icon_Add='Archive1.ico'
#Autoit3Wrapper_Testing=n
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_AU3Check=y
#AutoIt3Wrapper_Run_Debug_Mode=n
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#EndRegion ;Wrapper
;=============================================================================
#Region ;FileInstall
#include <File.au3>
#include <Marquee.au3>
#include <WinAPIEx.au3>
#include <Constants.au3>
#include <GuiListView.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
Global $__aGUIDropFiles = 0, $__hGUI = 0
Local $StringSep = 'SeparateHere'
Local $WFl, $Split, $Fop, $FRd, $Listview, $ContextMenu, $aReturn, $aList
Local $GetItemTxt1, $GetItemTxt2, $SectArray, $IRead, $SplitIni, $Splt, $Dir, $DropDir, $DropDirIni
Local $GMarquee, $Progress_1, $LabelP
;=============================================================================
;RegWrite(
;=============================================================================
Local $aProcessList = ProcessList(@AutoItPID)
If $aProcessList[0][1] >= 2 Then Exit
OnAutoItExitRegister("Quit")
Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
#EndRegion ;FileInstall
FileInstall("Marquee.au3", @TempDir & "\Marquee.au3")
FileInstall("Archive1.ico", @TempDir & "\Archive1.ico", 0)
TraySetIcon(@TempDir & "\Archive1.ico")
GUISetIcon(@TempDir & "\Archive1.ico")
;=============================================================================
If StringInStr($cmdlineRaw, "/source") Then
    FileInstall("SFX.au3", @TempDir & "\SFX.au3", 0)
    Exit
ElseIf StringInStr($cmdlineRaw, "/Ext") Then
    If FileExists($CmdLine[2]) Then
        $GMarquee = GUICreate("SFX", 240, 70, -1, @DesktopHeight / 4)
        GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
        $Progress_1 = GUICtrlCreateProgress(10, 10, 220, 20, 0x0008)
        $LabelP = GUICtrlCreateLabel('Working...', 10, 40, 100)
        GUISetState(@SW_SHOW)
        _ProgressMarquee_Start($Progress_1) ;Start
        $WFl = FileOpen($CmdLine[2], 512)
        $FRd = FileRead($WFl)
        $Split = StringSplit($FRd, $StringSep, 1)
        FileWrite('SFX.ini', Binary($Split[1]))
        $DropDirIni = IniRead("SFX.ini", "Path", 'DropDir', '')
        $SectArray = IniReadSection('SFX.ini', 'Binary')
        For $f = 1 To $SectArray[0][0]
            DirCreate($DropDirIni)
            FileWrite($DropDirIni & $SectArray[$f][0], Binary($Split[$f + 1]))
        Next
        FileClose($WFl)
        _ProgressMarquee_Stop($Progress_1) ;Stop
        GUIDelete($GMarquee)
        MsgBox(64, 'SFX', 'Complete!')
        FileDelete('SFX.ini')
        Exit
    Else
        MsgBox(64, 'Error', 'Parameter wrong or file not found: ' & @CRLF & 'Syntax Example: SFX.exe /Ext "C:\Somefile.dat"')
    EndIf
Else
    ;StringInStr($cmdlineRaw, "/Build") Then
    $__hGUI = GUICreate('Drag&Drop Multiple Files', 600, 315, 100, 100, Default, $WS_EX_ACCEPTFILES)
    $Listview = GUICtrlCreateListView('Path|Size', 10, 10, 580, 258, $LVS_SHOWSELALWAYS + $LVS_SINGLESEL + $LVS_EDITLABELS + $LVS_NOSORTHEADER, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
    $ContextMenu = GUICtrlCreateContextMenu($Listview)
    GUICtrlCreateMenuItem("Delete", $ContextMenu, 1)
    GUICtrlSetOnEvent(-1, "Delete")
    GUICtrlCreateMenuItem("Clear List", $ContextMenu, 2)
    GUICtrlSetOnEvent(-1, "Clear")
    GUICtrlCreateButton('Go', 10, 280, 50, -1)
    GUICtrlSetOnEvent(-1, 'Go')
    GUICtrlSetBkColor($Listview, 0x888888)
    GUICtrlSetState($Listview, $GUI_DROPACCEPTED)
    GUISetState(@SW_SHOW, $__hGUI)
    TraySetIcon(@TempDir & "\Archive1.ico")
    GUISetIcon(@TempDir & "\Archive1.ico")
    GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
    GUISetOnEvent($GUI_EVENT_DROPPED, "Drop")
    GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES')
    _WinAPI_ChangeWindowMessageFilterEx($__hGUI, $WM_DROPFILES, $MSGFLT_ALLOW)
    _WinAPI_ChangeWindowMessageFilterEx($__hGUI, $WM_COPYDATA, $MSGFLT_ALLOW)
    _WinAPI_ChangeWindowMessageFilterEx($__hGUI, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
        Sleep(500)
    WEnd
    GUIDelete($__hGUI)
EndIf
;=============================================================================
Func Go()
    $GMarquee = GUICreate("SFX", 240, 70, -1, @DesktopHeight / 4)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
    $Progress_1 = GUICtrlCreateProgress(10, 10, 220, 20, 0x0008)
    $LabelP = GUICtrlCreateLabel('Working...', 10, 40, 100)
    GUISetState(@SW_SHOW)
    _ProgressMarquee_Start($Progress_1) ;Start
    If _GUICtrlListView_GetItemCount($Listview) <> 0 Then
        For $c = 0 To _GUICtrlListView_GetItemCount($Listview) - 1
            $GetItemTxt1 = _GUICtrlListView_GetItemText($Listview, $c, 0)
            $GetItemTxt2 = _GUICtrlListView_GetItemText($Listview, $c, 1)
            IniWrite('SFX.ini', 'Binary', $GetItemTxt1, $GetItemTxt2)
        Next
    EndIf
    $SectArray = IniReadSection("SFX.ini", "Binary")
    $DropDirIni = IniRead("SFX.ini", "Path", 'DropDir', '')
    $Fop = FileOpen('SFX.ini', 16)
    $FRd = FileRead($Fop)
    FileClose($Fop)
    $WFl = FileOpen('SFX.Dat', 26)
    FileWrite($WFl, $FRd & StringToBinary($StringSep, 1))
    FileDelete('SFX.ini')
    ;=============================================================================
    For $s = 1 To $SectArray[0][0]
        $Fop = FileOpen($DropDir & $SectArray[$s][0], 16)
        $FRd = FileRead($Fop)
        FileClose($Fop)
        FileWrite($WFl, $FRd & StringToBinary($StringSep, 1))
    Next
    FileClose($WFl)
    _ProgressMarquee_Stop($Progress_1) ;Stop
    GUIDelete($GMarquee)
    MsgBox(64, 'SFX', 'Complete!')
EndFunc   ;==>Go
;=============================================================================
Func Delete()
    _GUICtrlListView_DeleteItemsSelected($Listview)
EndFunc   ;==>Delete
;=============================================================================
Func Clear()
    _GUICtrlListView_DeleteAllItems($Listview)
EndFunc   ;==>Clear
;=============================================================================
Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $lParam
    Switch $iMsg
        Case $WM_DROPFILES
            Local Const $aReturn = _WinAPI_DragQueryFileEx($wParam)
            If UBound($aReturn) Then
                $__aGUIDropFiles = $aReturn
            Else
                Local Const $aError[1] = [0]
                $__aGUIDropFiles = $aError
            EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DROPFILES
;=============================================================================
Func Drop()
    $GMarquee = GUICreate("SFX", 240, 70, -1, @DesktopHeight / 4)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
    $Progress_1 = GUICtrlCreateProgress(10, 10, 220, 20, 0x0008)
    $LabelP = GUICtrlCreateLabel('Working...', 10, 40, 100)
    GUISetState(@SW_SHOW)
    _ProgressMarquee_Start($Progress_1) ;Start
    $DropDir = StringLeft($__aGUIDropFiles[1], StringInStr($__aGUIDropFiles[1], '\', 2, -1))
    IniWrite('SFX.ini', 'Path', 'DropDir', StringLeft($__aGUIDropFiles[1], StringInStr($__aGUIDropFiles[1], '\', 2, -1)))
    For $i = 1 To $__aGUIDropFiles[0]
        Local $StrDropCheckFolder = StringInStr($__aGUIDropFiles[$i], '.')
        If $StrDropCheckFolder = 0 Then
            $aList = _FileListToArrayRec($__aGUIDropFiles[$i], '*', 1, 1, 0, 2)
            For $f = 1 To $aList[0]
                GUICtrlCreateListViewItem(StringTrimLeft($aList[$f], StringLen($DropDir)) & '|' & FileGetSize($aList[$f]), $Listview)
                GUICtrlSendMsg($Listview, $LVM_SETCOLUMNWIDTH, 0, -1)
                GUICtrlSendMsg($Listview, $LVM_SETCOLUMNWIDTH, 1, -1)
            Next
        Else
            GUICtrlCreateListViewItem(StringTrimLeft($__aGUIDropFiles[$i], StringLen($DropDir)) & '|' & FileGetSize($__aGUIDropFiles[$i]), $Listview)
            GUICtrlSendMsg($Listview, $LVM_SETCOLUMNWIDTH, 0, -1)
            GUICtrlSendMsg($Listview, $LVM_SETCOLUMNWIDTH, 1, -1)
        EndIf
    Next
    _ProgressMarquee_Stop($Progress_1) ;Stop
    GUIDelete($GMarquee)
EndFunc   ;==>Drop
;=============================================================================
Func Quit()
    Exit
EndFunc   ;==>Quit
;=============================================================================

EDIT: Bugfixes, now uses parameter to extract a specific filename .dat:

sfx.exe /ext "Filepath.dat"

It extracts to the same path as when it was packed.

Regfile to call the unpack (exe path has to be adjusted):

Quote

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\datfile\shell\Unpack]
"Icon"="\"C:\\ICO\\dat.ico\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\datfile\shell\Unpack\command]
@="C:\\Tools\\SFX.exe /Ext %1"

 

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

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

  • Similar Content

    • libreau3
      By libreau3
      Hello all I was wondering if any one new of a way to extract the files from a Comic Book Archive (.cbr)?
      My original thought was to use 7za.exe (&-zip console app) but when I run:
      7za x 1.cbr 
      7-zip returns:
      Processing archive: 1.cbr Error: Can not open file as archive   Does anyone a suggestion or other method? PS I am trying to make a .cbr to .pdf script