mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Finish deprecation of pnUtPath
This commit is contained in:
@ -816,10 +816,10 @@ static void SaveUserPass (LoginDialogParam *pLoginParam, char *password)
|
|||||||
// loaded the namePassHash from the file
|
// loaded the namePassHash from the file
|
||||||
if (thePass.Compare(FAKE_PASS_STRING) != 0)
|
if (thePass.Compare(FAKE_PASS_STRING) != 0)
|
||||||
{
|
{
|
||||||
wchar_t domain[15];
|
// Regex search for primary email domain
|
||||||
PathSplitEmail(theUser.ToWchar(), nil, 0, domain, arrsize(domain), nil, 0, nil, 0, 0);
|
std::vector<plString> match = theUser.RESearch("[^@]+@([^.]+\\.)*([^.]+)\\.[^.]+");
|
||||||
|
|
||||||
if (StrLen(domain) == 0 || StrCmpI(domain, L"gametap") == 0) {
|
if (match.empty() || match[2].CompareI("gametap") == 0) {
|
||||||
plSHA1Checksum shasum(StrLen(password) * sizeof(password[0]), (uint8_t*)password);
|
plSHA1Checksum shasum(StrLen(password) * sizeof(password[0]), (uint8_t*)password);
|
||||||
uint32_t* dest = reinterpret_cast<uint32_t*>(pLoginParam->namePassHash);
|
uint32_t* dest = reinterpret_cast<uint32_t*>(pLoginParam->namePassHash);
|
||||||
const uint32_t* from = reinterpret_cast<const uint32_t*>(shasum.GetValue());
|
const uint32_t* from = reinterpret_cast<const uint32_t*>(shasum.GetValue());
|
||||||
|
@ -47,6 +47,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
|
|
||||||
#include "Pch.h"
|
#include "Pch.h"
|
||||||
#include "hsThread.h"
|
#include "hsThread.h"
|
||||||
|
#include "plFile/hsFiles.h"
|
||||||
|
#include <algorithm>
|
||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
|
|
||||||
|
|
||||||
@ -128,7 +130,7 @@ static hsSemaphore s_dialogCreateEvent(0);
|
|||||||
static hsMutex s_critsect;
|
static hsMutex s_critsect;
|
||||||
static LISTDECL(WndEvent, link) s_eventQ;
|
static LISTDECL(WndEvent, link) s_eventQ;
|
||||||
static hsSemaphore s_shutdownEvent(0);
|
static hsSemaphore s_shutdownEvent(0);
|
||||||
static wchar_t s_workingDir[MAX_PATH];
|
static plFileName s_workingDir;
|
||||||
static hsSemaphore s_statusEvent(0);
|
static hsSemaphore s_statusEvent(0);
|
||||||
static char s_curlError[CURL_ERROR_SIZE];
|
static char s_curlError[CURL_ERROR_SIZE];
|
||||||
|
|
||||||
@ -633,9 +635,9 @@ int __stdcall WinMain (
|
|||||||
|
|
||||||
CCmdParser cmdParser(s_cmdLineArgs, arrsize(s_cmdLineArgs));
|
CCmdParser cmdParser(s_cmdLineArgs, arrsize(s_cmdLineArgs));
|
||||||
cmdParser.Parse();
|
cmdParser.Parse();
|
||||||
|
|
||||||
if (!cmdParser.IsSpecified(kArgCwd))
|
if (!cmdParser.IsSpecified(kArgCwd))
|
||||||
PathGetProgramDirectory(s_workingDir, arrsize(s_workingDir));
|
s_workingDir = plFileSystem::GetCurrentAppPath().StripFileName();
|
||||||
|
|
||||||
s_hInstance = hInstance;
|
s_hInstance = hInstance;
|
||||||
memset(&s_launcherInfo, 0, sizeof(s_launcherInfo));
|
memset(&s_launcherInfo, 0, sizeof(s_launcherInfo));
|
||||||
@ -754,12 +756,11 @@ int __stdcall WinMain (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clean up old temp files
|
// Clean up old temp files
|
||||||
ARRAY(PathFind) paths;
|
|
||||||
plFileName fileSpec = plFileSystem::GetCurrentAppPath().StripFileName();
|
plFileName fileSpec = plFileSystem::GetCurrentAppPath().StripFileName();
|
||||||
fileSpec = plFileName::Join(fileSpec, "*.tmp");
|
std::vector<plFileName> tmpFiles = plFileSystem::ListDir(fileSpec, "*.tmp");
|
||||||
PathFindFiles(&paths, fileSpec.AsString().ToWchar(), kPathFlagFile);
|
std::for_each(tmpFiles.begin(), tmpFiles.end(), [](const plFileName &tmp) {
|
||||||
for (PathFind * path = paths.Ptr(); path != paths.Term(); ++path)
|
plFileSystem::Unlink(tmp);
|
||||||
plFileSystem::Unlink(plString::FromWchar(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
|
||||||
@ -768,7 +769,7 @@ int __stdcall WinMain (
|
|||||||
ENetError selfPatchResult;
|
ENetError selfPatchResult;
|
||||||
if (false == (SelfPatch(cmdParser.IsSpecified(kArgNoSelfPatch), &s_shutdown, &selfPatchResult, &s_launcherInfo)) && IS_NET_SUCCESS(selfPatchResult)) {
|
if (false == (SelfPatch(cmdParser.IsSpecified(kArgNoSelfPatch), &s_shutdown, &selfPatchResult, &s_launcherInfo)) && IS_NET_SUCCESS(selfPatchResult)) {
|
||||||
// We didn't self-patch, so check for client updates and download them, then exec the client
|
// We didn't self-patch, so check for client updates and download them, then exec the client
|
||||||
StrCopy(s_launcherInfo.path, s_workingDir, arrsize(s_launcherInfo.path));
|
StrCopy(s_launcherInfo.path, s_workingDir.AsString().ToWchar(), arrsize(s_launcherInfo.path));
|
||||||
s_launcherInfo.prepCallback = PrepCallback;
|
s_launcherInfo.prepCallback = PrepCallback;
|
||||||
s_launcherInfo.initCallback = InitCallback;
|
s_launcherInfo.initCallback = InitCallback;
|
||||||
s_launcherInfo.startCallback = StartCallback;
|
s_launcherInfo.startCallback = StartCallback;
|
||||||
|
@ -440,6 +440,7 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wch
|
|||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
# define MAX_PATH PATH_MAX
|
# define MAX_PATH PATH_MAX
|
||||||
#endif
|
#endif
|
||||||
|
#define MAX_EXT (256)
|
||||||
|
|
||||||
// Useful floating point utilities
|
// Useful floating point utilities
|
||||||
inline float hsDegreesToRadians(float deg) { return float(deg * (M_PI / 180)); }
|
inline float hsDegreesToRadians(float deg) { return float(deg * (M_PI / 180)); }
|
||||||
|
@ -50,6 +50,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
|
# include <dirent.h>
|
||||||
|
# include <fnmatch.h>
|
||||||
# include <cstdlib>
|
# include <cstdlib>
|
||||||
# include <functional>
|
# include <functional>
|
||||||
# include <memory>
|
# include <memory>
|
||||||
@ -283,8 +285,11 @@ FILE *plFileSystem::Open(const plFileName &filename, const char *mode)
|
|||||||
bool plFileSystem::Unlink(const plFileName &filename)
|
bool plFileSystem::Unlink(const plFileName &filename)
|
||||||
{
|
{
|
||||||
#if HS_BUILD_FOR_WIN32
|
#if HS_BUILD_FOR_WIN32
|
||||||
return _wunlink(filename.AsString().ToWchar()) == 0;
|
plStringBuffer<wchar_t> wfilename = filename.AsString().ToWchar();
|
||||||
|
_wchmod(wfilename, S_IWRITE);
|
||||||
|
return _wunlink(wfilename) == 0;
|
||||||
#else
|
#else
|
||||||
|
chmod(filename.AsString().c_str(), S_IWRITE);
|
||||||
return unlink(filename.AsString().c_str()) == 0;
|
return unlink(filename.AsString().c_str()) == 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -343,6 +348,55 @@ bool plFileSystem::CreateDir(const plFileName &dir, bool checkParents)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<plFileName> plFileSystem::ListDir(const plFileName &path, const char *pattern)
|
||||||
|
{
|
||||||
|
std::vector<plFileName> contents;
|
||||||
|
|
||||||
|
#if HS_BUILD_FOR_WIN32
|
||||||
|
if (!pattern || !pattern[0])
|
||||||
|
pattern = "*";
|
||||||
|
plFileName searchPattern = plFileName::Join(path, pattern);
|
||||||
|
|
||||||
|
WIN32_FIND_DATAW findData;
|
||||||
|
HANDLE hFind = FindFirstFileW(searchPattern.AsString().ToWchar(), &findData);
|
||||||
|
if (hFind == INVALID_HANDLE_VALUE)
|
||||||
|
return contents;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
|
// Should also handle . and ..
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
contents.push_back(plFileName::Join(path, plString::FromWchar(findData.cFileName)));
|
||||||
|
} while (FindNextFileW(hFind, &findData));
|
||||||
|
|
||||||
|
FindClose(hFind);
|
||||||
|
#else
|
||||||
|
DIR *dir = opendir(path.AsString().c_str());
|
||||||
|
if (!dir)
|
||||||
|
return contents;
|
||||||
|
|
||||||
|
struct dirent *de;
|
||||||
|
while (de = readdir(dir)) {
|
||||||
|
if (plFileInfo(de->d_name).IsDirectory()) {
|
||||||
|
// Should also handle . and ..
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pattern && pattern[0] && fnmatch(pattern, de->d_name))
|
||||||
|
contents.push_back(plFileName::Join(path, de->d_name));
|
||||||
|
else if (!pattern || !pattern[0])
|
||||||
|
contents.push_back(plFileName::Join(path, de->d_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
plFileName plFileSystem::GetUserDataPath()
|
plFileName plFileSystem::GetUserDataPath()
|
||||||
{
|
{
|
||||||
static plFileName _userData;
|
static plFileName _userData;
|
||||||
|
@ -303,6 +303,15 @@ namespace plFileSystem
|
|||||||
*/
|
*/
|
||||||
bool CreateDir(const plFileName &dir, bool checkParents = false);
|
bool CreateDir(const plFileName &dir, bool checkParents = false);
|
||||||
|
|
||||||
|
/** Fetch a list of files contained in the supplied \a path.
|
||||||
|
* If \a pattern is specified (e.g. "*.tmp"), use that to filter
|
||||||
|
* matches. Otherwise, all files in the path will be returned.
|
||||||
|
* Note that returned filenames include the provided path -- to
|
||||||
|
* get only the filename, call .GetFileName() on an entry.
|
||||||
|
*/
|
||||||
|
std::vector<plFileName> ListDir(const plFileName &path,
|
||||||
|
const char *pattern = nullptr);
|
||||||
|
|
||||||
/** Get the User's data directory. If it doesn't exist, this will
|
/** Get the User's data directory. If it doesn't exist, this will
|
||||||
* create it.
|
* create it.
|
||||||
*/
|
*/
|
||||||
|
@ -49,75 +49,46 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
#include "HeadSpin.h"
|
#include "HeadSpin.h"
|
||||||
#include "hsExceptions.h"
|
#include "hsExceptions.h"
|
||||||
|
|
||||||
#ifdef HS_BUILD_FOR_WIN32
|
|
||||||
|
|
||||||
#include "hsWindows.h"
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
|
|
||||||
//// ParseDirectory //////////////////////////////////////////////////////////
|
//// ParseDirectory //////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const plString& mask /* = L"*.*" */)
|
bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const char* mask /* = L"*.*" */)
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATAW findInfo;
|
|
||||||
HANDLE handle;
|
|
||||||
|
|
||||||
hsAssert( fEngine != nil, "Cannot do a dir execute without an engine!" );
|
hsAssert( fEngine != nil, "Cannot do a dir execute without an engine!" );
|
||||||
|
|
||||||
handle = FindFirstFileW(plFileName::Join(path, mask).AsString().ToWchar(), &findInfo);
|
std::vector<plFileName> files = plFileSystem::ListDir(path, mask);
|
||||||
if (handle == INVALID_HANDLE_VALUE)
|
for (auto iter = files.begin(); iter != files.end(); ++iter)
|
||||||
return false;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
if (!( findInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
plFileName name = iter->GetFileName();
|
||||||
|
if (AlreadyProcessedFile(path, name))
|
||||||
|
continue;
|
||||||
|
AddProcessedFile(path, name);
|
||||||
|
if (!fEngine->ExecuteFile(*iter))
|
||||||
{
|
{
|
||||||
plFileName name = plString::FromWchar(findInfo.cFileName);
|
// Change the following line once we have a better way of reporting
|
||||||
plFileName fileAndPath = plFileName::Join(path, name);
|
// errors in the parsing
|
||||||
if (AlreadyProcessedFile(path, name))
|
plStringStream error, caption;
|
||||||
continue;
|
|
||||||
AddProcessedFile(path, name);
|
|
||||||
if (!fEngine->ExecuteFile(fileAndPath))
|
|
||||||
{
|
|
||||||
// Change the following line once we have a better way of reporting
|
|
||||||
// errors in the parsing
|
|
||||||
std::wstringstream error;
|
|
||||||
std::wstringstream caption;
|
|
||||||
wchar_t* errorMsg = hsStringToWString(fEngine->GetErrorMsg());
|
|
||||||
wchar_t* errorLine = hsStringToWString(fEngine->GetLastErrorLine());
|
|
||||||
|
|
||||||
caption << L"Error parsing " << findInfo.cFileName;
|
caption << "Error parsing " << name.AsString();
|
||||||
error << errorMsg << L":\n\nCommand: '" << errorLine << L"'\n\nPress OK to continue parsing files.";
|
error << fEngine->GetErrorMsg() << ":\n\nCommand: '" << fEngine->GetLastErrorLine()
|
||||||
|
<< "'\n\nPress OK to continue parsing files.";
|
||||||
|
|
||||||
hsMessageBox(error.str().c_str(), caption.str().c_str(), hsMessageBoxNormal);
|
hsMessageBox(error.GetString().c_str(), caption.GetString().c_str(), hsMessageBoxNormal);
|
||||||
|
|
||||||
delete [] errorMsg;
|
SetCheckProcessedFiles(true);
|
||||||
delete [] errorLine;
|
return false;
|
||||||
|
|
||||||
FindClose(handle);
|
|
||||||
SetCheckProcessedFiles(true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} while (FindNextFileW(handle, &findInfo) != 0);
|
}
|
||||||
|
|
||||||
FindClose(handle);
|
|
||||||
SetCheckProcessedFiles(true);
|
SetCheckProcessedFiles(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#error This needs to be implemented for this platform!!!!
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void pfConsoleDirSrc::ResetProcessedFiles()
|
void pfConsoleDirSrc::ResetProcessedFiles()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0;i<fProcessedFiles.size(); i++)
|
for(i=0;i<fProcessedFiles.size(); i++)
|
||||||
delete fProcessedFiles[i];
|
delete fProcessedFiles[i];
|
||||||
fProcessedFiles.clear();
|
fProcessedFiles.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -71,14 +71,14 @@ class pfConsoleDirSrc
|
|||||||
{
|
{
|
||||||
plFileName fPath;
|
plFileName fPath;
|
||||||
plFileName fFile;
|
plFileName fFile;
|
||||||
FileName() : fPath(""), fFile("") {}
|
FileName() {}
|
||||||
FileName(const plFileName& p, const plFileName& f) : fPath(p), fFile(f) {}
|
FileName(const plFileName& p, const plFileName& f) : fPath(p), fFile(f) {}
|
||||||
};
|
};
|
||||||
std::vector<FileName*> fProcessedFiles; // list of init files we've already executed
|
std::vector<FileName*> fProcessedFiles; // list of init files we've already executed
|
||||||
bool fCheckProcessedFiles; // set to check and skip files init files we've already executed
|
bool fCheckProcessedFiles; // set to check and skip files init files we've already executed
|
||||||
public:
|
public:
|
||||||
pfConsoleDirSrc(pfConsoleEngine *engine) : fCheckProcessedFiles(false) { fEngine = engine; }
|
pfConsoleDirSrc(pfConsoleEngine *engine) : fCheckProcessedFiles(false) { fEngine = engine; }
|
||||||
pfConsoleDirSrc(pfConsoleEngine *engine, const plFileName& path, const plString& mask = "*.ini")
|
pfConsoleDirSrc(pfConsoleEngine *engine, const plFileName& path, const char* mask = "*.ini")
|
||||||
: fCheckProcessedFiles(false)
|
: fCheckProcessedFiles(false)
|
||||||
{
|
{
|
||||||
fEngine = engine;
|
fEngine = engine;
|
||||||
@ -88,7 +88,7 @@ class pfConsoleDirSrc
|
|||||||
~pfConsoleDirSrc() { ResetProcessedFiles(); }
|
~pfConsoleDirSrc() { ResetProcessedFiles(); }
|
||||||
|
|
||||||
// Steps through the given directory and executes all files with the console engine
|
// Steps through the given directory and executes all files with the console engine
|
||||||
bool ParseDirectory(const plFileName& path, const plString& mask = "*.*");
|
bool ParseDirectory(const plFileName& path, const char* mask = "*.*");
|
||||||
|
|
||||||
void ResetProcessedFiles();
|
void ResetProcessedFiles();
|
||||||
bool AlreadyProcessedFile(const plFileName& path, const plFileName& file);
|
bool AlreadyProcessedFile(const plFileName& path, const plFileName& file);
|
||||||
|
@ -305,7 +305,7 @@ static bool DumpSpecificMsgInfo(plMessage* msg, plString& info)
|
|||||||
|
|
||||||
case plClientMsg::kLoadAgeKeys:
|
case plClientMsg::kLoadAgeKeys:
|
||||||
case plClientMsg::kReleaseAgeKeys:
|
case plClientMsg::kReleaseAgeKeys:
|
||||||
info += plString::Format(" - Age: %s", clientMsg->GetAgeName());
|
info += plString::Format(" - Age: %s", clientMsg->GetAgeName().c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -805,17 +805,15 @@ static void StartListenThread () {
|
|||||||
#ifdef HS_DEBUGGING
|
#ifdef HS_DEBUGGING
|
||||||
#include <StdIo.h>
|
#include <StdIo.h>
|
||||||
static void __cdecl DumpInvalidData (
|
static void __cdecl DumpInvalidData (
|
||||||
const wchar_t filename[],
|
const plFileName & filename,
|
||||||
unsigned bytes,
|
unsigned bytes,
|
||||||
const uint8_t data[],
|
const uint8_t data[],
|
||||||
const char fmt[],
|
const char fmt[],
|
||||||
...
|
...
|
||||||
) {
|
) {
|
||||||
wchar_t path[MAX_PATH];
|
plFileName path = plFileSystem::GetCurrentAppPath().StripFileName();
|
||||||
PathGetProgramDirectory(path, arrsize(path));
|
path = plFileName::Join(path, "Log", filename);
|
||||||
PathAddFilename(path, path, L"Log", arrsize(path));
|
if (FILE * f = plFileSystem::Open(path, "wb")) {
|
||||||
PathAddFilename(path, path, filename, arrsize(path));
|
|
||||||
if (FILE * f = _wfopen(path, L"wb")) {
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
vfprintf(f, fmt, args);
|
vfprintf(f, fmt, args);
|
||||||
@ -1027,7 +1025,7 @@ void INtSocketOpCompleteSocketRead (
|
|||||||
static long s_once;
|
static long s_once;
|
||||||
if (!AtomicAdd(&s_once, 1)) {
|
if (!AtomicAdd(&s_once, 1)) {
|
||||||
DumpInvalidData(
|
DumpInvalidData(
|
||||||
L"NtSockErr.log",
|
"NtSockErr.log",
|
||||||
sizeof(sock->buffer),
|
sizeof(sock->buffer),
|
||||||
sock->buffer,
|
sock->buffer,
|
||||||
"SocketDispatchRead error for %p: %d %d %d\r\n",
|
"SocketDispatchRead error for %p: %d %d %d\r\n",
|
||||||
|
@ -12,7 +12,6 @@ set(pnUtils_HEADERS
|
|||||||
pnUtHash.h
|
pnUtHash.h
|
||||||
pnUtList.h
|
pnUtList.h
|
||||||
pnUtMisc.h
|
pnUtMisc.h
|
||||||
pnUtPath.h
|
|
||||||
pnUtPragma.h
|
pnUtPragma.h
|
||||||
pnUtPriQ.h
|
pnUtPriQ.h
|
||||||
pnUtRef.h
|
pnUtRef.h
|
||||||
@ -28,7 +27,6 @@ set(pnUtils_SOURCES
|
|||||||
pnUtHash.cpp
|
pnUtHash.cpp
|
||||||
pnUtList.cpp
|
pnUtList.cpp
|
||||||
pnUtMisc.cpp
|
pnUtMisc.cpp
|
||||||
pnUtPath.cpp
|
|
||||||
pnUtStr.cpp
|
pnUtStr.cpp
|
||||||
pnUtTime.cpp
|
pnUtTime.cpp
|
||||||
)
|
)
|
||||||
@ -36,7 +34,6 @@ set(pnUtils_SOURCES
|
|||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(pnUtils_WIN32
|
set(pnUtils_WIN32
|
||||||
Win32/pnUtW32Misc.cpp
|
Win32/pnUtW32Misc.cpp
|
||||||
Win32/pnUtW32Path.cpp
|
|
||||||
Win32/pnUtW32Str.cpp
|
Win32/pnUtW32Str.cpp
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
|
@ -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);
|
|
||||||
}
|
|
@ -59,7 +59,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
#include "pnUtTime.h"
|
#include "pnUtTime.h"
|
||||||
#include "pnUtStr.h"
|
#include "pnUtStr.h"
|
||||||
#include "pnUtRef.h"
|
#include "pnUtRef.h"
|
||||||
#include "pnUtPath.h"
|
|
||||||
#include "pnUtCmd.h"
|
#include "pnUtCmd.h"
|
||||||
#include "pnUtMisc.h"
|
#include "pnUtMisc.h"
|
||||||
#include "pnUtCrypt.h"
|
#include "pnUtCrypt.h"
|
||||||
|
@ -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
|
|
@ -1203,14 +1203,14 @@ static bool s_running;
|
|||||||
static CCritSect s_critsect;
|
static CCritSect s_critsect;
|
||||||
static LISTDECL(CliAuConn, link) s_conns;
|
static LISTDECL(CliAuConn, link) s_conns;
|
||||||
static CliAuConn * s_active;
|
static CliAuConn * s_active;
|
||||||
static wchar_t s_accountName[kMaxAccountNameLength];
|
static wchar_t s_accountName[kMaxAccountNameLength];
|
||||||
static ShaDigest s_accountNamePassHash;
|
static ShaDigest s_accountNamePassHash;
|
||||||
static wchar_t s_authToken[kMaxPublisherAuthKeyLength];
|
static wchar_t s_authToken[kMaxPublisherAuthKeyLength];
|
||||||
static wchar_t s_os[kMaxGTOSIdLength];
|
static wchar_t s_os[kMaxGTOSIdLength];
|
||||||
|
|
||||||
static long s_perf[kNumPerf];
|
static long s_perf[kNumPerf];
|
||||||
|
|
||||||
static uint32_t s_encryptionKey[4];
|
static uint32_t s_encryptionKey[4];
|
||||||
|
|
||||||
static FNetCliAuthRecvBufferHandler s_bufRcvdCb;
|
static FNetCliAuthRecvBufferHandler s_bufRcvdCb;
|
||||||
static FNetCliAuthConnectCallback s_connectedCb;
|
static FNetCliAuthConnectCallback s_connectedCb;
|
||||||
@ -2635,13 +2635,11 @@ bool LoginRequestTrans::Send () {
|
|||||||
ShaDigest challengeHash;
|
ShaDigest challengeHash;
|
||||||
uint32_t clientChallenge = 0;
|
uint32_t clientChallenge = 0;
|
||||||
|
|
||||||
wchar_t domain[15];
|
// Regex search for primary email domain
|
||||||
PathSplitEmail(s_accountName, nil, 0, domain, arrsize(domain), nil, 0, nil, 0, 0);
|
std::vector<plString> match = plString::FromWchar(s_accountName).RESearch("[^@]+@([^.]+\\.)*([^.]+)\\.[^.]+");
|
||||||
|
if (match.empty() || match[2].CompareI("gametap") == 0) {
|
||||||
if (StrLen(domain) == 0 || StrCmpI(domain, L"gametap") == 0) {
|
|
||||||
memcpy(challengeHash, s_accountNamePassHash, sizeof(ShaDigest));
|
memcpy(challengeHash, s_accountNamePassHash, sizeof(ShaDigest));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
CryptCreateRandomSeed(
|
CryptCreateRandomSeed(
|
||||||
sizeof(clientChallenge),
|
sizeof(clientChallenge),
|
||||||
(uint8_t *) &clientChallenge
|
(uint8_t *) &clientChallenge
|
||||||
@ -5243,10 +5241,10 @@ void NetCliAuthAccountExistsRequest (
|
|||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
void NetCliAuthLoginRequest (
|
void NetCliAuthLoginRequest (
|
||||||
const wchar_t accountName[],
|
const wchar_t accountName[],
|
||||||
const ShaDigest * accountNamePassHash,
|
const ShaDigest * accountNamePassHash,
|
||||||
const wchar_t authToken[],
|
const wchar_t authToken[],
|
||||||
const wchar_t os[],
|
const wchar_t os[],
|
||||||
FNetCliAuthLoginRequestCallback callback,
|
FNetCliAuthLoginRequestCallback callback,
|
||||||
void * param
|
void * param
|
||||||
) {
|
) {
|
||||||
|
@ -135,10 +135,10 @@ typedef void (*FNetCliAuthLoginRequestCallback)(
|
|||||||
unsigned playerCount
|
unsigned playerCount
|
||||||
);
|
);
|
||||||
void NetCliAuthLoginRequest (
|
void NetCliAuthLoginRequest (
|
||||||
const wchar_t accountName[], // nil --> reuse previous acct name
|
const wchar_t accountName[], // nil --> reuse previous acct name
|
||||||
const ShaDigest * accountNamePassHash, // nil --> reuse previous acct pass
|
const ShaDigest * accountNamePassHash, // nil --> reuse previous acct pass
|
||||||
const wchar_t authToken[], // nil --> reuse previous auth token
|
const wchar_t authToken[], // nil --> reuse previous auth token
|
||||||
const wchar_t os[], // nil --> reuse previous os
|
const wchar_t os[], // nil --> reuse previous os
|
||||||
FNetCliAuthLoginRequestCallback callback,
|
FNetCliAuthLoginRequestCallback callback,
|
||||||
void * param
|
void * param
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user