From af870964b581734552d7aac72f45167e96d81b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomislav=20Safund=C5=BEi=C4=87?= Date: Tue, 6 Jan 2026 08:40:57 +0100 Subject: [PATCH 1/2] Use temp directory fallback when Pictures folder is unavailable --- .../camera_windows/windows/camera_plugin.cpp | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/camera/camera_windows/windows/camera_plugin.cpp b/packages/camera/camera_windows/windows/camera_plugin.cpp index c01db2603caa..9843bfe8d8c8 100644 --- a/packages/camera/camera_windows/windows/camera_plugin.cpp +++ b/packages/camera/camera_windows/windows/camera_plugin.cpp @@ -90,13 +90,28 @@ std::optional GetFilePathForPicture() { ComHeapPtr known_folder_path; HRESULT hr = SHGetKnownFolderPath(FOLDERID_Pictures, KF_FLAG_CREATE, nullptr, &known_folder_path); - if (FAILED(hr)) { - return std::nullopt; + + std::wstring wpath; + + if (SUCCEEDED(hr)) { + wpath = std::wstring(known_folder_path); + } else { + // Fallback to temp folder + wchar_t tempPath[MAX_PATH]; + DWORD len = GetTempPathW(MAX_PATH, tempPath); + if (len == 0 || len > MAX_PATH) { + return std::nullopt; + } + wpath = std::wstring(tempPath); } - std::string path = Utf8FromUtf16(std::wstring(known_folder_path)); + if (!wpath.empty() && wpath.back() != L'\\' && wpath.back() != L'/') { + wpath.push_back(L'\\'); + } + + std::string path = Utf8FromUtf16(wpath); - return path + "\\" + "PhotoCapture_" + GetCurrentTimeString() + "." + + return path + "PhotoCapture_" + GetCurrentTimeString() + "." + kPictureCaptureExtension; } From cdd1611e3546655b68bd7e15e09c6fbec4d6dfa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomislav=20Safund=C5=BEi=C4=87?= Date: Tue, 6 Jan 2026 21:07:52 +0100 Subject: [PATCH 2/2] Version bump, changelog update --- packages/camera/camera_windows/CHANGELOG.md | 4 ++++ packages/camera/camera_windows/pubspec.yaml | 2 +- packages/camera/camera_windows/windows/camera_plugin.cpp | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera_windows/CHANGELOG.md b/packages/camera/camera_windows/CHANGELOG.md index 7316cdb8b1ee..9186f9c1cd6f 100644 --- a/packages/camera/camera_windows/CHANGELOG.md +++ b/packages/camera/camera_windows/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.6+5 + +* Use temp directory fallback when Pictures folder is unavailable + ## 0.2.6+4 * Removes usage of the deprecated and ignored `maxVideoDuration` in the example. diff --git a/packages/camera/camera_windows/pubspec.yaml b/packages/camera/camera_windows/pubspec.yaml index ab42277ea399..e6341076d86d 100644 --- a/packages/camera/camera_windows/pubspec.yaml +++ b/packages/camera/camera_windows/pubspec.yaml @@ -2,7 +2,7 @@ name: camera_windows description: A Flutter plugin for getting information about and controlling the camera on Windows. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_windows issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.2.6+4 +version: 0.2.6+5 environment: sdk: ^3.8.0 diff --git a/packages/camera/camera_windows/windows/camera_plugin.cpp b/packages/camera/camera_windows/windows/camera_plugin.cpp index 9843bfe8d8c8..fffe85583273 100644 --- a/packages/camera/camera_windows/windows/camera_plugin.cpp +++ b/packages/camera/camera_windows/windows/camera_plugin.cpp @@ -86,6 +86,8 @@ std::string GetCurrentTimeString() { } // Builds file path for picture capture. +/// If Pictures folder exist use it, otherwise use temp directory +/// This fallback prevents crashes or unexpected failures on systems where the Pictures folder is unavailable or restricted std::optional GetFilePathForPicture() { ComHeapPtr known_folder_path; HRESULT hr = SHGetKnownFolderPath(FOLDERID_Pictures, KF_FLAG_CREATE, nullptr,