Michael Hansen
12 years ago
16 changed files with 123 additions and 889 deletions
@ -1,407 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Path.cpp |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#include "../pnUtils.h" |
|
||||||
#include "plProduct.h" |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Local functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
// make sure our definition is at least as big as the compiler's definition
|
|
||||||
static_assert(MAX_PATH >= _MAX_PATH, "Windows and STDlib MAX_PATH constants differ"); |
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
static inline bool IsSlash (wchar_t c) { |
|
||||||
return (c == L'\\') || (c == L'/'); |
|
||||||
} |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
static inline wchar_t ConvertSlash (wchar_t c) { |
|
||||||
return c != L'/' ? c : L'\\'; |
|
||||||
} |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
static inline bool IsUncPath (const wchar_t path[]) { |
|
||||||
return IsSlash(path[0]) && IsSlash(path[1]); |
|
||||||
} |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
static const wchar_t * SkipUncDrive (const wchar_t path[]) { |
|
||||||
// UNC drive: "//server/share"
|
|
||||||
|
|
||||||
// skip over leading "//"
|
|
||||||
path += 2; |
|
||||||
|
|
||||||
// scan forward to end of server name
|
|
||||||
for (;; ++path) { |
|
||||||
if (!*path) |
|
||||||
return path; |
|
||||||
if (IsSlash(*path)) |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
// skip over '/'
|
|
||||||
++path; |
|
||||||
|
|
||||||
// skip over share name
|
|
||||||
for (;; ++path) { |
|
||||||
if (!*path) |
|
||||||
return path; |
|
||||||
if (IsSlash(*path)) |
|
||||||
return path; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
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; |
|
||||||
} |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
static void GetProgramName ( |
|
||||||
void * instance, |
|
||||||
wchar_t * dst, |
|
||||||
unsigned dstChars |
|
||||||
) { |
|
||||||
ASSERT(dst); |
|
||||||
ASSERT(dstChars); |
|
||||||
|
|
||||||
if (!GetModuleFileNameW((HINSTANCE) instance, dst, dstChars)) { |
|
||||||
ErrorAssert(__LINE__, __FILE__, "GetModuleName failed"); |
|
||||||
*dst = 0; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* |
|
||||||
* Exports |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathGetProgramName ( |
|
||||||
wchar_t * dst, |
|
||||||
unsigned dstChars |
|
||||||
) { |
|
||||||
GetProgramName(nil, dst, dstChars); |
|
||||||
} |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
// 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
|
|
||||||
// of the buffers.
|
|
||||||
void PathSplitPath ( |
|
||||||
const wchar_t path[], |
|
||||||
wchar_t * drive, |
|
||||||
wchar_t * dir, |
|
||||||
wchar_t * fname, |
|
||||||
wchar_t * ext |
|
||||||
) { |
|
||||||
ASSERT(path); |
|
||||||
ASSERT(path != drive); |
|
||||||
ASSERT(path != dir); |
|
||||||
ASSERT(path != fname); |
|
||||||
ASSERT(path != ext); |
|
||||||
|
|
||||||
// check for UNC path
|
|
||||||
if (IsUncPath(path)) { |
|
||||||
const wchar_t * pathStart = path; |
|
||||||
path = SkipUncDrive(path); |
|
||||||
|
|
||||||
if (drive) |
|
||||||
StrCopy(drive, pathStart, min(MAX_DRIVE, path - pathStart + 1)); |
|
||||||
} |
|
||||||
// regular DOS path
|
|
||||||
else if (path[0] && (path[1] == L':')) { |
|
||||||
if (drive) { |
|
||||||
ASSERT(MAX_DRIVE >= 3); |
|
||||||
drive[0] = path[0]; |
|
||||||
drive[1] = L':'; |
|
||||||
drive[2] = L'\0'; |
|
||||||
} |
|
||||||
|
|
||||||
path += 2; // skip over 'C' ':'
|
|
||||||
} |
|
||||||
else if (drive) { |
|
||||||
*drive = 0; |
|
||||||
} |
|
||||||
|
|
||||||
// extract path string, if any. Path now points to the first character
|
|
||||||
// of the path, if any, or the filename or extension, if no path was
|
|
||||||
// specified. Scan ahead for the last occurence, if any, of a '/' or
|
|
||||||
// '\' path separator character. If none is found, there is no path.
|
|
||||||
// We will also note the last '.' character found, if any, to aid in
|
|
||||||
// handling the extension.
|
|
||||||
const wchar_t *last_slash = nil, *last_dot = nil, *p = path; |
|
||||||
for (; *p; p++) { |
|
||||||
if (IsSlash(*p)) |
|
||||||
last_slash = p + 1; // point to one beyond for later copy
|
|
||||||
else if (*p == L'.') |
|
||||||
last_dot = p; |
|
||||||
} |
|
||||||
|
|
||||||
if (last_slash) { |
|
||||||
if (dir) |
|
||||||
StrCopy(dir, path, min(MAX_DIR, last_slash - path + 1)); |
|
||||||
path = last_slash; |
|
||||||
} |
|
||||||
else if (dir) { |
|
||||||
*dir = 0; |
|
||||||
} |
|
||||||
|
|
||||||
// extract file name and extension, if any. Path now points to the
|
|
||||||
// first character of the file name, if any, or the extension if no
|
|
||||||
// file name was given. Dot points to the '.' beginning the extension,
|
|
||||||
// if any.
|
|
||||||
if (last_dot && (last_dot >= path)) { |
|
||||||
if (fname) |
|
||||||
StrCopy(fname, path, min(MAX_FNAME, last_dot - path + 1)); |
|
||||||
if (ext) |
|
||||||
StrCopy(ext, last_dot, MAX_EXT); |
|
||||||
} |
|
||||||
else { |
|
||||||
if (fname) |
|
||||||
StrCopy(fname, path, MAX_FNAME); |
|
||||||
if (ext) |
|
||||||
*ext = 0; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathMakePath ( |
|
||||||
wchar_t * path, |
|
||||||
unsigned chars, |
|
||||||
const wchar_t drive[], |
|
||||||
const wchar_t dir[], |
|
||||||
const wchar_t fname[], |
|
||||||
const wchar_t ext[] |
|
||||||
) { |
|
||||||
ASSERT(path); |
|
||||||
ASSERT(path != drive); |
|
||||||
ASSERT(path != dir); |
|
||||||
ASSERT(path != fname); |
|
||||||
ASSERT(path != ext); |
|
||||||
|
|
||||||
// save space for string terminator
|
|
||||||
if (!chars--) |
|
||||||
return; |
|
||||||
|
|
||||||
// copy drive
|
|
||||||
if (drive && *drive && chars) { |
|
||||||
do { |
|
||||||
*path++ = ConvertSlash(*drive++); |
|
||||||
} while (--chars && *drive); |
|
||||||
ASSERT(!IsSlash(path[-1])); |
|
||||||
} |
|
||||||
|
|
||||||
// copy directory
|
|
||||||
if (dir && *dir && chars) { |
|
||||||
do { |
|
||||||
*path++ = ConvertSlash(*dir++); |
|
||||||
} while (--chars && *dir); |
|
||||||
|
|
||||||
// add trailing backslash
|
|
||||||
if (chars && (path[-1] != '\\')) { |
|
||||||
*path++ = L'\\'; |
|
||||||
chars--; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// copy filename
|
|
||||||
if (fname && *fname && chars) { |
|
||||||
// skip leading backslash
|
|
||||||
if (IsSlash(*fname)) |
|
||||||
++fname; |
|
||||||
|
|
||||||
do { |
|
||||||
*path++ = ConvertSlash(*fname++); |
|
||||||
} while (--chars && *fname); |
|
||||||
} |
|
||||||
|
|
||||||
// copy extension
|
|
||||||
if (ext && *ext && chars) { |
|
||||||
if (*ext != L'.') { |
|
||||||
*path++ = L'.'; |
|
||||||
chars--; |
|
||||||
} |
|
||||||
while (chars-- && *ext) |
|
||||||
*path++ = ConvertSlash(*ext++); |
|
||||||
} |
|
||||||
|
|
||||||
// add string terminator
|
|
||||||
*path = L'\0'; |
|
||||||
} |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathFindFiles ( |
|
||||||
ARRAY(PathFind) * paths, |
|
||||||
const wchar_t fileSpec[], |
|
||||||
unsigned pathFlags |
|
||||||
) { |
|
||||||
ASSERT(paths); |
|
||||||
ASSERT(fileSpec); |
|
||||||
|
|
||||||
HANDLE find; |
|
||||||
WIN32_FIND_DATAW fd; |
|
||||||
wchar_t directory[MAX_PATH]; |
|
||||||
PathRemoveFilename(directory, fileSpec, arrsize(directory)); |
|
||||||
if (INVALID_HANDLE_VALUE == (find = FindFirstFileW(fileSpec, &fd))) { |
|
||||||
DWORD err = GetLastError(); |
|
||||||
if ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND)) |
|
||||||
ASSERTMSG(err, "PathFindFiles failed"); |
|
||||||
} |
|
||||||
else { |
|
||||||
// find all the items in the current directory
|
|
||||||
do { |
|
||||||
unsigned fileFlags = 0; |
|
||||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
|
||||||
if (! (pathFlags & kPathFlagDirectory)) |
|
||||||
continue; |
|
||||||
|
|
||||||
// don't add "." and ".."
|
|
||||||
if (fd.cFileName[0] == L'.') { |
|
||||||
if (!fd.cFileName[1]) |
|
||||||
continue; |
|
||||||
if (fd.cFileName[1] == L'.' && !fd.cFileName[2]) |
|
||||||
continue; |
|
||||||
} |
|
||||||
|
|
||||||
fileFlags = kPathFlagDirectory; |
|
||||||
} |
|
||||||
else { |
|
||||||
if (! (pathFlags & kPathFlagFile)) |
|
||||||
continue; |
|
||||||
fileFlags = kPathFlagFile; |
|
||||||
} |
|
||||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { |
|
||||||
if (! (pathFlags & kPathFlagHidden)) |
|
||||||
continue; |
|
||||||
fileFlags |= kPathFlagHidden; |
|
||||||
} |
|
||||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) { |
|
||||||
if (! (pathFlags & kPathFlagSystem)) |
|
||||||
continue; |
|
||||||
fileFlags |= kPathFlagSystem; |
|
||||||
} |
|
||||||
|
|
||||||
// add this one to the list of found files
|
|
||||||
PathFind * pf = paths->New(); |
|
||||||
pf->flags = fileFlags; |
|
||||||
pf->fileLength = ((uint64_t) fd.nFileSizeHigh << 32) | fd.nFileSizeLow; |
|
||||||
pf->lastWriteTime = * (const uint64_t *) &fd.ftLastWriteTime; |
|
||||||
PathAddFilename(pf->name, directory, fd.cFileName, arrsize(pf->name)); |
|
||||||
} while (FindNextFileW(find, &fd)); |
|
||||||
FindClose(find); |
|
||||||
} |
|
||||||
|
|
||||||
// check for directory recursing
|
|
||||||
if ((pathFlags & kPathFlagRecurse) || StrStr(fileSpec, L"**")) { |
|
||||||
// recurse directories
|
|
||||||
} |
|
||||||
else { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
wchar_t dirSpec[MAX_PATH]; |
|
||||||
PathAddFilename(dirSpec, directory, L"*", arrsize(dirSpec)); |
|
||||||
if (INVALID_HANDLE_VALUE == (find = FindFirstFileW(dirSpec, &fd))) { |
|
||||||
DWORD err = GetLastError(); |
|
||||||
if ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND)) |
|
||||||
ErrorAssert(__LINE__, __FILE__, "PathFindFiles failed"); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
// find all the directories in the current directory
|
|
||||||
const wchar_t * spec = PathFindFilename(fileSpec); |
|
||||||
do { |
|
||||||
if (! (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { |
|
||||||
if (! (pathFlags & kPathFlagHidden)) |
|
||||||
continue; |
|
||||||
} |
|
||||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) { |
|
||||||
if (! (pathFlags & kPathFlagSystem)) |
|
||||||
continue; |
|
||||||
} |
|
||||||
|
|
||||||
// don't recurse "." and ".."
|
|
||||||
if (fd.cFileName[0] == L'.') { |
|
||||||
if (!fd.cFileName[1]) |
|
||||||
continue; |
|
||||||
if (fd.cFileName[1] == L'.' && !fd.cFileName[2]) |
|
||||||
continue; |
|
||||||
} |
|
||||||
|
|
||||||
// recursively search subdirectory
|
|
||||||
PathAddFilename(dirSpec, directory, fd.cFileName, arrsize(dirSpec)); |
|
||||||
PathAddFilename(dirSpec, dirSpec, spec, arrsize(dirSpec)); |
|
||||||
PathFindFiles(paths, dirSpec, pathFlags); |
|
||||||
|
|
||||||
} while (FindNextFileW(find, &fd)); |
|
||||||
FindClose(find); |
|
||||||
} |
|
@ -1,214 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtPath.cpp |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#include "pnUtPath.h" |
|
||||||
#include "pnUtStr.h" |
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* |
|
||||||
* Exported functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathGetProgramDirectory ( |
|
||||||
wchar_t *dst, |
|
||||||
unsigned dstChars |
|
||||||
) { |
|
||||||
ASSERT(dst); |
|
||||||
ASSERT(dstChars); |
|
||||||
|
|
||||||
PathGetProgramName(dst, dstChars); |
|
||||||
PathRemoveFilename(dst, dst, dstChars); |
|
||||||
} |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathAddFilename ( |
|
||||||
wchar_t *dst,
|
|
||||||
const wchar_t src[],
|
|
||||||
const wchar_t fname[], |
|
||||||
unsigned dstChars |
|
||||||
) { |
|
||||||
ASSERT(dst); |
|
||||||
ASSERT(dstChars); |
|
||||||
|
|
||||||
wchar_t temp[MAX_PATH]; |
|
||||||
if (dst == src) { |
|
||||||
StrCopy(temp, src, arrsize(temp)); |
|
||||||
src = temp; |
|
||||||
} |
|
||||||
else if (dst == fname) { |
|
||||||
StrCopy(temp, fname, arrsize(temp)); |
|
||||||
fname = temp; |
|
||||||
} |
|
||||||
|
|
||||||
PathMakePath(dst, dstChars, 0, src, fname, 0); |
|
||||||
} |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void PathRemoveFilename ( |
|
||||||
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]; |
|
||||||
PathSplitPath(src, drive, dir, 0, 0); |
|
||||||
PathMakePath(dst, dstChars, drive, dir, 0, 0); |
|
||||||
} |
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Email formatting functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void PathSplitEmail ( |
|
||||||
const wchar_t emailAddr[], |
|
||||||
wchar_t * user, |
|
||||||
unsigned userChars, |
|
||||||
wchar_t * domain, |
|
||||||
unsigned domainChars, |
|
||||||
wchar_t * tld, |
|
||||||
unsigned tldChars, |
|
||||||
wchar_t * subDomains, |
|
||||||
unsigned subDomainChars, |
|
||||||
unsigned subDomainCount |
|
||||||
) { |
|
||||||
ASSERT(emailAddr); |
|
||||||
|
|
||||||
#define SUB_DOMAIN(i) subDomains[(i) * subDomainChars] |
|
||||||
|
|
||||||
// null-terminate all output parameters
|
|
||||||
if (userChars) { |
|
||||||
ASSERT(user); |
|
||||||
user[0] = 0; |
|
||||||
} |
|
||||||
if (domainChars) { |
|
||||||
ASSERT(domain); |
|
||||||
domain[0] = 0; |
|
||||||
} |
|
||||||
if (tldChars) { |
|
||||||
ASSERT(tld); |
|
||||||
tld[0] = 0; |
|
||||||
} |
|
||||||
if (subDomainChars || subDomainCount) { |
|
||||||
ASSERT(subDomains); |
|
||||||
for (unsigned i = 0; i < subDomainCount; ++i) |
|
||||||
SUB_DOMAIN(i) = 0; |
|
||||||
} |
|
||||||
|
|
||||||
// bail now if email address is zero-length
|
|
||||||
unsigned len = StrLen(emailAddr); |
|
||||||
if (!len) |
|
||||||
return; |
|
||||||
|
|
||||||
// copy email address so we can tokenize it
|
|
||||||
wchar_t * tmp = (wchar_t*)malloc(sizeof(wchar_t) * (len + 1)); |
|
||||||
StrCopy(tmp, emailAddr, len + 1); |
|
||||||
const wchar_t * work = tmp; |
|
||||||
|
|
||||||
// parse user
|
|
||||||
wchar_t token[MAX_PATH]; |
|
||||||
if (!StrTokenize(&work, token, arrsize(token), L"@")) |
|
||||||
return; |
|
||||||
|
|
||||||
// copy user to output parameter
|
|
||||||
if (userChars) |
|
||||||
StrCopy(user, token, userChars); |
|
||||||
|
|
||||||
// skip past the '@' symbol
|
|
||||||
if (!*work++) |
|
||||||
return; |
|
||||||
|
|
||||||
// parse all domains
|
|
||||||
ARRAY(wchar_t *) arr; |
|
||||||
while (StrTokenize(&work, token, arrsize(token), L".")) { |
|
||||||
unsigned toklen = StrLen(token); |
|
||||||
wchar_t * str = (wchar_t*)malloc(sizeof(wchar_t) * (toklen + 1)); |
|
||||||
StrCopy(str, token, toklen + 1); |
|
||||||
arr.Add(str); |
|
||||||
|
|
||||||
free(str); |
|
||||||
} |
|
||||||
|
|
||||||
// copy domains to output parameters
|
|
||||||
unsigned index = 0; |
|
||||||
if (arr.Count() > 2) { |
|
||||||
// all domains except for the last two are sub-domains
|
|
||||||
for (index = 0; index < arr.Count() - 2; ++index) { |
|
||||||
if (index < subDomainCount) |
|
||||||
if (subDomains) |
|
||||||
StrCopy(&SUB_DOMAIN(index), arr[index], subDomainChars); |
|
||||||
} |
|
||||||
} |
|
||||||
if (arr.Count() > 1) { |
|
||||||
// second to last domain is the primary domain
|
|
||||||
if (domain) |
|
||||||
StrCopy(domain, arr[index], domainChars); |
|
||||||
// last comes the top level domain
|
|
||||||
++index; |
|
||||||
if (tld) |
|
||||||
StrCopy(tld, arr[index], tldChars); |
|
||||||
} |
|
||||||
else if (arr.Count() == 1) { |
|
||||||
// if only one domain, return it as a sub-domain
|
|
||||||
if (index < subDomainCount) |
|
||||||
if (subDomains) |
|
||||||
StrCopy(&SUB_DOMAIN(index), arr[index], subDomainChars); |
|
||||||
} |
|
||||||
|
|
||||||
free(tmp); |
|
||||||
|
|
||||||
#undef SUB_DOMAIN |
|
||||||
} |
|
@ -1,173 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtPath.h |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTPATH_H |
|
||||||
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTPATH_H |
|
||||||
|
|
||||||
#include "Pch.h" |
|
||||||
#include "pnUtArray.h" |
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Path definitions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
#ifndef MAX_PATH |
|
||||||
#define MAX_PATH 260 |
|
||||||
#endif |
|
||||||
|
|
||||||
#define MAX_DRIVE 256 |
|
||||||
#define MAX_DIR 256 |
|
||||||
#define MAX_FNAME 256 |
|
||||||
#define MAX_EXT 256 |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const unsigned kPathFlagFile = 1<<0; |
|
||||||
const unsigned kPathFlagDirectory = 1<<1; |
|
||||||
const unsigned kPathFlagHidden = 1<<2; |
|
||||||
const unsigned kPathFlagSystem = 1<<3; |
|
||||||
const unsigned kPathFlagRecurse = 1<<4; // also set if "**" used in filespec
|
|
||||||
|
|
||||||
struct PathFind { |
|
||||||
unsigned flags; |
|
||||||
uint64_t fileLength; |
|
||||||
uint64_t lastWriteTime; |
|
||||||
wchar_t name[MAX_PATH]; |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Path "get" functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
void PathFindFiles ( |
|
||||||
ARRAY(PathFind) * paths, |
|
||||||
const wchar_t fileSpec[], |
|
||||||
unsigned pathFlags |
|
||||||
); |
|
||||||
void PathGetProgramName ( |
|
||||||
wchar_t * dst, |
|
||||||
unsigned dstChars |
|
||||||
); |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Path building functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
void PathSplitPath ( |
|
||||||
const wchar_t path[], |
|
||||||
wchar_t * drive, |
|
||||||
wchar_t * dir, |
|
||||||
wchar_t * fname, |
|
||||||
wchar_t * ext |
|
||||||
); |
|
||||||
|
|
||||||
void PathMakePath ( |
|
||||||
wchar_t * path, |
|
||||||
unsigned chars, |
|
||||||
const wchar_t drive[], |
|
||||||
const wchar_t dir[], |
|
||||||
const wchar_t fname[], |
|
||||||
const wchar_t ext[] |
|
||||||
); |
|
||||||
|
|
||||||
// c:\dir1 + dir2\file.txt => c:\dir1\dir2\file.txt
|
|
||||||
void PathAddFilename ( |
|
||||||
wchar_t * dst, |
|
||||||
const wchar_t src[],
|
|
||||||
const wchar_t fname[], |
|
||||||
unsigned dstChars |
|
||||||
); |
|
||||||
|
|
||||||
// c:\dir1\dir2\file.txt => c:\dir1\dir2\ * note trailing backslash
|
|
||||||
void PathRemoveFilename ( |
|
||||||
wchar_t * dst, |
|
||||||
const wchar_t src[], |
|
||||||
unsigned dstChars |
|
||||||
); |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Directory functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
// Get directory
|
|
||||||
void PathGetProgramDirectory ( |
|
||||||
wchar_t * dst, |
|
||||||
unsigned dstChars |
|
||||||
); |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Email formatting functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
// you may send nil for any fields you don't care about
|
|
||||||
void PathSplitEmail ( |
|
||||||
const wchar_t emailAddr[], |
|
||||||
wchar_t * user, |
|
||||||
unsigned userChars, |
|
||||||
wchar_t * domain, |
|
||||||
unsigned domainChars, |
|
||||||
wchar_t * tld, |
|
||||||
unsigned tldChars, |
|
||||||
wchar_t * subDomains, // (wchar_t *)&subs --> wchar_t subs[16][256];
|
|
||||||
unsigned subDomainChars, // arrsize(subs[0]) --> 256
|
|
||||||
unsigned subDomainCount // arrsize(subs) --> 16
|
|
||||||
); |
|
||||||
#endif |
|
Loading…
Reference in new issue