4747#include " Common/LocalFileSystem.h"
4848#include " Common/ArchiveFileSystem.h"
4949#include " Common/INI.h"
50+ #include " Common/Registry.h"
5051#include " Win32Device/Common/Win32LocalFileSystem.h"
5152#include " Win32Device/Common/Win32BIGFileSystem.h"
5253
@@ -257,11 +258,25 @@ static void extractChunkIDsFromRawData(const unsigned char* data, size_t dataSiz
257258 }
258259}
259260
261+ static bool getGameDirectoryFromRegistry (char * gameDir, size_t maxLen)
262+ {
263+ AsciiString installPath;
264+ if (GetStringFromRegistry (" " , " InstallPath" , installPath)) {
265+ if (installPath.getLength () > 0 && installPath.getLength () < (Int)maxLen) {
266+ strncpy (gameDir, installPath.str (), maxLen - 1 );
267+ gameDir[maxLen - 1 ] = ' \0 ' ;
268+ return true ;
269+ }
270+ }
271+ return false ;
272+ }
273+
260274static void printUsage (const char * exeName)
261275{
262- printf (" Usage: %s -in <input_file> -out <output_file>\n " , exeName);
276+ printf (" Usage: %s -in <input_file> -out <output_file> [-gamedir <game_directory>] \n " , exeName);
263277 printf (" Converts SCB files to JSON and vice versa.\n " );
264278 printf (" File format is auto-detected based on extension (.scb or .json)\n " );
279+ printf (" If -gamedir is not specified, attempts to find game directory from registry or current directory.\n " );
265280}
266281
267282
@@ -661,8 +676,7 @@ int main(int argc, char* argv[])
661676{
662677 initMemoryManager ();
663678
664- const char * gameDir = " C:\\ Program Files\\ EA Games\\ Command and Conquer Generals Zero Hour\\ Command and Conquer Generals Zero Hour" ;
665-
679+ char gameDir[MAX_PATH] = " " ;
666680 char currentDir[MAX_PATH];
667681 if (!GetCurrentDirectoryA (MAX_PATH, currentDir)) {
668682 printf (" Error: Could not get current directory. Error code: %d\n " , GetLastError ());
@@ -673,6 +687,24 @@ int main(int argc, char* argv[])
673687 bool inGameDir = (dataAttrs != INVALID_FILE_ATTRIBUTES && (dataAttrs & FILE_ATTRIBUTE_DIRECTORY));
674688
675689 if (!inGameDir) {
690+ const char * specifiedGameDir = NULL ;
691+
692+ for (int i = 1 ; i < argc; i++) {
693+ if (strcmp (argv[i], " -gamedir" ) == 0 && i + 1 < argc) {
694+ specifiedGameDir = argv[++i];
695+ break ;
696+ }
697+ }
698+
699+ if (specifiedGameDir) {
700+ strncpy (gameDir, specifiedGameDir, MAX_PATH - 1 );
701+ gameDir[MAX_PATH - 1 ] = ' \0 ' ;
702+ } else if (!getGameDirectoryFromRegistry (gameDir, MAX_PATH)) {
703+ printf (" Error: Could not find game directory.\n " );
704+ printf (" Please specify the game directory using -gamedir <path> or ensure the game is installed and registered.\n " );
705+ return 1 ;
706+ }
707+
676708 if (!SetCurrentDirectoryA (gameDir)) {
677709 printf (" Error: Could not set working directory to game directory: %s\n " , gameDir);
678710 return 1 ;
@@ -686,7 +718,7 @@ int main(int argc, char* argv[])
686718 }
687719 }
688720
689- if (argc != 5 ) {
721+ if (argc < 5 ) {
690722 printUsage (argv[0 ]);
691723 return 1 ;
692724 }
@@ -699,6 +731,8 @@ int main(int argc, char* argv[])
699731 inputPath = argv[++i];
700732 } else if (strcmp (argv[i], " -out" ) == 0 && i + 1 < argc) {
701733 outputPath = argv[++i];
734+ } else if (strcmp (argv[i], " -gamedir" ) == 0 && i + 1 < argc) {
735+ i++;
702736 }
703737 }
704738
0 commit comments