Merge pull request #607 from TheLastRar/dev9settings

dev9ghz: Use .ini for saving settings and delete old registry keys
This commit is contained in:
bositman 2015-06-22 17:35:37 +03:00
commit eb0f6eb953
3 changed files with 86 additions and 17 deletions

View File

@ -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)

View File

@ -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, ...);

View File

@ -26,24 +26,87 @@
#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);
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 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 DeleteRegConf() {
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);
//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);
//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 DEV9\n");
return;
}
if (RegDeleteKey(myKey, "DEV9linuz") != ERROR_SUCCESS) {
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 LoadIniConf() {
//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) {
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.hddEnable = GetPrivateProfileInt("DEV9", "hddEnable", config.hddEnable, file.c_str());
}
void LoadConf() {
@ -52,12 +115,15 @@ void LoadConf() {
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;
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);
@ -65,5 +131,7 @@ void LoadConf() {
GetKeyVdw("hddEnable", &config.hddEnable);
RegCloseKey(myKey);
SaveConf();
DeleteRegConf();
}