Giter VIP home page Giter VIP logo

bin2d's Introduction

Bin2D

A Command line application that produces D module files, which can be compiled into an executable and extracted at startup.

Features:

  • 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:

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:

Folder of needed stuff

I added the Bin2d.exe to my path for convience.

The process

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

Generated Module Api

Since the module have very little generated code it is nice to have all the functions and variables listed out.

Variables

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?)

Functions

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.

bin2d's People

Contributors

rikkimax avatar taylorh140 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.