From 5f068ec46a12b01950df3c3d53b995d7edf013e6 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Wed, 17 Jun 2015 19:24:48 +0100 Subject: [PATCH 1/4] dev9ghz: Use .ini for saving settings Import settings from the registry if needed. --- plugins/dev9ghzdrk/DEV9.cpp | 4 +- plugins/dev9ghzdrk/DEV9.h | 3 +- plugins/dev9ghzdrk/Win32/Config.cpp | 71 ++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/plugins/dev9ghzdrk/DEV9.cpp b/plugins/dev9ghzdrk/DEV9.cpp index b05fb3574b..ff5bd62849 100644 --- a/plugins/dev9ghzdrk/DEV9.cpp +++ b/plugins/dev9ghzdrk/DEV9.cpp @@ -81,7 +81,7 @@ u32 CALLBACK PS2EgetLibVersion2(u32 type) { } -//string s_strIniPath = "inis"; +std::string s_strIniPath = "inis"; std::string s_strLogPath = "logs"; // Warning: The below log function is SLOW. Better fix it before attempting to use it. #ifdef _DEBUG @@ -627,7 +627,7 @@ void CALLBACK DEV9setSettingsDir(const char* dir) { // Grab the ini directory. // TODO: Use - // s_strIniPath = (dir == NULL) ? "inis" : dir; + s_strIniPath = (dir == NULL) ? "inis" : dir; } void CALLBACK DEV9setLogDir(const char* dir) diff --git a/plugins/dev9ghzdrk/DEV9.h b/plugins/dev9ghzdrk/DEV9.h index 67d0958695..d9ca01192b 100644 --- a/plugins/dev9ghzdrk/DEV9.h +++ b/plugins/dev9ghzdrk/DEV9.h @@ -128,7 +128,8 @@ EXTERN DEV9callback DEV9irq; //void DEV9thread(); EXTERN PluginLog DEV9Log; -//Yes this is meant to be a lowercase extern +//Yes these are meant to be a lowercase extern +extern std::string s_strIniPath; extern std::string s_strLogPath; void __Log(char *fmt, ...); diff --git a/plugins/dev9ghzdrk/Win32/Config.cpp b/plugins/dev9ghzdrk/Win32/Config.cpp index 70d0efcace..4c8e895d9f 100644 --- a/plugins/dev9ghzdrk/Win32/Config.cpp +++ b/plugins/dev9ghzdrk/Win32/Config.cpp @@ -26,37 +26,46 @@ #define GetKeyVdw(name, var) \ GetKeyV(name, var, 4, REG_DWORD); -#define SetKeyV(name, var, s, t) \ - RegSetValueEx(myKey, name, 0, t, (LPBYTE) var, s); +//#define SetKeyV(name, var, s, t) \ +// RegSetValueEx(myKey, name, 0, t, (LPBYTE) var, s); -#define SetKeyVdw(name, var) \ - SetKeyV(name, var, 4, REG_DWORD); +//#define SetKeyVdw(name, var) \ +// SetKeyV(name, var, 4, REG_DWORD); -void SaveConf() { - HKEY myKey; - DWORD myDisp; - - RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\DEV9\\DEV9linuz", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &myKey, &myDisp); - SetKeyV("Eth", config.Eth, strlen(config.Eth), REG_SZ); - SetKeyV("Hdd", config.Hdd, strlen(config.Hdd), REG_SZ); - SetKeyVdw("HddSize", &config.HddSize); - SetKeyVdw("ethEnable", &config.ethEnable); - SetKeyVdw("hddEnable", &config.hddEnable); - - RegCloseKey(myKey); +BOOL WritePrivateProfileInt(LPCSTR lpAppName, LPCSTR lpKeyName, int intvar, LPCSTR lpFileName) +{ + return WritePrivateProfileString(lpAppName, lpKeyName, std::to_string(intvar).c_str(), lpFileName); +} +bool FileExists(std::string szPath) +{ + DWORD dwAttrib = GetFileAttributes(szPath.c_str()); + return (dwAttrib != INVALID_FILE_ATTRIBUTES && + !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); } -void LoadConf() { +void SaveConf() { + const std::string file(s_strIniPath + "/dev9ghz.ini"); + DeleteFile(file.c_str()); + + WritePrivateProfileString("DEV9", "Eth", config.Eth, file.c_str()); + WritePrivateProfileString("DEV9", "Hdd", config.Hdd, file.c_str()); + WritePrivateProfileInt("DEV9", "HddSize", config.HddSize, file.c_str()); + WritePrivateProfileInt("DEV9", "ethEnable", config.ethEnable, file.c_str()); + WritePrivateProfileInt("DEV9", "hddEnable", config.hddEnable, file.c_str()); +} + +void LoadRegConf() { HKEY myKey; DWORD type, size; - memset(&config, 0, sizeof(config)); - strcpy(config.Hdd, HDD_DEF); - config.HddSize=8*1024; - strcpy(config.Eth, ETH_DEF); + //memset(&config, 0, sizeof(config)); + //strcpy(config.Hdd, HDD_DEF); + //config.HddSize=8*1024; + //strcpy(config.Eth, ETH_DEF); if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\DEV9\\DEV9linuz", 0, KEY_ALL_ACCESS, &myKey)!=ERROR_SUCCESS) { - SaveConf(); return; + //SaveConf(); + return; } GetKeyV("Eth", config.Eth, sizeof(config.Eth), REG_SZ); GetKeyV("Hdd", config.Hdd, sizeof(config.Hdd), REG_SZ); @@ -66,4 +75,22 @@ void LoadConf() { RegCloseKey(myKey); } +void LoadConf() { + memset(&config, 0, sizeof(config)); + strcpy(config.Hdd, HDD_DEF); + config.HddSize = 8 * 1024; + strcpy(config.Eth, ETH_DEF); + + const std::string file(s_strIniPath + "/dev9ghz.ini"); + if (FileExists(file.c_str()) == false) { + LoadRegConf(); //Import old settings if user has upgraded this plugin + SaveConf(); + return; + } + GetPrivateProfileString("DEV9", "Eth", ETH_DEF, config.Eth, sizeof(config.Eth), file.c_str()); + GetPrivateProfileString("DEV9", "Hdd", HDD_DEF, config.Hdd, sizeof(config.Hdd), file.c_str()); + config.HddSize = GetPrivateProfileInt("DEV9", "HddSize", config.HddSize, file.c_str()); + config.ethEnable = GetPrivateProfileInt("DEV9", "ethEnable", config.ethEnable, file.c_str()); + config.ethEnable = GetPrivateProfileInt("DEV9", "hddEnable", config.hddEnable, file.c_str()); +} From 0d04ee440d5b023f981c5fffbee799e5e0630eb9 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Fri, 19 Jun 2015 15:39:49 +0100 Subject: [PATCH 2/4] dev9ghz: fix a typo... --- plugins/dev9ghzdrk/Win32/Config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/dev9ghzdrk/Win32/Config.cpp b/plugins/dev9ghzdrk/Win32/Config.cpp index 4c8e895d9f..9560c8400b 100644 --- a/plugins/dev9ghzdrk/Win32/Config.cpp +++ b/plugins/dev9ghzdrk/Win32/Config.cpp @@ -91,6 +91,6 @@ void LoadConf() { GetPrivateProfileString("DEV9", "Hdd", HDD_DEF, config.Hdd, sizeof(config.Hdd), file.c_str()); config.HddSize = GetPrivateProfileInt("DEV9", "HddSize", config.HddSize, file.c_str()); config.ethEnable = GetPrivateProfileInt("DEV9", "ethEnable", config.ethEnable, file.c_str()); - config.ethEnable = GetPrivateProfileInt("DEV9", "hddEnable", config.hddEnable, file.c_str()); + config.hddEnable = GetPrivateProfileInt("DEV9", "hddEnable", config.hddEnable, file.c_str()); } From 0be0f13acf14477342dd38f531c6980bcad55425 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Fri, 19 Jun 2015 15:46:51 +0100 Subject: [PATCH 3/4] dev9ghz: delete leftover registry keys --- plugins/dev9ghzdrk/Win32/Config.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugins/dev9ghzdrk/Win32/Config.cpp b/plugins/dev9ghzdrk/Win32/Config.cpp index 9560c8400b..c16bef80da 100644 --- a/plugins/dev9ghzdrk/Win32/Config.cpp +++ b/plugins/dev9ghzdrk/Win32/Config.cpp @@ -54,6 +54,29 @@ void SaveConf() { WritePrivateProfileInt("DEV9", "hddEnable", config.hddEnable, file.c_str()); } +void DeleteRegConf() { + HKEY myKey; + //DWORD type, size; + + if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\DEV9\\DEV9linuz", 0, KEY_ALL_ACCESS, &myKey) != ERROR_SUCCESS) { + return; + } + RegDeleteKey(myKey, "Eth"); + RegDeleteKey(myKey, "Hdd"); + RegDeleteKey(myKey, "HddSize"); + RegDeleteKey(myKey, "ethEnable"); + RegDeleteKey(myKey, "hddEnable"); + RegCloseKey(myKey); + if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\DEV9", 0, KEY_ALL_ACCESS, &myKey) != ERROR_SUCCESS) { + emu_printf("Error Opening Key DEV9linuz"); + return; + } + if (RegDeleteKey(myKey, "DEV9linuz") != ERROR_SUCCESS) { + emu_printf("Error Deleting Key DEV9linuz"); + return; + } +} + void LoadRegConf() { HKEY myKey; DWORD type, size; @@ -74,6 +97,7 @@ void LoadRegConf() { GetKeyVdw("hddEnable", &config.hddEnable); RegCloseKey(myKey); + DeleteRegConf(); } void LoadConf() { memset(&config, 0, sizeof(config)); From dcd477f2b606ac5a3eb6b961c14c12cd7c117d8c Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Mon, 22 Jun 2015 15:13:18 +0100 Subject: [PATCH 4/4] dev9ghz: Look in registry for settings first If settings found in the registry, create ini, fill with settings and then delete the settings stored in the registry. If no settings found in registry, load from ini. --- plugins/dev9ghzdrk/Win32/Config.cpp | 71 ++++++++++++++++++----------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/plugins/dev9ghzdrk/Win32/Config.cpp b/plugins/dev9ghzdrk/Win32/Config.cpp index c16bef80da..23b843a167 100644 --- a/plugins/dev9ghzdrk/Win32/Config.cpp +++ b/plugins/dev9ghzdrk/Win32/Config.cpp @@ -67,47 +67,38 @@ void DeleteRegConf() { RegDeleteKey(myKey, "ethEnable"); RegDeleteKey(myKey, "hddEnable"); RegCloseKey(myKey); + //Delete Key Software\PS2Eplugin\DEV9\DEV9linuz if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\DEV9", 0, KEY_ALL_ACCESS, &myKey) != ERROR_SUCCESS) { - emu_printf("Error Opening Key DEV9linuz"); + emu_printf("Error Opening Key DEV9\n"); return; } if (RegDeleteKey(myKey, "DEV9linuz") != ERROR_SUCCESS) { - emu_printf("Error Deleting Key DEV9linuz"); + emu_printf("Error Removing Key DEV9linuz\n"); + RegCloseKey(myKey); return; } + RegCloseKey(myKey); + //Delete Key Software\PS2Eplugin\DEV9 + if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin", 0, KEY_ALL_ACCESS, &myKey) != ERROR_SUCCESS) { + emu_printf("Error Opening Key PS2Eplugin\n"); + return; + } + if (RegDeleteKey(myKey, "DEV9") != ERROR_SUCCESS) { + emu_printf("Error Removing Key DEV9\n"); + RegCloseKey(myKey); + return; + } + RegCloseKey(myKey); } -void LoadRegConf() { - HKEY myKey; - DWORD type, size; - +void LoadIniConf() { //memset(&config, 0, sizeof(config)); //strcpy(config.Hdd, HDD_DEF); - //config.HddSize=8*1024; + //config.HddSize = 8 * 1024; //strcpy(config.Eth, ETH_DEF); - if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\DEV9\\DEV9linuz", 0, KEY_ALL_ACCESS, &myKey)!=ERROR_SUCCESS) { - //SaveConf(); - return; - } - GetKeyV("Eth", config.Eth, sizeof(config.Eth), REG_SZ); - GetKeyV("Hdd", config.Hdd, sizeof(config.Hdd), REG_SZ); - GetKeyVdw("HddSize", &config.HddSize); - GetKeyVdw("ethEnable", &config.ethEnable); - GetKeyVdw("hddEnable", &config.hddEnable); - - RegCloseKey(myKey); - DeleteRegConf(); -} -void LoadConf() { - memset(&config, 0, sizeof(config)); - strcpy(config.Hdd, HDD_DEF); - config.HddSize = 8 * 1024; - strcpy(config.Eth, ETH_DEF); - const std::string file(s_strIniPath + "/dev9ghz.ini"); if (FileExists(file.c_str()) == false) { - LoadRegConf(); //Import old settings if user has upgraded this plugin SaveConf(); return; } @@ -118,3 +109,29 @@ void LoadConf() { config.hddEnable = GetPrivateProfileInt("DEV9", "hddEnable", config.hddEnable, file.c_str()); } +void LoadConf() { + HKEY myKey; + DWORD type, size; + + memset(&config, 0, sizeof(config)); + strcpy(config.Hdd, HDD_DEF); + config.HddSize = 8 * 1024; + strcpy(config.Eth, ETH_DEF); + + if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\DEV9\\DEV9linuz", 0, KEY_ALL_ACCESS, &myKey)!=ERROR_SUCCESS) { + LoadIniConf(); + return; + } + printf("Importing Settings\n"); + //Import old settings if user has upgraded this plugin + GetKeyV("Eth", config.Eth, sizeof(config.Eth), REG_SZ); + GetKeyV("Hdd", config.Hdd, sizeof(config.Hdd), REG_SZ); + GetKeyVdw("HddSize", &config.HddSize); + GetKeyVdw("ethEnable", &config.ethEnable); + GetKeyVdw("hddEnable", &config.hddEnable); + + RegCloseKey(myKey); + SaveConf(); + DeleteRegConf(); +} +