更改默认config.ini和overlay.vhd路径

This commit is contained in:
MoeGrid
2026-07-31 20:21:02 +08:00
parent 2edce5f5f8
commit fac052d6c6
5 changed files with 16 additions and 7 deletions
+2 -4
View File
@@ -104,8 +104,7 @@ namespace icf_mount {
// overlay.vhd已存在 → 直接挂载(数据已在里面,无需重新拷贝)
if (all_ok && !app_entries.empty()) {
auto *last = app_entries.back();
std::wstring exe_dir = utils::get_exe_dir();
std::wstring overlay_vhd = std::format(L"{}\\overlay.vhd", exe_dir);
std::wstring overlay_vhd = std::format(L"{}\\overlay.vhd", utils::get_cwd());
std::wstring last_tag = std::format(L"APP_{}", last->part_index);
std::wstring parent_for_create = std::format(L"\\\\?\\FscryptDisk_{}\\internal_{}.vhd", last_tag,
last->part_index);
@@ -318,8 +317,7 @@ namespace icf_mount {
}
// 3) overlay.vhd:移除盘符 + detach(保留文件供下次沿用)
std::wstring exe_dir = utils::get_exe_dir();
std::wstring overlay_vhd = std::format(L"{}\\overlay.vhd", exe_dir);
std::wstring overlay_vhd = std::format(L"{}\\overlay.vhd", utils::get_cwd());
{
char drive = static_cast<char>(cfg.mount_letter);
std::wstring mount_point = std::format(L"{}:\\", cfg.mount_letter);
+2 -2
View File
@@ -82,12 +82,12 @@ int main(int argc, char *argv[]) {
return 1;
}
// 确定config.ini路径:优先命令行参数,否则使用exe所在目录
// 确定config.ini路径:优先命令行参数,否则使用当前运行目录
std::wstring config_path;
if (argc >= 3) {
config_path = utils::to_wstring(argv[2]);
} else {
config_path = std::format(L"{}\\config.ini", utils::get_exe_dir());
config_path = std::format(L"{}\\config.ini", utils::get_cwd());
}
// 解析config.ini
+8
View File
@@ -34,6 +34,14 @@ namespace utils {
return get_directory(std::wstring(buf, len));
}
// 获取当前运行目录(进程工作目录CWD)
std::wstring get_cwd() {
wchar_t buf[32768];
DWORD len = GetCurrentDirectoryW(_countof(buf), buf);
if (len == 0 || len >= _countof(buf)) return L".";
return std::wstring(buf, len);
}
// 递归拷贝目录
bool copy_dir_overwrite(const std::wstring &src_dir,
const std::wstring &dst_dir,
+3
View File
@@ -15,6 +15,9 @@ namespace utils {
// 获取当前exe所在目录(末尾不带反斜杠)
std::wstring get_exe_dir();
// 获取当前运行目录(进程工作目录CWD,末尾不带反斜杠)
std::wstring get_cwd();
// 递归拷贝 src_dir -> dst_dir,文件已存在时强制覆盖
// 返回:成功返回true,out_files_copied 输出已拷贝文件数
bool copy_dir_overwrite(const std::wstring &src_dir,
+1 -1
View File
@@ -26,7 +26,7 @@ namespace vhd_mount {
std::string *error);
// 创建差分VHD(overlay层),父盘指向parent_vhd_path
// vhd_path: 输出VHD文件路径(将被创建,如exe目录\overlay.vhd)
// vhd_path: 输出VHD文件路径(将被创建,如当前运行目录\overlay.vhd)
// parent_vhd_path: 父盘NT路径,如 \\?\FscryptDisk_APP_N\internal_N.vhd
// error: 输出错误信息
// 返回:成功返回true