aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/tools/FileToHeader/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/tools/FileToHeader/main.cpp')
-rw-r--r--libraries/irrlicht-1.8/tools/FileToHeader/main.cpp350
1 files changed, 175 insertions, 175 deletions
diff --git a/libraries/irrlicht-1.8/tools/FileToHeader/main.cpp b/libraries/irrlicht-1.8/tools/FileToHeader/main.cpp
index b3cc7a7..492f19b 100644
--- a/libraries/irrlicht-1.8/tools/FileToHeader/main.cpp
+++ b/libraries/irrlicht-1.8/tools/FileToHeader/main.cpp
@@ -1,175 +1,175 @@
1// Copyright (C) 2012 Gaz Davidson 1// Copyright (C) 2012 Gaz Davidson
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5/*** 5/***
6 This tool creates a .h file from a given input file by encoding it into a C string, 6 This tool creates a .h file from a given input file by encoding it into a C string,
7 allowing you to build your resources directly into your binaries, just like Irrlicht's 7 allowing you to build your resources directly into your binaries, just like Irrlicht's
8 built-in font. 8 built-in font.
9 9
10 To distribute your app as a single executable file of minimal size: 10 To distribute your app as a single executable file of minimal size:
11 11
12 1. Put all your resources into a single directory and add it to Irrlicht's filesystem 12 1. Put all your resources into a single directory and add it to Irrlicht's filesystem
13 as a folder through IFileSystem::addArchive. Develop and test your app as usual. 13 as a folder through IFileSystem::addArchive. Develop and test your app as usual.
14 2. Open IrrCompileConfig.h and comment out all the options that your app does not use. 14 2. Open IrrCompileConfig.h and comment out all the options that your app does not use.
15 This will reduce the size of the Irrlicht library considerably. 15 This will reduce the size of the Irrlicht library considerably.
16 * You should remove the D3D video drivers, because they rely on external DLLs. 16 * You should remove the D3D video drivers, because they rely on external DLLs.
17 * You should keep either the TAR or ZIP archive loader, used in step 6. 17 * You should keep either the TAR or ZIP archive loader, used in step 6.
18 * If you remove the JPEG loader, you don't have to say you use JPEG code in your 18 * If you remove the JPEG loader, you don't have to say you use JPEG code in your
19 documentation. 19 documentation.
20 3. Recompile Irrlicht as a static library, editing the IRR_STATIC_LIB line in 20 3. Recompile Irrlicht as a static library, editing the IRR_STATIC_LIB line in
21 IrrCompileConfig.h. 21 IrrCompileConfig.h.
22 The next time you compile your application it will take a while longer, but 22 The next time you compile your application it will take a while longer, but
23 Irrlicht will be built into your binary. 23 Irrlicht will be built into your binary.
24 4. TAR or ZIP your resource directory using your favourite archiving tool (ie 7zip). 24 4. TAR or ZIP your resource directory using your favourite archiving tool (ie 7zip).
25 * If you chose ZIP but compiled without zlib, don't compress this archive or it 25 * If you chose ZIP but compiled without zlib, don't compress this archive or it
26 won't open. 26 won't open.
27 5. Run this tool to convert your resource file into a .h file, like so: 27 5. Run this tool to convert your resource file into a .h file, like so:
28 FileToHeader res.zip > EmbeddedResources.h 28 FileToHeader res.zip > EmbeddedResources.h
29 6. Add the .h file to your project, create the embedded read file then mount as a 29 6. Add the .h file to your project, create the embedded read file then mount as a
30 ZIP or TAR archive instead of the folder, like so: 30 ZIP or TAR archive instead of the folder, like so:
31 io::IReadFile *f = io::createEmbeddedFile(device->getFileSystem(), "res.zip"); 31 io::IReadFile *f = io::createEmbeddedFile(device->getFileSystem(), "res.zip");
32 device->getFileSystem()->addFileArchive(f); 32 device->getFileSystem()->addFileArchive(f);
33 archive->drop(); 33 archive->drop();
34 7. Recompile your app. 34 7. Recompile your app.
35 * If you use Microsoft's compiler, make sure your CRT (common run-time) is 35 * If you use Microsoft's compiler, make sure your CRT (common run-time) is
36 the static library version, otherwise you'll have a dependency on the CRT DLLs. 36 the static library version, otherwise you'll have a dependency on the CRT DLLs.
37 Your binary should now be completely portable; you can distribute just the exe file. 37 Your binary should now be completely portable; you can distribute just the exe file.
38 8. Optional: Use UPX (upx.sf.net) to compress your binary. 38 8. Optional: Use UPX (upx.sf.net) to compress your binary.
39*/ 39*/
40 40
41#include <iostream> 41#include <iostream>
42#include <fstream> 42#include <fstream>
43#include <sstream> 43#include <sstream>
44 44
45using namespace std; 45using namespace std;
46 46
47int main(int argc, char* argv[]) 47int main(int argc, char* argv[])
48{ 48{
49 if (argc < 2) 49 if (argc < 2)
50 { 50 {
51 // print usage 51 // print usage
52 cerr << "You must to specify at least one input file" << endl; 52 cerr << "You must to specify at least one input file" << endl;
53 cerr << "usage: " << argv[0] << "<file1> [file2...]" << endl; 53 cerr << "usage: " << argv[0] << "<file1> [file2...]" << endl;
54 cerr << "outputs a header file to stdout, so for example use"; 54 cerr << "outputs a header file to stdout, so for example use";
55 return 1; 55 return 1;
56 } 56 }
57 57
58 int i = 1; 58 int i = 1;
59 59
60 // write file header 60 // write file header
61 cout << "// File made by FileToHeader, part of the Irrlicht Engine" << endl 61 cout << "// File made by FileToHeader, part of the Irrlicht Engine" << endl
62 << endl 62 << endl
63 << "#ifndef _EMBEDDED_FILES_H_INCLUDED_" << endl 63 << "#ifndef _EMBEDDED_FILES_H_INCLUDED_" << endl
64 << "#define _EMBEDDED_FILES_H_INCLUDED_" << endl 64 << "#define _EMBEDDED_FILES_H_INCLUDED_" << endl
65 << endl 65 << endl
66 << "#include \"irrTypes.h\"" << endl 66 << "#include \"irrTypes.h\"" << endl
67 << "#include \"IReadFile.h\"" << endl 67 << "#include \"IReadFile.h\"" << endl
68 << "#include \"IFileSystem.h\"" << endl 68 << "#include \"IFileSystem.h\"" << endl
69 << endl 69 << endl
70 << "namespace irr" << endl 70 << "namespace irr" << endl
71 << "{" << endl 71 << "{" << endl
72 << "namespace io" << endl 72 << "namespace io" << endl
73 << "{" << endl 73 << "{" << endl
74 << endl 74 << endl
75 << " const c8* EmbeddedFileData[] = " << endl 75 << " const c8* EmbeddedFileData[] = " << endl
76 << " {" << endl; 76 << " {" << endl;
77 77
78 // store sizes and file names 78 // store sizes and file names
79 stringstream sizes; 79 stringstream sizes;
80 stringstream names; 80 stringstream names;
81 sizes << "const u32 EmbeddedFileSizes[] = {"; 81 sizes << "const u32 EmbeddedFileSizes[] = {";
82 names << "const c8* EmbeddedFileNames[] = {"; 82 names << "const c8* EmbeddedFileNames[] = {";
83 int fileCount = 0; 83 int fileCount = 0;
84 84
85 // char to hex digit table, probably doesn't help for speed due to fstream. better than using sprintf though 85 // char to hex digit table, probably doesn't help for speed due to fstream. better than using sprintf though
86 char hextable[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; 86 char hextable[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
87 87
88 while (i < argc) 88 while (i < argc)
89 { 89 {
90 // open and seek to end of file 90 // open and seek to end of file
91 ifstream input; 91 ifstream input;
92 input.open(argv[i], ios::in | ios::binary | ios::ate); 92 input.open(argv[i], ios::in | ios::binary | ios::ate);
93 93
94 if (input.is_open()) 94 if (input.is_open())
95 { 95 {
96 int size = input.tellg(); 96 int size = input.tellg();
97 input.seekg(0, ios::beg); 97 input.seekg(0, ios::beg);
98 // read the file into RAM 98 // read the file into RAM
99 char *entireFile = new char[size]; 99 char *entireFile = new char[size];
100 input.read(entireFile, size); 100 input.read(entireFile, size);
101 101
102 if (fileCount) 102 if (fileCount)
103 { 103 {
104 sizes << ", "; 104 sizes << ", ";
105 names << ", "; 105 names << ", ";
106 cout << "," << endl; 106 cout << "," << endl;
107 } 107 }
108 108
109 // save file size and name 109 // save file size and name
110 sizes << size; 110 sizes << size;
111 names << '"' << argv[i] << '"'; 111 names << '"' << argv[i] << '"';
112 112
113 // write the file data 113 // write the file data
114 cout << " \""; 114 cout << " \"";
115 for (int count=0; count < size; ++count) 115 for (int count=0; count < size; ++count)
116 { 116 {
117 if (count && (count % 16) == 0) 117 if (count && (count % 16) == 0)
118 cout << "\"" << endl << " \""; 118 cout << "\"" << endl << " \"";
119 119
120 cout << "\\x" << hextable[(entireFile[count] >> 4) & 0xF] << hextable[entireFile[count] & 0x0F]; 120 cout << "\\x" << hextable[(entireFile[count] >> 4) & 0xF] << hextable[entireFile[count] & 0x0F];
121 } 121 }
122 cout << "\""; 122 cout << "\"";
123 123
124 delete [] entireFile; 124 delete [] entireFile;
125 // 125 //
126 input.close(); 126 input.close();
127 127
128 fileCount++; 128 fileCount++;
129 } 129 }
130 else 130 else
131 { 131 {
132 cerr << "Failed to open file: " << argv[i] << endl; 132 cerr << "Failed to open file: " << argv[i] << endl;
133 } 133 }
134 134
135 ++i; 135 ++i;
136 } 136 }
137 137
138 // close binary file list and write file metadata 138 // close binary file list and write file metadata
139 cout << endl 139 cout << endl
140 << " , 0};" << endl 140 << " , 0};" << endl
141 << endl 141 << endl
142 << " const u32 EmbeddedFileCount = " << fileCount << ";" << endl 142 << " const u32 EmbeddedFileCount = " << fileCount << ";" << endl
143 << " " << sizes.str() << "};" << endl 143 << " " << sizes.str() << "};" << endl
144 << " " << names.str() << "};" << endl 144 << " " << names.str() << "};" << endl
145 << endl; 145 << endl;
146 146
147 // write functions to create embedded IReadFiles 147 // write functions to create embedded IReadFiles
148 cout << " IReadFile* createEmbeddedFile(IFileSystem *fs, u32 index)" << endl 148 cout << " IReadFile* createEmbeddedFile(IFileSystem *fs, u32 index)" << endl
149 << " {" << endl 149 << " {" << endl
150 << " if (EmbeddedFileCount < index)" << endl 150 << " if (EmbeddedFileCount < index)" << endl
151 << " return 0;" << endl 151 << " return 0;" << endl
152 << endl 152 << endl
153 << " return fs->createMemoryReadFile((void*)EmbeddedFileData[index], " << endl 153 << " return fs->createMemoryReadFile((void*)EmbeddedFileData[index], " << endl
154 << " EmbeddedFileSizes[index], EmbeddedFileNames[index]);" << endl 154 << " EmbeddedFileSizes[index], EmbeddedFileNames[index]);" << endl
155 << " }" << endl 155 << " }" << endl
156 << endl 156 << endl
157 << " IReadFile* createEmbeddedFile(IFileSystem *fs, path filename)" << endl 157 << " IReadFile* createEmbeddedFile(IFileSystem *fs, path filename)" << endl
158 << " {" << endl 158 << " {" << endl
159 << " for (u32 i=0; i < EmbeddedFileCount; ++i)" << endl 159 << " for (u32 i=0; i < EmbeddedFileCount; ++i)" << endl
160 << " if (filename == EmbeddedFileNames[i])" << endl 160 << " if (filename == EmbeddedFileNames[i])" << endl
161 << " return createEmbeddedFile(fs, i);" << endl 161 << " return createEmbeddedFile(fs, i);" << endl
162 << endl 162 << endl
163 << " return 0;" << endl 163 << " return 0;" << endl
164 << " }" << endl 164 << " }" << endl
165 << endl; 165 << endl;
166 166
167 // write footer 167 // write footer
168 cout << "} // namespace io" << endl 168 cout << "} // namespace io" << endl
169 << "} // namespace irr" << endl 169 << "} // namespace irr" << endl
170 << endl 170 << endl
171 << "#endif // _EMBEDDED_FILES_H_INCLUDED_" << endl; 171 << "#endif // _EMBEDDED_FILES_H_INCLUDED_" << endl;
172 172
173 return 0; 173 return 0;
174} 174}
175 175