refactor
修改了目录和部分源文件名称
This commit is contained in:
1 parent
1435b864f8
commit
cf87cfe93d
21 files changed
+8
-7
No files matched your search
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include "mcp_utils.h"
|
||||
#include <Windows.h>
|
||||
#include <tchar.h>
|
||||
#include <ghc/filesystem.hpp>
|
||||
|
||||
namespace mcp_utils
|
||||
{
|
||||
std::wstring utf8ToWString(const std::string &utf8Str)
|
||||
{
|
||||
if (utf8Str.empty()) return std::wstring();
|
||||
|
||||
// 第一次调用获取需要的宽字符缓冲区大小
|
||||
int sizeNeeded = ::MultiByteToWideChar(CP_UTF8, 0, &utf8Str[0], (int)utf8Str.size(), NULL, 0);
|
||||
std::wstring wstrTo(sizeNeeded, 0);
|
||||
|
||||
// 第二次调用真正进行转换
|
||||
::MultiByteToWideChar(CP_UTF8, 0, &utf8Str[0], (int)utf8Str.size(), &wstrTo[0], sizeNeeded);
|
||||
return wstrTo;
|
||||
}
|
||||
|
||||
bool mcp_utils::hasFileExist(const std::wstring &filePath) { return _taccess(filePath.c_str(), 0) == 0; }
|
||||
|
||||
bool mcp_utils::hasDirExist(const std::wstring &filePath) { return _taccess(filePath.c_str(), 0) == 0; }
|
||||
|
||||
std::wstring getModelDir()
|
||||
{
|
||||
TCHAR szPath[MAX_PATH];
|
||||
::GetModuleFileName(_hdllInstance, szPath, MAX_PATH);
|
||||
ghc::filesystem::path path(szPath);
|
||||
return path.parent_path().wstring();
|
||||
}
|
||||
|
||||
fs::path getModelDirPath()
|
||||
{
|
||||
return fs::path(getModelDir());
|
||||
}
|
||||
|
||||
fs::path relative2absolute(const std::string &relativePath, const fs::path &rootPath)
|
||||
{
|
||||
return relative2absolute(fs::path(utf8ToWString(relativePath)), rootPath);
|
||||
}
|
||||
|
||||
fs::path relative2absolute(const fs::path &relativePath, const fs::path &rootPath)
|
||||
{
|
||||
fs::path absolutePath = rootPath / relativePath;
|
||||
return absolutePath.lexically_normal().wstring();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user