mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-06 05:49:03 +08:00
windows: filter file name before call WIN API
This commit is contained in:
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user