使用lua实现npk操作

This commit is contained in:
2025-09-03 09:34:30 +08:00
parent 25e7cff75d
commit 80390e48a7
10 changed files with 34 additions and 354 deletions
+16 -16
View File
@@ -186,13 +186,13 @@ void freeFileBuffer(uint8_t* buffer)
delete[] buffer;
}
bool clearPath(const char* szPath, bool recursion, bool removeSelf)
bool clearPath(const wchar_t* szPath, bool recursion, bool removeSelf)
{
char szTemp[MAX_PATH] = { 0 };
StringCbCopyA(szTemp, sizeof(szTemp)-1, szPath);
PathAppend(szTemp, "*.*");
wchar_t szTemp[MAX_PATH] = { 0 };
StringCbCopyW(szTemp, sizeof(szTemp)-1, szPath);
PathAppendW(szTemp, L"*.*");
SHFILEOPSTRUCT shf;
SHFILEOPSTRUCTW shf;
SecureZeroMemory(&shf, sizeof(SHFILEOPSTRUCT));
shf.hwnd = NULL;
@@ -204,37 +204,37 @@ bool clearPath(const char* szPath, bool recursion, bool removeSelf)
shf.fFlags |= FOF_NORECURSION;
}
if (0 != SHFileOperation(&shf))
if (0 != SHFileOperationW(&shf))
{
return false; // Failed to delete files
}
if (removeSelf)
{
if (!RemoveDirectory(szPath))
if (!RemoveDirectoryW(szPath))
{
printf("Error: Failed to remove directory %s\n", szPath);
printf("Error: Failed to remove directory\n");
return false; // Failed to remove directory
}
}
return true; // Successfully cleared the path
}
bool createEmptyPath(const char* szPath)
bool createEmptyPath(const wchar_t* szPath)
{
if (!szPath || szPath[0] == 0)
{
printf("Error: Invalid path provided for directory creation.\n");
return false; // Invalid path
}
if (::PathFileExists(szPath))
if (::PathFileExistsW(szPath))
{
if (::PathIsDirectory(szPath))
if (::PathIsDirectoryW(szPath))
{
// Clear the directory
if (!clearPath(szPath, true, false))
{
printf("Failed to clear output directory: '%s'\n", szPath);
printf("Failed to clear output directory\n");
return false; // Failed to clear output directory
}
return true; // Directory exists and is cleared
@@ -242,17 +242,17 @@ bool createEmptyPath(const char* szPath)
else
{
// If it exists but is not a directory, delete the file
if(!DeleteFileA(szPath) && ::GetLastError() != ERROR_FILE_NOT_FOUND)
if(!DeleteFileW(szPath) && ::GetLastError() != ERROR_FILE_NOT_FOUND)
{
printf("Failed to delete existing file: '%s', Error=%d\n", szPath, ::GetLastError());
printf("Failed to delete existing file, Error=%d\n", ::GetLastError());
return false; // Failed to delete existing file
}
}
}
if (!::CreateDirectory(szPath, NULL) && ::GetLastError() != ERROR_ALREADY_EXISTS)
if (!::CreateDirectoryW(szPath, NULL) && ::GetLastError() != ERROR_ALREADY_EXISTS)
{
printf("Failed to create output directory: '%s', Error=%d\n", szPath, ::GetLastError());
printf("Failed to create output directory, Error=%d\n", ::GetLastError());
return false; // Failed to create output directory
}
return true;