增加Lua函数

This commit is contained in:
2025-09-02 22:45:41 +08:00
parent 6788128cc3
commit 25e7cff75d
14 changed files with 260 additions and 22 deletions
+22 -14
View File
@@ -258,34 +258,42 @@ bool createEmptyPath(const char* szPath)
return true;
}
void getParentPath(char* szPath)
void getParentPath(wchar_t* szPath)
{
if (!szPath || szPath[0] == 0) return;
size_t length = strlen(szPath);
std::replace(szPath, szPath+length, '/', '\\');
size_t length = wcslen(szPath);
std::replace(szPath, szPath+length, L'/', L'\\');
::PathRemoveFileSpecA(szPath);
::PathRemoveFileSpecW(szPath);
}
bool forceCreatePath(const char* szPath)
bool forceCreatePath(const wchar_t* szPath)
{
char szCurrentPath[MAX_PATH] = { 0 };
StringCchCopyA(szCurrentPath, MAX_PATH, szPath);
size_t length = strlen(szPath);
std::replace(szCurrentPath, szCurrentPath + length, '/', '\\');
wchar_t szCurrentPath[MAX_PATH] = { 0 };
StringCchCopyW(szCurrentPath, MAX_PATH, szPath);
size_t length = wcslen(szPath);
std::replace(szCurrentPath, szCurrentPath + length, L'/', L'\\');
//目录已经存在
if (::PathFileExists(szCurrentPath)) return true;
if (::PathFileExistsW(szCurrentPath)) return true;
//能够直接创建
if (::CreateDirectory(szCurrentPath, 0)) return true;
if (::CreateDirectoryW(szCurrentPath, 0)) return true;
//取得上一级目录
char szParentPath[MAX_PATH] = { 0 };
StringCchCopyA(szParentPath, MAX_PATH, szPath);
wchar_t szParentPath[MAX_PATH] = { 0 };
StringCchCopyW(szParentPath, MAX_PATH, szPath);
getParentPath(szParentPath);
//创建上一级目录
if (!forceCreatePath(szParentPath)) return false;
return TRUE == ::CreateDirectory(szCurrentPath, 0);
return TRUE == ::CreateDirectoryW(szCurrentPath, 0);
}
bool forceCreatePathForFile(const wchar_t* szFilePath)
{
wchar_t szPathForFile[MAX_PATH] = { 0 };
StringCchCopyW(szPathForFile, MAX_PATH, szFilePath);
getParentPath(szPathForFile);
return forceCreatePath(szPathForFile);
}