A Command line application that produces D module files, which can be compiled into an executable and extracted at startup.
- Limit code generated by:
- package modifier
version(unittest)
- Option for enum for usage at compile time, instead of
const(ubyte[])
- Automatic finding/inclusion of files in folders.
- Outputs included files at runtime to a specified directory or temporary directory
- Warning extra files in specified folder will be removed
Basic usage is as follows
Bin2D <output file>[=<module name>] <files or directories...>
Example I have a tkd project that I want to pack up into a single executable. I need some files and dll's for it to work.
Folder of needed stuff:
I added the Bin2d.exe to my path for convience.
Bin2D MODULE.d=Resource_Reference library tk86t.dll tcl86t.dll "my tkd app.exe"
This generates a short report
|-------------------------------------------------------------|
| REPORT |
|------------------------------|------------------------------|
| tcl86t.dll | tcl86t_dll |
| tk86t.dll | tk86t_dll |
| library/auto.tcl | auto_tcl |
| library/bgerror.tcl | bgerror_tcl |
| library/button.tcl | button_tcl |
| library/choosedir.tcl | choosedir_tcl |
| library/clock.tcl | clock_tcl |
...
| library/ttk/vistaTheme.tcl | vistaTheme_tcl |
| library/ttk/winTheme.tcl | winTheme_tcl |
| library/ttk/xpTheme.tcl | xpTheme_tcl |
| library/unsupported.tcl | unsupported_tcl |
| library/word.tcl | word_tcl |
| library/xmfbox.tcl | xmfbox_tcl |
| my tkd app.exe | my tkd app_exe |
|------------------------------|------------------------------|
The first column is the relative path. The second are the identifier names for using in D.
Create this(MAIN.d) file and added to my C:\temp folder.
import std.stdio;
import std.process;
import PKG = Resource_Reference; /*It might be best to alias due to "values" being
a scope variable which might interfer with
associtive array's "values" variable.*/
void main() {
/*Extract Files to temporary folder, returns an array that you can
get files absolute location from relative path*/
string[string] FILE_LOCATIONS = PKG.outputFilesToFileSystem();
foreach(string key; PKG.originalNames){
writeln("extracting: ", key , " : " , FILE_LOCATIONS[key] );
}
execute(FILE_LOCATIONS["my tkd app.exe"]); //Executes the program an waits for it to complete
PKG.cleanup(); //deletes all extract files
}
Compile with:
dmd MAIN.d MODULE.d
If you want to do what I did with a gui app you might want to link to windows:subsystem.
dmd MAIN.d MODULE.d -L/subsystem:windows
Since the module have very little generated code it is nice to have all the functions and variables listed out.
string rootDirectory
- Contains the location that files were extracted too. It is undefined if you haven't extracted them
const(string[]) names
- Contains A list of File Identifiers that D uses to store the files.
const(string[]) originalNames
- Contains A list of relative paths (relative to where they BIN2d created them from) for each file.
const(ubyte[]*[]) values
- This is an Array of pointers to all the raw hex data for each resource. (You can use the resources with-out extracting them you know?)
void cleanup();
- Recursivly removes all files inside of the rootDirectory and deletes the rootDirectory
string[string] outputFilesToFileSystem();
- Creates a new temporary folder and extracts files to that folder.
- Creates sub-folders as necessary for files to be extracted too.
- Returns an array of absolute paths that are keyed by relative path strings.
string[string] outputFilesToFileSystem(string dir);
- Creates the dir folder.
- If the dir folder already exist it will delete all its contents before extraction.
- Creates sub-folders as necessary for files to be extracted too.
- Returns an array of absolute paths that are keyed by relative path strings.