diff --git a/journal/w32/.gitignore b/journal/w32/.gitignore new file mode 100644 index 0000000..53e7d64 --- /dev/null +++ b/journal/w32/.gitignore @@ -0,0 +1,7 @@ +.vs +Debug +journal/Debug +!*.sln +!*.vcxproj +!*.vcxproj.filters +!*.bmp \ No newline at end of file diff --git a/journal/w32/journal.sln b/journal/w32/journal.sln new file mode 100644 index 0000000..303676e --- /dev/null +++ b/journal/w32/journal.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30309.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "journal", "journal\journal.vcxproj", "{0AC54FE5-AE4B-4B4F-9B06-2A29101AE745}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0AC54FE5-AE4B-4B4F-9B06-2A29101AE745}.Debug|x64.ActiveCfg = Debug|x64 + {0AC54FE5-AE4B-4B4F-9B06-2A29101AE745}.Debug|x64.Build.0 = Debug|x64 + {0AC54FE5-AE4B-4B4F-9B06-2A29101AE745}.Debug|x86.ActiveCfg = Debug|Win32 + {0AC54FE5-AE4B-4B4F-9B06-2A29101AE745}.Debug|x86.Build.0 = Debug|Win32 + {0AC54FE5-AE4B-4B4F-9B06-2A29101AE745}.Release|x64.ActiveCfg = Release|x64 + {0AC54FE5-AE4B-4B4F-9B06-2A29101AE745}.Release|x64.Build.0 = Release|x64 + {0AC54FE5-AE4B-4B4F-9B06-2A29101AE745}.Release|x86.ActiveCfg = Release|Win32 + {0AC54FE5-AE4B-4B4F-9B06-2A29101AE745}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FE54145F-EE02-422A-BE71-80A6862C6C91} + EndGlobalSection +EndGlobal diff --git a/journal/w32/journal/img/default.bmp b/journal/w32/journal/img/default.bmp new file mode 100644 index 0000000..e25e1ee Binary files /dev/null and b/journal/w32/journal/img/default.bmp differ diff --git a/journal/w32/journal/img/niko1.bmp b/journal/w32/journal/img/niko1.bmp new file mode 100644 index 0000000..e47ee1d Binary files /dev/null and b/journal/w32/journal/img/niko1.bmp differ diff --git a/journal/w32/journal/img/niko2.bmp b/journal/w32/journal/img/niko2.bmp new file mode 100644 index 0000000..54371c8 Binary files /dev/null and b/journal/w32/journal/img/niko2.bmp differ diff --git a/journal/w32/journal/img/niko3.bmp b/journal/w32/journal/img/niko3.bmp new file mode 100644 index 0000000..ea317b7 Binary files /dev/null and b/journal/w32/journal/img/niko3.bmp differ diff --git a/journal/w32/journal/journal.vcxproj b/journal/w32/journal/journal.vcxproj new file mode 100644 index 0000000..e8d7617 --- /dev/null +++ b/journal/w32/journal/journal.vcxproj @@ -0,0 +1,155 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + 16.0 + Win32Proj + {0ac54fe5-ae4b-4b4f-9b06-2a29101ae745} + journal + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + \ No newline at end of file diff --git a/journal/w32/journal/journal.vcxproj.filters b/journal/w32/journal/journal.vcxproj.filters new file mode 100644 index 0000000..5d136f8 --- /dev/null +++ b/journal/w32/journal/journal.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Source Files + + + Source Files + + + Source Files + + + + + Source Files + + + \ No newline at end of file diff --git a/journal/w32/icon.ico b/journal/w32/journal/src/icon.ico similarity index 100% rename from journal/w32/icon.ico rename to journal/w32/journal/src/icon.ico diff --git a/journal/w32/journal.c b/journal/w32/journal/src/journal.c similarity index 70% rename from journal/w32/journal.c rename to journal/w32/journal/src/journal.c index 68b7736..45b9af6 100644 --- a/journal/w32/journal.c +++ b/journal/w32/journal/src/journal.c @@ -1,5 +1,8 @@ #define WINVER 0x0600 #define _WIN32_WINNT 0x0600 +// needed to suppress warnings about wcscpy and such +#define _CRT_SECURE_NO_WARNINGS 1 + #include #include #include @@ -8,6 +11,7 @@ #define DEFAULT_WIDTH 800 #define DEFAULT_HEIGHT 600 #define IN_BUFFER_SIZE 256 +#define IMAGE_PATH_MAX_SIZE 512 #define WINDOW_STYLE (WS_OVERLAPPEDWINDOW ^ (WS_THICKFRAME | WS_MAXIMIZEBOX)) @@ -20,25 +24,61 @@ static DWORD err = 0; static HWND window = NULL; +static char DataPath[512]; + static void loadImage(const char *name) { - char copy_space[IN_BUFFER_SIZE]; - const char* lang_ptr; + char imagePath[IMAGE_PATH_MAX_SIZE]; + if (image_handle) { DeleteObject(image_handle); } - image_handle = LoadBitmapA(GetModuleHandleW(NULL), name); - // In the event we can't find an image's translated value - // try to find a matching resource without any language code suffix - if (!image_handle) { - lang_ptr = strchr(name, '_'); - if (lang_ptr) { - memset(copy_space, 0, IN_BUFFER_SIZE); - strncpy(copy_space, name, lang_ptr - name); - //terminate the string because I guess strncpy doesn't - image_handle = LoadBitmapA(GetModuleHandleW(NULL), copy_space); - if (!image_handle) { - err = GetLastError(); - } + + // handle default as a special case, since we'll keep that image internally + if (strcmp(name, "default") == 0) { + image_handle = LoadBitmapA(GetModuleHandleW(NULL), "default"); + } + else { + // names come in the format XX_YY + // where XX is the image (ex: c1) + // and YY is the lang code (ex: ja, or pt_br) + // so let's separate this into 2 char pointers + char imageName[IN_BUFFER_SIZE]; + char* langCode = 0; + char* emptyString = "\0"; + strcpy(imageName, name); + langCode = strchr(imageName, '_'); + if (langCode > 0) { + // replace the code with 0 to null terminate the image name where this is + // then use the rest of the string as the language code + // so c1_ja becomes "c1\0ja", thus imageName is "c1" and then langCode is "ja" + (*langCode) = 0; + langCode++; + } + else { + langCode = emptyString; + } + + // build imagePath + strcpy(imagePath, DataPath); + strcat(imagePath, "Graphics\\Journal\\"); + strcat(imagePath, langCode); + strcat(imagePath, "\\"); + strcat(imagePath, imageName); + strcat(imagePath, ".bmp"); + + image_handle = LoadImageA(NULL, imagePath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); + // In the event we can't find an image's translated value + // try to find a matching file in the root folder + if (!image_handle) { + // build imagePath + strcpy(imagePath, DataPath); + strcat(imagePath, "Graphics\\Journal\\"); + strcat(imagePath, imageName); + strcat(imagePath, ".bmp"); + image_handle = LoadImageA(NULL, imagePath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); + if (!image_handle) { + err = GetLastError(); + } } } } @@ -146,11 +186,34 @@ void init_check_save(WCHAR* save_path) { } } +// images should be loaded from gamepath folder +// so we need a gamepath, which should be saved in the registry +boolean readGamePath() { + // clear data path + memset(&DataPath[0], 0, sizeof(DataPath)); + DWORD dataPathSize = sizeof(DataPath); + + HKEY key; + long keyOpenError = RegOpenKey(HKEY_CURRENT_USER, TEXT("Software\\OneShot\\"), &key); + + if (keyOpenError == ERROR_SUCCESS) { + long dirReadError = RegQueryValueEx(key, TEXT("GameDirectory"), NULL, NULL, (LPBYTE)DataPath, &dataPathSize); + + RegCloseKey(key); + + return dirReadError == ERROR_SUCCESS; + } + return FALSE; +} + int do_journal() { // Create HINSTANCE module = GetModuleHandleW(NULL); + // load data path from registry + readGamePath(); + // Default image WCHAR save_path[MAX_PATH]; PWSTR folder_path = NULL; diff --git a/journal/w32/main.c b/journal/w32/journal/src/main.c similarity index 100% rename from journal/w32/main.c rename to journal/w32/journal/src/main.c diff --git a/journal/w32/niko.c b/journal/w32/journal/src/niko.c similarity index 100% rename from journal/w32/niko.c rename to journal/w32/journal/src/niko.c diff --git a/journal/w32/journal/src/resources.rc b/journal/w32/journal/src/resources.rc new file mode 100644 index 0000000..8afb395 --- /dev/null +++ b/journal/w32/journal/src/resources.rc @@ -0,0 +1,9 @@ +#include +MAINICON ICON "icon.ico" + +NIKO1 BITMAP "img/NIKO1.bmp" +NIKO2 BITMAP "img/NIKO2.bmp" +NIKO3 BITMAP "img/NIKO3.bmp" + +default BITMAP "img/DEFAULT.bmp" + diff --git a/journal/w32/resources.rc b/journal/w32/resources.rc deleted file mode 100644 index 9c04a61..0000000 --- a/journal/w32/resources.rc +++ /dev/null @@ -1,223 +0,0 @@ -#include -MAINICON ICON "icon.ico" - -NIKO1 BITMAP "img/NIKO1.bmp" -NIKO2 BITMAP "img/NIKO2.bmp" -NIKO3 BITMAP "img/NIKO3.bmp" - -default BITMAP "img/DEFAULT.bmp" -t1 BITMAP "img/T1.bmp" -t2 BITMAP "img/T2.bmp" -t3 BITMAP "img/T3.bmp" -t4 BITMAP "img/T4.bmp" -t5 BITMAP "img/T5.bmp" -t6 BITMAP "img/T6.bmp" -t7 BITMAP "img/T7.bmp" -t8 BITMAP "img/T8.bmp" -t9 BITMAP "img/T9.bmp" -t10 BITMAP "img/T10.bmp" -t11 BITMAP "img/T11.bmp" -t12 BITMAP "img/T12.bmp" -t13 BITMAP "img/T13.bmp" -t14 BITMAP "img/T14.bmp" -t15 BITMAP "img/T15.bmp" -t16 BITMAP "img/T16.bmp" -c1 BITMAP "img/C1.bmp" -c2 BITMAP "img/C2.bmp" -c3 BITMAP "img/C3.bmp" -c4 BITMAP "img/C4.bmp" -c5 BITMAP "img/C5.bmp" -c6 BITMAP "img/C6.bmp" -c7 BITMAP "img/C7.bmp" -s1 BITMAP "img/S1.bmp" -s2 BITMAP "img/S2.bmp" -s3 BITMAP "img/S3.bmp" -s4 BITMAP "img/S4.bmp" -save BITMAP "img/SAVE.bmp" -final BITMAP "img/FINAL.bmp" - -//french -t1_FR BITMAP "img/fr/T1.bmp" -t2_FR BITMAP "img/fr/T2.bmp" -t3_FR BITMAP "img/fr/T3.bmp" -t4_FR BITMAP "img/fr/T4.bmp" -t5_FR BITMAP "img/fr/T5.bmp" -t6_FR BITMAP "img/fr/T6.bmp" -t7_FR BITMAP "img/fr/T7.bmp" -t8_FR BITMAP "img/fr/T8.bmp" -t9_FR BITMAP "img/fr/T9.bmp" -t10_FR BITMAP "img/fr/T10.bmp" -t11_FR BITMAP "img/fr/T11.bmp" -t12_FR BITMAP "img/fr/T12.bmp" -t13_FR BITMAP "img/fr/T13.bmp" -t14_FR BITMAP "img/fr/T14.bmp" -t15_FR BITMAP "img/fr/T15.bmp" -t16_FR BITMAP "img/fr/T16.bmp" -c1_FR BITMAP "img/fr/C1.bmp" -c2_FR BITMAP "img/fr/C2.bmp" -c3_FR BITMAP "img/fr/C3.bmp" -c4_FR BITMAP "img/fr/C4.bmp" -c5_FR BITMAP "img/fr/C5.bmp" -c6_FR BITMAP "img/fr/C6.bmp" -c7_FR BITMAP "img/fr/C7.bmp" -s1_FR BITMAP "img/fr/S1.bmp" -s2_FR BITMAP "img/fr/S2.bmp" -s3_FR BITMAP "img/fr/S3.bmp" -s4_FR BITMAP "img/fr/S4.bmp" -save_FR BITMAP "img/fr/SAVE.bmp" -final_FR BITMAP "img/fr/FINAL.bmp" - -//spanish -t1_ES BITMAP "img/es/T1.bmp" -t2_ES BITMAP "img/es/T2.bmp" -t3_ES BITMAP "img/es/T3.bmp" -t4_ES BITMAP "img/es/T4.bmp" -t5_ES BITMAP "img/es/T5.bmp" -t6_ES BITMAP "img/es/T6.bmp" -t7_ES BITMAP "img/es/T7.bmp" -t8_ES BITMAP "img/es/T8.bmp" -t9_ES BITMAP "img/es/T9.bmp" -t10_ES BITMAP "img/es/T10.bmp" -t11_ES BITMAP "img/es/T11.bmp" -t12_ES BITMAP "img/es/T12.bmp" -t13_ES BITMAP "img/es/T13.bmp" -t14_ES BITMAP "img/es/T14.bmp" -t15_ES BITMAP "img/es/T15.bmp" -t16_ES BITMAP "img/es/T16.bmp" -c1_ES BITMAP "img/es/C1.bmp" -c2_ES BITMAP "img/es/C2.bmp" -c3_ES BITMAP "img/es/C3.bmp" -c4_ES BITMAP "img/es/C4.bmp" -c5_ES BITMAP "img/es/C5.bmp" -c6_ES BITMAP "img/es/C6.bmp" -c7_ES BITMAP "img/es/C7.bmp" -s1_ES BITMAP "img/es/S1.bmp" -s2_ES BITMAP "img/es/S2.bmp" -s3_ES BITMAP "img/es/S3.bmp" -s4_ES BITMAP "img/es/S4.bmp" -save_ES BITMAP "img/es/SAVE.bmp" -final_ES BITMAP "img/es/FINAL.bmp" - -//japanese -t1_JA BITMAP "img/ja/T1.bmp" -t2_JA BITMAP "img/ja/T2.bmp" -t3_JA BITMAP "img/ja/T3.bmp" -t4_JA BITMAP "img/ja/T4.bmp" -t5_JA BITMAP "img/ja/T5.bmp" -t6_JA BITMAP "img/ja/T6.bmp" -t7_JA BITMAP "img/ja/T7.bmp" -t8_JA BITMAP "img/ja/T8.bmp" -t9_JA BITMAP "img/ja/T9.bmp" -t10_JA BITMAP "img/ja/T10.bmp" -t11_JA BITMAP "img/ja/T11.bmp" -t12_JA BITMAP "img/ja/T12.bmp" -t13_JA BITMAP "img/ja/T13.bmp" -t14_JA BITMAP "img/ja/T14.bmp" -t15_JA BITMAP "img/ja/T15.bmp" -t16_JA BITMAP "img/ja/T16.bmp" -c1_JA BITMAP "img/ja/C1.bmp" -c2_JA BITMAP "img/ja/C2.bmp" -c3_JA BITMAP "img/ja/C3.bmp" -c4_JA BITMAP "img/ja/C4.bmp" -c5_JA BITMAP "img/ja/C5.bmp" -c6_JA BITMAP "img/ja/C6.bmp" -c7_JA BITMAP "img/ja/C7.bmp" -s1_JA BITMAP "img/ja/S1.bmp" -s2_JA BITMAP "img/ja/S2.bmp" -s3_JA BITMAP "img/ja/S3.bmp" -s4_JA BITMAP "img/ja/S4.bmp" -save_JA BITMAP "img/ja/SAVE.bmp" -final_JA BITMAP "img/ja/FINAL.bmp" - -//korean -t1_KO BITMAP "img/ko/T1.bmp" -t2_KO BITMAP "img/ko/T2.bmp" -t3_KO BITMAP "img/ko/T3.bmp" -t4_KO BITMAP "img/ko/T4.bmp" -t5_KO BITMAP "img/ko/T5.bmp" -t6_KO BITMAP "img/ko/T6.bmp" -t7_KO BITMAP "img/ko/T7.bmp" -t8_KO BITMAP "img/ko/T8.bmp" -t9_KO BITMAP "img/ko/T9.bmp" -t10_KO BITMAP "img/ko/T10.bmp" -t11_KO BITMAP "img/ko/T11.bmp" -t12_KO BITMAP "img/ko/T12.bmp" -t13_KO BITMAP "img/ko/T13.bmp" -t14_KO BITMAP "img/ko/T14.bmp" -t15_KO BITMAP "img/ko/T15.bmp" -t16_KO BITMAP "img/ko/T16.bmp" -c1_KO BITMAP "img/ko/C1.bmp" -c2_KO BITMAP "img/ko/C2.bmp" -c3_KO BITMAP "img/ko/C3.bmp" -c4_KO BITMAP "img/ko/C4.bmp" -c5_KO BITMAP "img/ko/C5.bmp" -c6_KO BITMAP "img/ko/C6.bmp" -c7_KO BITMAP "img/ko/C7.bmp" -s1_KO BITMAP "img/ko/S1.bmp" -s2_KO BITMAP "img/ko/S2.bmp" -s3_KO BITMAP "img/ko/S3.bmp" -s4_KO BITMAP "img/ko/S4.bmp" -save_KO BITMAP "img/ko/SAVE.bmp" -final_KO BITMAP "img/ko/FINAL.bmp" - -//portuges -t1_PT_BR BITMAP "img/pt_br/T1.bmp" -t2_PT_BR BITMAP "img/pt_br/T2.bmp" -t3_PT_BR BITMAP "img/pt_br/T3.bmp" -t4_PT_BR BITMAP "img/pt_br/T4.bmp" -t5_PT_BR BITMAP "img/pt_br/T5.bmp" -t6_PT_BR BITMAP "img/pt_br/T6.bmp" -t7_PT_BR BITMAP "img/pt_br/T7.bmp" -t8_PT_BR BITMAP "img/pt_br/T8.bmp" -t9_PT_BR BITMAP "img/pt_br/T9.bmp" -t10_PT_BR BITMAP "img/pt_br/T10.bmp" -t11_PT_BR BITMAP "img/pt_br/T11.bmp" -t12_PT_BR BITMAP "img/pt_br/T12.bmp" -t13_PT_BR BITMAP "img/pt_br/T13.bmp" -t14_PT_BR BITMAP "img/pt_br/T14.bmp" -t15_PT_BR BITMAP "img/pt_br/T15.bmp" -t16_PT_BR BITMAP "img/pt_br/T16.bmp" -c1_PT_BR BITMAP "img/pt_br/C1.bmp" -c2_PT_BR BITMAP "img/pt_br/C2.bmp" -c3_PT_BR BITMAP "img/pt_br/C3.bmp" -c4_PT_BR BITMAP "img/pt_br/C4.bmp" -c5_PT_BR BITMAP "img/pt_br/C5.bmp" -c6_PT_BR BITMAP "img/pt_br/C6.bmp" -c7_PT_BR BITMAP "img/pt_br/C7.bmp" -s1_PT_BR BITMAP "img/pt_br/S1.bmp" -s2_PT_BR BITMAP "img/pt_br/S2.bmp" -s3_PT_BR BITMAP "img/pt_br/S3.bmp" -s4_PT_BR BITMAP "img/pt_br/S4.bmp" -save_PT_BR BITMAP "img/pt_br/SAVE.bmp" -final_PT_BR BITMAP "img/pt_br/FINAL.bmp" - -//chinese -t1_ZH_CN BITMAP "img/zh_cn/T1.bmp" -t2_ZH_CN BITMAP "img/zh_cn/T2.bmp" -t3_ZH_CN BITMAP "img/zh_cn/T3.bmp" -t4_ZH_CN BITMAP "img/zh_cn/T4.bmp" -t5_ZH_CN BITMAP "img/zh_cn/T5.bmp" -t6_ZH_CN BITMAP "img/zh_cn/T6.bmp" -t7_ZH_CN BITMAP "img/zh_cn/T7.bmp" -t8_ZH_CN BITMAP "img/zh_cn/T8.bmp" -t9_ZH_CN BITMAP "img/zh_cn/T9.bmp" -t10_ZH_CN BITMAP "img/zh_cn/T10.bmp" -t11_ZH_CN BITMAP "img/zh_cn/T11.bmp" -t12_ZH_CN BITMAP "img/zh_cn/T12.bmp" -t13_ZH_CN BITMAP "img/zh_cn/T13.bmp" -t14_ZH_CN BITMAP "img/zh_cn/T14.bmp" -t15_ZH_CN BITMAP "img/zh_cn/T15.bmp" -t16_ZH_CN BITMAP "img/zh_cn/T16.bmp" -c1_ZH_CN BITMAP "img/zh_cn/C1.bmp" -c2_ZH_CN BITMAP "img/zh_cn/C2.bmp" -c3_ZH_CN BITMAP "img/zh_cn/C3.bmp" -c4_ZH_CN BITMAP "img/zh_cn/C4.bmp" -c5_ZH_CN BITMAP "img/zh_cn/C5.bmp" -c6_ZH_CN BITMAP "img/zh_cn/C6.bmp" -c7_ZH_CN BITMAP "img/zh_cn/C7.bmp" -s1_ZH_CN BITMAP "img/zh_cn/S1.bmp" -s2_ZH_CN BITMAP "img/zh_cn/S2.bmp" -s3_ZH_CN BITMAP "img/zh_cn/S3.bmp" -s4_ZH_CN BITMAP "img/zh_cn/S4.bmp" -save_ZH_CN BITMAP "img/zh_cn/SAVE.bmp" -final_ZH_CN BITMAP "img/zh_cn/FINAL.bmp" diff --git a/src/i18n.cpp b/src/i18n.cpp index b6c81a4..13f2492 100644 --- a/src/i18n.cpp +++ b/src/i18n.cpp @@ -60,8 +60,8 @@ void loadLocale(const char* locale) { _setLocaleFamily(locale); - int dictSize = 52; - // currently there are 52 + int dictSize = 100; + // currently there are 52, but 100 should be plenty if we ever do add more strdict = (char**)malloc(sizeof(char*) * dictSize); sprintf(pathbuf, "Languages/internal/%s.po", locale); diff --git a/src/main.cpp b/src/main.cpp index a803bd7..4aa55fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -192,6 +192,45 @@ static void setupWindowIcon(const Config &conf, SDL_Window *win) } } +// mainly doing this so journal app knows where to load images from +static void setGamePathInRegistry() { + + // this logic is currently windows specific + char* dataDir = SDL_GetBasePath(); + if (dataDir) + { + HKEY key; + long keyOpenError = RegOpenKey(HKEY_CURRENT_USER, TEXT("Software\\OneShot\\"), &key); + + if (keyOpenError != ERROR_SUCCESS) { + // try creating the key first + long keyCreateError = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\OneShot\\"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL); + + if (keyCreateError != ERROR_SUCCESS) + { + showInitError("Unable to create key in registry."); + } + else { + keyOpenError = ERROR_SUCCESS; + } + } + + if (keyOpenError != ERROR_SUCCESS) + { + showInitError("Unable to open registry."); + } + else { + DWORD dataSize = (strlen(dataDir) + 1) * sizeof(char); + if (RegSetValueEx(key, TEXT("GameDirectory"), 0, REG_SZ, (LPBYTE)dataDir, dataSize) != ERROR_SUCCESS) + { + showInitError("Unable to set GameDirectory registry value."); + } + RegCloseKey(key); + } + SDL_free(dataDir); + } +} + int main(int argc, char *argv[]) { SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); @@ -231,6 +270,8 @@ int main(int argc, char *argv[]) } #endif + setGamePathInRegistry(); + /* Initialize physfs here so that config can call PHYSFS_getPrefDir */ PHYSFS_init(argv[0]);