mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-17 18:59:09 +00:00
Kill as much of pnUtPath as possible.
This commit is contained in:
@ -834,7 +834,7 @@ int __stdcall WinMain (
|
|||||||
// Wait for the other process to exit
|
// Wait for the other process to exit
|
||||||
Sleep(1000);
|
Sleep(1000);
|
||||||
|
|
||||||
if (!PathDeleteFile(newPatcherFile)) {
|
if (!plFileUtils::RemoveFile(newPatcherFile)) {
|
||||||
wchar_t error[256];
|
wchar_t error[256];
|
||||||
DWORD errorCode = GetLastError();
|
DWORD errorCode = GetLastError();
|
||||||
wchar_t *msg = TranslateErrorCode(errorCode);
|
wchar_t *msg = TranslateErrorCode(errorCode);
|
||||||
@ -844,7 +844,7 @@ int __stdcall WinMain (
|
|||||||
LocalFree(msg);
|
LocalFree(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!PathMoveFile(curPatcherFile, newPatcherFile)) {
|
if (!plFileUtils::FileMove(curPatcherFile, newPatcherFile)) {
|
||||||
wchar_t error[256];
|
wchar_t error[256];
|
||||||
DWORD errorCode = GetLastError();
|
DWORD errorCode = GetLastError();
|
||||||
wchar_t *msg = TranslateErrorCode(errorCode);
|
wchar_t *msg = TranslateErrorCode(errorCode);
|
||||||
@ -852,7 +852,7 @@ int __stdcall WinMain (
|
|||||||
StrPrintf(error, arrsize(error), L"Failed to replace old patcher executable. %s", msg);
|
StrPrintf(error, arrsize(error), L"Failed to replace old patcher executable. %s", msg);
|
||||||
MessageBoxW(GetTopWindow(nil), error, L"Error", MB_OK);
|
MessageBoxW(GetTopWindow(nil), error, L"Error", MB_OK);
|
||||||
// attempt to clean up this tmp file
|
// attempt to clean up this tmp file
|
||||||
PathDeleteFile(curPatcherFile);
|
plFileUtils::RemoveFile(curPatcherFile);
|
||||||
LocalFree(msg);
|
LocalFree(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -896,7 +896,7 @@ int __stdcall WinMain (
|
|||||||
PathAddFilename(fileSpec, fileSpec, L"*.tmp", arrsize(fileSpec));
|
PathAddFilename(fileSpec, fileSpec, L"*.tmp", arrsize(fileSpec));
|
||||||
PathFindFiles(&paths, fileSpec, kPathFlagFile);
|
PathFindFiles(&paths, fileSpec, kPathFlagFile);
|
||||||
for (PathFind * path = paths.Ptr(); path != paths.Term(); ++path)
|
for (PathFind * path = paths.Ptr(); path != paths.Term(); ++path)
|
||||||
PathDeleteFile(path->name);
|
plFileUtils::RemoveFile(path->name);
|
||||||
|
|
||||||
SetConsoleCtrlHandler(CtrlHandler, TRUE);
|
SetConsoleCtrlHandler(CtrlHandler, TRUE);
|
||||||
InitAsyncCore(); // must do this before self patch, since it needs to connect to the file server
|
InitAsyncCore(); // must do this before self patch, since it needs to connect to the file server
|
||||||
|
@ -232,7 +232,7 @@ static void FileSrvIpAddressCallback (
|
|||||||
|
|
||||||
PathGetProgramDirectory(s_newPatcherFile, arrsize(s_newPatcherFile));
|
PathGetProgramDirectory(s_newPatcherFile, arrsize(s_newPatcherFile));
|
||||||
GetTempFileNameW(s_newPatcherFile, kPatcherExeFilename, 0, s_newPatcherFile);
|
GetTempFileNameW(s_newPatcherFile, kPatcherExeFilename, 0, s_newPatcherFile);
|
||||||
PathDeleteFile(s_newPatcherFile);
|
plFileUtils::RemoveFile(s_newPatcherFile);
|
||||||
|
|
||||||
NetCliFileManifestRequest(ManifestCallback, nil, s_manifest);
|
NetCliFileManifestRequest(ManifestCallback, nil, s_manifest);
|
||||||
}
|
}
|
||||||
|
@ -112,47 +112,21 @@ static wchar_t * PathSkipOverSeparator (wchar_t * path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
static unsigned CommonPrefixLength (
|
const wchar_t * PathFindFilename (
|
||||||
const wchar_t src1[],
|
const wchar_t path[]
|
||||||
const wchar_t src2[]
|
|
||||||
) {
|
) {
|
||||||
ASSERT(src1);
|
ASSERT(path);
|
||||||
ASSERT(src2);
|
|
||||||
|
|
||||||
wchar_t const * const base = src1;
|
if (IsUncPath(path))
|
||||||
const wchar_t * common = nil;
|
path = SkipUncDrive(path);
|
||||||
for (;;) {
|
|
||||||
// Are the next components equal in length?
|
|
||||||
const wchar_t * next1 = PathSkipOverSeparator(const_cast<wchar_t *>(src1));
|
|
||||||
const wchar_t * next2 = PathSkipOverSeparator(const_cast<wchar_t *>(src2));
|
|
||||||
const int componentLen = next1 - src1;
|
|
||||||
if (componentLen != (next2 - src2))
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Are the next components equal in value?
|
const wchar_t * last_slash = path;
|
||||||
if (!StrCmpI(src1, src2, componentLen))
|
for (const wchar_t * p = path; *p; p++) {
|
||||||
common = next1;
|
if ((*p == L'/') || (*p == L'\\') || (*p == L':'))
|
||||||
else
|
last_slash = p + 1;
|
||||||
break;
|
|
||||||
|
|
||||||
if (!*next1)
|
|
||||||
break;
|
|
||||||
src1 = next1 + 1;
|
|
||||||
|
|
||||||
if (!*next2)
|
|
||||||
break;
|
|
||||||
src2 = next2 + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!common)
|
return last_slash;
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Compute length of common subchunk;
|
|
||||||
// if it is "C:" convert it to "C:\"
|
|
||||||
unsigned commonLen = common - base;
|
|
||||||
if ((commonLen == 2) && (base[1] == L':'))
|
|
||||||
++commonLen;
|
|
||||||
return commonLen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
@ -170,6 +144,16 @@ static void GetProgramName (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
bool PathDoesDirectoryExist (const wchar_t directory[]) {
|
||||||
|
uint32_t attributes = GetFileAttributesW(directory);
|
||||||
|
if (attributes == (uint32_t) -1)
|
||||||
|
return false;
|
||||||
|
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
@ -177,14 +161,6 @@ static void GetProgramName (
|
|||||||
*
|
*
|
||||||
***/
|
***/
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathGetModuleName (
|
|
||||||
wchar_t * dst,
|
|
||||||
unsigned dstChars
|
|
||||||
) {
|
|
||||||
GetProgramName(ModuleGetInstance(), dst, dstChars);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void PathGetProgramName (
|
void PathGetProgramName (
|
||||||
wchar_t * dst,
|
wchar_t * dst,
|
||||||
@ -226,32 +202,6 @@ bool PathFromString (
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
bool PathFromString (
|
|
||||||
wchar_t * dst, // ASSERT(dst);
|
|
||||||
const wchar_t src[], // ASSERT(src);
|
|
||||||
unsigned dstChars, // ASSERT(dstChars);
|
|
||||||
const wchar_t baseDir[] // ASSERT(baseDir);
|
|
||||||
) {
|
|
||||||
ASSERT(baseDir);
|
|
||||||
ASSERT(dstChars);
|
|
||||||
|
|
||||||
// Save current directory
|
|
||||||
wchar_t curr[MAX_PATH];
|
|
||||||
PathGetCurrentDirectory(curr, arrsize(curr));
|
|
||||||
|
|
||||||
// Perform string conversion from specified directory
|
|
||||||
bool result;
|
|
||||||
if (0 != (result = PathSetCurrentDirectory(baseDir)))
|
|
||||||
result = PathFromString(dst, src, dstChars);
|
|
||||||
else
|
|
||||||
*dst = 0;
|
|
||||||
|
|
||||||
// Restore directory
|
|
||||||
PathSetCurrentDirectory(curr);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
// this function was originally derived from _tsplitpath in the MSVCRT library,
|
// this function was originally derived from _tsplitpath in the MSVCRT library,
|
||||||
// but has been updated to support UNC paths and to avoid blasting off the end
|
// but has been updated to support UNC paths and to avoid blasting off the end
|
||||||
@ -399,140 +349,6 @@ void PathMakePath (
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
bool PathMakeRelative (
|
|
||||||
wchar_t *dst,
|
|
||||||
unsigned fromFlags, // 0 or kPathFlagDirectory
|
|
||||||
const wchar_t from[],
|
|
||||||
unsigned toFlags, // 0 or kPathFlagDirectory
|
|
||||||
const wchar_t to[],
|
|
||||||
unsigned dstChars
|
|
||||||
) {
|
|
||||||
ASSERT(dst);
|
|
||||||
ASSERT(from);
|
|
||||||
ASSERT(to);
|
|
||||||
ASSERT(dstChars);
|
|
||||||
*dst = 0;
|
|
||||||
|
|
||||||
unsigned prefixLength = CommonPrefixLength(from, to);
|
|
||||||
if (!prefixLength)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
wchar_t fromBuf[MAX_PATH];
|
|
||||||
if (fromFlags & kPathFlagDirectory)
|
|
||||||
StrCopy(fromBuf, from, arrsize(fromBuf));
|
|
||||||
else
|
|
||||||
PathRemoveFilename(fromBuf, from, arrsize(fromBuf));
|
|
||||||
|
|
||||||
wchar_t toBuf[MAX_PATH];
|
|
||||||
if (toFlags & kPathFlagDirectory)
|
|
||||||
StrCopy(toBuf, to, arrsize(toBuf));
|
|
||||||
else
|
|
||||||
PathRemoveFilename(toBuf, to, arrsize(toBuf));
|
|
||||||
|
|
||||||
const wchar_t * curr = fromBuf + prefixLength;
|
|
||||||
if (*curr) {
|
|
||||||
// build ..\.. part of the path
|
|
||||||
if (IsSlash(*curr))
|
|
||||||
curr++; // skip slash
|
|
||||||
|
|
||||||
while (*curr) {
|
|
||||||
curr = PathSkipOverSeparator(const_cast<wchar_t *>(curr));
|
|
||||||
StrPack(dst, *curr ? L"..\\" : L"..", dstChars);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
StrCopy(dst, L".", dstChars);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (to[prefixLength]) {
|
|
||||||
// deal with root case
|
|
||||||
if (!IsSlash(to[prefixLength]))
|
|
||||||
--prefixLength;
|
|
||||||
|
|
||||||
ASSERT(IsSlash(to[prefixLength]));
|
|
||||||
StrPack(dst, to + prefixLength, dstChars);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
bool PathIsRelative (
|
|
||||||
const wchar_t src[]
|
|
||||||
) {
|
|
||||||
ASSERT(src);
|
|
||||||
if (!src[0])
|
|
||||||
return true;
|
|
||||||
if (IsSlash(src[0]))
|
|
||||||
return false;
|
|
||||||
if (src[1] == L':')
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
const wchar_t * PathFindFilename (
|
|
||||||
const wchar_t path[]
|
|
||||||
) {
|
|
||||||
ASSERT(path);
|
|
||||||
|
|
||||||
if (IsUncPath(path))
|
|
||||||
path = SkipUncDrive(path);
|
|
||||||
|
|
||||||
const wchar_t * last_slash = path;
|
|
||||||
for (const wchar_t * p = path; *p; p++) {
|
|
||||||
if ((*p == L'/') || (*p == L'\\') || (*p == L':'))
|
|
||||||
last_slash = p + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return last_slash;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
const wchar_t * PathFindExtension (
|
|
||||||
const wchar_t path[]
|
|
||||||
) {
|
|
||||||
ASSERT(path);
|
|
||||||
|
|
||||||
const wchar_t * last_dot = 0;
|
|
||||||
const wchar_t * p = PathFindFilename(path);
|
|
||||||
for ( ; *p; p++) {
|
|
||||||
if (*p == L'.')
|
|
||||||
last_dot = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
return last_dot ? last_dot : p;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathGetCurrentDirectory (
|
|
||||||
wchar_t * dst,
|
|
||||||
unsigned dstChars
|
|
||||||
) {
|
|
||||||
ASSERT(dst);
|
|
||||||
ASSERT(dstChars);
|
|
||||||
|
|
||||||
DWORD result = GetCurrentDirectoryW(dstChars, dst);
|
|
||||||
if (!result || (result >= dstChars)) {
|
|
||||||
ErrorAssert(__LINE__, __FILE__, "GetDir failed");
|
|
||||||
*dst = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathGetTempDirectory (
|
|
||||||
wchar_t * dst,
|
|
||||||
unsigned dstChars
|
|
||||||
) {
|
|
||||||
ASSERT(dst);
|
|
||||||
ASSERT(dstChars);
|
|
||||||
|
|
||||||
DWORD result = GetTempPathW(dstChars, dst);
|
|
||||||
if (!result || (result >= dstChars))
|
|
||||||
StrCopy(dst, L"C:\\temp\\", dstChars);
|
|
||||||
}
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void PathGetUserDirectory (
|
void PathGetUserDirectory (
|
||||||
wchar_t * dst,
|
wchar_t * dst,
|
||||||
unsigned dstChars
|
unsigned dstChars
|
||||||
@ -578,21 +394,6 @@ void PathGetInitDirectory (
|
|||||||
PathCreateDirectory(dst, kPathCreateDirFlagEntireTree);
|
PathCreateDirectory(dst, kPathCreateDirFlagEntireTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
bool PathSetCurrentDirectory (
|
|
||||||
const wchar_t path[]
|
|
||||||
) {
|
|
||||||
ASSERT(path);
|
|
||||||
return SetCurrentDirectoryW(path) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathSetProgramDirectory () {
|
|
||||||
wchar_t dir[MAX_PATH];
|
|
||||||
PathGetProgramDirectory(dir, arrsize(dir));
|
|
||||||
PathSetCurrentDirectory(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void PathFindFiles (
|
void PathFindFiles (
|
||||||
ARRAY(PathFind) * paths,
|
ARRAY(PathFind) * paths,
|
||||||
@ -772,46 +573,6 @@ EPathCreateDirError PathCreateDirectory (const wchar_t path[], unsigned flags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathDeleteDirectory (const wchar_t path[], unsigned flags) {
|
|
||||||
ASSERT(path);
|
|
||||||
|
|
||||||
// convert from relative path to full path
|
|
||||||
wchar_t dir[MAX_PATH];
|
|
||||||
if (!PathFromString(dir, path, arrsize(dir)))
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
// Important: in order to ensure that we don't delete NTFS
|
|
||||||
// partition links, we must ensure that this is a directory!
|
|
||||||
uint32_t attributes = GetFileAttributesW(dir);
|
|
||||||
if (attributes == (uint32_t) -1)
|
|
||||||
break;
|
|
||||||
if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
|
|
||||||
break;
|
|
||||||
if (attributes & FILE_ATTRIBUTE_REPARSE_POINT)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!RemoveDirectoryW(dir))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if ((flags & kPathCreateDirFlagEntireTree) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
wchar_t * filename = PathFindFilename(dir);
|
|
||||||
if (!filename)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Move up one level in the directory hierarchy
|
|
||||||
unsigned oldLength = StrLen(dir);
|
|
||||||
while ((filename > dir) && IsSlash(filename[-1]))
|
|
||||||
--filename;
|
|
||||||
*filename = 0;
|
|
||||||
if (oldLength == StrLen(dir))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
bool PathDoesFileExist (const wchar_t fileName[]) {
|
bool PathDoesFileExist (const wchar_t fileName[]) {
|
||||||
uint32_t attributes = GetFileAttributesW(fileName);
|
uint32_t attributes = GetFileAttributesW(fileName);
|
||||||
@ -822,35 +583,3 @@ bool PathDoesFileExist (const wchar_t fileName[]) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
bool PathDoesDirectoryExist (const wchar_t directory[]) {
|
|
||||||
uint32_t attributes = GetFileAttributesW(directory);
|
|
||||||
if (attributes == (uint32_t) -1)
|
|
||||||
return false;
|
|
||||||
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
bool PathDeleteFile (
|
|
||||||
const wchar_t file[]
|
|
||||||
) {
|
|
||||||
return DeleteFileW(file) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
bool PathMoveFile (
|
|
||||||
const wchar_t src[],
|
|
||||||
const wchar_t dst[]
|
|
||||||
) {
|
|
||||||
return MoveFileW(src, dst) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
bool PathCopyFile (
|
|
||||||
const wchar_t src[],
|
|
||||||
const wchar_t dst[]
|
|
||||||
) {
|
|
||||||
return CopyFileW(src, dst, FALSE) != 0;
|
|
||||||
}
|
|
||||||
|
@ -106,86 +106,6 @@ void PathRemoveFilename (
|
|||||||
PathMakePath(dst, dstChars, drive, dir, 0, 0);
|
PathMakePath(dst, dstChars, drive, dir, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathRemoveExtension (
|
|
||||||
wchar_t *dst,
|
|
||||||
const wchar_t src[],
|
|
||||||
unsigned dstChars
|
|
||||||
) {
|
|
||||||
ASSERT(dst);
|
|
||||||
ASSERT(src);
|
|
||||||
ASSERT(dstChars);
|
|
||||||
|
|
||||||
wchar_t drive[MAX_DRIVE];
|
|
||||||
wchar_t dir[MAX_DIR];
|
|
||||||
wchar_t fname[MAX_FNAME];
|
|
||||||
PathSplitPath(src, drive, dir, fname, 0);
|
|
||||||
PathMakePath(dst, dstChars, drive, dir, fname, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathSetExtension (
|
|
||||||
wchar_t *dst,
|
|
||||||
const wchar_t src[],
|
|
||||||
const wchar_t ext[],
|
|
||||||
unsigned dstChars
|
|
||||||
) {
|
|
||||||
ASSERT(dst);
|
|
||||||
ASSERT(src);
|
|
||||||
ASSERT(dst != ext);
|
|
||||||
ASSERT(dstChars);
|
|
||||||
|
|
||||||
wchar_t drive[MAX_DRIVE];
|
|
||||||
wchar_t dir[MAX_DIR];
|
|
||||||
wchar_t fname[MAX_FNAME];
|
|
||||||
PathSplitPath(src, drive, dir, fname, 0);
|
|
||||||
PathMakePath(dst, dstChars, drive, dir, fname, ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathAddExtension (
|
|
||||||
wchar_t *dst,
|
|
||||||
const wchar_t src[],
|
|
||||||
const wchar_t ext[],
|
|
||||||
unsigned dstChars
|
|
||||||
) {
|
|
||||||
ASSERT(dst);
|
|
||||||
ASSERT(src);
|
|
||||||
ASSERT(dst != ext);
|
|
||||||
ASSERT(dstChars);
|
|
||||||
|
|
||||||
wchar_t drive[MAX_DRIVE];
|
|
||||||
wchar_t dir[MAX_DIR];
|
|
||||||
wchar_t fname[MAX_FNAME];
|
|
||||||
wchar_t oldext[MAX_EXT];
|
|
||||||
PathSplitPath(src, drive, dir, fname, oldext);
|
|
||||||
PathMakePath(
|
|
||||||
dst,
|
|
||||||
dstChars,
|
|
||||||
drive,
|
|
||||||
dir,
|
|
||||||
fname,
|
|
||||||
oldext[0] ? oldext : ext
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathRemoveDirectory (
|
|
||||||
wchar_t *dst,
|
|
||||||
const wchar_t src[],
|
|
||||||
unsigned dstChars
|
|
||||||
) {
|
|
||||||
ASSERT(dst);
|
|
||||||
ASSERT(src);
|
|
||||||
ASSERT(dstChars);
|
|
||||||
|
|
||||||
wchar_t fname[MAX_FNAME];
|
|
||||||
wchar_t ext[MAX_EXT];
|
|
||||||
PathSplitPath(src, 0, 0, fname, ext);
|
|
||||||
PathMakePath(dst, dstChars, 0, 0, fname, ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* Email formatting functions
|
* Email formatting functions
|
||||||
|
@ -97,43 +97,10 @@ void PathGetProgramName (
|
|||||||
wchar_t * dst,
|
wchar_t * dst,
|
||||||
unsigned dstChars
|
unsigned dstChars
|
||||||
);
|
);
|
||||||
void PathGetModuleName (
|
|
||||||
wchar_t * dst,
|
|
||||||
unsigned dstChars
|
|
||||||
);
|
|
||||||
|
|
||||||
// this function will use the current directory if <src> is a relative path
|
|
||||||
// (see PathSetCurrentDirectory/PathGetCurrentDirectory)
|
|
||||||
bool PathFromString (
|
|
||||||
wchar_t * dst,
|
|
||||||
const wchar_t src[],
|
|
||||||
unsigned dstChars
|
|
||||||
);
|
|
||||||
bool PathFromString (
|
|
||||||
wchar_t * dst,
|
|
||||||
const wchar_t src[],
|
|
||||||
unsigned dstChars,
|
|
||||||
const wchar_t baseDir[]
|
|
||||||
);
|
|
||||||
|
|
||||||
bool PathDoesFileExist (
|
bool PathDoesFileExist (
|
||||||
const wchar_t fileName[]
|
const wchar_t fileName[]
|
||||||
);
|
);
|
||||||
bool PathDoesDirectoryExist (
|
|
||||||
const wchar_t directory[]
|
|
||||||
);
|
|
||||||
|
|
||||||
bool PathDeleteFile (
|
|
||||||
const wchar_t file[]
|
|
||||||
);
|
|
||||||
bool PathMoveFile (
|
|
||||||
const wchar_t src[],
|
|
||||||
const wchar_t dst[]
|
|
||||||
);
|
|
||||||
bool PathCopyFile (
|
|
||||||
const wchar_t src[],
|
|
||||||
const wchar_t dst[]
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -174,64 +141,6 @@ void PathRemoveFilename (
|
|||||||
unsigned dstChars
|
unsigned dstChars
|
||||||
);
|
);
|
||||||
|
|
||||||
// c:\file.txt => c:\dir1\dir2\file
|
|
||||||
void PathRemoveExtension (
|
|
||||||
wchar_t * dst,
|
|
||||||
const wchar_t src[],
|
|
||||||
unsigned dstChars
|
|
||||||
);
|
|
||||||
|
|
||||||
// c:\file + .out => c:\file.out
|
|
||||||
// c:\file. + .out => c:\file.out
|
|
||||||
// c:\file.txt + .out => c:\file.out
|
|
||||||
void PathSetExtension (
|
|
||||||
wchar_t * dst,
|
|
||||||
const wchar_t src[],
|
|
||||||
const wchar_t ext[],
|
|
||||||
unsigned dstChars
|
|
||||||
);
|
|
||||||
|
|
||||||
// c:\file + .out => c:\file.out
|
|
||||||
// c:\file. + .out => c:\file.
|
|
||||||
// c:\file.txt + .out => c:\file.txt
|
|
||||||
void PathAddExtension (
|
|
||||||
wchar_t * dst,
|
|
||||||
const wchar_t src[],
|
|
||||||
const wchar_t ext[],
|
|
||||||
unsigned dstChars
|
|
||||||
);
|
|
||||||
|
|
||||||
// c:\dir1\dir2\file.txt => file.txt
|
|
||||||
void PathRemoveDirectory (
|
|
||||||
wchar_t * dst,
|
|
||||||
const wchar_t src[],
|
|
||||||
unsigned dstChars
|
|
||||||
);
|
|
||||||
|
|
||||||
// c:\dir1\dir2\file.txt - c:\dir1 => .\dir2\file.txt
|
|
||||||
// c:\dir1\dir2\file1.txt - c:\dir1\dir4\file2.txt => ..\dir4\file2.txt
|
|
||||||
bool PathMakeRelative (
|
|
||||||
wchar_t * dst,
|
|
||||||
unsigned fromFlags,
|
|
||||||
const wchar_t from[],
|
|
||||||
unsigned toFlags,
|
|
||||||
const wchar_t to[],
|
|
||||||
unsigned dstChars
|
|
||||||
);
|
|
||||||
bool PathIsRelative (
|
|
||||||
const wchar_t src[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const wchar_t * PathFindFilename (const wchar_t path[]);
|
|
||||||
inline wchar_t * PathFindFilename (wchar_t * path) {
|
|
||||||
return const_cast<wchar_t *>(PathFindFilename(const_cast<const wchar_t *>(path)));
|
|
||||||
}
|
|
||||||
|
|
||||||
const wchar_t * PathFindExtension (const wchar_t path[]);
|
|
||||||
inline wchar_t * PathFindExtension (wchar_t * path) {
|
|
||||||
return const_cast<wchar_t *>(PathFindExtension(const_cast<const wchar_t *>(path)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
@ -263,30 +172,14 @@ EPathCreateDirError PathCreateDirectory (
|
|||||||
const wchar_t path[],
|
const wchar_t path[],
|
||||||
unsigned flags
|
unsigned flags
|
||||||
);
|
);
|
||||||
void PathDeleteDirectory (
|
|
||||||
const wchar_t path[],
|
|
||||||
unsigned flags
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// Set directory
|
|
||||||
bool PathSetCurrentDirectory (const wchar_t path[]);
|
|
||||||
void PathSetProgramDirectory ();
|
|
||||||
|
|
||||||
|
|
||||||
// Get directory
|
// Get directory
|
||||||
void PathGetProgramDirectory (
|
void PathGetProgramDirectory (
|
||||||
wchar_t * dst,
|
wchar_t * dst,
|
||||||
unsigned dstChars
|
unsigned dstChars
|
||||||
);
|
);
|
||||||
void PathGetCurrentDirectory (
|
|
||||||
wchar_t * dst,
|
|
||||||
unsigned dstChars
|
|
||||||
);
|
|
||||||
void PathGetTempDirectory (
|
|
||||||
wchar_t * dst,
|
|
||||||
unsigned dstChars
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// Product and user-specific common directory locations
|
// Product and user-specific common directory locations
|
||||||
|
@ -120,18 +120,6 @@ static chartype * IStrChr (chartype * str, findchartype ch, unsigned chars) {
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
template<class chartype, class findchartype>
|
|
||||||
static chartype * IStrChrR (chartype * str, findchartype ch) {
|
|
||||||
chartype * start = str;
|
|
||||||
for (; *str; ++str)
|
|
||||||
NULL_STMT;
|
|
||||||
while (str-- > start)
|
|
||||||
if (*str == ch)
|
|
||||||
return str;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
static inline bool ICharUnicodeToUtf8 (char ** dest, const wchar_t * source[], unsigned destChars) {
|
static inline bool ICharUnicodeToUtf8 (char ** dest, const wchar_t * source[], unsigned destChars) {
|
||||||
unsigned ch = *(*source)++;
|
unsigned ch = *(*source)++;
|
||||||
@ -226,20 +214,6 @@ static int IStrCmpI (const chartype str1[], const chartype str2[], unsigned char
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
// returns StrLen(dest)
|
|
||||||
template<class chartype>
|
|
||||||
static unsigned IStrCopyLen (chartype * dest, const chartype source[], unsigned chars) {
|
|
||||||
chartype * const start = dest;
|
|
||||||
while ((chars > 1) && ((*dest = *source++) != 0)) {
|
|
||||||
--chars;
|
|
||||||
++dest;
|
|
||||||
}
|
|
||||||
if (chars)
|
|
||||||
*dest = 0;
|
|
||||||
return dest - start;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
template<class chartype>
|
template<class chartype>
|
||||||
static void IStrPack (chartype * dest, const chartype source[], unsigned chars) {
|
static void IStrPack (chartype * dest, const chartype source[], unsigned chars) {
|
||||||
@ -273,46 +247,6 @@ static chartype * IStrStr (chartype source[], const chartype match[]) {
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
template<class chartype>
|
|
||||||
static chartype * IStrStrI (chartype source[], const chartype match[]) {
|
|
||||||
if (!*match)
|
|
||||||
return source;
|
|
||||||
|
|
||||||
for (chartype * curr = source; *curr; ++curr) {
|
|
||||||
chartype * s1 = curr;
|
|
||||||
const chartype * s2 = match;
|
|
||||||
while (*s1 && *s2 && (CharLowerFast(*s1) == CharLowerFast(*s2)))
|
|
||||||
s1++, s2++;
|
|
||||||
if (!*s2)
|
|
||||||
return curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
template<class chartype>
|
|
||||||
static void IStrLower (chartype * dest, unsigned chars) {
|
|
||||||
while ((chars > 1) && ((*dest = CharLowerFast(*dest)) != 0)) {
|
|
||||||
--chars;
|
|
||||||
++dest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
template<class chartype>
|
|
||||||
static void IStrLower (chartype * dest, const chartype source[], unsigned chars) {
|
|
||||||
while ((chars > 1) && ((*dest = CharLowerFast(*source)) != 0)) {
|
|
||||||
--chars;
|
|
||||||
++dest;
|
|
||||||
++source;
|
|
||||||
}
|
|
||||||
if (chars)
|
|
||||||
*dest = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
template<class chartype>
|
template<class chartype>
|
||||||
static uint32_t IStrHash (const chartype str[], unsigned chars) {
|
static uint32_t IStrHash (const chartype str[], unsigned chars) {
|
||||||
@ -496,26 +430,6 @@ const wchar_t * StrChr (const wchar_t str[], wchar_t ch, unsigned chars) {
|
|||||||
return IStrChr(str, ch, chars);
|
return IStrChr(str, ch, chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
char * StrChrR (char * str, char ch) {
|
|
||||||
return IStrChrR(str, ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
wchar_t * StrChrR (wchar_t * str, wchar_t ch) {
|
|
||||||
return IStrChrR(str, ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
const char * StrChrR (const char str[], char ch) {
|
|
||||||
return IStrChrR(str, ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
const wchar_t * StrChrR (const wchar_t str[], wchar_t ch) {
|
|
||||||
return IStrChrR(str, ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
unsigned StrPrintf (char * dest, unsigned count, const char format[], ...) {
|
unsigned StrPrintf (char * dest, unsigned count, const char format[], ...) {
|
||||||
va_list argList;
|
va_list argList;
|
||||||
@ -576,16 +490,6 @@ void StrCopy (wchar_t * dest, const wchar_t source[], unsigned chars) {
|
|||||||
IStrCopy(dest, source, chars);
|
IStrCopy(dest, source, chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
unsigned StrCopyLen (char * dest, const char source[], unsigned chars) {
|
|
||||||
return IStrCopyLen(dest, source, chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
unsigned StrCopyLen (wchar_t * dest, const wchar_t source[], unsigned chars) {
|
|
||||||
return IStrCopyLen(dest, source, chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void StrPack (char * dest, const char source[], unsigned chars) {
|
void StrPack (char * dest, const char source[], unsigned chars) {
|
||||||
IStrPack(dest, source, chars);
|
IStrPack(dest, source, chars);
|
||||||
@ -616,26 +520,6 @@ const wchar_t * StrStr (const wchar_t source[], const wchar_t match[]) {
|
|||||||
return IStrStr<const wchar_t>(source, match);
|
return IStrStr<const wchar_t>(source, match);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
char * StrStrI (char * source, const char match[]) {
|
|
||||||
return IStrStrI(source, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
const char * StrStrI (const char source[], const char match[]) {
|
|
||||||
return IStrStrI<const char>(source, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
wchar_t * StrStrI (wchar_t * source, const wchar_t match[]) {
|
|
||||||
return IStrStrI(source, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
const wchar_t * StrStrI (const wchar_t source[], const wchar_t match[]) {
|
|
||||||
return IStrStrI<const wchar_t>(source, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
unsigned StrLen (const char str[]) {
|
unsigned StrLen (const char str[]) {
|
||||||
return IStrLen(str);
|
return IStrLen(str);
|
||||||
@ -647,29 +531,6 @@ unsigned StrLen (const wchar_t str[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
unsigned StrUnicodeToUtf8 (char * dest, const wchar_t source[], unsigned destChars) {
|
|
||||||
char * destCurr = dest;
|
|
||||||
char * destTerm = dest + destChars;
|
|
||||||
while (*source && (destCurr + 1 < destTerm))
|
|
||||||
if (!ICharUnicodeToUtf8(&destCurr, &source, destTerm - destCurr - 1))
|
|
||||||
break;
|
|
||||||
if (destCurr < destTerm)
|
|
||||||
*destCurr = 0;
|
|
||||||
return destCurr - dest; // dest chars not including null terminator
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
unsigned StrUtf8ToUnicode (wchar_t * dest, const char source[], unsigned destChars) {
|
|
||||||
wchar_t * destCurr = dest;
|
|
||||||
wchar_t * destTerm = dest + destChars;
|
|
||||||
while (*source && (destCurr + 1 < destTerm))
|
|
||||||
ICharUtf8ToUnicode(&destCurr, &source);
|
|
||||||
if (destCurr < destTerm)
|
|
||||||
*destCurr = 0;
|
|
||||||
return destCurr - dest; // dest chars not including null terminator
|
|
||||||
}
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
float StrToFloat (const char source[], const char ** endptr) {
|
float StrToFloat (const char source[], const char ** endptr) {
|
||||||
return (float) strtod(source, const_cast<char **>(endptr));
|
return (float) strtod(source, const_cast<char **>(endptr));
|
||||||
}
|
}
|
||||||
@ -710,26 +571,6 @@ unsigned StrToUnsigned (const wchar_t source[], const wchar_t ** endptr, int rad
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void StrLower (char * dest, unsigned chars) {
|
|
||||||
IStrLower(dest, chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void StrLower (wchar_t * dest, unsigned chars) {
|
|
||||||
IStrLower(dest, chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void StrLower (char * dest, const char source[], unsigned chars) {
|
|
||||||
IStrLower(dest, source, chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void StrLower (wchar_t * dest, const wchar_t source[], unsigned chars) {
|
|
||||||
IStrLower(dest, source, chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
uint32_t StrHash (const char str[], unsigned chars) {
|
uint32_t StrHash (const char str[], unsigned chars) {
|
||||||
return IStrHash(str, chars);
|
return IStrHash(str, chars);
|
||||||
}
|
}
|
||||||
|
@ -61,9 +61,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
inline char CharLowerFast (char ch) { return ((ch >= 'A') && (ch <= 'Z')) ? (char )(ch + 'a' - 'A') : ch; }
|
inline char CharLowerFast (char ch) { return ((ch >= 'A') && (ch <= 'Z')) ? (char )(ch + 'a' - 'A') : ch; }
|
||||||
inline wchar_t CharLowerFast (wchar_t ch) { return ((ch >= L'A') && (ch <= L'Z')) ? (wchar_t)(ch + L'a' - L'A') : ch; }
|
inline wchar_t CharLowerFast (wchar_t ch) { return ((ch >= L'A') && (ch <= L'Z')) ? (wchar_t)(ch + L'a' - L'A') : ch; }
|
||||||
|
|
||||||
inline char CharUpperFast (char ch) { return ((ch >= 'a') && (ch <= 'z')) ? (char )(ch + 'A' - 'a') : ch; }
|
|
||||||
inline wchar_t CharUpperFast (wchar_t ch) { return ((ch >= L'a') && (ch <= L'z')) ? (wchar_t)(ch + L'A' - L'a') : ch; }
|
|
||||||
|
|
||||||
unsigned StrBytes (const char str[]); // includes space for terminator
|
unsigned StrBytes (const char str[]); // includes space for terminator
|
||||||
unsigned StrBytes (const wchar_t str[]); // includes space for terminator
|
unsigned StrBytes (const wchar_t str[]); // includes space for terminator
|
||||||
|
|
||||||
@ -101,22 +98,9 @@ const char * StrStr (const char source[], const char match[]);
|
|||||||
wchar_t * StrStr (wchar_t * source, const wchar_t match[]);
|
wchar_t * StrStr (wchar_t * source, const wchar_t match[]);
|
||||||
const wchar_t * StrStr (const wchar_t source[], const wchar_t match[]);
|
const wchar_t * StrStr (const wchar_t source[], const wchar_t match[]);
|
||||||
|
|
||||||
char * StrStrI (char * source, const char match[]);
|
|
||||||
const char * StrStrI (const char source[], const char match[]);
|
|
||||||
wchar_t * StrStrI (wchar_t * source, const wchar_t match[]);
|
|
||||||
const wchar_t * StrStrI (const wchar_t source[], const wchar_t match[]);
|
|
||||||
|
|
||||||
char * StrChrR (char * str, char ch);
|
|
||||||
wchar_t * StrChrR (wchar_t * str, wchar_t ch);
|
|
||||||
const char * StrChrR (const char str[], char ch);
|
|
||||||
const wchar_t * StrChrR (const wchar_t str[], wchar_t ch);
|
|
||||||
|
|
||||||
void StrCopy (char * dest, const char source[], unsigned chars);
|
void StrCopy (char * dest, const char source[], unsigned chars);
|
||||||
void StrCopy (wchar_t * dest, const wchar_t source[], unsigned chars);
|
void StrCopy (wchar_t * dest, const wchar_t source[], unsigned chars);
|
||||||
|
|
||||||
unsigned StrCopyLen (char * dest, const char source[], unsigned chars);
|
|
||||||
unsigned StrCopyLen (wchar_t * dest, const wchar_t source[], unsigned chars);
|
|
||||||
|
|
||||||
void StrPack (char * dest, const char source[], unsigned chars);
|
void StrPack (char * dest, const char source[], unsigned chars);
|
||||||
void StrPack (wchar_t * dest, const wchar_t source[], unsigned chars);
|
void StrPack (wchar_t * dest, const wchar_t source[], unsigned chars);
|
||||||
|
|
||||||
@ -126,9 +110,6 @@ unsigned StrToAnsi (char * dest, const wchar_t source[], unsigned destChars, uns
|
|||||||
unsigned StrToUnicode (wchar_t * dest, const char source[], unsigned destChars);
|
unsigned StrToUnicode (wchar_t * dest, const char source[], unsigned destChars);
|
||||||
unsigned StrToUnicode (wchar_t * dest, const char source[], unsigned destChars, unsigned codePage);
|
unsigned StrToUnicode (wchar_t * dest, const char source[], unsigned destChars, unsigned codePage);
|
||||||
|
|
||||||
unsigned StrUnicodeToUtf8 (char * dest, const wchar_t source[], unsigned destChars);
|
|
||||||
unsigned StrUtf8ToUnicode (wchar_t * dest, const char source[], unsigned destChars);
|
|
||||||
|
|
||||||
float StrToFloat (const char source[], const char ** endptr);
|
float StrToFloat (const char source[], const char ** endptr);
|
||||||
float StrToFloat (const wchar_t source[], const wchar_t ** endptr);
|
float StrToFloat (const wchar_t source[], const wchar_t ** endptr);
|
||||||
|
|
||||||
@ -140,11 +121,6 @@ unsigned StrToUnsigned (wchar_t source[], wchar_t ** endptr, int radix);
|
|||||||
unsigned StrToUnsigned (const char source[], const char ** endptr, int radix);
|
unsigned StrToUnsigned (const char source[], const char ** endptr, int radix);
|
||||||
unsigned StrToUnsigned (const wchar_t source[], const wchar_t ** endptr, int radix);
|
unsigned StrToUnsigned (const wchar_t source[], const wchar_t ** endptr, int radix);
|
||||||
|
|
||||||
void StrLower (char * dest, unsigned chars = (unsigned) -1);
|
|
||||||
void StrLower (wchar_t * dest, unsigned chars = (unsigned) -1);
|
|
||||||
void StrLower (char * dest, const char source[], unsigned chars);
|
|
||||||
void StrLower (wchar_t * dest, const wchar_t source[], unsigned chars);
|
|
||||||
|
|
||||||
uint32_t StrHash (const char str[], unsigned chars = (unsigned)-1);
|
uint32_t StrHash (const char str[], unsigned chars = (unsigned)-1);
|
||||||
uint32_t StrHash (const wchar_t str[], unsigned chars = (unsigned)-1);
|
uint32_t StrHash (const wchar_t str[], unsigned chars = (unsigned)-1);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user