{"id":21561062,"url":"https://github.com/end2endzone/bin2cpp","last_synced_at":"2025-04-09T07:08:01.909Z","repository":{"id":49996908,"uuid":"111166149","full_name":"end2endzone/bin2cpp","owner":"end2endzone","description":"bin2cpp: The easiest way to embed small files into a c++ executable. bin2cpp converts text or binary files to C++ files (*.h, *.cpp) for easy access within the code.","archived":false,"fork":false,"pushed_at":"2025-02-11T14:48:33.000Z","size":1922,"stargazers_count":86,"open_issues_count":9,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T05:08:01.780Z","etag":null,"topics":["cpp","embedded-files","ressources"],"latest_commit_sha":null,"homepage":"http://www.end2endzone.com/bin2cpp-the-easiest-way-to-embed-small-files-into-a-c-executable/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/end2endzone.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-18T01:21:08.000Z","updated_at":"2025-02-26T00:51:51.000Z","dependencies_parsed_at":"2022-08-29T09:00:26.298Z","dependency_job_id":null,"html_url":"https://github.com/end2endzone/bin2cpp","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/end2endzone%2Fbin2cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/end2endzone%2Fbin2cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/end2endzone%2Fbin2cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/end2endzone%2Fbin2cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/end2endzone","download_url":"https://codeload.github.com/end2endzone/bin2cpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994121,"owners_count":21030050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","embedded-files","ressources"],"created_at":"2024-11-24T09:18:38.856Z","updated_at":"2025-04-09T07:08:01.893Z","avatar_url":"https://github.com/end2endzone.png","language":"C++","readme":"![bin2cpp logo](docs/bin2cpp-splashscreen.png)\n\n# bin2cpp\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Github Releases](https://img.shields.io/github/release/end2endzone/bin2cpp.svg)](https://github.com/end2endzone/bin2cpp/releases)\n\nbin2cpp is a command line tool for embedding small files (like images, icons or raw data files) into a C++ executable.\n\nWhen executed, bin2cpp takes binary file as input and outputs c++ code (a function) that when called allows a c++ program to retrieve the content of the input binary file.\n\n\n\n## Status\n\nBuild:\n\n| Service/Platform    | Build                                                                                                                                                                                   | Tests                                                                                                                                                                                                                                                  |\n| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| AppVeyor            | [![Build status](https://img.shields.io/appveyor/ci/end2endzone/bin2cpp/master.svg?logo=AppVeyor\u0026logoColor=white)](https://ci.appveyor.com/project/end2endzone/bin2cpp)                 | [![Tests status](https://img.shields.io/appveyor/tests/end2endzone/bin2cpp/master.svg?logo=AppVeyor\u0026logoColor=white)](https://ci.appveyor.com/project/end2endzone/bin2cpp/branch/master/tests)                                                         |\n| Travis CI           | [![Build Status](https://img.shields.io/travis/end2endzone/bin2cpp/master.svg?logo=Travis-CI\u0026style=flat\u0026logoColor=white)](https://travis-ci.org/end2endzone/bin2cpp)                    |                                                                                                                                                                                                                                                        |\n| Windows Server 2019 | [![Build on Windows](https://github.com/end2endzone/bin2cpp/actions/workflows/build_windows.yml/badge.svg)](https://github.com/end2endzone/bin2cpp/actions/workflows/build_windows.yml) | [![Tests on Windows](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/end2endzone/58cf6c72c08e706335337d5ef9ca48e8/raw/bin2cpp.master.Windows.json)](https://github.com/end2endzone/bin2cpp/actions/workflows/build_windows.yml) |\n| Ubuntu 20.04        | [![Build on Linux](https://github.com/end2endzone/bin2cpp/actions/workflows/build_linux.yml/badge.svg)](https://github.com/end2endzone/bin2cpp/actions/workflows/build_linux.yml)       | [![Tests on Linux](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/end2endzone/58cf6c72c08e706335337d5ef9ca48e8/raw/bin2cpp.master.Linux.json)](https://github.com/end2endzone/bin2cpp/actions/workflows/build_linux.yml)       |\n| macOS 10.15         | [![Build on macOS](https://github.com/end2endzone/bin2cpp/actions/workflows/build_macos.yml/badge.svg)](https://github.com/end2endzone/bin2cpp/actions/workflows/build_macos.yml)       | [![Tests on macOS](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/end2endzone/58cf6c72c08e706335337d5ef9ca48e8/raw/bin2cpp.master.macOS.json)](https://github.com/end2endzone/bin2cpp/actions/workflows/build_macos.yml)       |\n\nStatistics:\n\n| AppVeyor                                                                                                                                       | Travic CI                                                                                                              | GitHub                                                                                                                     |\n| ---------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |\n| [![Statistics](https://buildstats.info/appveyor/chart/end2endzone/bin2cpp)](https://ci.appveyor.com/project/end2endzone/bin2cpp/branch/master) | [![Statistics](https://buildstats.info/travisci/chart/end2endzone/bin2cpp)](https://travis-ci.org/end2endzone/bin2cpp) | [![Statistics](https://buildstats.info/github/chart/end2endzone/bin2cpp)](https://github.com/end2endzone/bin2cpp/actions/) |\n\n\n\n\n# Purpose\n\nbin2cpp is not implemented using [executable resources](http://en.wikipedia.org/wiki/Resource_(Windows)). Instead, bin2cpp creates a single function call for retrieving the content and the properties of a file which makes it harder to steal the executable's content. It also makes it even harder to replace an existing resource of the executable.\n\nIt is designed to be easy to use by developers and to provide easy call functions to get access to the data of the embedded files.\n\nThe generated functions that reads and extracts the embedded content does not rely on external libraries so you don't need to setup your projects to use any third party library to start using bin2cpp. All your embedded data can be accessed right away.\n\n\n\n\n# Features\n\nThe main features of the project are:\n\n* Easily converts small files as C++ source code for embedding into a C++ executable.\n* Access content with a unique function call for each embedded file.\n* Supports multiple embedded files at once.\n* Keep the directory structure when embedding directories.\n* Supports encoding and extracting files with a custom directory structure.\n* Makes it harder for resource hacker to modify or steal the embedded files.\n* No third party libraries required for retrieving the data of the embedded files.\n* Supports different types of code generator: string, segment, array, win32 resources.\n* File's originals `size`, `filename` and `directory` properties available from generated source code.\n* Control generated source code: choose your custom _File_ interface and namespace.\n* Print a file encoded content to stdout. Useful for scripts and integration with third party application.\n* Generated code is C++98 standard-compliant.\n\n\n\n## Use cases\n\nThe following list show situations where bin2cpp is useful:\n\n* Embedding default configuration files if none are provided.\n* Embedding GLSL shaders into the executable.\n* Embedding text or XML databases (gui layout, names, dictionaries or localization strings)\n* A portable alternative to C++11 raw string literals.\n* Prevent stealing copyrighted resources.\n* Embedding images/icons/sounds for a GUI application. The application executable can be shipped/copied as a single file. \n* Embedding a long PL/SQL code string.\n* Allowing an executable to be downloaded from an intranet server as a single file.\n* Distributing an application without an installer package. All configurations files and resources can be embedded and extracted at first launch of the application.\n\n\n\n\n# Usage\n\nThe following section shows how to use bin2cpp with code examples:\n\n\n\n## Command Line Usage\n\n```\nbin2cpp --file=\u003cpath\u003e --output=\u003cpath\u003e [--headerfile=\u003cname\u003e] [--identifier=\u003cname\u003e]\n        [--generator=\u003cname\u003e] [--encoding=\u003cname\u003e] [--chunksize=\u003cvalue\u003e] [--namespace=\u003cvalue\u003e]\n        [--baseclass=\u003cname\u003e] [--managerfile=\u003cname\u003e] [--registerfile] \n        [--reportedfilepath=\u003cvalue\u003e] [--override] [--noheader] [--quiet]\nbin2cpp --dir=\u003cpath\u003e --output=\u003cpath\u003e [--keepdirs]\n        [--generator=\u003cname\u003e] [--encoding=\u003cname\u003e] [--chunksize=\u003cvalue\u003e] [--namespace=\u003cvalue\u003e]\n        [--baseclass=\u003cname\u003e] [--managerfile=\u003cname\u003e] [--registerfile] \n        [--override] [--noheader] [--quiet]\nbin2cpp --help\nbin2cpp --version\n```\n\n| Argument                        | Description                                                                                                                                                                                                                                                                         |\n|---------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| --help                          | Display this help message.                                                                                                                                                                                                                                                          |\n| --version                       | Display this application version.                                                                                                                                                                                                                                                   |\n| --file=\u0026lt;path\u0026gt;             | Path of the input file used for embedding as C++ source code.                                                                                                                                                                                                                       |\n| --dir=\u0026lt;path\u0026gt;              | Path of the input directory used for embedding all files of the directory as C++ source code.                                                                                                                                                                                       |\n| --output=\u0026lt;path\u0026gt;           | Path of the output directory where to create generated code.\u003cbr\u003eie: ./generated_files                                                                                                                                                                                               |\n| --headerfile=\u0026lt;name\u0026gt;       | File name or relative path of the generated C++ header file. If a relative path from the output directory is specified, the #include statement in the generated cpp file will match the relative path. \u003cbr\u003eie: SplashScreen.h\u003cbr\u003eDefault value: input file name (without extension) |\n| --identifier=\u0026lt;name\u0026gt;       | Identifier of the function name that is used to get an instance of the file.\u003cbr\u003eie: SplashScreen\u003cbr\u003eDefault value is based on input file with format 'NameExt'.                                                                                                                     |\n| --generator=\u0026lt;name\u0026gt;        | Name of the generator to use. Possible values are 'segment', 'string', 'array' and 'win32'.\u003cbr\u003e[default: segment]                                                                                                                                                                   |\n| --encoding=\u0026lt;name\u0026gt;         | Name of the binary to string literal encoding to use. Possible values are 'oct' and 'hex'.\u003cbr\u003e[default: oct]                                                                                                                                                                        |\n| --chunksize=\u0026lt;value\u0026gt;       | Size in bytes of each string segments (bytes per LoC).\u003cbr\u003e[default: 200]                                                                                                                                                                                                            |\n| --baseclass=\u0026lt;name\u0026gt;        | The name of the interface for embedded files.\u003cbr\u003e[default: File]                                                                                                                                                                                                                    |\n| --namespace=\u0026lt;name\u0026gt;        | The namespace of the generated source code.\u003cbr\u003e[default: bin2cpp]                                                                                                                                                                                                                   |\n| --reportedfilepath=\u0026lt;path\u0026gt; | The relative reported path of the File. Path returned when calling method getFilePath() of the File class. Automatically calculated when --dir mode is used.\u003cbr\u003eie: images/DCIM/IMG_0001.jpg                                                                                        |\n| --managerfile=\u0026lt;path\u0026gt;      | File name or relative path of the generated C++ header file for the FileManager class.\u003cbr\u003eie: FileManager.h.                                                                                                                                                                        |\n| --registerfile                  | Register the generated file to the FileManager class. This flags is automatically set when parameter 'managerfile' is specified.                                                                                                                                                    |\n| --keepdirs                      | Keep the directory structure. Forces the output files to have the same directory structure as the input files. Valid only when --dir is used.                                                                                                                                       |\n| --plainoutput                   | Print the encoded string in plain format to stdout. Useful for scripts and integration with third party application.                                                                                                                                                                |\n| --override                      | Tells bin2cpp to overwrite the destination files.                                                                                                                                                                                                                                   |\n| --noheader                      | Do not print program header to standard output.                                                                                                                                                                                                                                     |\n| --quiet                         | Do not log any message to standard output.                                                                                                                                                                                                                                          |\n\n\n\n## Example 1 - single file\n\nThis example shows how to use bin2cpp to convert a single html file to c++ source code.\n\n\n### Input file: helloworld.html\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n  \u003cmeta charset=\"utf-8\"\u003e\n  \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=yes\"\u003e\n  \u003ctitle\u003eHello World!\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\nHello World!\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n\n### Command:\n\n```\nbin2cpp.exe --file=helloworld.html --output=.\\outdir\n```\n\n\n### Console output\n\n```\nbin2cpp v3.0.0 - Convert binary files into C++ source code.\nCopyright (C) 2013-2021 end2endzone.com. All rights reserved.\nbin2cpp is open source software, see http://github.com/end2endzone/bin2cpp\nEmbedding \"helloworld.html\"...\nWriting file \".\\outdir\\helloworld.h\"...\nWriting file \".\\outdir\\helloworld.cpp\"...\n```\n\n\n### Output file: helloworld.h\n\n```cpp\n/**\n * This file was generated by bin2cpp v3.0.0\n * Copyright (C) 2013-2021 end2endzone.com. All rights reserved.\n * bin2cpp is open source software, see http://github.com/end2endzone/bin2cpp\n * Source code for file 'helloworld.html', last modified 1548537787.\n * Do not modify this file.\n */\n#ifndef HELLOWORLD_H\n#define HELLOWORLD_H\n\n#include \u003cstddef.h\u003e\n\nnamespace bin2cpp\n{\n  #ifndef BIN2CPP_EMBEDDEDFILE_CLASS\n  #define BIN2CPP_EMBEDDEDFILE_CLASS\n  class File\n  {\n  public:\n    virtual size_t getSize() const = 0;\n    virtual const char * getFileName() const = 0;\n    virtual const char * getFilePath() const = 0;\n    virtual const char * getBuffer() const = 0;\n    virtual bool save(const char * filename) const = 0;\n  };\n  #endif //BIN2CPP_EMBEDDEDFILE_CLASS\n  const File \u0026 getHelloworldHtmlFile();\n}; //bin2cpp\n\n#endif //HELLOWORLD_H\n```\n\n\n### Output file: helloworld.cpp\n\n```cpp\n/**\n * This file was generated by bin2cpp v3.0.0\n * Copyright (C) 2013-2021 end2endzone.com. All rights reserved.\n * bin2cpp is open source software, see http://github.com/end2endzone/bin2cpp\n * Source code for file 'helloworld.html', last modified 1548537787.\n * Do not modify this file.\n */\n#if defined(_WIN32) \u0026\u0026 !defined(_CRT_SECURE_NO_WARNINGS)\n#define _CRT_SECURE_NO_WARNINGS\n#endif\n#include \"helloworld.h\"\n#include \u003cstring\u003e //for std::string\n#include \u003ciostream\u003e\n#include \u003cfstream\u003e  //for ofstream\nnamespace bin2cpp\n{\n  class HelloworldHtmlFile : public virtual bin2cpp::File\n  {\n  public:\n    HelloworldHtmlFile() { build(); }\n    virtual ~HelloworldHtmlFile() {}\n    virtual size_t getSize() const { return 238; }\n    virtual const char * getFileName() const { return \"helloworld.html\"; }\n    virtual const char * getFilePath() const { return getFileName(); }\n    virtual const char * getBuffer() const { return mBuffer.c_str(); }\n    void build()\n    {\n      mBuffer.clear();\n      mBuffer.reserve(getSize()); //allocate all required memory at once to prevent reallocations\n      mBuffer.append(\"\u003c!DOCTYPE html\u003e\\r\\n\u003chtml lang=\\\"en\\\"\u003e\\r\\n\u003chead\u003e\\r\\n  \u003cmeta charset=\\\"utf-8\\\"\u003e\\r\\n  \u003cmeta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1, user-scalable=yes\\\"\u003e\\r\\n  \u003ctitle\u003eHello World!\u003c/title\u003e\\r\\n\u003c/head\u003e\\r\\n\", 200);\n      mBuffer.append(\"\u003cbody\u003e\\r\\nHello World!\\r\\n\u003c/body\u003e\\r\\n\u003c/html\u003e\", 38);\n    }\n    virtual bool save(const char * filename) const\n    {\n      std::ofstream f(filename, std::ios::out | std::ios::binary | std::ios::trunc);\n      if (f.fail()) return false;\n      size_t fileSize = getSize();\n      const char * buffer = getBuffer();\n      f.write(buffer, fileSize);\n      f.close();\n      return true;\n    }\n  private:\n    std::string mBuffer;\n  };\n  const File \u0026 getHelloworldHtmlFile() { static HelloworldHtmlFile _instance; return _instance; }\n}; //bin2cpp\n```\n\n\n### Code sample (querying the generated code)\n\nAt runtime, show file properties and save/export data back to a file.\n\n```cpp\n#include \u003cstdio.h\u003e\n#include \u003cstring\u003e\n#include \u003ciostream\u003e\n\n#include \"helloworld.h\" //a single include file is all you need\n\nint main(int argc, char* argv[])\n{\n  //get a reference to the embedded file\n  const bin2cpp::File \u0026 resource = bin2cpp::getHelloworldhtmlFile();\n\n  //print information about the file.\n  std::cout \u003c\u003c \"Embedded file '\" \u003c\u003c resource.getFileName() \u003c\u003c \"' is \" \u003c\u003c resource.getSize() \u003c\u003c \" bytes long.\\n\";\n\n  //Saving content back to a file.\n  std::cout \u003c\u003c \" Saving embedded file to 'helloworld_copy.html'...\\n\";\n  bool saved = resource.save(\"helloworld_copy.html\");\n  if (saved)\n    std::cout \u003c\u003c \"saved\\n\";\n  else\n    std::cout \u003c\u003c \"failed\\n\";\n\n  //Get the internal buffer and do something with the binary data\n  const char * buffer = resource.getBuffer();\n  size_t bufferSize = resource.getSize();\n  //...\n  \n  return 0;\n}\n```\n\n\n\n## Example 2 - directory\n\nThis example shows how to use bin2cpp to convert multiple files of the same directory to c++ source code.\n\n\n### Input directory: [samples/demo_icons/flat-color-icons](samples/demo_icons/flat-color-icons).\n\nThe [samples/demo_icons/flat-color-icons](samples/demo_icons/flat-color-icons) directory contains the following 56 icons :\n\n![Flat Color Icons by Icons8](docs/Flat%20Color%20Icons%20by%20Icons8.png)\n\nThese icons are from the *Very Basic* set of [Icons8 Flat Color Icons](https://github.com/icons8/flat-color-icons) and are licensed under the [Good Boy License](https://icons8.com/good-boy-license).\n\n\n### Command:\n\n```\nbin2cpp.exe --dir=flat-color-icons --managerfile=IconsFileManager.h --output=.\\outdir --chunksize=50\n```\n\n\n### Console output\n\n```\nbin2cpp v3.0.0 - Convert binary files into C++ source code.\nCopyright (C) 2013-2021 end2endzone.com. All rights reserved.\nbin2cpp is open source software, see http://github.com/end2endzone/bin2cpp\nEmbedding \"flat-color-icons\\about.png\" using chunks of 50 bytes...\nWriting file \".\\outdir\\about.h\"...\nWriting file \".\\outdir\\about.cpp\"...\nEmbedding \"flat-color-icons\\address_book.png\" using chunks of 50 bytes...\nWriting file \".\\outdir\\address_book.h\"...\nWriting file \".\\outdir\\address_book.cpp\"...\n...\nEmbedding \"flat-color-icons\\video_file.png\" using chunks of 50 bytes...\nWriting file \".\\outdir\\video_file.h\"...\nWriting file \".\\outdir\\video_file.cpp\"...\nGenerating \"IconsFileManager.h\"...\nWriting file \".\\outdir\\IconsFileManager.h\"...\nWriting file \".\\outdir\\IconsFileManager.cpp\"...\n```\n\nNotice that additional files `IconsFileManager.h` and `IconsFileManager.cpp` were also generated and will allow retreiving all files at once.\n\n\n### Code sample (querying the generated code)\n\nAt runtime, show a file listing and save/export the icons files in users temporary directory.\n\n```cpp\n#include \u003cstdio.h\u003e  // printf\n#include \u003cstdlib.h\u003e // getenv\n#include \u003ciostream\u003e\n\n#include \"IconsFileManager.h\"\n\nint main(int argc, char* argv[])\n{\n  bin2cpp::FileManager \u0026 mgr = bin2cpp::FileManager::getInstance();\n\n  //Print information about all files generated with \"--managerfile\" or --registerfile flags.\n  size_t num_files = mgr.getFileCount();\n  std::cout \u003c\u003c \"Found \" \u003c\u003c num_files \u003c\u003c \" embedded icons...\\n\";\n\n  //Listing files.\n  for(size_t i=0; i\u003cnum_files; i++)\n  {\n    const bin2cpp::File * file = mgr.getFile(i);\n    std::cout \u003c\u003c \"  File '\" \u003c\u003c file-\u003egetFileName() \u003c\u003c \"', \" \u003c\u003c file-\u003egetSize() \u003c\u003c \" bytes\\n\";\n  }\n\n  //Saving content back to files.\n  const char * temp_dir = getenv(\"TEMP\");\n  std::cout \u003c\u003c \"Saving embedded icons to directory '\" \u003c\u003c temp_dir \u003c\u003c \"'...\\n\";\n  bool saved = mgr.saveFiles(temp_dir);\n  if (saved)\n    std::cout \u003c\u003c \"saved\\n\";\n  else\n    std::cout \u003c\u003c \"failed\\n\";\n\n  return 0;\n}\n```\n\n\n### Console output\n\n```\nFound 56 embedded icons...\n  File 'about.png', 520 bytes\n  File 'address_book.png', 1412 bytes\n  File 'alarm_clock.png', 2334 bytes\n  File 'audio_file.png', 523 bytes\n  File 'binoculars.png', 1347 bytes\n  File 'bookmark.png', 478 bytes\n  File 'broken_link.png', 1522 bytes\n  File 'calculator.png', 574 bytes\n  File 'calendar.png', 574 bytes\n  File 'cancel.png', 1159 bytes\n  File 'checkmark.png', 666 bytes\n  File 'clock.png', 1534 bytes\n  File 'contacts.png', 626 bytes\n  ...\n  File 'support.png', 1292 bytes\n  File 'synchronize.png', 1269 bytes\n  File 'unlock.png', 718 bytes\n  File 'upload.png', 467 bytes\n  File 'video_file.png', 472 bytes\nSaving embedded icons to directory 'C:\\Users\\foobar\\AppData\\Local\\Temp'...\nsaved\n```\n\n\n\n## Example 3 - relative header file (project's *include* directory)\n\nThis example shows how to use bin2cpp to generate files in a relative sub directory based on the project's root directory.\n\nMany projects has an *include* directory located at the project's root directory. These projects are usually configured to add *$ROOT_DIR/include* to the list of include directories. bin2cpp can be configured to take advantage of this situation.\n\nIf you output files in the *include* directory (with the command  `--output=$ROOT_DIR/include --headerfile=foo.h`), the generated `#include \"foo.h\"` statement will have no problem finding the generated header. However if you want the generated files to be in a sub directory (for example with the command  `--output=$ROOT_DIR/include/bin2cpp`), this won't work since you would need the sub directory path in the include statement.\n\nThe solution is to specify a *relative path* for the header file which also changes the generated `#include` statement. For example, the command  `--output=$ROOT_DIR/include --headerfile=bin2cpp/foo.h`), generates `#include \"bin2cpp/foo.h\"` which is perfect since `$ROOT_DIR/include` is already an include directory.\n\nThis example shows how to specify a relative path for the header file.\n\n\n\n### Command:\n\n```\nbin2cpp.exe --file=res/icon.ico --output=include --headerfile=bin2cpp/file_icon.h --identifier=icon  \n```\n\nNote the *bin2cpp* sub directory in `--headerfile=bin2cpp/file_icon.h`. The output sub directory must already exists.\n\n\n\n### Console output\n\n```\nbin2cpp v3.0.0 - Convert binary files into C++ source code.\nCopyright (C) 2013-2021 end2endzone.com. All rights reserved.\nbin2cpp is open source software, see http://github.com/end2endzone/bin2cpp\nEmbedding \"res/icon.ico\"...\nWriting file \"include/bin2cpp/file_icon.h\"...\nWriting file \"include/bin2cpp/file_icon.cpp\"...\n```\n\n\n\n### Output file: file_icon.cpp\n\nHere are the first few generated lines of file `file_icon.cpp`.\n\n```cpp\n/**\n * This file was generated by bin2cpp v3.0.0\n * Copyright (C) 2013-2021 end2endzone.com. All rights reserved.\n * bin2cpp is open source software, see http://github.com/end2endzone/bin2cpp\n * Source code for file 'icon.ico', last modified 1548537787.\n * Do not modify this file.\n */\n#if defined(_WIN32) \u0026\u0026 !defined(_CRT_SECURE_NO_WARNINGS)\n#define _CRT_SECURE_NO_WARNINGS\n#endif\n#include \"bin2cpp/file_icon.h\"\n#include \u003cstring\u003e //for std::string\n#include \u003ciostream\u003e\n#include \u003cfstream\u003e  //for ofstream\n...\n```\n\nNote the `#include \"bin2cpp/file_icon.h\"` statement which is relative to the project's *include* directory.\n\n\n\n## Example 4 - web site (embedding directory structure)\n\nThis example shows how to use bin2cpp to convert files from multiple directories to c++ source code. The input directory structure and file location are preserved.\n\n\n### Input directory: [samples/demo_website/www](samples/demo_website/www).\n\nThe [samples/demo_website/www](samples/demo_website/www) directory contains web pages in the following directory structure :\n\n```\nwww\n├── blog\n│   ├── how-to-create-a-web-site\n│   │   └── index.html\n│   ├── index.html\n│   └── using-bin2cpp\n│       └── index.html\n├── contact\n│   └── index.html\n├── home\n│   └── index.html\n└── index.html\n```\n\nThe directories above contains multiple files named `index.html`.\n\nbin2cpp can create unique identifiers for each files. In case of duplicate identifiers, bin2cpp appends a counter that increases by 1 on every duplicate. The pattern `_\u003ccounter\u003e` is added to the end where `\u003ccounter\u003e` is the next counter value. For example, the files above create the following identifiers:\n * Indexhtml\n * Indexhtml_1\n * Indexhtml_2\n * Indexhtml_3\n * Indexhtml_4\n * Indexhtml_5\n\nThe same strategy is implemented for duplicate file names.\n\n\n### Command:\n\n```\nbin2cpp.exe --dir=www --managerfile=PagesFileManager.h --namespace=www --output=.\\outdir --chunksize=50 --keepdirs\n```\n\nNote the `--keepdirs` command line option which keep the input directory structure and allows the output files to have the same directory structure as the input files. This prevents duplicate file names.\n\n\n### Console output\n\n```\nbin2cpp v3.0.0 - Convert binary files into C++ source code.\nCopyright (C) 2013-2021 end2endzone.com. All rights reserved.\nbin2cpp is open source software, see http://github.com/end2endzone/bin2cpp\nEmbedding \"www\\blog\\how-to-create-a-web-site\\index.html\" using chunks of 50 bytes...\nCreating directory \".\\outdir\\blog\\how-to-create-a-web-site\"...\nWriting file \".\\outdir\\blog\\how-to-create-a-web-site\\index.h\"...\nWriting file \".\\outdir\\blog\\how-to-create-a-web-site\\index.cpp\"...\nEmbedding \"www\\blog\\index.html\" using chunks of 50 bytes...\nWriting file \".\\outdir\\blog\\index.h\"...\nWriting file \".\\outdir\\blog\\index.cpp\"...\nEmbedding \"www\\blog\\using-bin2cpp\\index.html\" using chunks of 50 bytes...\nCreating directory \".\\outdir\\blog\\using-bin2cpp\"...\nWriting file \".\\outdir\\blog\\using-bin2cpp\\index.h\"...\nWriting file \".\\outdir\\blog\\using-bin2cpp\\index.cpp\"...\nEmbedding \"www\\contact\\index.html\" using chunks of 50 bytes...\nCreating directory \".\\outdir\\contact\"...\nWriting file \".\\outdir\\contact\\index.h\"...\nWriting file \".\\outdir\\contact\\index.cpp\"...\nEmbedding \"www\\home\\index.html\" using chunks of 50 bytes...\nCreating directory \".\\outdir\\home\"...\nWriting file \".\\outdir\\home\\index.h\"...\nWriting file \".\\outdir\\home\\index.cpp\"...\nEmbedding \"www\\index.html\" using chunks of 50 bytes...\nWriting file \".\\outdir\\index.h\"...\nWriting file \".\\outdir\\index.cpp\"...\nGenerating \"PagesFileManager.h\"...\nWriting file \".\\outdir\\PagesFileManager.h\"...\nWriting file \".\\outdir\\PagesFileManager.cpp\"...\n```\n\nNotice that files `PagesFileManager.h` and `PagesFileManager.cpp` were also generated. They provide support for extracting the content of the embedded ***www*** directory.\n\n\n### Code sample (querying the generated code)\n\nAt runtime, show a file listing and save/export all `index.html` files in the right directories.\n\n```cpp\n#include \u003cstdio.h\u003e  // printf\n#include \u003cstdlib.h\u003e // getenv\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n\n#include \"PagesFileManager.h\"\n\nint main(int argc, char* argv[])\n{\n  www::FileManager \u0026 mgr = www::FileManager::getInstance();\n\n  //Print information about all files generated with \"--managerfile\" or --registerfile flags.\n  size_t num_files = mgr.getFileCount();\n  std::cout \u003c\u003c \"Found \" \u003c\u003c num_files \u003c\u003c \" embedded web pages...\\n\";\n\n  //Listing files.\n  for(size_t i=0; i\u003cnum_files; i++)\n  {\n    const www::File * file = mgr.getFile(i);\n    std::cout \u003c\u003c \"  File '\" \u003c\u003c file-\u003egetFilePath() \u003c\u003c \"', \" \u003c\u003c file-\u003egetSize() \u003c\u003c \" bytes\\n\";\n  }\n\n  //Saving content back to files preserving the original directory structure.\n  std::string temp_dir = getenv(\"TEMP\");\n#ifdef _Win32\n  temp_dir += \"\\\\\";\n#else\n  temp_dir += \"/\";\n#endif\n  temp_dir += \"www\";\n  std::cout \u003c\u003c \"Saving embedded web pages to directory '\" \u003c\u003c temp_dir \u003c\u003c \"'...\\n\";\n  bool saved = mgr.saveFiles(temp_dir.c_str());\n  if (saved)\n    std::cout \u003c\u003c \"saved\\n\";\n  else\n    std::cout \u003c\u003c \"failed\\n\";\n\n  return 0;\n}\n```\n\n\n### Console output\n\n```\nFound 6 embedded web pages...\n  File 'index.html', 241 bytes\n  File 'blog\\index.html', 543 bytes\n  File 'blog\\using-bin2cpp\\index.html', 4332 bytes\n  File 'blog\\how-to-create-a-web-site\\index.html', 3645 bytes\n  File 'contact\\index.html', 2375 bytes\n  File 'home\\index.html', 1422 bytes\nSaving embedded web pages to directory 'C:\\Users\\foobar\\AppData\\Local\\Temp\\www'...\nsaved\n```\n\nThe executed code above has extracted the files above with the following directory structure:\n\n```\nC:\\Users\\username\\AppData\\Local\\Temp\\www\n├── blog\n│   ├── how-to-create-a-web-site\n│   │   └── index.html\n│   ├── index.html\n│   └── using-bin2cpp\n│       └── index.html\n├── contact\n│   └── index.html\n├── home\n│   └── index.html\n└── index.html\n```\n\n\n\n## Screenshots\n\n[![bin2cpp v2.4.0 Sample](docs/bin2cpp-v2.4.0-sample.png)](docs/bin2cpp-v2.4.0-sample.png)\n\nbin2cpp v2.4.0 Sample\n\n[![Demo extraction sample](docs/demo-extraction-sample.png)](docs/demo-extraction-sample.png)\n\nDemo extraction sample\n\n\n\n\n# Build\n\nPlease refer to file [INSTALL.md](INSTALL.md) for details on how installing/building the application.\n\n\n\n\n# Platform\n\nbin2cpp has been tested with the following platform:\n\n* Linux, 32 and 64 bit\n* Windows, 32 and 64 bit\n* macOS, 32 and 64 bit\n\n\n\n\n# Versioning\n\nWe use [Semantic Versioning 2.0.0](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/end2endzone/bin2cpp/tags).\n\n\n\n\n# Authors\n\n* **Antoine Beauchamp** - *Initial work* - [end2endzone](https://github.com/end2endzone)\n\nSee also the list of [contributors](https://github.com/end2endzone/bin2cpp/blob/master/AUTHORS) who participated in this project.\n\n\n\n\n# License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fend2endzone%2Fbin2cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fend2endzone%2Fbin2cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fend2endzone%2Fbin2cpp/lists"}