`vendor/MetasequoiaImeEngine` submodule 改为 `engine/` 目录,导入的是 product-lock.json 原本钉住的提交 c810d201,逐文件核对过 blob,因此这是一次 搬迁而不是引擎升级。引擎自己的嵌套 submodule(googlepinyinime-rev、utfcpp、 miniaudio)按各自 gitlink 一并展开,来源与提交见 engine/UPSTREAM.md。 Windows 专门化裁掉了不属于本产品的部分:whisper.cpp 与本地推理 provider、 macOS 示例宿主、整个 dictionary/ 建库流水线、上游 CI 与 release-please 配置。 词库仍按 product-lock.json 在构建时取发布产物。 引擎不再进 product-lock.json:没有 gitlink 就没有可比对的东西,锁里写一个上游 commit 等于宣称这棵树仍等于上游,而第一个 Windows 专门化改动落地时这句话就假了。 verify-contracts / verify-checkout 随之移除,verify-published 保留。 CI 与工具链:引擎源码并入根 scripts/format.sh(删掉引擎自己的那份,避免两套排除 列表分叉);引擎 voice.yml 里的 silero_vad.onnx 摘要校验移到本仓 lock job; engine-bump-triage 工作流与其测试删除;gitsubmodule 的 dependabot 频率由 daily 改为 monthly。 README、README.en、AGENTS.md、CONTRIBUTING、docs/product-release.md 及各子目录 文档同步说明新的位置与边界。
112 lines
2.8 KiB
C++
112 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <cstdlib>
|
|
#include <filesystem>
|
|
|
|
#ifdef _WIN32
|
|
#include <Windows.h>
|
|
#include <shlobj.h>
|
|
#endif
|
|
|
|
namespace metasequoia
|
|
{
|
|
inline std::filesystem::path path_from_utf8(const char *path)
|
|
{
|
|
#if defined(__cpp_lib_char8_t)
|
|
return std::filesystem::path(std::u8string(reinterpret_cast<const char8_t *>(path)));
|
|
#else
|
|
return std::filesystem::u8path(path);
|
|
#endif
|
|
}
|
|
|
|
inline std::filesystem::path data_directory()
|
|
{
|
|
#ifdef _WIN32
|
|
if (const wchar_t *override_path = _wgetenv(L"METASEQUOIA_IME_DATA_DIR"))
|
|
{
|
|
const std::filesystem::path path(override_path);
|
|
if (path.is_absolute())
|
|
{
|
|
return path;
|
|
}
|
|
}
|
|
#else
|
|
if (const char *override_path = std::getenv("METASEQUOIA_IME_DATA_DIR"))
|
|
{
|
|
const std::filesystem::path path = path_from_utf8(override_path);
|
|
if (path.is_absolute())
|
|
{
|
|
return path;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
if (const wchar_t *local_app_data = _wgetenv(L"LOCALAPPDATA"))
|
|
{
|
|
const std::filesystem::path root(local_app_data);
|
|
if (root.is_absolute())
|
|
{
|
|
return root / L"metasequoiaime";
|
|
}
|
|
}
|
|
|
|
PWSTR known_path = nullptr;
|
|
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_DEFAULT, nullptr, &known_path)) && known_path)
|
|
{
|
|
const std::filesystem::path result = std::filesystem::path(known_path) / L"metasequoiaime";
|
|
CoTaskMemFree(known_path);
|
|
return result;
|
|
}
|
|
#elif defined(__APPLE__)
|
|
if (const char *home = std::getenv("HOME"))
|
|
{
|
|
const std::filesystem::path root(home);
|
|
if (root.is_absolute())
|
|
{
|
|
return root / "Library" / "Application Support" / "metasequoiaime";
|
|
}
|
|
}
|
|
#else
|
|
if (const char *xdg_data_home = std::getenv("XDG_DATA_HOME"))
|
|
{
|
|
const std::filesystem::path root(xdg_data_home);
|
|
if (root.is_absolute())
|
|
{
|
|
return root / "metasequoiaime";
|
|
}
|
|
}
|
|
if (const char *home = std::getenv("HOME"))
|
|
{
|
|
const std::filesystem::path root(home);
|
|
if (root.is_absolute())
|
|
{
|
|
return root / ".local" / "share" / "metasequoiaime";
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return {};
|
|
}
|
|
|
|
inline std::filesystem::path data_file_path(const std::filesystem::path &relative_path)
|
|
{
|
|
const std::filesystem::path directory = data_directory();
|
|
if (directory.empty() || relative_path.empty() || relative_path.is_absolute())
|
|
{
|
|
return {};
|
|
}
|
|
return directory / relative_path;
|
|
}
|
|
|
|
inline std::string path_to_utf8(const std::filesystem::path &path)
|
|
{
|
|
const auto utf8_path = path.u8string();
|
|
#if defined(__cpp_lib_char8_t)
|
|
return {reinterpret_cast<const char *>(utf8_path.data()), utf8_path.size()};
|
|
#else
|
|
return utf8_path;
|
|
#endif
|
|
}
|
|
} // namespace metasequoia
|