diff --git a/UI/ShareFiles.cpp b/UI/ShareFiles.cpp index 2b62f65bef..9fe6698246 100644 --- a/UI/ShareFiles.cpp +++ b/UI/ShareFiles.cpp @@ -30,14 +30,15 @@ #include "Common/System/Request.h" #include "Common/System/System.h" #include "Common/TimeUtil.h" -#include "Core/Config.h" +#include "Core/Util/PathUtil.h" #include "UI/ShareFiles.h" // How long a shared zip is kept for the receiving app to read. static constexpr int64_t SHARE_KEEP_SECONDS = 60 * 60; static Path ShareDirectory() { - return g_Config.appCacheDirectory / "share"; + // Falls back to the memstick cache folder on platforms without an app cache directory (Windows). + return GetSysDirectory(DIRECTORY_APP_CACHE) / "share"; } // Deletes the folders of earlier shares (named by their time) once they're old enough. @@ -57,7 +58,7 @@ static void CleanUpOldShares(int64_t now) { } bool CanShareFiles() { - return System_GetPropertyBool(SYSPROP_SUPPORTS_SHARE_FILE) && !g_Config.appCacheDirectory.empty(); + return System_GetPropertyBool(SYSPROP_SUPPORTS_SHARE_FILE); } bool ShareFilesAsZip(std::string_view zipName, const std::vector &files) { diff --git a/Windows/W32Util/ShellUtil.cpp b/Windows/W32Util/ShellUtil.cpp index 7da6300114..01322313bf 100644 --- a/Windows/W32Util/ShellUtil.cpp +++ b/Windows/W32Util/ShellUtil.cpp @@ -135,7 +135,7 @@ std::string BrowseForFolder2(HWND parent, std::string_view title, std::string_vi ofn.nMaxFile = ARRAY_SIZE(fileBuffer); ofn.Flags = OFN_NOCHANGEDIR | OFN_EXPLORER; if (!_bLoad) - ofn.Flags |= OFN_HIDEREADONLY; + ofn.Flags |= OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; int success = _bLoad ? GetOpenFileName(&ofn) : GetSaveFileName(&ofn); if (success) { diff --git a/Windows/main.cpp b/Windows/main.cpp index 8ff1fc464b..985217108a 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -455,6 +455,7 @@ bool System_GetPropertyBool(SystemProperty prop) { case SYSPROP_CAN_SHOW_FILE: case SYSPROP_CAN_LAUNCH_URL: case SYSPROP_HAS_TRASH_BIN: + case SYSPROP_SUPPORTS_SHARE_FILE: return true; case SYSPROP_HAS_IMAGE_BROWSER: return true; @@ -782,6 +783,38 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string }).detach(); return true; + case SystemRequestType::SHARE_FILE: + { + // No share sheet here yet, so offer to save a copy instead. param2 (the MIME type) isn't needed. + const Path source(param1); + if (!File::Exists(source)) { + ERROR_LOG(Log::System, "SHARE_FILE: '%s' doesn't exist", param1.c_str()); + return false; + } + std::thread([source] { + SetCurrentThreadName("ShareFile"); + std::wstring filter; + std::wstring extension; + const std::string ext = source.GetFileExtension(); // Lowercase, with the dot. + if (ext.size() > 1) { + extension = ConvertUTF8ToWString(ext.substr(1)); + std::wstring upper = extension; + std::transform(upper.begin(), upper.end(), upper.begin(), towupper); + filter = upper + L" files (*." + extension + L")|*." + extension + L"|"; + } + filter = FinalizeFilter(filter + L"All files (*.*)|*.*||"); + std::string out; + if (!W32Util::BrowseForFileName(false, MainWindow::GetHWND(), L"", nullptr, ConvertUTF8ToWString(source.GetFilename()).c_str(), filter.c_str(), extension.c_str(), out)) { + return; + } + const Path dest(out); + if (dest != source && !File::Copy(source, dest)) { + ERROR_LOG(Log::System, "SHARE_FILE: Couldn't copy '%s' to '%s'", source.c_str(), dest.c_str()); + } + }).detach(); + return true; + } + case SystemRequestType::APPLY_FULLSCREEN_STATE: { MainWindow::SendApplyFullscreenState();