#pragma once #include #include #include namespace updater { class Utils { public: static std::wstring Utf8ToWide(const std::string& s); static std::string WideToUtf8(const std::wstring& s); static std::wstring CodePageToWide(const std::string& s, UINT codePage); static bool IsValidUtf8(const std::string& s); static std::wstring DecodeEntryName(const std::string& raw); static std::wstring GetModuleDir(); static std::wstring GetTempDir(); static std::wstring JoinPath(const std::wstring& dir, const std::wstring& rel); static std::wstring GetParentDir(const std::wstring& path); static std::wstring Trim(const std::wstring& s); static std::wstring NormalizeSlashes(std::wstring path); static bool CreateDirRecursive(const std::wstring& dir); static bool FileExists(const std::wstring& path); static bool DirExists(const std::wstring& path); static bool DeleteFileForce(const std::wstring& path); static std::wstring MakeUniqueTempFile(const std::wstring& dir, const std::wstring& prefix); static std::wstring FormatSize(unsigned long long bytes); static std::wstring FormatSpeed(unsigned long long bytesPerSec); static std::string Sha256Hex(const void* data, size_t size); static std::string Sha256HexFile(const std::wstring& path); static std::string ToLowerAscii(const std::string& s); static std::wstring UrlEncode(const std::wstring& s); static bool IsAbsoluteUrl(const std::wstring& url); static bool LaunchProcess(const std::wstring& exe, const std::wstring& args, const std::wstring& workDir); static bool WaitForProcessExit(const std::wstring& processName, int timeoutSec); // 桌面快捷方式:后台给包里的文件勾选"创建快捷方式"时调用 static std::wstring GetDesktopDir(); static bool CreateDesktopShortcut(const std::wstring& targetPath, const std::wstring& linkName); // 关闭指定名称的进程:先投递 WM_CLOSE 请求其自行退出,超时后强制结束。 // 运行中的 EXE 无法被覆盖,更新前必须让它们先退出 static bool CloseProcesses(const std::wstring& processName, int timeoutSec); static bool ReplaceInUse(const std::wstring& srcTmp, const std::wstring& target); }; }