2014-04-06 13:11:19 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2014 David Quintana [gigaherz]
|
|
|
|
*
|
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-03-19 22:01:41 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <winsock2.h>
|
2013-03-20 13:58:00 +00:00
|
|
|
#include "..\DEV9.h"
|
2013-03-19 22:01:41 +00:00
|
|
|
|
|
|
|
#define GetKeyV(name, var, s, t) \
|
|
|
|
size = s; type = t; \
|
|
|
|
RegQueryValueEx(myKey, name, 0, &type, (LPBYTE) var, &size);
|
|
|
|
|
|
|
|
#define GetKeyVdw(name, var) \
|
|
|
|
GetKeyV(name, var, 4, REG_DWORD);
|
|
|
|
|
2015-06-17 18:24:48 +00:00
|
|
|
//#define SetKeyV(name, var, s, t) \
|
|
|
|
// RegSetValueEx(myKey, name, 0, t, (LPBYTE) var, s);
|
2013-03-19 22:01:41 +00:00
|
|
|
|
2015-06-17 18:24:48 +00:00
|
|
|
//#define SetKeyVdw(name, var) \
|
|
|
|
// SetKeyV(name, var, 4, REG_DWORD);
|
2013-03-19 22:01:41 +00:00
|
|
|
|
2015-06-17 18:24:48 +00:00
|
|
|
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));
|
|
|
|
}
|
2013-03-19 22:01:41 +00:00
|
|
|
|
2015-06-17 18:24:48 +00:00
|
|
|
void SaveConf() {
|
|
|
|
const std::string file(s_strIniPath + "/dev9ghz.ini");
|
|
|
|
DeleteFile(file.c_str());
|
2013-03-19 22:01:41 +00:00
|
|
|
|
2015-06-17 18:24:48 +00:00
|
|
|
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());
|
2013-03-19 22:01:41 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 14:46:51 +00:00
|
|
|
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);
|
2015-06-22 14:13:18 +00:00
|
|
|
//Delete Key Software\PS2Eplugin\DEV9\DEV9linuz
|
2015-06-19 14:46:51 +00:00
|
|
|
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\DEV9", 0, KEY_ALL_ACCESS, &myKey) != ERROR_SUCCESS) {
|
2015-06-22 14:13:18 +00:00
|
|
|
emu_printf("Error Opening Key DEV9\n");
|
2015-06-19 14:46:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (RegDeleteKey(myKey, "DEV9linuz") != ERROR_SUCCESS) {
|
2015-06-22 14:13:18 +00:00
|
|
|
emu_printf("Error Removing Key DEV9linuz\n");
|
|
|
|
RegCloseKey(myKey);
|
2015-06-19 14:46:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-22 14:13:18 +00:00
|
|
|
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);
|
2015-06-19 14:46:51 +00:00
|
|
|
}
|
|
|
|
|
2015-06-22 14:13:18 +00:00
|
|
|
void LoadIniConf() {
|
2015-06-17 18:24:48 +00:00
|
|
|
//memset(&config, 0, sizeof(config));
|
|
|
|
//strcpy(config.Hdd, HDD_DEF);
|
2015-06-22 14:13:18 +00:00
|
|
|
//config.HddSize = 8 * 1024;
|
2015-06-17 18:24:48 +00:00
|
|
|
//strcpy(config.Eth, ETH_DEF);
|
2013-03-19 22:01:41 +00:00
|
|
|
|
2015-06-22 14:13:18 +00:00
|
|
|
const std::string file(s_strIniPath + "/dev9ghz.ini");
|
|
|
|
if (FileExists(file.c_str()) == false) {
|
|
|
|
SaveConf();
|
2015-06-17 18:24:48 +00:00
|
|
|
return;
|
2013-03-19 22:01:41 +00:00
|
|
|
}
|
2015-06-22 14:13:18 +00:00
|
|
|
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());
|
2013-03-19 22:01:41 +00:00
|
|
|
}
|
2015-06-22 14:13:18 +00:00
|
|
|
|
2015-06-17 18:24:48 +00:00
|
|
|
void LoadConf() {
|
2015-06-22 14:13:18 +00:00
|
|
|
HKEY myKey;
|
|
|
|
DWORD type, size;
|
|
|
|
|
2015-06-17 18:24:48 +00:00
|
|
|
memset(&config, 0, sizeof(config));
|
|
|
|
strcpy(config.Hdd, HDD_DEF);
|
|
|
|
config.HddSize = 8 * 1024;
|
|
|
|
strcpy(config.Eth, ETH_DEF);
|
|
|
|
|
2015-06-22 14:13:18 +00:00
|
|
|
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\DEV9\\DEV9linuz", 0, KEY_ALL_ACCESS, &myKey)!=ERROR_SUCCESS) {
|
|
|
|
LoadIniConf();
|
2015-06-17 18:24:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-22 14:13:18 +00:00
|
|
|
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();
|
2015-06-17 18:24:48 +00:00
|
|
|
}
|
2013-03-19 22:01:41 +00:00
|
|
|
|