windows: filter file name before call WIN API

This commit is contained in:
2023-09-16 20:44:02 +08:00
parent 743aa42d34
commit f7475cbced

View File

@@ -12,6 +12,7 @@
#include <fcntl.h>
#include <io.h>
#include <regex>
#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.");