From db41390587614d5f3b1936a32bf4c87b6b19c59f Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Sat, 2 Sep 2023 23:17:30 +0200 Subject: [PATCH] BACKENDS: Make browser_lastpath a Path object --- backends/dialogs/amigaos/amigaos-dialogs.cpp | 7 ++++--- backends/dialogs/gtk/gtk-dialogs.cpp | 9 +++++---- backends/dialogs/morphos/morphos-dialogs.cpp | 4 ++-- backends/dialogs/win32/win32-dialogs.cpp | 12 ++++++------ backends/platform/android/android.cpp | 2 +- gui/browser.cpp | 4 ++-- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/backends/dialogs/amigaos/amigaos-dialogs.cpp b/backends/dialogs/amigaos/amigaos-dialogs.cpp index cf9d32fc5d0..0f7fda892b7 100644 --- a/backends/dialogs/amigaos/amigaos-dialogs.cpp +++ b/backends/dialogs/amigaos/amigaos-dialogs.cpp @@ -55,7 +55,7 @@ Common::DialogManager::DialogResult AmigaOSDialogManager::showFileBrowser(const struct FileRequester *fr = nullptr; if (ConfMan.hasKey("browser_lastpath")) { - strncpy(pathBuffer, ConfMan.get("browser_lastpath").c_str(), sizeof(pathBuffer) - 1); + strncpy(pathBuffer, ConfMan.getPath("browser_lastpath").toString(Common::Path::kNativeSeparator).c_str(), sizeof(pathBuffer) - 1); } fr = (struct FileRequester *)IAsl->AllocAslRequestTags(ASL_FileRequest, TAG_DONE); @@ -70,8 +70,9 @@ Common::DialogManager::DialogResult AmigaOSDialogManager::showFileBrowser(const if (!isDirBrowser) { IDOS->AddPart(pathBuffer, fr->fr_File, sizeof(pathBuffer)); } - choice = Common::FSNode(pathBuffer); - ConfMan.set("browser_lastpath", pathBuffer); + Common::Path path(pathBuffer); + choice = Common::FSNode(path); + ConfMan.setPath("browser_lastpath", path); result = kDialogOk; } IAsl->FreeAslRequest((APTR)fr); diff --git a/backends/dialogs/gtk/gtk-dialogs.cpp b/backends/dialogs/gtk/gtk-dialogs.cpp index 8bbbb13c048..8aa3e867cf5 100644 --- a/backends/dialogs/gtk/gtk-dialogs.cpp +++ b/backends/dialogs/gtk/gtk-dialogs.cpp @@ -83,7 +83,7 @@ Common::DialogManager::DialogResult GtkDialogManager::showFileBrowser(const Comm // Customize dialog gtk_file_chooser_set_show_hidden(chooser, ConfMan.getBool("gui_browser_show_hidden", Common::ConfigManager::kApplicationDomain)); if (ConfMan.hasKey("browser_lastpath")) { - gtk_file_chooser_set_current_folder(chooser, ConfMan.get("browser_lastpath").c_str()); + gtk_file_chooser_set_current_folder(chooser, ConfMan.getPath("browser_lastpath").toString(Common::Path::kNativeSeparator).c_str()); } // Show dialog @@ -99,11 +99,12 @@ Common::DialogManager::DialogResult GtkDialogManager::showFileBrowser(const Comm #endif if (res == GTK_RESPONSE_ACCEPT) { // Get the selection from the user - char *path = gtk_file_chooser_get_filename(chooser); + char *pathS = gtk_file_chooser_get_filename(chooser); + Common::Path path(pathS, Common::Path::kNativeSeparator); choice = Common::FSNode(path); - ConfMan.set("browser_lastpath", path); + ConfMan.setPath("browser_lastpath", path); result = kDialogOk; - g_free(path); + g_free(pathS); } _inDialog = FALSE; diff --git a/backends/dialogs/morphos/morphos-dialogs.cpp b/backends/dialogs/morphos/morphos-dialogs.cpp index 2029b7420da..9c70d5afd8f 100644 --- a/backends/dialogs/morphos/morphos-dialogs.cpp +++ b/backends/dialogs/morphos/morphos-dialogs.cpp @@ -46,7 +46,7 @@ Common::DialogManager::DialogResult MorphosDialogManager::showFileBrowser(const struct FileRequester *fr = NULL; if (ConfMan.hasKey("browser_lastpath")) { - strncpy(pathBuffer, ConfMan.get("browser_lastpath").c_str(), sizeof(pathBuffer) - 1); + strncpy(pathBuffer, ConfMan.getPath("browser_lastpath").toString(Common::Path::kNativeSeparator).c_str(), sizeof(pathBuffer) - 1); } fr = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest, TAG_DONE); @@ -58,7 +58,7 @@ Common::DialogManager::DialogResult MorphosDialogManager::showFileBrowser(const if (strlen(fr->fr_Drawer) < sizeof(pathBuffer)) { strncpy(pathBuffer, fr->fr_Drawer, sizeof(pathBuffer)); - ConfMan.set("browser_lastpath", pathBuffer); // only path + ConfMan.setPath("browser_lastpath", pathBuffer); // only path if (!isDirBrowser) { AddPart(pathBuffer, fr->fr_File, sizeof(pathBuffer)); } diff --git a/backends/dialogs/win32/win32-dialogs.cpp b/backends/dialogs/win32/win32-dialogs.cpp index 55e443536fb..edb36334c24 100644 --- a/backends/dialogs/win32/win32-dialogs.cpp +++ b/backends/dialogs/win32/win32-dialogs.cpp @@ -87,12 +87,12 @@ HRESULT winCreateItemFromParsingName(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, return func(pszPath, pbc, riid, ppv); } -HRESULT getShellPath(IShellItem *item, Common::String &path) { +HRESULT getShellPath(IShellItem *item, Common::Path &path) { LPWSTR name = nullptr; HRESULT hr = item->GetDisplayName(SIGDN_FILESYSPATH, &name); if (SUCCEEDED(hr)) { char *str = Win32::unicodeToAnsi(name); - path = Common::String(str); + path = Common::Path(str, Common::Path::kNativeSeparator); CoTaskMemFree(name); free(str); } @@ -139,7 +139,7 @@ Common::DialogManager::DialogResult Win32DialogManager::showFileBrowser(const Co LPWSTR str; if (ConfMan.hasKey("browser_lastpath")) { - str = Win32::ansiToUnicode(ConfMan.get("browser_lastpath").c_str()); + str = Win32::ansiToUnicode(ConfMan.getPath("browser_lastpath").toString(Common::Path::kNativeSeparator).c_str()); IShellItem *item = nullptr; hr = winCreateItemFromParsingName(str, nullptr, IID_IShellItem, reinterpret_cast (&(item))); if (SUCCEEDED(hr)) { @@ -156,7 +156,7 @@ Common::DialogManager::DialogResult Win32DialogManager::showFileBrowser(const Co IShellItem *selectedItem = nullptr; hr = dialog->GetResult(&selectedItem); if (SUCCEEDED(hr)) { - Common::String path; + Common::Path path; hr = getShellPath(selectedItem, path); if (SUCCEEDED(hr)) { choice = Common::FSNode(path); @@ -169,10 +169,10 @@ Common::DialogManager::DialogResult Win32DialogManager::showFileBrowser(const Co IShellItem *lastFolder = nullptr; hr = dialog->GetFolder(&lastFolder); if (SUCCEEDED(hr)) { - Common::String path; + Common::Path path; hr = getShellPath(lastFolder, path); if (SUCCEEDED(hr)) { - ConfMan.set("browser_lastpath", path); + ConfMan.setPath("browser_lastpath", path); } lastFolder->Release(); } diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index f945cc183e1..fb01783888e 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -524,7 +524,7 @@ void OSystem_Android::initBackend() { } if (!ConfMan.hasKey("browser_lastpath")) { - ConfMan.set("browser_lastpath", "/"); + ConfMan.setPath("browser_lastpath", "/"); } if (!ConfMan.hasKey("gui_scale")) { diff --git a/gui/browser.cpp b/gui/browser.cpp index 418f970193e..3c1a0a94a9c 100644 --- a/gui/browser.cpp +++ b/gui/browser.cpp @@ -186,12 +186,12 @@ void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data void BrowserDialog::updateListing() { // Update the path display - _currentPath->setEditString(_node.getPath()); + _currentPath->setEditString(_node.getPath().toString(Common::Path::kNativeSeparator)); // We memorize the last visited path. // Don't memorize a path that is not a directory if (_node.isDirectory()) { - ConfMan.set("browser_lastpath", _node.getPath()); + ConfMan.setPath("browser_lastpath", _node.getPath()); } // Read in the data from the file system