Popular Post Yashied Posted March 22, 2012 Popular Post Share Posted March 22, 2012 (edited) LAST VERSION - 1.022-Mar-12I think many of you would like to combine any data of your project, for example skin images, into a single file (package), and as necessary extract them from it. Moreover, it would be better to avoid creating temporary files on the disk. Yes, of course, you can use a resources of the executable file or native FileInstall() function, but in the first case you can not add data after compilation the script, the second case leads inevitably to write data to disk that is not good. Alternatively, you can use, for example, .zip archives, but here again you are limited to using only the files. For this reason, I decided to invent their own file format (.pkr) for storing any data (it can be a files or a memory data directly), and devoid of all the above shortcomings. Below is the detailed structure of the .pkr file (package).As you can see from the screenshot, the package consists of a header and one or more data packets following one another. The package header has a length of 256 bytes and represents PKHEADER structure that contains a basic information about .pkr file, including a short text comment. Here is a description of the PKHEADER structure. -------------------------------------------------------------------------------------------------- | PKHEADER | |--------------------------------------------------------------------------------------------------| | Offset | Length | Purpose | |--------|--------|--------------------------------------------------------------------------------| | 0 | 4 | The file signature (0x504B5221) | |--------|--------|--------------------------------------------------------------------------------| | 4 | 4 | The package version, 1.0 | |--------|--------|--------------------------------------------------------------------------------| | 8 | 8 | The file size, in bytes | |--------|--------|--------------------------------------------------------------------------------| | 16 | 4 | The number of packets in the package | |--------|--------|--------------------------------------------------------------------------------| | 20 | 4 | Reserved | |--------|--------|--------------------------------------------------------------------------------| | 24 | 8 | The absolute offset, in bytes, of the first packet in package | |--------|--------|--------------------------------------------------------------------------------| | 32 | 224 | The package comment, max 224 bytes (112 characters) | --------------------------------------------------------------------------------------------------The first four bytes of the .pkr file always contain the same sequence of bytes (signature) - 0x504B5221 ("PKR!" in ASCII characters). This allows to uniquely identify the package. Then follows a DWORD value representing the package version, currently 1.0 (0x00000100). Next is the size of the package file (INT64), in bytes. Although the size of the .pkr file is not limited, the length of one packet may not exceed a little more than 4 gigabytes (see below). Note that the value of this member should be equal to the actual file size, otherwise it is assumed that the package is damaged. The next member (DWORD) of the structure contains the number of packets in the package. It should not be zero, since it is not allowed to create empty packages. The next four bytes are reserved for future use. The sixth member (INT64) of the PKHEADER structure is the most important and contains an offset of the first packet in the package from the beginning of a file, in bytes. This means that the first packet does not necessarily follow immediately after the header. The latest in the package header is a comment. The length of the comment is limited to 224 bytes (112 wide characters, including the null-terminating character).After the packet header may be located a Packet Relocation Table (PRT) of variable size that contains information for fast packets searching, but is not currently used and has a zero length.Following the PKHEADER and PRT begins a packets. Each packet consists of its own header and three data sections: Description, Info, and Data. Why three? Because so much easier to classify the data within the package. You will understand this when you try to use the library for their projects. A description of the packet (PKPACKET structure) shown in the following table. -------------------------------------------------------------------------------------------------- | PKPACKET | |--------------------------------------------------------------------------------------------------| | Offset | Length | Purpose | |--------|--------|--------------------------------------------------------------------------------| | 0 | 4 | The size, in bytes, of the packet header structure (40 bytes) | |--------|--------|--------------------------------------------------------------------------------| | 4 | 4 | The size, in bytes, of the description block, max 8192 bytes (4096 characters) | |--------|--------|--------------------------------------------------------------------------------| | 8 | 4 | The size, in bytes, of the information block, max 64 KB | |--------|--------|--------------------------------------------------------------------------------| | 12 | 4 | The size, in bytes, of the data block, max 4 GB | |--------|--------|--------------------------------------------------------------------------------| | 16 | 8 | The 64-bit unique identifier of the packet | |--------|--------|--------------------------------------------------------------------------------| | 24 | 4 | The checksum (CRC32) of the compressed data, or zero if no compression | |--------|--------|--------------------------------------------------------------------------------| | 28 | 4 | The uncompressed data size, in bytes, or zero if no compression | |--------|--------|--------------------------------------------------------------------------------| | 32 | 8 | Reserved | |--------------------------------------------------------------------------------------------------| | Description | |--------------------------------------------------------------------------------------------------| | Information | |--------------------------------------------------------------------------------------------------| | Data | --------------------------------------------------------------------------------------------------The first member (DWORD) of the PKPACKET structure always contains the length, in bytes, of the packet header and currently is 40 bytes, but can be changed in the future. The second, third, and fourth members (DWORD) of the structure contains the lengths of the corresponding data sections, in bytes. If any section is missing, the value of its length is zero. A full packet length, in bytes, can be calculated by summing the four values is listed above. The fifth member (INT64) of the structure represents a unique packet identifier (ID). It is a 64-bit positive number that uniquely identifies a packet within the package. The sixth and seventh members (DWORD) of the PKPACKET structure is used only if a data of the Data sections are compressed, otherwise have a zero values. In the case of compression, the sixth member of the structure contains the exact data size of the Data section, in bytes, after uncompression. The last member (INT64) of the packet header is reserved for future use. Immediately after the packet header begins a three data sections that are described in more detail below.The Description section is the first in the packet and designed to store any text information. It may be, for example, the name of the file, in the case of adding a file into the packet, or just a short description of the data that is in the packet. The maximum length of the this section is 8 kilobytes (8,192 bytes) or 4096 wide characters (including the null-terminating character).The Info section immediately follows after the Description section. Here you can store any auxiliary binary data, for example, the attributes of the file, the date and time that a file was created, last accessed, and last modified., or something else. Alternatively, you can store in this section are small files such as cursors, icons, etc. The length of this section is limited to 64 kilobytes (65,535 bytes).The Data section is the third in the packet, and used to store main packet data. The maximum length of this section may be up to 4 gigabytes (4,294,967,295 bytes). Moreover, the data of this section can be compressed by using the native LZ algorithm (not the most optimal but fast enough).These three data sections represents a one packet, and must follow continuously each other that as shown above. Furthermore, any or all of these sections can be missing in the packet.Then after the first packet immediately begins another packet, if any, etc.As you can see, the .pkr files have a simple structure consisting of the sequential blocks of data. Especially for ease of use of packages, I wrote the UDF library which you can download below. A detailed description of each function you can find inside the library. Also, the archive includes all the examples and supporting files. As an additional example, you can download the Package.pkr file containing the same files as the .zip archive, but only created by using this library. I hope this UDF library will be useful for your projects. Also, if anyone have any questions or comments, please post it in this thread. I will be glad to any feedback and constructive suggestions.Almost forgot, this library requires >WinAPIEx UDF library version 3.7 or later.Available functions_PK_AddPacket_PK_AddPacketFromFile_PK_Close_PK_Create_PK_DisplayPackage_PK_EnumPackets_PK_ExtractPacketData_PK_ExtractPacketDataToFile_PK_FindPacket_PK_Flush_PK_GetComment_PK_GetCount_PK_GetInfo_PK_GetPacketCompression_PK_GetPacketDataLength_PK_GetPacketDescription_PK_GetPacketDescriptionLength_PK_GetPacketID_PK_GetPacketIndex_PK_GetPacketInfo_PK_GetPacketInfoLength_PK_GetPath_PK_GetVersion_PK_Open_PK_Purge_PK_QueryPacket_PK_QueryPacketEx_PK_ReadPacketData_PK_RemovePacket_PK_SetBuffer_PK_SetComment_PK_TestPackage UDF Library v1.0Package.zipExamplesAdding file (Simple) #Include "Package.au3" Global Const $sPackage = @ScriptDir & '\MyFile.pkr' $hPackage = _PK_Create($sPackage, 'Demonstration Package', 1) _PK_AddPacketFromFile($hPackage, @ScriptFullPath, @ScriptName, 1) _PK_DisplayPackage($hPackage) _PK_Close($hPackage)Extracting file (Simple)#Include "Package.au3" Global Const $sPackage = @ScriptDir & '\MyFile.pkr' $hPackage = _PK_Open($sPackage) _PK_ExtractPacketDataToFile($hPackage, -1, StringRegExpReplace(_PK_GetPacketDescription($hPackage, -1), '.[^.]*Z', '.bak'), 1) _PK_Close($hPackage)Adding binary data (Simple)#Include "Package.au3" Global Const $sPackage = @ScriptDir & '\MyData.pkr' $hPackage = _PK_Create($sPackage, 'Demonstration Package', 1) $tData = DllStructCreate('byte[16]') DllStructSetData($tData, 1, '0x00112233445566778899AABBCCDDEEFF') _PK_AddPacket($hPackage, DllStructGetPtr($tData), DllStructGetSize($tData), 'Binary data', 1) _PK_DisplayPackage($hPackage) _PK_Close($hPackage)Extracting binary data (Simple)#Include "Package.au3" Global Const $sPackage = @ScriptDir & '\MyData.pkr' $hPackage = _PK_Open($sPackage) $tData = DllStructCreate('byte[' & _PK_GetPacketDataLength($hPackage, -1) & ']') _PK_ExtractPacketData($hPackage, -1, DllStructGetPtr($tData), DllStructGetSize($tData)) ConsoleWrite(DllStructGetData($tData, 1) & @CR) _PK_Close($hPackage)Addition#Include <WinAPIEx.au3> #Include "Package.au3" Opt('MustDeclareVars', 1) Global Const $sPackage = @ScriptDir & '\MyPackage.pkr' Global $hPackage, $ID, $File If Not FileExists($sPackage) Then $hPackage = _PK_Create($sPackage, 'Demonstration Package') Else $hPackage = _PK_Open($sPackage) EndIf Do $File = FileOpenDialog('Add File', @WorkingDir, 'All Files (*.*)', 3) If @Error Then ExitLoop EndIf $ID = _PK_AddPacketFromFile($hPackage, $File, _WinAPI_PathStripPath($File)) If @Error Then $ID = MsgBox(20, 'Package', 'An error occurred while adding file to the package.' & @CR & @CR & 'Error: ' & @Error & @CR & @CR & 'Do you want to add another file?') Else $ID = MsgBox(68, 'Package', 'File added successfully.' & @CR & @CR & 'ID: ' & $ID & @CR & @CR & 'Do you want to add another file?') EndIf Until $ID <> 6 _PK_DisplayPackage($hPackage) _PK_Close($hPackage)Extractionexpandcollapse popup#Include <Array.au3> #Include <WinAPIEx.au3> #Include "Package.au3" Opt('MustDeclareVars', 1) Global Const $sPackage = @ScriptDir & '\MyPackage.pkr' Global $hPackage, $ID, $Data, $File, $Path $hPackage = _PK_Open($sPackage) If @Error Then MsgBox(16, 'Package', _WinAPI_PathStripPath($sPackage) & ' not found.') Exit EndIf $Data = _PK_EnumPackets($hPackage) If @Error Then MsgBox(16, 'Package', 'Unable to enumerate packets in the package.' & @CR & @CR & 'Error: ' & @Error) Else For $i = 1 To $Data[0][0] ConsoleWrite($i & ' - ' & $Data[$i][1] & @CR) Next While 1 $ID = InputBox('Package', 'Type a one based index of the packet to extract.', '1', '', 274, 142) If @Error Then ExitLoop EndIf $File = _PK_GetPacketDescription($hPackage, -$ID) If @Error Then MsgBox(16, 'Package', 'Packet not found.') Else $Path = _WinAPI_PathYetAnotherMakeUniqueName(@ScriptDir & '\' & $File) If Not _PK_ExtractPacketDataToFile($hPackage, -$ID, $Path) Then $ID = MsgBox(20, 'Package', 'An error occurred while extracting file from the package.' & @CR & @CR & 'Error: ' & @Error & @CR & @CR & 'Do you want to extract another file?') Else $ID = MsgBox(68, 'Package', 'File has been saved to ' & _WinAPI_PathStripPath($Path) & '.' & @CR & @CR & 'Do you want to extract another file?') EndIf If $ID <> 6 Then ExitLoop EndIf EndIf WEnd EndIf _PK_Close($hPackage)GUI (Advanced)expandcollapse popup#NoTrayIcon #Include <APIConstants.au3> #Include <GUIListView.au3> #Include <GUIConstantsEx.au3> #Include <ListViewConstants.au3> #Include <StaticConstants.au3> #Include <WinAPIEx.au3> #Include "Package.au3" Opt('MustDeclareVars', 1) Opt('WinWaitDelay', 0) #Region Initialization Global $hForm, $hDrop, $hPackage, $hLV, $LV, $Button[3], $Dummy[2], $Label, $Area, $Item #EndRegion Initialization #Region Body _CreateForm() While 1 Switch GUIGetMsg() Case 0 ContinueLoop Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_DROPPED _AddPacket(@GUI_DRAGFILE) Case $Button[0] _AddPacket() Case $Button[1], $Dummy[1] _RemovePacket() Case $Button[2], $Dummy[0] _ExtractPacket() Case Else EndSwitch WEnd _DeleteForm() #EndRegion Body #Region Additional Functions Func _AddPacket($sFile = '') Local $tInfo, $ID, $Data, $Flag, $Error If Not $sFile Then $sFile = FileOpenDialog('Add File', @WorkingDir, 'All Files (*.*)', 3, '', $hDrop) If @Error Then Return EndIf EndIf If FileGetSize($sFile) > 104857600 Then If MsgBox(52, 'Package', _WinAPI_PathStripPath($sFile) & ' is too large (over 100 MB) and can not be compressed on the fly.' & @CR & @CR & 'Do you want to add this file without compression?', 0, $hDrop) <> 6 Then Return EndIf $Flag = 0 Else $Flag = 1 EndIf Opt('GUIOnEventMode', 1) GUISetState(@SW_DISABLE, $hForm) GUISetCursor(15, 1, $hForm) $tInfo = _GetFileInfo($sFile) $ID = _PK_AddPacketFromFile($hPackage, $sFile, _WinAPI_PathStripPath($sFile), $Flag, DllStructGetPtr($tInfo), DllStructGetSize($tInfo), '_Progress') $Error = @Error GUISetCursor(2, 0, $hForm) GUISetState(@SW_ENABLE, $hForm) Opt('GUIOnEventMode', 0) If $Error Then MsgBox(16, 'Package', 'An error occurred while adding file to the package.' & @CR & @CR & 'Error: ' & $Error, 0, $hDrop) Return EndIf $Data = _PK_QueryPacket($hPackage, $ID) If @Error Then Return EndIf _GUICtrlListView_BeginUpdate($hLV) $ID = _GUICtrlListView_AddItem($hLV, $Data[0]) For $i = 1 To 4 _GUICtrlListView_AddSubItem($hLV, $ID, $Data[$i], $i) Next _GUICtrlListView_SetItemParam($hLV, $ID, $Data[5]) _GUICtrlListView_SetItemSelected($hLV, $ID, 1, 1) _GUICtrlListView_EnsureVisible($hLV, $ID) _GUICtrlListView_EndUpdate($hLV) GUICtrlSetState($LV, $GUI_FOCUS) WinActivate($hDrop) EndFunc ;==>_AddPacket Func _CreateForm() Local $ID, $Path, $File, $Data $Path = FileOpenDialog('Open Package', @ScriptDir, 'Package Files (*.pkr)|All Files (*.*)', 10, 'MyPackage.pkr') If @Error Then Exit EndIf $File = _WinAPI_PathStripPath($Path) If Not FileExists($Path) Then $hPackage = _PK_Create($Path, 'Demonstration Package') Else $hPackage = _PK_Open($Path) EndIf If @Error Then MsgBox(16, 'Package', 'Unable to open ' & $File & '.' & @CR & @CR & 'Error: ' & @Error) Exit EndIf OnAutoItExitRegister('_Quit') If _PK_GetCount($hPackage) Then $Data = _PK_EnumPackets($hPackage) If @Error Then MsgBox(16, 'Package', 'Unexpected error.' & @CR & @CR & 'Error: ' & @Error) Exit EndIf Else $Data = 0 EndIf $hForm = GUICreate($File & ' - ' & _PK_GetComment($hPackage), 660, 440, -1, -1, BitOR($WS_CAPTION, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_POPUP, $WS_SIZEBOX, $WS_SYSMENU)) $hDrop = GUICreate('', 660, 398, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP, $WS_VISIBLE), $WS_EX_ACCEPTFILES, $hForm) $LV = GUICtrlCreateListView('', 0, 0, 660, 398, BitOR($LVS_DEFAULT, $LVS_NOSORTHEADER), BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP)) GUICtrlSetFont(-1, 8.5, 400, 0, 'Tahoma') GUICtrlSetState(-1, $GUI_DROPACCEPTED) $hLV = GUICtrlGetHandle(-1) _GUICtrlListView_AddColumn($hLV, '#', 30) _GUICtrlListView_AddColumn($hLV, 'ID', 140) _GUICtrlListView_AddColumn($hLV, 'Description', 313) _GUICtrlListView_AddColumn($hLV, 'Info Length', 80, 1) _GUICtrlListView_AddColumn($hLV, 'Data Length', 80, 1) If _WinAPI_GetVersion() >= '6.0' Then _WinAPI_SetWindowTheme($hLV, 'Explorer') EndIf If IsArray($Data) Then For $i = 1 To $Data[0][0] $ID = _GUICtrlListView_AddItem($hLV, $i) For $j = 0 To 3 _GUICtrlListView_AddSubItem($hLV, $ID, $Data[$i][$j], $j + 1) Next _GUICtrlListView_SetItemParam($hLV, $ID, $Data[$i][4]) Next _GUICtrlListView_SetItemSelected($hLV, 0, 1, 1) $Item = 0 Else $Item =-1 EndIf GUISwitch($hForm) GUISetIcon(@ScriptDir & '\Package.ico') $Label = GUICtrlCreateLabel('', 0, 398, 663, 2, $SS_ETCHEDHORZ) $Button[0] = GUICtrlCreateButton('Add...', 5, 405, 214, 30) $Button[1] = GUICtrlCreateButton('Remove', 223, 405, 214, 30) $Button[2] = GUICtrlCreateButton('Extract...', 441, 405, 214, 30) For $i = 0 To 1 $Dummy[$i] = GUICtrlCreateDummy() Next $Area = WinGetPos($hForm) GUIRegisterMsg($WM_GETMINMAXINFO, 'WM_GETMINMAXINFO') GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUIRegisterMsg($WM_SIZE, 'WM_SIZE') GUICtrlSetState($LV, $GUI_FOCUS) GUISetState() EndFunc ;==>_CreateForm Func _DeleteForm() GUIDelete($hForm) GUIDelete($hDrop) EndFunc ;==>_DeleteForm Func _ExtractPacket() Local $tInfo, $File, $Error $File = FileSaveDialog('Extract File', @WorkingDir, 'All Files (*.*)', 18, _PK_GetPacketDescription($hPackage, -($Item + 1)), $hDrop) If @Error Then Return EndIf Opt('GUIOnEventMode', 1) GUISetState(@SW_DISABLE, $hForm) GUISetCursor(15, 1, $hForm) _PK_ExtractPacketDataToFile($hPackage, -($Item + 1), $File, 1, '_Progress') $Error = @Error If $Error Then Else $tInfo = _PK_GetPacketInfo($hPackage, -($Item + 1)) If Not _SetFileInfo($File, $tInfo) Then ; Nothing EndIf EndIf GUISetCursor(2, 0, $hForm) GUISetState(@SW_ENABLE, $hForm) Opt('GUIOnEventMode', 0) If $Error Then MsgBox(16, 'Package', 'An error occurred while adding file to the package.' & @CR & @CR & 'Error: ' & $Error, 0, $hDrop) EndIf EndFunc ;==>_ExtractPacket Func _GetFileInfo($sFile) Local $hFile, $tInfo $hFile = _WinAPI_CreateFileEx($sFile, $OPEN_EXISTING, $GENERIC_READ, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE)) If @Error Then Return 0 EndIf $tInfo = _WinAPI_GetFileInformationByHandleEx($hFile) _WinAPI_CloseHandle($hFile) Return $tInfo EndFunc ;==>_GetFileInfo Func _Quit() _PK_Close($hPackage) EndFunc ;==>_Quit Func _RemovePacket() Local $Count, $Error, $Sel = $Item If MsgBox(36, 'Package', 'Are you sure you want to remove ' & _PK_GetPacketDescription($hPackage, -($Item + 1)) & ' from the package?', 0, $hDrop) <> 6 Then Return EndIf Opt('GUIOnEventMode', 1) GUISetState(@SW_DISABLE, $hForm) GUISetCursor(15, 1, $hForm) _PK_RemovePacket($hPackage, -($Item + 1)) $Error = @Error GUISetCursor(2, 0, $hForm) GUISetState(@SW_ENABLE, $hForm) Opt('GUIOnEventMode', 0) If $Error Then MsgBox(16, 'Package', 'An error occurred while remove file from the package.' & @CR & @CR & 'Error: ' & $Error, 0, $hDrop) Return EndIf _GUICtrlListView_BeginUpdate($hLV) _GUICtrlListView_DeleteItem($hLV, $Item) $Count = _GUICtrlListView_GetItemCount($hLV) If $Count Then If $Sel > $Count - 1 Then $Sel -= 1 Else For $i = $Sel To $Count - 1 _GUICtrlListView_SetItemText($hLV, $i, $i + 1) Next EndIf _GUICtrlListView_SetItemSelected($hLV, $Sel, 1, 1) EndIf _GUICtrlListView_EndUpdate($hLV) GUICtrlSetState($LV, $GUI_FOCUS) WinActivate($hDrop) EndFunc ;==>_RemovePacket Func _SetFileInfo($sFile, $tInfo) Local $hFile If DllStructGetSize($tInfo) < 40 Then Return 0 EndIf $hFile = _WinAPI_CreateFileEx($sFile, $OPEN_EXISTING, $GENERIC_WRITE, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE)) If @Error Then Return 0 EndIf _WinAPI_SetFileInformationByHandleEx($hFile, $tInfo) _WinAPI_CloseHandle($hFile) Return 1 EndFunc ;==>_SetFileInfo #EndRegion Additional Functions #Region Callback Functions Func _Progress($hPackage, $ID, $iTotalSize, $iTotalBytesTransferred, $vData) #forceref $hPackage, $ID, $vData Static $hDlg = Ptr(0), $Progress Local $Pos, $Percent If $iTotalSize <> $iTotalBytesTransferred Then $Percent = Round($iTotalBytesTransferred / $iTotalSize * 100) Else $Percent = 100 EndIf If Not $hDlg Then If $Percent < 100 Then $Pos = WinGetPos($hDrop) $hDlg = GUICreate('', 300, 44, $Pos[0] + ($Pos[2] - 300) / 2, $Pos[1] + ($Pos[3] - 44) / 2, BitOR($WS_BORDER, $WS_DISABLED, $WS_POPUP), 0, $hForm) $Progress = GUICtrlCreateProgress(15, 15, 270, 14) GUICtrlSetData(-1, $Percent) GUISetCursor(15, 1) GUISetState() EndIf Else GUICtrlSetData($Progress, $Percent) If $Percent = 100 Then GUISetState(@SW_ENABLE, $hForm) GUIDelete($hDlg) $hDlg = 0 EndIf EndIf Return $PK_PROGRESS_CONTINUE EndFunc ;==>_Progress #EndRegion Callback Functions #Region Windows Message Functions Func WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam) Local $tMMI = DllStructCreate('long Reserved[2];long MaxSize[2];long MaxPosition[2];long MinTrackSize[2];long MaxTrackSize[2]', $lParam) Switch $hWnd Case $hForm If IsArray($Area) Then DllStructSetData($tMMI, 'MinTrackSize', $Area[2], 1) DllStructSetData($tMMI, 'MinTrackSize', $Area[3], 2) EndIf Return 0 EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_GETMINMAXINFO Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Static $Flag = False If @AutoItX64 Then Local $tNMLV = DllStructCreate($tagNMHDR & ';uint Aligment;int Item;int SubItem;uint NewState;uint OldState;uint Changed;long ActionX;long ActionY;lparam Param', $lParam) Else Local $tNMLV = DllStructCreate($tagNMHDR & ';int Item;int SubItem;uint NewState;uint OldState;uint Changed;long ActionX;long ActionY;lparam Param', $lParam) EndIf Local $hTarget = DllStructGetData($tNMLV, 'hWndFrom') Local $ID = DllStructGetData($tNMLV, 'Code') Switch $hTarget Case $hLV Switch $ID Case $LVN_BEGINDRAG Return 0 Case $LVN_ITEMACTIVATE If $Item <> -1 Then GUICtrlSendToDummy($Dummy[0]) EndIf Case $LVN_ITEMCHANGED If (BitAND(DllStructGetData($tNMLV, 'Changed'), $LVIF_STATE)) And (BitXOR(DllStructGetData($tNMLV, 'NewState'), DllStructGetData($tNMLV, 'OldState'))) Then If BitAND(DllStructGetData($tNMLV, 'NewState'), $LVIS_SELECTED) Then $Item = DllStructGetData($tNMLV, 'Item') For $i = 1 To 2 GUICtrlSetState($Button[$i], $GUI_ENABLE) Next $Flag = 0 Else If BitAND(DllStructGetData($tNMLV, 'OldState'), $LVIS_FOCUSED) Then $Flag = 1 Else If Not $Flag Then For $i = 1 To 2 GUICtrlSetState($Button[$i], $GUI_DISABLE) Next $Item = -1 EndIf $Flag = 0 EndIf EndIf EndIf Case $NM_CUSTOMDRAW If @AutoItX64 Then Local $tNMLVCD = DllStructCreate($tagNMHDR & ';uint Aligment1;dword DrawStage;hwnd hDC;long Left;long Top;long Right;long Bottom;dword_ptr ItemSpec;uint ItemState;lparam ItemParam;uint Aligment2[5];dword clrText;dword clrTextBk;int SubItem;dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartId;int StateId;long TextLeft;long TextTop;long TextRight;long TextBottom;uint Align', $lParam) Else Local $tNMLVCD = DllStructCreate($tagNMHDR & ';dword DrawStage;hwnd hDC;long Left;long Top;long Right;long Bottom;dword_ptr ItemSpec;uint ItemState;lparam ItemParam;dword clrText;dword clrTextBk;int SubItem;dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartId;int StateId;long TextLeft;long TextTop;long TextRight;long TextBottom;uint Align', $lParam) EndIf Local $Stage = DllStructGetData($tNMLVCD, 'DrawStage') Switch $Stage Case $CDDS_ITEMPREPAINT Return $CDRF_NOTIFYSUBITEMDRAW Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) If _GUICtrlListView_GetItemParam($hLV, DllStructGetData($tNMLVCD, 'ItemSpec')) Then DllStructSetData($tNMLVCD, 'clrText', 0xFF0000) EndIf Return $CDRF_DODEFAULT Case Else EndSwitch Case $LVN_KEYDOWN If @AutoItX64 Then Local $tNMLVKD = DllStructCreate($tagNMHDR & ';uint Aligment;ushort VKey;uint Flags', $lParam) Else Local $tNMLVKD = DllStructCreate($tagNMHDR & ';ushort VKey;uint Flags', $lParam) EndIf Local $Key = DllStructGetData($tNMLVKD, 'VKey') Switch BitAND($Key, 0xFF) Case 0x2E ; VK_DELETE If $Item <> -1 Then GUICtrlSendToDummy($Dummy[1]) EndIf Case Else EndSwitch Case $NM_CLICK, $NM_DBLCLK, $NM_RCLICK, $NM_RDBLCLK Return 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) Local $WC, $HC, $WT Switch $hWnd Case $hForm $WC = _WinAPI_LoWord($lParam) $HC = _WinAPI_HiWord($lParam) $WT = Floor(($WC - 18) / 3) WinMove($hDrop, '', 0, 0, $WC, $HC - 42) GUICtrlSetPos($LV, 0, 0, $WC, $HC - 42) GUICtrlSetPos($Label, 0, $HC - 42, $WC + 3) GUICtrlSetPos($Button[0], 5, $HC - 35, $WT) GUICtrlSetPos($Button[1], $WT + 9, $HC - 35, $WC - 2 * $WT - 18) GUICtrlSetPos($Button[2], $WC - $WT - 5, $HC - 35, $WT) Return 0 EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE #EndRegion Windows Message Functions Edited December 10, 2013 by Yashied KaFu, genius257, PlayHD and 7 others 10 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
flashlab Posted March 22, 2012 Share Posted March 22, 2012 sofa~great job! I'm reading the document here → http://www.pkware.com/documents/casestudies/APPNOTE.TXT Link to comment Share on other sites More sharing options...
Yashied Posted March 22, 2012 Author Share Posted March 22, 2012 This is not ZIP file format. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Kealper Posted March 22, 2012 Share Posted March 22, 2012 (edited) Nice! It's actually kind of weird, I made something similar a few months ago that I never released that was essentially a pure AutoIt archiver with optional compression, and it's file format is almost exactly the same (with a few minor details, like my format doesn't have file hashes, because the thing it was intended to archive can have the possibility of corrupt files; It's intent was to be faster at storing many files in many subdirectories than zip).. I guess great minds think alike! EDIT: Although one thing I would like to make is a GUI version of mine, as it is CLI-only, because I'm lazy. Edited March 22, 2012 by Kealper Link to comment Share on other sites More sharing options...
Yashied Posted March 22, 2012 Author Share Posted March 22, 2012 (edited) I mostly did it to store a memory data, not a files. Edited March 22, 2012 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
guinness Posted March 22, 2012 Share Posted March 22, 2012 Brilliant! 5 stars from me. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
James Posted March 22, 2012 Share Posted March 22, 2012 Outstanding! This would have been absolutely perfect for some of my previous projects. Actually, the use that sticks out to me the most is for an auto-updater. Downloaded as a .pkr you have everything you need, and since you can store data, you have all the instructions you need 5*. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
UEZ Posted March 22, 2012 Share Posted March 22, 2012 (edited) Very nice art of coding (as usually)! I don't know whether I will use it yet but nice to have for any future case... Br, UEZ Edited March 22, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
JScript Posted March 22, 2012 Share Posted March 22, 2012 Excellent, five, no, I say ten stars! What about adding compression: _LZNTCompress() and _Base64Encode() by trancex ? Wonderful, now I will change many scripts that fit under these conditions! Regards, João Carlos. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
ProgAndy Posted March 22, 2012 Share Posted March 22, 2012 (edited) That's really nice.What about adding compression: _LZNTCompress() and _Base64Encode() by trancex ?Base64-Encoding won't compress your data, it will result in larger data blocks. Edited March 22, 2012 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Yashied Posted March 22, 2012 Author Share Posted March 22, 2012 (edited) What about adding compression: _LZNTCompress()..._WinAPI_CompressBuffer() that are used is the same. Edited March 22, 2012 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
JScript Posted March 22, 2012 Share Posted March 22, 2012 (edited) That's really nice.Base64-Encoding won't compress your data, it will result in larger data blocks.I think that I can not agree, check out this link: And this: Regards,João Carlos. Edited March 22, 2012 by JScript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
JScript Posted March 22, 2012 Share Posted March 22, 2012 @YashiedIt is true, thank you!Regards,João Carlos. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
twitchyliquid64 Posted March 22, 2012 Share Posted March 22, 2012 Absolutely brillant. An excellent project; well done. Its a pity this isnt in C++, cause I need something like this for one of my projects. ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search Link to comment Share on other sites More sharing options...
Yashied Posted March 24, 2012 Author Share Posted March 24, 2012 Thanks to all. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
FaridAgl Posted April 2, 2012 Share Posted April 2, 2012 I found some great usage for this, thank you so much Yashied, great as always. http://faridaghili.ir Link to comment Share on other sites More sharing options...
Andreik Posted August 29, 2012 Share Posted August 29, 2012 Nicely done Yashied. This will be very usefull for some projects. Just one thing that I observed: your PKHEADER structure doesn't have 256 bytes as is presented in the image from first post, it have 480 bytes because for Comment you use wide chars that are 2 bytes every char. As long $__PK_MAXCOMMENTLENGTH = 224, for Comment the user can use 224 characters not just 112. If you want a perfect 256 bytes PKHEADER structure then you just change $__PK_MAXCOMMENTLENGTH value to 112. In this case user can set a comment with 112 wide characters (as is described all around in UDF file) and the structure is 256 bytes lenght. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Yashied Posted August 30, 2012 Author Share Posted August 30, 2012 You are right. But in this case it is not critical. You should always use the offset from the header. I can't fix it now, because it would lead to incompatibility of the scripts. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Andreik Posted August 31, 2012 Share Posted August 31, 2012 No, isn't critical because you use an absolute offset to identify the first packet. The UDF will work properly, it's just about description of UDF in some cases but nothing critical. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
johnmcloud Posted September 5, 2012 Share Posted September 5, 2012 I have a problem to save the .zip, give me error CRC and i can't extract files. Please check it out Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now