Skip to content

Commit 9ec7f4d

Browse files
committed
Additional UTF-8 adaptations for ModManager/CheckLogs
1 parent 2dcd774 commit 9ec7f4d

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

src/modmanager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ void ModManagerFrame::OnSearch(wxCommandEvent&) {
924924
void ModManagerFrame::OnSave(wxCommandEvent&) {
925925
wxFileDialog dlg(this, "Save Enabled Mods", "", "", "Text files (*.txt)|*.txt", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
926926
if (dlg.ShowModal() == wxID_OK) {
927-
std::ofstream out(dlg.GetPath().ToUTF8());
927+
std::ofstream out(fs::path(dlg.GetPath().ToStdWstring()));
928928
for (const auto& mod : allMods) {
929929
if (!IsDisabled(mod.folderName)) {
930930
out << wxString(mod.folderName).ToUTF8() << "\n";
@@ -956,7 +956,7 @@ bool ExtractWorkshopId(const std::wstring& input, uint64_t& outId)
956956
void ModManagerFrame::OnLoad(wxCommandEvent&) {
957957
wxFileDialog dlg(this, "Load Enabled Mods", "", "", "Text files (*.txt)|*.txt", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
958958
if (dlg.ShowModal() == wxID_OK) {
959-
std::ifstream in(dlg.GetPath().ToUTF8());
959+
std::ifstream in(fs::path(dlg.GetPath().ToStdWstring()));
960960
std::unordered_set<std::wstring> enabledSet;
961961
std::string line;
962962

src/windows/launcher.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,10 +1008,17 @@ namespace Launcher {
10081008
window.luaDebug->Enable(!_configuration->LuaDebugHasOverride());
10091009
}
10101010

1011-
void ShowFileInExplorer(const std::string& filePath) { //played around a few alternatives I found online, most suggested executing shell scripts....but those are slow as sin and if the user does anything before they execute, the fileexplorer window may not be on focus anymore....so its not ideal
1012-
std::wstring stemp = std::wstring(filePath.begin(), filePath.end());
1011+
std::wstring GetFileAddress(const std::filesystem::path& filePath) {
1012+
return L"file:///" + fs::absolute(filePath).lexically_normal().wstring();
1013+
}
1014+
1015+
void OpenFile(const std::filesystem::path& filePath) {
1016+
wxLaunchDefaultBrowser(GetFileAddress(filePath));
1017+
}
1018+
1019+
void ShowFileInExplorer(const std::filesystem::path& filePath) { //played around a few alternatives I found online, most suggested executing shell scripts....but those are slow as sin and if the user does anything before they execute, the fileexplorer window may not be on focus anymore....so its not ideal
10131020
PIDLIST_ABSOLUTE pidl = nullptr;
1014-
HRESULT hr = SHParseDisplayName(stemp.c_str(), nullptr, &pidl, 0, nullptr);
1021+
HRESULT hr = SHParseDisplayName(GetFileAddress(filePath).c_str(), nullptr, &pidl, 0, nullptr);
10151022
if (SUCCEEDED(hr)) {
10161023
SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0);
10171024
CoTaskMemFree(pidl);
@@ -1029,29 +1036,29 @@ namespace Launcher {
10291036
break;
10301037

10311038
case CHECKLOGS_EVENT_LAUNCHERLOG:
1032-
wxLaunchDefaultBrowser("file:///" + fs::absolute("launcher.log").string());
1039+
OpenFile("launcher.log");
10331040
break;
10341041

10351042
case CHECKLOGS_EVENT_RGONLOG:
1036-
wxLaunchDefaultBrowser("file:///" + fs::absolute(_installation->GetIsaacInstallation()
1037-
.GetRepentogonInstallation().GetExePath()).parent_path().string() + "/repentogon.log");
1043+
OpenFile(_installation->GetIsaacInstallation()
1044+
.GetRepentogonInstallation().GetFolderPath() + "/repentogon.log");
10381045
break;
10391046

10401047
case CHECKLOGS_EVENT_GAMELOG:
1041-
wxLaunchDefaultBrowser("file:///" + _installation->GetIsaacInstallation().GetLogFilePath());
1048+
OpenFile(_installation->GetIsaacInstallation().GetLogFilePath());
10421049
break;
10431050

10441051
case CHECKLOGS_EVENT_LAUNCHERLOG_LOCATE:
1045-
ShowFileInExplorer("file:///" + fs::absolute("launcher.log").string());
1052+
ShowFileInExplorer("launcher.log");
10461053
break;
10471054

10481055
case CHECKLOGS_EVENT_RGONLOG_LOCATE:
1049-
ShowFileInExplorer("file:///" + fs::absolute(_installation->GetIsaacInstallation()
1050-
.GetRepentogonInstallation().GetExePath()).parent_path().string() + "/repentogon.log");
1056+
ShowFileInExplorer(_installation->GetIsaacInstallation()
1057+
.GetRepentogonInstallation().GetFolderPath() + "/repentogon.log");
10511058
break;
10521059

10531060
case CHECKLOGS_EVENT_GAMELOG_LOCATE:
1054-
ShowFileInExplorer("file:///" + _installation->GetIsaacInstallation().GetLogFilePath());
1061+
ShowFileInExplorer(_installation->GetIsaacInstallation().GetLogFilePath());
10551062
break;
10561063

10571064

0 commit comments

Comments
 (0)