mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Create openIniFile function in FileUtil to avoid duplicates
+ correction
This commit is contained in:
parent
434c95700e
commit
24fd336e60
4 changed files with 55 additions and 93 deletions
|
@ -680,6 +680,55 @@ void CopyDir(const std::string &source_path, const std::string &dest_path)
|
|||
#endif
|
||||
}
|
||||
|
||||
void openIniFile(const std::string fileName) {
|
||||
std::string iniFile;
|
||||
#if defined(_WIN32)
|
||||
iniFile = fileName;
|
||||
// Can't rely on a .txt file extension to auto-open in the right editor,
|
||||
// so let's find notepad
|
||||
wchar_t notepad_path[MAX_PATH + 1];
|
||||
GetSystemDirectory(notepad_path, MAX_PATH);
|
||||
wcscat(notepad_path, L"\\notepad.exe");
|
||||
|
||||
wchar_t ini_path[MAX_PATH + 1] = { 0 };
|
||||
wcsncpy(ini_path, ConvertUTF8ToWString(iniFile).c_str(), MAX_PATH);
|
||||
// Flip any slashes...
|
||||
for (size_t i = 0; i < wcslen(ini_path); i++) {
|
||||
if (ini_path[i] == '/')
|
||||
ini_path[i] = '\\';
|
||||
}
|
||||
|
||||
// One for the space, one for the null.
|
||||
wchar_t command_line[MAX_PATH * 2 + 1 + 1];
|
||||
wsprintf(command_line, L"%s %s", notepad_path, ini_path);
|
||||
|
||||
STARTUPINFO si;
|
||||
memset(&si, 0, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
si.wShowWindow = SW_SHOW;
|
||||
PROCESS_INFORMATION pi;
|
||||
memset(&pi, 0, sizeof(pi));
|
||||
UINT retval = CreateProcess(0, command_line, 0, 0, 0, 0, 0, 0, &si, &pi);
|
||||
if (!retval) {
|
||||
ERROR_LOG(COMMON, "Failed creating notepad process");
|
||||
}
|
||||
CloseHandle(pi.hThread);
|
||||
CloseHandle(pi.hProcess);
|
||||
#elif !defined(MOBILE_DEVICE)
|
||||
#if defined(__APPLE__)
|
||||
iniFile = "open ";
|
||||
#else
|
||||
iniFile = "xdg-open ";
|
||||
#endif
|
||||
iniFile.append(fileName);
|
||||
NOTICE_LOG(BOOT, "Launching %s", iniFile.c_str());
|
||||
int retval = system(iniFile.c_str());
|
||||
if (retval != 0) {
|
||||
ERROR_LOG(COMMON, "Failed to launch ini file");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Returns the current directory
|
||||
std::string GetCurrentDir()
|
||||
{
|
||||
|
|
|
@ -113,6 +113,9 @@ std::string GetCurrentDir();
|
|||
// Create directory and copy contents (does not overwrite existing files)
|
||||
void CopyDir(const std::string &source_path, const std::string &dest_path);
|
||||
|
||||
// Opens ini file (cheats, texture replacements etc.)
|
||||
void openIniFile(const std::string fileName);
|
||||
|
||||
// Set the current directory to given directory
|
||||
bool SetCurrentDir(const std::string &directory);
|
||||
|
||||
|
|
|
@ -172,57 +172,12 @@ UI::EventReturn CwCheatScreen::OnAddCheat(UI::EventParams ¶ms) {
|
|||
}
|
||||
|
||||
UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams ¶ms) {
|
||||
std::string cheatFile;
|
||||
g_Config.bReloadCheats = true;
|
||||
if (MIPSComp::jit) {
|
||||
MIPSComp::jit->ClearCache();
|
||||
}
|
||||
screenManager()->finishDialog(this, DR_OK);
|
||||
#ifdef _WIN32
|
||||
cheatFile = activeCheatFile;
|
||||
// Can't rely on a .txt file extension to auto-open in the right editor,
|
||||
// so let's find notepad
|
||||
wchar_t notepad_path[MAX_PATH + 1];
|
||||
GetSystemDirectory(notepad_path, MAX_PATH);
|
||||
wcscat(notepad_path, L"\\notepad.exe");
|
||||
|
||||
wchar_t cheat_path[MAX_PATH + 1] = {0};
|
||||
wcsncpy(cheat_path, ConvertUTF8ToWString(cheatFile).c_str(), MAX_PATH);
|
||||
// Flip any slashes...
|
||||
for (size_t i = 0; i < wcslen(cheat_path); i++) {
|
||||
if (cheat_path[i] == '/')
|
||||
cheat_path[i] = '\\';
|
||||
}
|
||||
|
||||
// One for the space, one for the null.
|
||||
wchar_t command_line[MAX_PATH * 2 + 1 + 1];
|
||||
wsprintf(command_line, L"%s %s", notepad_path, cheat_path);
|
||||
|
||||
STARTUPINFO si;
|
||||
memset(&si, 0, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
si.wShowWindow = SW_SHOW;
|
||||
PROCESS_INFORMATION pi;
|
||||
memset(&pi, 0, sizeof(pi));
|
||||
UINT retval = CreateProcess(0, command_line, 0, 0, 0, 0, 0, 0, &si, &pi);
|
||||
if (!retval) {
|
||||
ERROR_LOG(COMMON, "Failed creating notepad process");
|
||||
}
|
||||
CloseHandle(pi.hThread);
|
||||
CloseHandle(pi.hProcess);
|
||||
#elif !defined(MOBILE_DEVICE)
|
||||
#if defined(__APPLE__)
|
||||
cheatFile = "open ";
|
||||
#else
|
||||
cheatFile = "xdg-open ";
|
||||
#endif
|
||||
cheatFile.append(activeCheatFile);
|
||||
NOTICE_LOG(BOOT, "Launching %s", cheatFile.c_str());
|
||||
int retval = system(cheatFile.c_str());
|
||||
if (retval != 0) {
|
||||
ERROR_LOG(COMMON, "Failed to launch cheat file");
|
||||
}
|
||||
#endif
|
||||
File::openIniFile(activeCheatFile);
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
|
|
|
@ -1158,7 +1158,7 @@ UI::EventReturn DeveloperToolsScreen::OnOpenTexturesIniFile(UI::EventParams &e)
|
|||
fclose(f);
|
||||
// Let's also write some defaults
|
||||
std::fstream fs;
|
||||
File::OpenCPPFile(fs, texturesDirectory + "textures.ini", std::ios::out);
|
||||
File::OpenCPPFile(fs, texturesDirectory + "textures.ini", std::ios::out | std::ios::ate);
|
||||
fs << "# This file is optional\n";
|
||||
fs << "# for syntax explanation check:\n";
|
||||
fs << "# - https://github.com/hrydgard/ppsspp/pull/8715 \n";
|
||||
|
@ -1176,52 +1176,7 @@ UI::EventReturn DeveloperToolsScreen::OnOpenTexturesIniFile(UI::EventParams &e)
|
|||
enabled_ = File::Exists(texturesDirectory + "textures.ini");
|
||||
}
|
||||
if (enabled_) {
|
||||
std::string texturesIniFile;
|
||||
#if defined(_WIN32)
|
||||
texturesIniFile = texturesDirectory + "textures.ini";
|
||||
// Can't rely on a .txt file extension to auto-open in the right editor,
|
||||
// so let's find notepad
|
||||
wchar_t notepad_path[MAX_PATH + 1];
|
||||
GetSystemDirectory(notepad_path, MAX_PATH);
|
||||
wcscat(notepad_path, L"\\notepad.exe");
|
||||
|
||||
wchar_t ini_path[MAX_PATH + 1] = { 0 };
|
||||
wcsncpy(ini_path, ConvertUTF8ToWString(texturesIniFile).c_str(), MAX_PATH);
|
||||
// Flip any slashes...
|
||||
for (size_t i = 0; i < wcslen(ini_path); i++) {
|
||||
if (ini_path[i] == '/')
|
||||
ini_path[i] = '\\';
|
||||
}
|
||||
|
||||
// One for the space, one for the null.
|
||||
wchar_t command_line[MAX_PATH * 2 + 1 + 1];
|
||||
wsprintf(command_line, L"%s %s", notepad_path, ini_path);
|
||||
|
||||
STARTUPINFO si;
|
||||
memset(&si, 0, sizeof(si));
|
||||
si.cb = sizeof(si);
|
||||
si.wShowWindow = SW_SHOW;
|
||||
PROCESS_INFORMATION pi;
|
||||
memset(&pi, 0, sizeof(pi));
|
||||
UINT retval = CreateProcess(0, command_line, 0, 0, 0, 0, 0, 0, &si, &pi);
|
||||
if (!retval) {
|
||||
ERROR_LOG(COMMON, "Failed creating notepad process");
|
||||
}
|
||||
CloseHandle(pi.hThread);
|
||||
CloseHandle(pi.hProcess);
|
||||
#elif !defined(MOBILE_DEVICE)
|
||||
#if defined(__APPLE__)
|
||||
texturesIniFile = "open ";
|
||||
#else
|
||||
texturesIniFile = "xdg-open ";
|
||||
#endif
|
||||
texturesIniFile.append(texturesDirectory + "textures.ini");
|
||||
NOTICE_LOG(BOOT, "Launching %s", texturesIniFile.c_str());
|
||||
int retval = system(texturesIniFile.c_str());
|
||||
if (retval != 0) {
|
||||
ERROR_LOG(COMMON, "Failed to launch textures.ini file");
|
||||
}
|
||||
#endif
|
||||
File::openIniFile(texturesDirectory + "textures.ini");
|
||||
}
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue