I have always wanted a way to pack files into a script for portability but I have never been able to find one.
That came to this:
Store virtually any file in a .ahk script (or compiled .exe)
Download: Here
Current version: 2.5
Compatible with: AHK Basic, AHK L ANSI, AHK L Unicode (X86/X64)
File types i've tested and know work: .zip, .exe, .txt, .ahk, ...anything?
The .ahk size of the file is rougly 1.33x the normal filesize(s). The compiled .exe (without compression) is rougly 1-1.05x the included filesize(s).
If you find any bugs or have anything to suggest please feel free to post.
How to use!:
1. Download and save the .ahk to a directory of your choosing.
2. Run the script
3. Select a file you want to include with your script(s)
4. Enter a name for the function you call to recreate the file (valid function names only)
5. Wait for it to do its stuff
6. Answer the questions on how you want to save the script
7. Simply include the code via #include or pasting it into your script
8. Call the function with Extract_*name* and the path/name of the file you want it to save as and it will recreate the file
Hi Rseding91,
First of all thank you very much for this fine piece of coding, just awesome thanks !!!
I wonder if you could help me I am stuck on a problem.
When I extract the first time the file compared to the orginal its exactly the same.
But when repeating or using the same function again the new file created is corrupt.
example script;
#persistent
~f5::
IfNotExist, dummyfile_org.dat
Extract_dummyfile("dummyfile_org.dat")
Extract_dummyfile("dummyfile_corrupt.dat")
return
Extract_dummyfile(_Filename, _DumpData = 0)
{
;This function "extracts" the file to the location+name you pass to it.
Static HasData = 1, Out_Data, Ptr
Static 1 = "AAAAAAAAAAAAAPA/AAAAAAEAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJAAAACQAAAAkAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAABAAAAAAAAAAAAgD8CAAAAAQAAAAEAAAABAAAAAQAAABdERV9NUBpJX0gXFkkFT1MgVAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAQAAAAEA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyEIAAMhCAADIQgAAyEIHR3JhcGggOAAAAAAAAAAAAQAAAAAAAAAAAIA/AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMhCAADIQgAAyEIAAMhC"
If (!HasData)
Return -1
If (!Out_Data){
Ptr := A_IsUnicode ? "Ptr" : "UInt"
, VarSetCapacity(TD, 1768 * (A_IsUnicode ? 2 : 1))
Loop, 1
TD .= %A_Index%, %A_Index% := ""
VarSetCapacity(Out_Data, Bytes := 1290, 0)
, DllCall("Crypt32.dll\CryptStringToBinary" (A_IsUnicode ? "W" : "A"), Ptr, &TD, "UInt", 0, "UInt", 1, Ptr, &Out_Data, A_IsUnicode ? "UIntP" : "UInt*", Bytes, "Int", 0, "Int", 0, "CDECL Int")
, TD := ""
}
IfExist, %_Filename%
FileDelete, %_Filename%
h := DllCall("CreateFile", Ptr, &_Filename, "Uint", 0x40000000, "Uint", 0, "UInt", 0, "UInt", 4, "Uint", 0, "UInt", 0)
, DllCall("WriteFile", Ptr, h, Ptr, &Out_Data, "UInt", 1290, "UInt", 0, "UInt", 0)
, DllCall("CloseHandle", Ptr, h)
If (_DumpData)
VarSetCapacity(Out_Data, 1290, 0)
, VarSetCapacity(Out_Data, 0)
, HasData := 0
}
So in other words if you put the above into a .ahk file and run it for the firsttime the second file is corrupt.
If the script is reloaded only the first time the function is used the first extraction is only okay
Note: deleting both testfiles while test script is already running and function is already used also results in the first file to be corrupt so compared to the second corrupt they are both equal and corrupt. also when the org file(extracted) exist and script skips to the corrupt file extraction its good only for the first time the function is used.
I.o.w. using the function more then once without reloading the script results in a corrupt extraction.
Using: Version v1.1.14.01
What can I do without reloading every time I use the function?
Greetz,
Lee