Skip to content
Permalink
Browse files

Simplify openIniFile to use ShellExecute so .ini files get opened in …

…an associated text editor

This is safe, because by default .ini files are associated with Notepad
  • Loading branch information...
CookiePLMonster committed Aug 15, 2019
1 parent 3356f94 commit abdf685ac9df3aaa7664e76354c1163fc4e617f9
Showing with 4 additions and 32 deletions.
  1. +3 −31 Common/FileUtil.cpp
  2. +1 −1 Common/FileUtil.h
@@ -763,43 +763,15 @@ void CopyDir(const std::string &source_path, const std::string &dest_path)
#endif
}

void openIniFile(const std::string fileName) {
std::string iniFile;
void openIniFile(const std::string& fileName) {
#if defined(_WIN32)
#if PPSSPP_PLATFORM(UWP)
// Do nothing.
#else
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{};
si.cb = sizeof(si);
si.wShowWindow = SW_SHOW;
PROCESS_INFORMATION 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);
ShellExecuteW(nullptr, L"open", ConvertUTF8ToWString(fileName).c_str(), nullptr, nullptr, SW_SHOW);
#endif
#elif !defined(MOBILE_DEVICE)
std::string iniFile;
#if defined(__APPLE__)
iniFile = "open ";
#else
@@ -117,7 +117,7 @@ std::string GetCurrentDir();
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);
void openIniFile(const std::string& fileName);

// Set the current directory to given directory
bool SetCurrentDir(const std::string &directory);

0 comments on commit abdf685

Please sign in to comment.
You can’t perform that action at this time.