winport: path settings support unicode now (fixes #669). old ini files may malfunction since they're now expected to be written with unicode. old ones can't be effectively upgraded (consequence of using obsolete ini file apis).

This commit is contained in:
zeromus 2023-05-28 14:21:21 -04:00
parent 3cefa5d78e
commit 3511e14ac6
9 changed files with 135 additions and 89 deletions

View File

@ -272,7 +272,7 @@ void HK_PrintScreen(int param, bool justPressed)
dir = Path::GetFileDirectoryPath(outFilename); dir = Path::GetFileDirectoryPath(outFilename);
path.setpath(path.SCREENSHOTS, dir); path.setpath(path.SCREENSHOTS, dir);
WritePrivateProfileString(SECTION, SCREENSHOTKEY, dir.c_str(), IniName); WritePrivateProfileStringW(LSECTION, SCREENSHOTKEY, mbstowcs(dir).c_str(), IniNameW);
} }
if(unpause) NDS_UnPause(false); if(unpause) NDS_UnPause(false);

View File

@ -23,6 +23,7 @@
#include "MMU.h" #include "MMU.h"
#include "NDSSystem.h" #include "NDSSystem.h"
#include "utils/advanscene.h" #include "utils/advanscene.h"
#include "utils/xstring.h"
#include "resource.h" #include "resource.h"
@ -190,7 +191,7 @@ bool importSave(HWND hwnd, HINSTANCE hAppInst)
{ {
std::string dir = Path::GetFileDirectoryPath(SavFName); std::string dir = Path::GetFileDirectoryPath(SavFName);
path.setpath(path.SRAM_IMPORT_EXPORT, dir); path.setpath(path.SRAM_IMPORT_EXPORT, dir);
WritePrivateProfileString(SECTION, SRAMIMPORTKEY, dir.c_str(), IniName); WritePrivateProfileStringW(LSECTION, SRAMIMPORTKEY, mbstowcs(dir).c_str(), IniNameW);
res = MMU_new.backupDevice.importData(SavFName, save_types[res+1].size); res = MMU_new.backupDevice.importData(SavFName, save_types[res+1].size);
if (res) if (res)
@ -227,7 +228,7 @@ bool exportSave(HWND hwnd, HINSTANCE hAppInst)
dir = Path::GetFileDirectoryPath(SavFName); dir = Path::GetFileDirectoryPath(SavFName);
path.setpath(path.SRAM_IMPORT_EXPORT, dir); path.setpath(path.SRAM_IMPORT_EXPORT, dir);
WritePrivateProfileString(SECTION, SRAMIMPORTKEY, dir.c_str(), IniName); WritePrivateProfileStringW(LSECTION, SRAMIMPORTKEY, mbstowcs(dir).c_str(), IniNameW);
if (ofn.nFilterIndex == 2) strcat(SavFName, "*"); if (ofn.nFilterIndex == 2) strcat(SavFName, "*");

View File

@ -2937,7 +2937,7 @@ void AviRecordTo()
dir = Path::GetFileDirectoryPath(outFilename); dir = Path::GetFileDirectoryPath(outFilename);
path.setpath(path.AVI_FILES, dir); path.setpath(path.AVI_FILES, dir);
WritePrivateProfileString(SECTION, AVIKEY, dir.c_str(), IniName); WritePrivateProfileStringW(LSECTION, AVIKEY, mbstowcs(dir).c_str(), IniNameW);
} }
NDS_UnPause(); NDS_UnPause();
@ -3063,7 +3063,7 @@ void WavRecordTo(int wavmode)
dir = Path::GetFileDirectoryPath(outFilename); dir = Path::GetFileDirectoryPath(outFilename);
path.setpath(path.AVI_FILES, dir); path.setpath(path.AVI_FILES, dir);
WritePrivateProfileString(SECTION, AVIKEY, dir.c_str(), IniName); WritePrivateProfileStringW(LSECTION, AVIKEY, mbstowcs(dir).c_str(), IniNameW);
} }
NDS_UnPause(); NDS_UnPause();
@ -3192,7 +3192,7 @@ LRESULT OpenFile()
{ {
std::string dir = Path::GetFileDirectoryPath(wcstombs(filename)); std::string dir = Path::GetFileDirectoryPath(wcstombs(filename));
path.setpath(path.ROMS, dir); path.setpath(path.ROMS, dir);
WritePrivateProfileString(SECTION, ROMKEY, dir.c_str(), IniName); WritePrivateProfileStringW(LSECTION, ROMKEY, mbstowcs(dir).c_str(), IniNameW);
} }
} }
@ -4780,7 +4780,7 @@ DOKEYDOWN:
std::string utf8dir = Path::GetFileDirectoryPath(wcstombs(SavName)); std::string utf8dir = Path::GetFileDirectoryPath(wcstombs(SavName));
path.setpath(path.STATES, utf8dir); path.setpath(path.STATES, utf8dir);
WritePrivateProfileString(SECTION, STATEKEY, utf8dir.c_str(), IniName); WritePrivateProfileStringW(LSECTION, STATEKEY, mbstowcs(utf8dir).c_str(), IniNameW);
savestate_load(wcstombs(SavName).c_str()); savestate_load(wcstombs(SavName).c_str());
UpdateToolWindows(); UpdateToolWindows();
@ -4811,7 +4811,7 @@ DOKEYDOWN:
std::string utf8dir = Path::GetFileDirectoryPath(wcstombs(SavName)); std::string utf8dir = Path::GetFileDirectoryPath(wcstombs(SavName));
path.setpath(path.STATES, utf8dir); path.setpath(path.STATES, utf8dir);
WritePrivateProfileString(SECTION, STATEKEY, utf8dir.c_str(), IniName); WritePrivateProfileStringW(LSECTION, STATEKEY, mbstowcs(utf8dir).c_str(), IniNameW);
if(unpause) NDS_UnPause(); if(unpause) NDS_UnPause();
return 0; return 0;
@ -6174,7 +6174,7 @@ LRESULT CALLBACK EmulationSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, L
{ {
std::string dir = Path::GetFileDirectoryPath(fileName); std::string dir = Path::GetFileDirectoryPath(fileName);
path.setpath(path.FIRMWARE, dir); path.setpath(path.FIRMWARE, dir);
WritePrivateProfileString(SECTION, FIRMWAREKEY, dir.c_str(), IniName); WritePrivateProfileStringW(LSECTION, FIRMWAREKEY, mbstowcs(dir).c_str(), IniNameW);
HWND cur; HWND cur;
@ -6294,7 +6294,7 @@ LRESULT CALLBACK MicrophoneSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
{ {
std::string dir = Path::GetFileDirectoryPath(fileName); std::string dir = Path::GetFileDirectoryPath(fileName);
path.setpath(path.SOUNDS, dir); path.setpath(path.SOUNDS, dir);
WritePrivateProfileString(SECTION, SOUNDKEY, dir.c_str(), IniName); WritePrivateProfileStringW(LSECTION, SOUNDKEY, mbstowcs(dir).c_str(), IniNameW);
HWND cur; HWND cur;

View File

@ -26,6 +26,7 @@
#include "main.h" #include "main.h"
#include "path.h" #include "path.h"
#include "pathsettings.h" #include "pathsettings.h"
#include "utils/xstring.h"
extern bool autoLoadLua; extern bool autoLoadLua;
@ -105,18 +106,18 @@ void DoAssociations()
void WritePathSettings() void WritePathSettings()
{ {
WritePrivateProfileString(SECTION, ROMKEY, path.pathToRoms, IniName); WritePrivateProfileStringW(LSECTION, ROMKEY, mbstowcs((std::string)path.pathToRoms).c_str(), IniNameW);
WritePrivateProfileString(SECTION, BATTERYKEY, path.pathToBattery, IniName); WritePrivateProfileStringW(LSECTION, BATTERYKEY, mbstowcs((std::string)path.pathToBattery).c_str(), IniNameW);
WritePrivateProfileString(SECTION, SRAMIMPORTKEY, path.pathToSramImportExport, IniName); WritePrivateProfileStringW(LSECTION, SRAMIMPORTKEY, mbstowcs((std::string)path.pathToSramImportExport).c_str(), IniNameW);
WritePrivateProfileString(SECTION, STATEKEY, path.pathToStates, IniName); WritePrivateProfileStringW(LSECTION, STATEKEY, mbstowcs((std::string)path.pathToStates).c_str(), IniNameW);
WritePrivateProfileString(SECTION, STATESLOTKEY, path.pathToStateSlots, IniName); WritePrivateProfileStringW(LSECTION, STATESLOTKEY, mbstowcs((std::string)path.pathToStateSlots).c_str(), IniNameW);
WritePrivateProfileString(SECTION, SCREENSHOTKEY, path.pathToScreenshots, IniName); WritePrivateProfileStringW(LSECTION, SCREENSHOTKEY, mbstowcs((std::string)path.pathToScreenshots).c_str(), IniNameW);
WritePrivateProfileString(SECTION, AVIKEY, path.pathToAviFiles, IniName); WritePrivateProfileStringW(LSECTION, AVIKEY, mbstowcs((std::string)path.pathToAviFiles).c_str(), IniNameW);
WritePrivateProfileString(SECTION, CHEATKEY, path.pathToCheats, IniName); WritePrivateProfileStringW(LSECTION, CHEATKEY, mbstowcs((std::string)path.pathToCheats).c_str(), IniNameW);
WritePrivateProfileInt(SECTION, R4FORMATKEY, path.r4Format, IniName); WritePrivateProfileInt(SECTION, R4FORMATKEY, path.r4Format, IniName);
WritePrivateProfileString(SECTION, SOUNDKEY, path.pathToSounds, IniName); WritePrivateProfileStringW(LSECTION, SOUNDKEY, mbstowcs((std::string)path.pathToSounds).c_str(), IniNameW);
WritePrivateProfileString(SECTION, FIRMWAREKEY, path.pathToFirmware, IniName); WritePrivateProfileStringW(LSECTION, FIRMWAREKEY, mbstowcs((std::string)path.pathToFirmware).c_str(), IniNameW);
WritePrivateProfileString(SECTION, LUAKEY, path.pathToLua, IniName); WritePrivateProfileStringW(LSECTION, LUAKEY, mbstowcs((std::string)path.pathToLua).c_str(), IniNameW);
WritePrivateProfileInt(SECTION, DEFAULTFORMATKEY, path.currentimageformat, IniName); WritePrivateProfileInt(SECTION, DEFAULTFORMATKEY, path.currentimageformat, IniName);
WritePrivateProfileString(SECTION, FORMATKEY, path.screenshotFormat, IniName); WritePrivateProfileString(SECTION, FORMATKEY, path.screenshotFormat, IniName);
@ -171,15 +172,15 @@ BOOL PathSettings_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam)
SetWindowPos(toolTip, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); SetWindowPos(toolTip, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
SetDlgItemText(hDlg, IDC_ROMPATHEDIT, path.pathToRoms); SetDlgItemTextW(hDlg, IDC_ROMPATHEDIT, mbstowcs(path.pathToRoms).c_str());
SetDlgItemText(hDlg, IDC_SAVERAMPATHEDIT, path.pathToBattery); SetDlgItemTextW(hDlg, IDC_SAVERAMPATHEDIT, mbstowcs(path.pathToBattery).c_str());
SetDlgItemText(hDlg, IDC_SRAMIMPORTPATHEDIT, path.pathToSramImportExport); SetDlgItemTextW(hDlg, IDC_SRAMIMPORTPATHEDIT, mbstowcs(path.pathToSramImportExport).c_str());
SetDlgItemText(hDlg, IDC_STATEPATHEDIT, path.pathToStates); SetDlgItemTextW(hDlg, IDC_STATEPATHEDIT, mbstowcs(path.pathToStates).c_str());
SetDlgItemText(hDlg, IDC_STATESLOTPATHEDIT, path.pathToStateSlots); SetDlgItemTextW(hDlg, IDC_STATESLOTPATHEDIT, mbstowcs(path.pathToStateSlots).c_str());
SetDlgItemText(hDlg, IDC_SCREENSHOTPATHEDIT, path.pathToScreenshots); SetDlgItemTextW(hDlg, IDC_SCREENSHOTPATHEDIT, mbstowcs(path.pathToScreenshots).c_str());
SetDlgItemText(hDlg, IDC_AVIPATHEDIT, path.pathToAviFiles); SetDlgItemTextW(hDlg, IDC_AVIPATHEDIT, mbstowcs(path.pathToAviFiles).c_str());
SetDlgItemText(hDlg, IDC_CHEATPATHEDIT, path.pathToCheats); SetDlgItemTextW(hDlg, IDC_CHEATPATHEDIT, mbstowcs(path.pathToCheats).c_str());
SetDlgItemText(hDlg, IDC_LUAPATHEDIT, path.pathToLua); SetDlgItemTextW(hDlg, IDC_LUAPATHEDIT, mbstowcs(path.pathToLua).c_str());
TOOLINFO ti; TOOLINFO ti;
ZeroMemory(&ti, sizeof(ti)); ZeroMemory(&ti, sizeof(ti));
@ -213,7 +214,7 @@ BOOL BrowseForPath(char *pathToBrowse)
LPMALLOC shMalloc; LPMALLOC shMalloc;
BOOL changed = false; BOOL changed = false;
LPITEMIDLIST idList; LPITEMIDLIST idList;
BROWSEINFO bi; BROWSEINFOW bi;
//stupid shell //stupid shell
if(SHGetMalloc( &shMalloc) != S_OK) if(SHGetMalloc( &shMalloc) != S_OK)
@ -226,7 +227,7 @@ BOOL BrowseForPath(char *pathToBrowse)
strncpy(tmp, pathToBrowse, MAX_PATH); strncpy(tmp, pathToBrowse, MAX_PATH);
bi.hwndOwner = MainWindow->getHWnd(); bi.hwndOwner = MainWindow->getHWnd();
bi.lpszTitle = "Choose a Folder"; bi.lpszTitle = L"Choose a Folder";
bi.ulFlags = BIF_NONEWFOLDERBUTTON | BIF_USENEWUI; bi.ulFlags = BIF_NONEWFOLDERBUTTON | BIF_USENEWUI;
/*wanted to add a callback function for the folder initialization but it crashes everytime i do /*wanted to add a callback function for the folder initialization but it crashes everytime i do
@ -234,10 +235,12 @@ BOOL BrowseForPath(char *pathToBrowse)
bi.lParam = (LPARAM)pathToBrowse; bi.lParam = (LPARAM)pathToBrowse;
*/ */
if( (idList = SHBrowseForFolder(&bi)) ) if( (idList = SHBrowseForFolderW(&bi)) )
{ {
changed = true; changed = true;
SHGetPathFromIDList(idList, pathToBrowse); wchar_t wPathToBrowse[MAX_PATH];
SHGetPathFromIDListW(idList, wPathToBrowse);
strcpy(pathToBrowse,wcstombs((std::wstring)wPathToBrowse).c_str());
// shMalloc->Free(&idList); // shMalloc->Free(&idList);
} }
@ -252,49 +255,49 @@ void PathSettings_OnCommand(HWND hDlg, int id, HWND hwndCtl, UINT codeNotify)
case IDC_BROWSEROMS: case IDC_BROWSEROMS:
{ {
if(BrowseForPath(path.pathToRoms)) if(BrowseForPath(path.pathToRoms))
SetDlgItemText(hDlg, IDC_ROMPATHEDIT, path.pathToRoms); SetDlgItemTextW(hDlg, IDC_ROMPATHEDIT, mbstowcs((std::string)path.pathToRoms).c_str());
} }
break; break;
case IDC_BROWSESRAM: case IDC_BROWSESRAM:
{ {
if(BrowseForPath(path.pathToBattery)) if(BrowseForPath(path.pathToBattery))
SetDlgItemText(hDlg, IDC_SAVERAMPATHEDIT, path.pathToBattery); SetDlgItemTextW(hDlg, IDC_SAVERAMPATHEDIT, mbstowcs((std::string)path.pathToBattery).c_str());
} }
break; break;
case IDC_BROWSESRAMIMPORT: case IDC_BROWSESRAMIMPORT:
{ {
if(BrowseForPath(path.pathToSramImportExport)) if(BrowseForPath(path.pathToSramImportExport))
SetDlgItemText(hDlg, IDC_SRAMIMPORTPATHEDIT, path.pathToSramImportExport); SetDlgItemTextW(hDlg, IDC_SRAMIMPORTPATHEDIT, mbstowcs((std::string)path.pathToSramImportExport).c_str());
} }
break; break;
case IDC_BROWSESTATES: case IDC_BROWSESTATES:
{ {
if(BrowseForPath(path.pathToStates)) if(BrowseForPath(path.pathToStates))
SetDlgItemText(hDlg, IDC_STATEPATHEDIT, path.pathToStates); SetDlgItemTextW(hDlg, IDC_STATEPATHEDIT, mbstowcs((std::string)path.pathToStates).c_str());
} }
break; break;
case IDC_BROWSESTATESLOTS: case IDC_BROWSESTATESLOTS:
{ {
if(BrowseForPath(path.pathToStateSlots)) if(BrowseForPath(path.pathToStateSlots))
SetDlgItemText(hDlg, IDC_STATESLOTPATHEDIT, path.pathToStateSlots); SetDlgItemTextW(hDlg, IDC_STATESLOTPATHEDIT, mbstowcs((std::string)path.pathToStateSlots).c_str());
} }
break; break;
case IDC_BROWSESCREENSHOTS: case IDC_BROWSESCREENSHOTS:
{ {
if(BrowseForPath(path.pathToScreenshots)) if(BrowseForPath(path.pathToScreenshots))
SetDlgItemText(hDlg, IDC_SCREENSHOTPATHEDIT, path.pathToScreenshots); SetDlgItemTextW(hDlg, IDC_SCREENSHOTPATHEDIT, mbstowcs((std::string)path.pathToScreenshots).c_str());
} }
break; break;
case IDC_BROWSEAVI: case IDC_BROWSEAVI:
{ {
if(BrowseForPath(path.pathToAviFiles)) if(BrowseForPath(path.pathToAviFiles))
SetDlgItemText(hDlg, IDC_AVIPATHEDIT, path.pathToAviFiles); SetDlgItemTextW(hDlg, IDC_AVIPATHEDIT, mbstowcs((std::string)path.pathToAviFiles).c_str());
} }
break; break;
case IDC_BROWSECHEATS: case IDC_BROWSECHEATS:
{ {
if(BrowseForPath(path.pathToCheats)) if(BrowseForPath(path.pathToCheats))
SetDlgItemText(hDlg, IDC_CHEATPATHEDIT, path.pathToCheats); SetDlgItemTextW(hDlg, IDC_CHEATPATHEDIT, mbstowcs((std::string)path.pathToCheats).c_str());
} }
break; break;
case IDC_R4TYPE1: case IDC_R4TYPE1:
@ -356,15 +359,16 @@ void PathSettings_OnCommand(HWND hDlg, int id, HWND hwndCtl, UINT codeNotify)
break; break;
case IDOK: case IDOK:
GetDlgItemText(hDlg, IDC_ROMPATHEDIT, path.pathToRoms, MAX_PATH); wchar_t wtmp[MAX_PATH];
GetDlgItemText(hDlg, IDC_SAVERAMPATHEDIT, path.pathToBattery, MAX_PATH); GetDlgItemTextW(hDlg, IDC_ROMPATHEDIT, wtmp, MAX_PATH); strcpy(path.pathToRoms,wcstombs((std::wstring)wtmp).c_str());
GetDlgItemText(hDlg, IDC_SRAMIMPORTPATHEDIT, path.pathToSramImportExport, MAX_PATH); GetDlgItemTextW(hDlg, IDC_SAVERAMPATHEDIT, wtmp, MAX_PATH); strcpy(path.pathToBattery,wcstombs((std::wstring)wtmp).c_str());
GetDlgItemText(hDlg, IDC_STATEPATHEDIT, path.pathToStates, MAX_PATH); GetDlgItemTextW(hDlg, IDC_SRAMIMPORTPATHEDIT, wtmp, MAX_PATH); strcpy(path.pathToSramImportExport,wcstombs((std::wstring)wtmp).c_str());
GetDlgItemText(hDlg, IDC_STATESLOTPATHEDIT, path.pathToStateSlots, MAX_PATH); GetDlgItemTextW(hDlg, IDC_STATEPATHEDIT, wtmp, MAX_PATH); strcpy(path.pathToStates,wcstombs((std::wstring)wtmp).c_str());
GetDlgItemText(hDlg, IDC_SCREENSHOTPATHEDIT, path.pathToScreenshots, MAX_PATH); GetDlgItemTextW(hDlg, IDC_STATESLOTPATHEDIT, wtmp, MAX_PATH); strcpy(path.pathToStateSlots,wcstombs((std::wstring)wtmp).c_str());
GetDlgItemText(hDlg, IDC_AVIPATHEDIT, path.pathToAviFiles, MAX_PATH); GetDlgItemTextW(hDlg, IDC_SCREENSHOTPATHEDIT, wtmp, MAX_PATH); strcpy(path.pathToScreenshots,wcstombs((std::wstring)wtmp).c_str());
GetDlgItemText(hDlg, IDC_CHEATPATHEDIT, path.pathToCheats, MAX_PATH); GetDlgItemTextW(hDlg, IDC_AVIPATHEDIT, wtmp, MAX_PATH); strcpy(path.pathToAviFiles,wcstombs((std::wstring)wtmp).c_str());
GetDlgItemText(hDlg, IDC_LUAPATHEDIT, path.pathToLua, MAX_PATH); GetDlgItemTextW(hDlg, IDC_CHEATPATHEDIT, wtmp, MAX_PATH); strcpy(path.pathToCheats,wcstombs((std::wstring)wtmp).c_str());
GetDlgItemTextW(hDlg, IDC_LUAPATHEDIT, wtmp, MAX_PATH); strcpy(path.pathToLua,wcstombs((std::wstring)wtmp).c_str());
DoAssociations(); DoAssociations();
WritePathSettings(); WritePathSettings();
EndDialog(hDlg, 0); EndDialog(hDlg, 0);

View File

@ -25,6 +25,7 @@
#include "debug.h" #include "debug.h"
#include "NDSSystem.h" #include "NDSSystem.h"
#include "path.h" #include "path.h"
#include "utils/xstring.h"
#include "resource.h" #include "resource.h"
#include "main.h" #include "main.h"
@ -346,7 +347,7 @@ void slot1Dialog(HWND hwnd)
if (strlen(tmp_fs_path)) if (strlen(tmp_fs_path))
{ {
path.setpath(path.SLOT1D, tmp_fs_path); path.setpath(path.SLOT1D, tmp_fs_path);
WritePrivateProfileString(SECTION, SLOT1DKEY, path.pathToSlot1D, IniName); WritePrivateProfileStringW(LSECTION, SLOT1DKEY, mbstowcs((std::string)path.pathToSlot1D).c_str(), IniNameW);
} }
break; break;
default: default:

View File

@ -26,6 +26,7 @@
char IniName[MAX_PATH]; char IniName[MAX_PATH];
wchar_t IniNameW[MAX_PATH];
std::string _hack_alternateModulePathUtf8; std::string _hack_alternateModulePathUtf8;
@ -86,6 +87,21 @@ void GetINIPath()
} }
FCEUD_MakePathDirs(IniName); FCEUD_MakePathDirs(IniName);
wcscpy(IniNameW,mbstowcs(IniName).c_str()); //careful to use locale C-style mbstowcs to get IniName (which is with locale encoding) to unicode
//write BOM to get unicode
FILE* test = fopen(IniName,"rb");
if(test)
fclose(test);
else
{
test = fopen(IniName,"wb");
if(test)
{
fputs("\xFF\xFE",test);
fclose(test);
}
}
} }
void PreventScreensaver() void PreventScreensaver()

View File

@ -23,6 +23,7 @@
#include <string> #include <string>
extern char IniName[MAX_PATH]; extern char IniName[MAX_PATH];
extern wchar_t IniNameW[MAX_PATH];
void GetINIPath(); void GetINIPath();
void PreventScreensaver(); void PreventScreensaver();

View File

@ -232,6 +232,25 @@ void PathInfo::GetDefaultPath(char *pathToDefault, const char *key, int maxCount
#endif #endif
} }
void PathInfo::ReadKeyW(char *pathToRead, const wchar_t *key)
{
wchar_t wpath[MAX_PATH];
#ifdef HOST_WINDOWS
GetPrivateProfileStringW(LSECTION, key, key, wpath, MAX_PATH, IniNameW);
if (wcscmp(wpath, key) == 0) {
//since the variables are all intialized in this file they all use MAX_PATH
char temppath[MAX_PATH];
temppath[0] = 0;
GetDefaultPath(temppath, wcstombs((std::wstring)key).c_str(), MAX_PATH);
wcscpy(wpath,mbstowcs((std::string)temppath).c_str());
}
strcpy(pathToRead,wcstombs((std::wstring)wpath).c_str());
#else
//since the variables are all intialized in this file they all use MAX_PATH
GetDefaultPath(pathToRead, key, MAX_PATH);
#endif
}
void PathInfo::ReadKey(char *pathToRead, const char *key) void PathInfo::ReadKey(char *pathToRead, const char *key)
{ {
#ifdef HOST_WINDOWS #ifdef HOST_WINDOWS
@ -251,18 +270,18 @@ void PathInfo::ReadPathSettings()
if ((strcmp(pathToModule, "") == 0) || !pathToModule) if ((strcmp(pathToModule, "") == 0) || !pathToModule)
LoadModulePath(); LoadModulePath();
ReadKey(pathToRoms, ROMKEY); ReadKeyW(pathToRoms, ROMKEY);
ReadKey(pathToBattery, BATTERYKEY); ReadKeyW(pathToBattery, BATTERYKEY);
ReadKey(pathToSramImportExport, SRAMIMPORTKEY); ReadKeyW(pathToSramImportExport, SRAMIMPORTKEY);
ReadKey(pathToStates, STATEKEY); ReadKeyW(pathToStates, STATEKEY);
ReadKey(pathToStateSlots, STATESLOTKEY); ReadKeyW(pathToStateSlots, STATESLOTKEY);
ReadKey(pathToScreenshots, SCREENSHOTKEY); ReadKeyW(pathToScreenshots, SCREENSHOTKEY);
ReadKey(pathToAviFiles, AVIKEY); ReadKeyW(pathToAviFiles, AVIKEY);
ReadKey(pathToCheats, CHEATKEY); ReadKeyW(pathToCheats, CHEATKEY);
ReadKey(pathToSounds, SOUNDKEY); ReadKeyW(pathToSounds, SOUNDKEY);
ReadKey(pathToFirmware, FIRMWAREKEY); ReadKeyW(pathToFirmware, FIRMWAREKEY);
ReadKey(pathToLua, LUAKEY); ReadKeyW(pathToLua, LUAKEY);
ReadKey(pathToSlot1D, SLOT1DKEY); ReadKeyW(pathToSlot1D, SLOT1DKEY);
#ifdef HOST_WINDOWS #ifdef HOST_WINDOWS
GetPrivateProfileString(SECTION, FORMATKEY, "%f_%s_%r", screenshotFormat, MAX_FORMAT, IniName); GetPrivateProfileString(SECTION, FORMATKEY, "%f_%s_%r", screenshotFormat, MAX_FORMAT, IniName);
savelastromvisit = GetPrivateProfileBool(SECTION, LASTVISITKEY, true, IniName); savelastromvisit = GetPrivateProfileBool(SECTION, LASTVISITKEY, true, IniName);

View File

@ -69,24 +69,25 @@ public:
#define MAX_FORMAT 20 #define MAX_FORMAT 20
#define SECTION "PathSettings" #define SECTION "PathSettings"
#define LSECTION L"PathSettings"
#define ROMKEY "Roms" #define ROMKEY L"Roms"
#define BATTERYKEY "Battery" #define BATTERYKEY L"Battery"
#define SRAMIMPORTKEY "SramImportExport" #define SRAMIMPORTKEY L"SramImportExport"
#define STATEKEY "States" #define STATEKEY L"States"
#define STATESLOTKEY "StateSlots" #define STATESLOTKEY L"StateSlots"
#define SCREENSHOTKEY "Screenshots" #define SCREENSHOTKEY L"Screenshots"
#define AVIKEY "AviFiles" #define AVIKEY L"AviFiles"
#define CHEATKEY "Cheats" #define CHEATKEY L"Cheats"
#define R4FORMATKEY "R4format" #define R4FORMATKEY "R4format"
#define SOUNDKEY "SoundSamples" #define SOUNDKEY L"SoundSamples"
#define FIRMWAREKEY "Firmware" #define FIRMWAREKEY L"Firmware"
#define FORMATKEY "format" #define FORMATKEY "format"
#define DEFAULTFORMATKEY "defaultFormat" #define DEFAULTFORMATKEY "defaultFormat"
#define NEEDSSAVINGKEY "needsSaving" #define NEEDSSAVINGKEY "needsSaving"
#define LASTVISITKEY "lastVisit" #define LASTVISITKEY "lastVisit"
#define LUAKEY "Lua" #define LUAKEY L"Lua"
#define SLOT1DKEY "Slot1D" #define SLOT1DKEY L"Slot1D"
char screenshotFormat[MAX_FORMAT]; char screenshotFormat[MAX_FORMAT];
bool savelastromvisit; bool savelastromvisit;
@ -108,19 +109,21 @@ public:
MAXKNOWNPATH = MODULE MAXKNOWNPATH = MODULE
}; };
char pathToRoms[MAX_PATH]; //ALL UTF8, NOT SYSTEM LOCALE!! BLEGH!
char pathToBattery[MAX_PATH]; //should probably have set locale to utf-8 but it's too late for that
char pathToSramImportExport[MAX_PATH]; char pathToRoms[MAX_PATH*8];
char pathToStates[MAX_PATH]; char pathToBattery[MAX_PATH*8];
char pathToStateSlots[MAX_PATH]; char pathToSramImportExport[MAX_PATH*8];
char pathToScreenshots[MAX_PATH]; char pathToStates[MAX_PATH*8];
char pathToAviFiles[MAX_PATH]; char pathToStateSlots[MAX_PATH*8];
char pathToCheats[MAX_PATH]; char pathToScreenshots[MAX_PATH*8];
char pathToSounds[MAX_PATH]; char pathToAviFiles[MAX_PATH*8];
char pathToFirmware[MAX_PATH]; char pathToCheats[MAX_PATH*8];
char pathToModule[MAX_PATH]; char pathToSounds[MAX_PATH*8];
char pathToLua[MAX_PATH]; char pathToFirmware[MAX_PATH*8];
char pathToSlot1D[MAX_PATH]; char pathToModule[MAX_PATH*8];
char pathToLua[MAX_PATH*8];
char pathToSlot1D[MAX_PATH*8];
void init(const char *filename); void init(const char *filename);
@ -135,6 +138,7 @@ public:
void GetDefaultPath(char *pathToDefault, const char *key, int maxCount); void GetDefaultPath(char *pathToDefault, const char *key, int maxCount);
void ReadKey(char *pathToRead, const char *key); void ReadKey(char *pathToRead, const char *key);
void ReadKeyW(char *pathToRead, const wchar_t *key);
void ReadPathSettings(); void ReadPathSettings();