@@ -46,7 +46,7 @@ using namespace bin2cpp;
4646
4747enum APP_ERROR_CODES
4848{
49- APP_ERROR_SUCCESS,
49+ APP_ERROR_SUCCESS = 0 ,
5050 APP_ERROR_MISSINGARGUMENTS,
5151 APP_ERROR_INPUTFILENOTFOUND,
5252 APP_ERROR_UNABLETOCREATEOUTPUTFILES,
@@ -152,6 +152,7 @@ struct ARGUMENTS
152152 bool version;
153153 bool hasFile;
154154 bool hasDir;
155+ bool hasManagerFile;
155156 std::string inputFile;
156157 std::string inputDir;
157158 std::string outputFolder;
@@ -162,7 +163,7 @@ struct ARGUMENTS
162163 std::string codeNamespace;
163164 std::string baseClass;
164165 std::string managerHeaderFilename;
165- bool usefilemanager ;
166+ bool registerfile ;
166167 IGenerator::CppEncoderEnum encoding;
167168 std::string generatorName;
168169};
@@ -185,7 +186,7 @@ void printUsage()
185186 // usage string in docopt format. See http://docopt.org/
186187 static const char usage[] =
187188 " Usage:\n "
188- " bin2cpp --file=<path> --output=<path> --headerfile=<name> --identifier=<name> [--generator=<name>] [--encoding=<name>] [--chunksize=<value>] [--namespace=<value>] [--baseclass=<value>] [--managerfile=<name>] [--override] [--noheader] [--quiet]\n "
189+ " bin2cpp --file=<path> --output=<path> --headerfile=<name> --identifier=<name> [--generator=<name>] [--encoding=<name>] [--chunksize=<value>] [--namespace=<value>] [--baseclass=<value>] [--managerfile=<name>] [--registerfile] [-- override] [--noheader] [--quiet]\n "
189190 " bin2cpp --help\n "
190191 " bin2cpp --version\n "
191192 " \n "
@@ -205,9 +206,9 @@ void printUsage()
205206 " --identifier=<name> Identifier of the function name that is used to get an instance of the file. ie: SplashScreen\n "
206207 " --chunksize=<value> Size in bytes of each string segments (bytes per row). [default: 200].\n "
207208 " --baseclass=<value> The name of the interface for embedded files. [default: File].\n "
208- " --managerfile=<name> File name of the generated C++ Header file for the FileManager class. ie: FileManager.h\n "
209209 " --namespace=<value> The namespace of the generated source code [default: bin2cpp].\n "
210- " --usefilemanager Register the generated file to the FileManager class. [default: false].\n "
210+ " --managerfile=<name> File name of the generated C++ Header file for the FileManager class. ie: FileManager.h\n "
211+ " --registerfile Register the generated file to the FileManager class. [default: false].\n "
211212 " --override Tells bin2cpp to overwrite the destination files.\n "
212213 " --noheader Do not print program header to standard output.\n "
213214 " --quiet Do not log any message to standard output.\n "
@@ -224,9 +225,10 @@ int main(int argc, char* argv[])
224225 args.version = false ;
225226 args.hasFile = false ;
226227 args.hasDir = false ;
228+ args.hasManagerFile = false ;
227229 args.chunkSize = 0 ;
228230 args.overrideExisting ;
229- args.usefilemanager = false ;
231+ args.registerfile = false ;
230232
231233 std::string dummy;
232234
@@ -266,11 +268,12 @@ int main(int argc, char* argv[])
266268 // mandatory arguments
267269 args.hasFile = ra::cli::ParseArgument (" file" , args.inputFile , argc, argv);
268270 args.hasDir = ra::cli::ParseArgument (" dir" , args.inputDir , argc, argv);
269- if (!args.hasFile && !args.hasDir )
271+ args.hasManagerFile = ra::cli::ParseArgument (" managerfile" , args.managerHeaderFilename , argc, argv);
272+ if (!args.hasFile && !args.hasDir && !args.hasManagerFile )
270273 {
271- // file or dir must be specified
274+ // file, dir or managerfile must be specified
272275 APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS;
273- ra::logging::Log (ra::logging::LOG_ERROR, " %s (file, dir)" , getErrorCodeDescription (error));
276+ ra::logging::Log (ra::logging::LOG_ERROR, " %s (file, dir, managerfile )" , getErrorCodeDescription (error));
274277 printUsage ();
275278 return error;
276279 }
@@ -356,14 +359,12 @@ int main(int argc, char* argv[])
356359 args.baseClass = DEFAULT_BASECLASSNAME;
357360 }
358361
359- ra::cli::ParseArgument (" managerfile" , args.managerHeaderFilename , argc, argv);
360-
361- args.usefilemanager = ra::cli::ParseArgument (" usefilemanager" , dummy, argc, argv);
362+ args.registerfile = ra::cli::ParseArgument (" registerfile" , dummy, argc, argv);
362363
363- // force usefilemanager if managerfile is specified
364- if (! args.managerHeaderFilename . empty () )
364+ // force registerfile if managerfile is specified
365+ if (args.hasManagerFile )
365366 {
366- args.usefilemanager = true ;
367+ args.registerfile = true ;
367368 }
368369
369370 std::string encodingStr;
@@ -435,19 +436,8 @@ int main(int argc, char* argv[])
435436 if (error != APP_ERROR_SUCCESS)
436437 {
437438 ra::logging::Log (ra::logging::LOG_ERROR, " %s" , getErrorCodeDescription (error));
439+ return error;
438440 }
439-
440- // should we also generate the FileManager class?
441- if (!args.managerHeaderFilename .empty ())
442- {
443- error = processManagerFiles (args, generator);
444- if (error != APP_ERROR_SUCCESS)
445- {
446- ra::logging::Log (ra::logging::LOG_ERROR, " %s" , getErrorCodeDescription (error));
447- }
448- }
449-
450- return error;
451441 }
452442 else if (args.hasDir )
453443 {
@@ -517,10 +507,20 @@ int main(int argc, char* argv[])
517507 }
518508
519509 // all files processed
520- return APP_ERROR_SUCCESS;
521510 }
522511
523- return APP_ERROR_UNABLETOCREATEOUTPUTFILES;
512+ // should we also generate the FileManager class?
513+ if (args.hasManagerFile )
514+ {
515+ APP_ERROR_CODES error = processManagerFiles (args, generator);
516+ if (error != APP_ERROR_SUCCESS)
517+ {
518+ ra::logging::Log (ra::logging::LOG_ERROR, " %s" , getErrorCodeDescription (error));
519+ return error;
520+ }
521+ }
522+
523+ return APP_ERROR_SUCCESS;
524524}
525525
526526APP_ERROR_CODES processSingleFile (const ARGUMENTS & args, bin2cpp::IGenerator * generator)
@@ -558,7 +558,7 @@ APP_ERROR_CODES processSingleFile(const ARGUMENTS & args, bin2cpp::IGenerator *
558558 generator->setBaseClass (args.baseClass .c_str ());
559559 generator->setCppEncoder (args.encoding );
560560 generator->setManagerHeaderFile (args.managerHeaderFilename .c_str ());
561- generator->setManagerEnabled (args.usefilemanager );
561+ generator->setRegisterFileEnabled (args.registerfile );
562562
563563 // process files
564564 bool headerResult = generateFile (args.inputFile , outputHeaderPath, generator, args.overrideExisting );
@@ -651,7 +651,6 @@ bool generateManagerFile(const std::string & iOutputFilePath, bin2cpp::IGenerato
651651 if (!result)
652652 {
653653 // there was an error generating file
654- ra::logging::Log (ra::logging::LOG_ERROR, " %s" , getErrorCodeDescription (APP_ERROR_UNABLETOCREATEOUTPUTFILES));
655654 ra::logging::Log (ra::logging::LOG_ERROR, " %s failed!" , getUpdateModeText (mode));
656655 }
657656 return result;
0 commit comments