refactor(account): change home_path type to fs path

This commit is contained in:
Changhua 2025-02-18 01:11:46 +08:00
parent 48bf47f1e4
commit f964dba48a
2 changed files with 6 additions and 6 deletions

View File

@ -20,7 +20,7 @@ using get_data_path_t = QWORD (*)(QWORD);
// 缓存避免重复查询 // 缓存避免重复查询
static std::optional<std::string> cachedWxid; static std::optional<std::string> cachedWxid;
static std::optional<std::string> cachedHomePath; static std::optional<fs::path> cachedHomePath;
// 清除缓存 // 清除缓存
static void clear_cached_wxid() { cachedWxid.reset(); } static void clear_cached_wxid() { cachedWxid.reset(); }
@ -46,7 +46,7 @@ bool is_logged_in()
return service_addr && util::get_qword(service_addr + OsAcc::LOGIN) != 0; return service_addr && util::get_qword(service_addr + OsAcc::LOGIN) != 0;
} }
std::string get_home_path() fs::path get_home_path()
{ {
if (cachedHomePath) { if (cachedHomePath) {
return *cachedHomePath; return *cachedHomePath;
@ -56,8 +56,7 @@ std::string get_home_path()
int64_t service_addr = get_account_service(); int64_t service_addr = get_account_service();
GetDataPath((QWORD)&home); GetDataPath((QWORD)&home);
if (home.wptr) { if (home.wptr) {
fs::path path = util::w2s(std::wstring(home.wptr, home.size)); cachedHomePath = util::w2s(std::wstring(home.wptr, home.size));
cachedHomePath = path.generic_string();
} }
return *cachedHomePath; return *cachedHomePath;
} }
@ -81,7 +80,7 @@ UserInfo_t get_user_info()
if (!service_addr) return ui; if (!service_addr) return ui;
ui.wxid = get_self_wxid(); ui.wxid = get_self_wxid();
ui.home = get_home_path(); ui.home = get_home_path().generic_string();
ui.name = get_string_value(service_addr, OsAcc::NAME); ui.name = get_string_value(service_addr, OsAcc::NAME);
ui.mobile = get_string_value(service_addr, OsAcc::MOBILE); ui.mobile = get_string_value(service_addr, OsAcc::MOBILE);
return ui; return ui;

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <filesystem>
#include <optional> #include <optional>
#include <string> #include <string>
@ -12,7 +13,7 @@ namespace account
bool is_logged_in(); bool is_logged_in();
// 获取 WeChat 数据存储路径 // 获取 WeChat 数据存储路径
std::string get_home_path(); std::filesystem::path get_home_path();
// 获取自身 wxid // 获取自身 wxid
std::string get_self_wxid(); std::string get_self_wxid();