diff --git a/windows/runner/flutter_window.cpp b/windows/runner/flutter_window.cpp index e110618..4095a21 100644 --- a/windows/runner/flutter_window.cpp +++ b/windows/runner/flutter_window.cpp @@ -12,6 +12,7 @@ #include #include +#include #include "err.h" #include "fileop.h" #include "wchar_util.h" @@ -23,6 +24,11 @@ FlutterWindow::FlutterWindow(const flutter::DartProject& project) FlutterWindow::~FlutterWindow() {} +void filterFilename(std::wstring& fileName) { + const static std::wregex re(L"[/\\\\:\\*\\?\"\\<\\>\\|]"); + fileName = std::regex_replace(fileName, re, L"_"); +} + void updateDataFromMimeType(std::wstring& defExt, std::wstring& filter, std::string mimeType) { if (mimeType == "image/jpeg") { filter.append(std::wstring(L"JPEG File(*.jpg)\0*.jpg\0", 23)); @@ -96,6 +102,7 @@ bool FlutterWindow::OnCreate() { result->Error("ERROR", "Failed to convert file name to wstring."); return; } + filterFilename(wFileName); std::wstring wDir; if (!dir->empty() && !wchar_util::str_to_wstr(wDir, *dir, CP_UTF8)) { result->Error("ERROR", "Failed to convert dir to wstring."); @@ -153,6 +160,7 @@ bool FlutterWindow::OnCreate() { result->Error("ERROR", "Failed to convert file name to wstring."); return; } + filterFilename(wFileName); std::wstring wDir; if (!dir->empty() && !wchar_util::str_to_wstr(wDir, *dir, CP_UTF8)) { result->Error("ERROR", "Failed to convert dir to wstring.");