@@ -149,7 +149,7 @@ namespace bin2cpp
149149 fprintf (cpp, " const %s & %s() { static %s _instance; return _instance; }\n " , getContext ().baseClass .c_str (), getterFunctionName.c_str (), className.c_str ());
150150 if (mContext .registerFiles )
151151 {
152- std::string fileManagerTemplate = getFileManagerRegistrationTemplate ();
152+ std::string fileManagerTemplate = getCppFileManagerRegistrationImplementationTemplate ();
153153 fprintf (cpp, " %s" , fileManagerTemplate.c_str ());
154154 }
155155 fprintf (cpp, " }; //%s\n " , getContext ().codeNamespace .c_str ());
@@ -167,7 +167,7 @@ namespace bin2cpp
167167 if ( !input )
168168 return false ;
169169
170- // Uppercase function identifier
170+ // Lowercase function identifier
171171 std::string functionIdentifier = ra::strings::Lowercase (mContext .functionIdentifier );
172172
173173 // Build header and cpp file path
@@ -211,11 +211,8 @@ namespace bin2cpp
211211 fprintf (fout, " static bool %s_initialized = false;\n " , functionIdentifier.c_str ());
212212 fprintf (fout, " \n " );
213213
214- if ( mContext .registerFiles )
215- {
216- fprintf (fout, " extern bool bin2c_filemanager_register_file(%s * file);\n " , mContext .baseClass .c_str ());
217- fprintf (fout, " \n " );
218- }
214+ // File registration predeclaration code
215+ fprintf (fout, " %s" , getCFileManagerRegistrationPredeclarationTemplate ().c_str ());
219216
220217 fprintf (fout, " bool %s_load()\n " , functionIdentifier.c_str ());
221218 fprintf (fout, " {\n " );
@@ -304,14 +301,12 @@ namespace bin2cpp
304301 fprintf (fout, " file->load = %s_load;\n " , functionIdentifier.c_str ());
305302 fprintf (fout, " file->unload = %s_free;\n " , functionIdentifier.c_str ());
306303 fprintf (fout, " file->save = %s_save;\n " , functionIdentifier.c_str ());
307-
308304 if ( mContext .registerFiles )
309305 {
310306 fprintf (fout, " \n " );
311- fprintf (fout, " // register\n " );
307+ fprintf (fout, " // register when loaded if static initialisation does not work \n " );
312308 fprintf (fout, " bin2c_filemanager_register_file(file);\n " );
313309 }
314-
315310 fprintf (fout, " }\n " );
316311 fprintf (fout, " \n " );
317312 fprintf (fout, " %s* %s(void)\n " , mContext .baseClass .c_str (), getGetterFunctionName ().c_str ());
@@ -320,11 +315,8 @@ namespace bin2cpp
320315 fprintf (fout, " return &%s_file;\n " , functionIdentifier.c_str ());
321316 fprintf (fout, " }\n " );
322317
323- // if ( mContext.registerFiles )
324- // {
325- // std::string fileManagerTemplate = getFileManagerRegistrationTemplate();
326- // fprintf(fout, "%s", fileManagerTemplate.c_str());
327- // }
318+ // File registration implementation code
319+ fprintf (fout, " %s" , getCFileManagerRegistrationImplementationTemplate ().c_str ());
328320
329321 fclose (input);
330322 fclose (fout);
0 commit comments