优化fscrypt,添加GUI目标

This commit is contained in:
MoeGrid
2026-08-01 16:32:29 +08:00
parent 3d316146ee
commit bc4714234f
24 changed files with 1507 additions and 319 deletions
+48
View File
@@ -0,0 +1,48 @@
#include "gui_utils.h"
#include "gui_common.h"
#include "config.h"
#include "utils/strings.h"
#include <windows.h>
#include <commdlg.h>
#include <shlobj.h>
#include <format>
void load_config_file(const std::wstring &path) {
g_config_path_w = path;
g_config_path = utils::wstr_to_str(path);
std::string err;
if (parse_config(path, g_cfg, &err)) {
g_log_lines.push_back(std::format("[INFO] Config loaded: {}", g_config_path));
} else {
g_log_lines.push_back(std::format("[ERROR] {}", err));
}
}
std::string open_file_dialog(const char *filter_desc, const char *filter_ext) {
wchar_t buf[MAX_PATH] = {};
OPENFILENAMEW ofn = {};
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = buf;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
std::wstring wfilter = utils::to_wstring(std::string(filter_desc) + '\0' + filter_ext + '\0');
ofn.lpstrFilter = wfilter.c_str();
if (GetOpenFileNameW(&ofn))
return utils::wstr_to_str(buf);
return {};
}
std::string open_folder_dialog() {
BROWSEINFOW bi = {};
bi.hwndOwner = nullptr;
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
LPITEMIDLIST pidl = SHBrowseForFolderW(&bi);
if (!pidl) return {};
wchar_t buf[MAX_PATH] = {};
if (!SHGetPathFromIDListW(pidl, buf)) return {};
CoTaskMemFree(pidl);
return utils::wstr_to_str(buf);
}