1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 03:09:13 +00:00

Deprecate plFileUtils and parts of pnUtPath

This commit is contained in:
2013-01-20 13:47:14 -08:00
parent 970ad3e729
commit 6e564476b7
114 changed files with 982 additions and 2117 deletions

View File

@ -58,7 +58,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsTimer.h"
#include "plPipeline/hsG3DDeviceSelector.h"
#include "plFile/plEncryptedStream.h"
#include "plFile/plFileUtils.h"
#include "plInputCore/plInputManager.h"
#include "plInputCore/plInputInterfaceMgr.h"
#include "plInputCore/plInputDevice.h"

View File

@ -75,7 +75,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plStatusLog/plStatusLog.h"
#include "plProduct.h"
#include "plNetGameLib/plNetGameLib.h"
#include "plFile/plFileUtils.h"
#include "plPhysX/plSimulationMgr.h"
@ -542,7 +541,7 @@ bool InitClient( HWND hWnd )
resMgr->SetDataPath("dat");
hsgResMgr::Init(resMgr);
if(!plFileUtils::FileExists("resource.dat"))
if (!plFileInfo("resource.dat").Exists())
{
hsMessageBox("Required file 'resource.dat' not found.", "Error", hsMessageBoxNormal);
return false;

View File

@ -66,21 +66,21 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
struct ManifestFile
{
ManifestFile(const wchar_t clientName[], const wchar_t downloadName[], const wchar_t md5val[], int flags, plLauncherInfo *info)
ManifestFile(const plFileName &clientName, const plFileName &downloadName, const plString &md5val, int flags, plLauncherInfo *info)
{
StrCopy(filename, clientName, arrsize(filename));
StrCopy(zipName, downloadName, arrsize(zipName));
StrCopy(md5, md5val, arrsize(md5));
filename = clientName;
zipName = downloadName;
md5 = md5val;
this->flags = flags;
this->info = info;
md5failed = false;
md5failed = false;
}
wchar_t filename[MAX_PATH];
wchar_t zipName[MAX_PATH];
wchar_t md5[MAX_PATH];
plFileName filename;
plFileName zipName;
plString md5;
int flags;
bool md5failed;
bool md5failed;
plLauncherInfo *info;
};
@ -117,10 +117,10 @@ struct ManifestResult {
static void DownloadCallback (
ENetError result,
void * param,
const wchar_t filename[],
hsStream * writer
ENetError result,
void * param,
const plFileName & filename,
hsStream * writer
);
@ -140,7 +140,7 @@ static unsigned s_fileListRequests;
static bool s_patchComplete;
static PROCESS_INFORMATION s_pi;
static long s_numFiles;
static char s_workingDir[MAX_PATH];
static plFileName s_workingDir;
static bool s_patchError;
static long s_asyncCoreInitCount;
static long s_numConnectFailures;
@ -179,9 +179,9 @@ double ProcessManifestEntryParam::startTime = 0;
// leaving clients with older patchers "dead in the water", without
// a way to play Uru.
#ifdef PLASMA_EXTERNAL_RELEASE
const wchar_t kPatcherExeFilename[] = L"UruLauncher.exe";
plFileName kPatcherExeFilename = "UruLauncher.exe";
#else
const wchar_t kPatcherExeFilename[] = L"plUruLauncher.exe";
plFileName kPatcherExeFilename = "plUruLauncher.exe";
#endif
@ -285,14 +285,11 @@ static void WaitUruExitProc (void * param) {
*/
//============================================================================
static bool MD5Check (const char filename[], const wchar_t md5[]) {
// Do md5 check
char md5copy[MAX_PATH];
static bool MD5Check (const plFileName& filename, const char *md5) {
plMD5Checksum existingMD5(filename);
plMD5Checksum latestMD5;
StrToAnsi(md5copy, md5, arrsize(md5copy));
latestMD5.SetFromHexString(md5copy);
latestMD5.SetFromHexString(md5);
return (existingMD5 == latestMD5);
}
@ -304,9 +301,8 @@ static void DecompressOgg (ManifestFile *mf) {
// decompress ogg if necessary
if ( (hsCheckBits(flags, plManifestFile::kSndFlagCacheSplit) || hsCheckBits(flags, plManifestFile::kSndFlagCacheStereo)) )
{
char path[MAX_PATH];
StrPrintf(path, arrsize(path), "%s%S", s_workingDir, mf->filename);
plFileName path = plFileName::Join(s_workingDir, mf->filename);
plAudioFileReader* reader = plAudioFileReader::CreateReader(path, plAudioCore::kAll, plAudioFileReader::kStreamNative);
if (!reader)
{
@ -355,12 +351,8 @@ static void RequestNextManifestFile () {
ManifestFile* nextfile = manifestQueue.front();
manifestQueue.pop();
char path[MAX_PATH];
wchar_t basePath[MAX_PATH];
StrPrintf(path, arrsize(path), "%s%S", s_workingDir, nextfile->filename);
StrToUnicode(basePath, path, arrsize(basePath));
PathRemoveFilename(basePath, basePath, arrsize(basePath));
PathCreateDirectory(basePath, kPathCreateDirFlagEntireTree);
plFileName path = plFileName::Join(s_workingDir, nextfile->filename);
plFileSystem::CreateDir(path.StripFileName(), true);
ProgressStream *writer = new ProgressStream(); // optimization: dont delete and recreate. Doesn't seem to be working currently, ZLibStream is breaking
if(!writer->Open(path, "wb"))
@ -374,7 +366,7 @@ static void RequestNextManifestFile () {
{
#ifndef PLASMA_EXTERNAL_RELEASE
char text[256];
StrPrintf(text, arrsize(text), "Updating URU... %S", nextfile->filename);
StrPrintf(text, arrsize(text), "Updating URU... %s", nextfile->filename.AsString().c_str());
nextfile->info->SetText(text);
#endif
NetCliFileDownloadRequest(nextfile->zipName, writer, DownloadCallback, nextfile, nextfile->info->buildId);
@ -383,19 +375,18 @@ static void RequestNextManifestFile () {
//============================================================================
static void DownloadCallback (
ENetError result,
void * param,
const wchar_t filename[],
hsStream * writer
ENetError result,
void * param,
const plFileName & filename,
hsStream * writer
) {
s_numConnectFailures = 0;
ManifestFile *mf = (ManifestFile *)param;
if (IS_NET_ERROR(result) && s_running && !s_patchError) {
if (result == kNetErrFileNotFound) {
char str[256];
StrPrintf(str, arrsize(str), "File not found on server: %S", filename);
MessageBox(nil, str, "URU Launcher", MB_ICONERROR);
plString str = plString::Format("File not found on server: %s", filename.AsString().c_str());
MessageBox(nil, str.c_str(), "URU Launcher", MB_ICONERROR);
s_patchError = true;
}
else if (result == kNetErrRemoteShutdown) {
@ -414,24 +405,17 @@ static void DownloadCallback (
writer->Close();
delete writer; // delete our stream
char path[MAX_PATH];
StrPrintf(
path,
arrsize(path),
"%s%S",
s_workingDir,
mf->filename
);
if(s_running)
plFileName path = plFileName::Join(s_workingDir, mf->filename);
if (s_running)
{
if(!MD5Check(path, mf->md5)) {
if(mf->md5failed)
if (!MD5Check(path, mf->md5.c_str())) {
if (mf->md5failed)
{
#ifdef PLASMA_EXTERNAL_RELEASE
MessageBox(nil, s_md5CheckError, "URU Launcher", MB_ICONERROR);
#else
char str[256];
StrPrintf(str, arrsize(str), "%s %s ", path, s_md5CheckError);
StrPrintf(str, arrsize(str), "%s %s ", path.AsString().c_str(), s_md5CheckError);
MessageBox(nil, str, "URU Launcher", MB_ICONERROR);
#endif // PLASMA_EXTERNAL_RELEASE
Shutdown(mf->info);
@ -442,7 +426,7 @@ static void DownloadCallback (
MessageBox(nil, s_fileOpenError, "URU Launcher", MB_ICONERROR);
#else
char str[256];
StrPrintf(str, arrsize(str), "%s %s", s_fileOpenError, path);
StrPrintf(str, arrsize(str), "%s %s", s_fileOpenError, path.AsString().c_str());
MessageBox(nil, str, "URU Launcher", MB_ICONERROR);
#endif // PLASMA_EXTERNAL_RELEASE
Shutdown(mf->info);
@ -456,11 +440,9 @@ static void DownloadCallback (
AtomicAdd(&s_numFiles, -1);
if(s_running)
if (s_running)
{
wchar_t ext[MAX_EXT];
PathSplitPath(mf->filename, nil, nil, nil, ext);
if(!StrCmpI(L".ogg", ext))
if (!mf->filename.GetFileExt().CompareI("ogg"))
{
DecompressOgg(mf);
}
@ -490,16 +472,9 @@ static void ProcessManifestEntry (void * param, ENetError error) {
StrPrintf(text, arrsize(text), "Checking for updates... %S", p->mr->manifest[p->index].clientName);
p->mr->info->SetText(text);
#endif
char path[MAX_PATH];
StrPrintf(
path,
arrsize(path),
"%s%S",
s_workingDir,
p->mr->manifest[p->index].clientName
);
plFileName path = plFileName::Join(s_workingDir, p->mr->manifest[p->index].clientName);
uint32_t start = (uint32_t)(TimeGetTime() / kTimeIntervalsPerMs);
if(!MD5Check(path, p->mr->manifest[p->index].md5)) {
if (!MD5Check(path, p->mr->manifest[p->index].md5.c_str())) {
p->mr->critsect.Lock();
p->mr->indices.Add(p->index);
p->mr->critsect.Unlock();
@ -547,10 +522,8 @@ static void ProcessManifest (void * param) {
VLDEnable();
#endif
wchar_t basePath[MAX_PATH];
char path[MAX_PATH];
AtomicAdd(&s_perf[kPerfThreadTaskCount], 1);
ManifestResult * mr = (ManifestResult *)param;
PatchInfo patchInfo;
@ -574,14 +547,13 @@ static void ProcessManifest (void * param) {
p->index = i;
p->mr = mr;
p->exists = false;
StrPrintf(path, arrsize(path), "%s%S", s_workingDir, mr->manifest[i].clientName);
fd = fopen(path, "r");
if(fd)
plFileName path = plFileName::Join(s_workingDir, mr->manifest[i].clientName);
fd = plFileSystem::Open(path, "r");
if (fd)
{
p->exists = true;
p->totalSize += p->mr->manifest[i].zipSize;
fclose(fd);
}
}
@ -617,10 +589,8 @@ static void ProcessManifest (void * param) {
if(s_running)
{
unsigned index = mr->indices[i];
StrPrintf(path, arrsize(path), "%s%S", s_workingDir, manifest[index].clientName);
StrToUnicode(basePath, path, arrsize(basePath));
PathRemoveFilename(basePath, basePath, arrsize(basePath));
PathCreateDirectory(basePath, kPathCreateDirFlagEntireTree);
plFileName path = plFileName::Join(s_workingDir, manifest[index].clientName);
plFileSystem::CreateDir(path.StripFileName(), true);
ManifestFile* mf = new ManifestFile(
manifest[index].clientName,
@ -637,7 +607,7 @@ static void ProcessManifest (void * param) {
MessageBox(nil, s_fileOpenError, "URU Launcher", MB_ICONERROR);
#else
char str[256];
StrPrintf(str, arrsize(str), "%s %s", path, s_fileOpenError);
StrPrintf(str, arrsize(str), "%s %s", path.AsString().c_str(), s_fileOpenError);
MessageBox(nil, str, "URU Launcher", MB_ICONERROR);
#endif
Shutdown(mr->info);
@ -711,10 +681,10 @@ static void ManifestCallback (
noDuplicates.Reserve(mr->manifest.Count());
for(unsigned i = 0; i < entryCount - 1; ++i)
{
if(StrCmp(mr->manifest[i].clientName, mr->manifest[i+1].clientName))
if (mr->manifest[i].clientName != mr->manifest[i+1].clientName)
{
noDuplicates.Add(mr->manifest[i]);
}
}
}
noDuplicates.Add(mr->manifest[entryCount - 1]);
@ -759,11 +729,12 @@ static void ThinManifestCallback (
return;
}
s_patchComplete = true;
char path[MAX_PATH];
for (unsigned i = 0; i < entryCount; ++i) {
if(!s_running) return;
StrPrintf(path, arrsize(path), "%s%S", s_workingDir, manifest[i].clientName);
if(!MD5Check(path, manifest[i].md5)){
if (!s_running)
return;
plFileName path = plFileName::Join(s_workingDir, manifest[i].clientName);
if (!MD5Check(path, manifest[i].md5.c_str())) {
s_patchComplete = false;
NetCliFileManifestRequest(ManifestCallback, info, s_manifest, info->buildId);
break;
@ -775,7 +746,7 @@ static void ThinManifestCallback (
info->progressCallback(kStatusPending, &patchInfo);
#ifndef PLASMA_EXTERNAL_RELEASE
char text[256];
StrPrintf(text, arrsize(text), "Checking for updates... %S", manifest[i].clientName);
StrPrintf(text, arrsize(text), "Checking for updates... %s", manifest[i].clientName.AsString().c_str());
info->SetText(text);
#endif
}
@ -894,9 +865,8 @@ void UruPrepProc (void * param) {
s_running = true;
plLauncherInfo *info = (plLauncherInfo *) param;
s_workingDir = plString::FromWchar(info->path);
StrToAnsi(s_workingDir, info->path, arrsize(s_workingDir));
InitAsyncCore();
NetClientInitialize();
NetClientSetErrorHandler(NetErrorHandler);

View File

@ -64,4 +64,4 @@ void UruStartProc (void * param);
void PlayerTerminateProc (void * param);
void PlayerStopProc (void * param);
extern const wchar_t kPatcherExeFilename[];
extern plFileName kPatcherExeFilename;

View File

@ -40,7 +40,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "plFile/hsFiles.h"
#include "plFile/plFileUtils.h"
#include "plFile/plSecureStream.h"
#include "plProduct.h"

View File

@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsTimer.h"
#include "plFile/hsFiles.h"
#include "plFile/plFileUtils.h"
#include "plResMgr/plResManager.h"
#include "plResMgr/plResMgrSettings.h"
@ -61,7 +60,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
plResManager* gResMgr = nil;
bool DumpStats(const char* patchDir);
bool DumpStats(const plFileName& patchDir);
bool DumpSounds();
//// PrintVersion ///////////////////////////////////////////////////////////////
@ -117,7 +116,7 @@ int main(int argc, char* argv[])
}
// Make sure we have 1 arg left after getting the options
char* pageFile = nil;
plFileName pageFile;
if (arg < argc)
pageFile = argv[arg];
else
@ -134,12 +133,7 @@ int main(int argc, char* argv[])
if (sounds)
DumpSounds();
if (stats)
{
char path[256];
strcpy(path, pageFile);
plFileUtils::StripFile(path);
DumpStats(path);
}
DumpStats(pageFile.StripFileName());
hsgResMgr::Shutdown();
@ -180,12 +174,12 @@ bool DumpSounds()
buffer->GetKey()->RefObject();
// Get the filename from it and add that file if necessary
const char* filename = buffer->GetFileName();
if (filename)
plFileName filename = buffer->GetFileName();
if (filename.IsValid())
{
uint32_t flags = 0;
if (stricmp(plFileUtils::GetFileExt(filename), "wav") != 0)
if (filename.GetFileExt().CompareI("wav") != 0)
{
if (buffer->HasFlag(plSoundBuffer::kOnlyLeftChannel) ||
buffer->HasFlag(plSoundBuffer::kOnlyRightChannel))
@ -196,9 +190,9 @@ bool DumpSounds()
hsSetBits(flags, plManifestFile::kSndFlagCacheStereo);
}
printf("%s,%u\n", filename, flags);
printf("%s,%u\n", filename.AsString().c_str(), flags);
}
// Unref the object so it goes away
buffer->GetKey()->UnRefObject();
}
@ -218,11 +212,11 @@ bool DumpSounds()
class plStatDumpIterator : public plRegistryPageIterator, public plRegistryKeyIterator
{
protected:
const char* fOutputDir;
plFileName fOutputDir;
hsUNIXStream fStream;
public:
plStatDumpIterator(const char* outputDir) : fOutputDir(outputDir) {}
plStatDumpIterator(const plFileName& outputDir) : fOutputDir(outputDir) {}
bool EatKey(const plKey& key)
{
@ -246,8 +240,8 @@ public:
{
const plPageInfo& info = page->GetPageInfo();
char fileName[256];
sprintf(fileName, "%s%s_%s.csv", fOutputDir, info.GetAge().c_str(), info.GetPage().c_str());
plFileName fileName = plFileName::Join(fOutputDir,
plString::Format("%s_%s.csv", info.GetAge().c_str(), info.GetPage().c_str()));
fStream.Open(fileName, "wt");
page->LoadKeys();
@ -259,7 +253,7 @@ public:
}
};
bool DumpStats(const char* patchDir)
bool DumpStats(const plFileName& patchDir)
{
plStatDumpIterator statDump(patchDir);
gResMgr->IterateAllPages(&statDump);

View File

@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plResMgr/plResManager.h"
#include "plPageOptimizer.h"
#include "plFile/plFileUtils.h"
#include "pnNetCommon/plSynchedObject.h"
int main(int argc, char* argv[])
@ -53,7 +52,8 @@ int main(int argc, char* argv[])
return 1;
}
printf("Optimizing %s...", plFileUtils::GetFileName(argv[1]));
plFileName filename = argv[1];
printf("Optimizing %s...", filename.GetFileName().c_str());
#ifndef _DEBUG
try {

View File

@ -50,21 +50,18 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnFactory/plFactory.h"
#include "pnKeyedObject/plKeyImp.h"
#include "plFile/plFileUtils.h"
#include "hsStream.h"
plPageOptimizer* plPageOptimizer::fInstance = nil;
plPageOptimizer::plPageOptimizer(const char* pagePath) :
plPageOptimizer::plPageOptimizer(const plFileName& pagePath) :
fOptimized(true),
fPageNode(nil),
fPagePath(pagePath)
{
fInstance = this;
strcpy(fTempPagePath, fPagePath);
plFileUtils::StripExt(fTempPagePath);
strcat(fTempPagePath, "_opt.prp");
fTempPagePath = fPagePath.StripFileExt() + "_opt.prp";
fResMgr = (plResManager*)hsgResMgr::ResMgr();
}
@ -135,8 +132,8 @@ void plPageOptimizer::Optimize()
if (loaded)
IRewritePage();
uint32_t oldSize = plFileUtils::GetFileSize(fPagePath);
uint32_t newSize = plFileUtils::GetFileSize(fTempPagePath);
uint64_t oldSize = plFileInfo(fPagePath).FileSize();
uint64_t newSize = plFileInfo(fTempPagePath).FileSize();
if (!loaded)
{
@ -144,19 +141,19 @@ void plPageOptimizer::Optimize()
}
else if (fOptimized)
{
plFileUtils::RemoveFile(fTempPagePath);
plFileSystem::Unlink(fTempPagePath);
puts("already optimized.");
}
else if (oldSize == newSize)
{
plFileUtils::RemoveFile(fPagePath, true);
plFileUtils::FileMove(fTempPagePath, fPagePath);
plFileSystem::Unlink(fPagePath);
plFileSystem::Move(fTempPagePath, fPagePath);
puts("complete");
}
else
{
plFileUtils::RemoveFile(fTempPagePath);
plFileSystem::Unlink(fTempPagePath);
puts("failed. File sizes different");
}
}

View File

@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnKeyedObject/plKey.h"
#include "pnKeyedObject/plUoid.h"
#include "plFileSystem.h"
#include <vector>
#include <set>
@ -63,8 +64,8 @@ protected:
bool fOptimized; // True after optimization if the page was already optimized
const char* fPagePath; // Path to our page
char fTempPagePath[512]; // Path to the temp output page
plFileName fPagePath; // Path to our page
plFileName fTempPagePath; // Path to the temp output page
plLocation fLoc; // Location of our page
plRegistryPageNode* fPageNode; // PageNode for our page
@ -78,7 +79,7 @@ protected:
void IRewritePage();
public:
plPageOptimizer(const char* pagePath);
plPageOptimizer(const plFileName& pagePath);
void Optimize();
};

View File

@ -601,7 +601,7 @@ static const CmdArgDef s_cmdLineArgs[] = {
PF_CONSOLE_LINK_FILE(Core)
//============================================================================
int __stdcall WinMain (
int __stdcall WinMain (
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
@ -619,18 +619,15 @@ int __stdcall WinMain (
while (*appCmdLine == L' ')
++appCmdLine;
wchar_t curPatcherFile[MAX_PATH];
wchar_t newPatcherFile[MAX_PATH];
bool isTempPatcher = false;
PathGetProgramName(curPatcherFile, arrsize(curPatcherFile));
PathRemoveFilename(newPatcherFile, curPatcherFile, arrsize(newPatcherFile));
PathAddFilename(newPatcherFile, newPatcherFile, kPatcherExeFilename, arrsize(newPatcherFile));
plFileName curPatcherFile = plFileSystem::GetCurrentAppPath();
plFileName newPatcherFile = plFileName::Join(curPatcherFile.StripFileName(), kPatcherExeFilename);
// If our exe name doesn't match the "real" patcher exe name, then we are a newly
// downloaded patcher that needs to be copied over to the "real" exe.. so do that,
// exec it, and exit.
if (0 != StrCmpI(curPatcherFile, newPatcherFile)) {
if (0 != curPatcherFile.AsString().CompareI(newPatcherFile.AsString())) {
isTempPatcher = true;
}
@ -683,12 +680,12 @@ int __stdcall WinMain (
for (;;) {
// Wait for previous process to exit. This will happen if we just patched.
HANDLE mutex = CreateMutexW(NULL, TRUE, kPatcherExeFilename);
HANDLE mutex = CreateMutexW(NULL, TRUE, kPatcherExeFilename.AsString().ToWchar());
DWORD wait = WaitForSingleObject(mutex, 0);
while(!s_shutdown && wait != WAIT_OBJECT_0)
wait = WaitForSingleObject(mutex, 100);
// User canceled
// User canceled
if (s_shutdown)
break;
@ -701,7 +698,7 @@ int __stdcall WinMain (
// Wait for the other process to exit
Sleep(1000);
if (!plFileUtils::RemoveFile(newPatcherFile)) {
if (!plFileSystem::Unlink(newPatcherFile)) {
wchar_t error[256];
DWORD errorCode = GetLastError();
wchar_t *msg = TranslateErrorCode(errorCode);
@ -711,7 +708,7 @@ int __stdcall WinMain (
LocalFree(msg);
break;
}
if (!plFileUtils::FileMove(curPatcherFile, newPatcherFile)) {
if (!plFileSystem::Move(curPatcherFile, newPatcherFile)) {
wchar_t error[256];
DWORD errorCode = GetLastError();
wchar_t *msg = TranslateErrorCode(errorCode);
@ -719,7 +716,7 @@ int __stdcall WinMain (
StrPrintf(error, arrsize(error), L"Failed to replace old patcher executable. %s", msg);
MessageBoxW(GetTopWindow(nil), error, L"Error", MB_OK);
// attempt to clean up this tmp file
plFileUtils::RemoveFile(curPatcherFile);
plFileSystem::Unlink(curPatcherFile);
LocalFree(msg);
break;
}
@ -732,7 +729,7 @@ int __stdcall WinMain (
si.cb = sizeof(si);
wchar_t cmdline[MAX_PATH];
StrPrintf(cmdline, arrsize(cmdline), L"%s %s", newPatcherFile, s_launcherInfo.cmdLine);
StrPrintf(cmdline, arrsize(cmdline), L"%S %s", newPatcherFile.AsString().c_str(), s_launcherInfo.cmdLine);
// we have only successfully patched if we actually launch the new version of the patcher
(void)CreateProcessW(
@ -758,12 +755,11 @@ int __stdcall WinMain (
// Clean up old temp files
ARRAY(PathFind) paths;
wchar_t fileSpec[MAX_PATH];
PathGetProgramDirectory(fileSpec, arrsize(fileSpec));
PathAddFilename(fileSpec, fileSpec, L"*.tmp", arrsize(fileSpec));
PathFindFiles(&paths, fileSpec, kPathFlagFile);
plFileName fileSpec = plFileSystem::GetCurrentAppPath().StripFileName();
fileSpec = plFileName::Join(fileSpec, "*.tmp");
PathFindFiles(&paths, fileSpec.AsString().ToWchar(), kPathFlagFile);
for (PathFind * path = paths.Ptr(); path != paths.Term(); ++path)
plFileUtils::RemoveFile(path->name);
plFileSystem::Unlink(plString::FromWchar(path->name));
SetConsoleCtrlHandler(CtrlHandler, TRUE);
InitAsyncCore(); // must do this before self patch, since it needs to connect to the file server

View File

@ -63,7 +63,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnNetCli/pnNetCli.h"
#include "plNetGameLib/plNetGameLib.h"
#include "pnEncryption/plChecksum.h"
#include "plFile/plFileUtils.h"
#include "plCompression/plZlibStream.h"
#include "plClientPatcher/UruPlayer.h"

View File

@ -77,7 +77,7 @@ static bool s_downloadComplete;
static long s_numFiles;
static ENetError s_patchResult;
static bool s_updated;
static wchar_t s_newPatcherFile[MAX_PATH];
static plFileName s_newPatcherFile;
/*****************************************************************************
@ -106,10 +106,10 @@ static void NetErrorHandler (ENetProtocol protocol, ENetError error) {
//============================================================================
static void DownloadCallback (
ENetError result,
void * param,
const wchar_t filename[],
hsStream * writer
ENetError result,
void * param,
const plFileName & filename,
hsStream * writer
) {
if(IS_NET_ERROR(result)) {
switch (result) {
@ -140,14 +140,12 @@ static void DownloadCallback (
}
//============================================================================
static bool MD5Check (const char filename[], const wchar_t md5[]) {
static bool MD5Check (const plFileName &filename, const char *md5) {
// Do md5 check
char md5copy[MAX_PATH];
plMD5Checksum existingMD5(filename);
plMD5Checksum latestMD5;
StrToAnsi(md5copy, md5, arrsize(md5copy));
latestMD5.SetFromHexString(md5copy);
latestMD5.SetFromHexString(md5);
return (existingMD5 == latestMD5);
}
@ -155,7 +153,7 @@ static bool MD5Check (const char filename[], const wchar_t md5[]) {
static void ManifestCallback (
ENetError result,
void * param,
const wchar_t group[],
const wchar_t group[],
const NetCliFileManifestEntry manifest[],
unsigned entryCount
) {
@ -183,24 +181,19 @@ static void ManifestCallback (
}
#endif
char ansi[MAX_PATH];
// MD5 check current patcher against value in manifest
ASSERT(entryCount == 1);
wchar_t curPatcherFile[MAX_PATH];
PathGetProgramName(curPatcherFile, arrsize(curPatcherFile));
StrToAnsi(ansi, curPatcherFile, arrsize(ansi));
if (!MD5Check(ansi, manifest[0].md5)) {
plFileName curPatcherFile = plFileSystem::GetCurrentAppPath();
if (!MD5Check(curPatcherFile, manifest[0].md5.c_str())) {
// MessageBox(GetTopWindow(nil), "MD5 failed", "Msg", MB_OK);
SelfPatcherStream::totalBytes += manifest[0].zipSize;
AtomicAdd(&s_numFiles, 1);
SetText("Downloading new patcher...");
StrToAnsi(ansi, s_newPatcherFile, arrsize(ansi));
SelfPatcherStream * stream = new SelfPatcherStream;
if (!stream->Open(ansi, "wb"))
ErrorAssert(__LINE__, __FILE__, "Failed to create file: %s, errno: %u", ansi, errno);
if (!stream->Open(s_newPatcherFile, "wb"))
ErrorAssert(__LINE__, __FILE__, "Failed to create file: %s, errno: %u", s_newPatcherFile.AsString().c_str(), errno);
NetCliFileDownloadRequest(manifest[0].downloadName, stream, DownloadCallback, nil);
}
@ -213,7 +206,7 @@ static void ManifestCallback (
static void FileSrvIpAddressCallback (
ENetError result,
void * param,
const wchar_t addr[]
const wchar_t addr[]
) {
NetCliGateKeeperDisconnect();
@ -230,9 +223,9 @@ static void FileSrvIpAddressCallback (
NetCliFileStartConnect(&caddr, 1, true);
delete[] caddr;
PathGetProgramDirectory(s_newPatcherFile, arrsize(s_newPatcherFile));
GetTempFileNameW(s_newPatcherFile, kPatcherExeFilename, 0, s_newPatcherFile);
plFileUtils::RemoveFile(s_newPatcherFile);
s_newPatcherFile = plFileSystem::GetCurrentAppPath().StripFileName();
s_newPatcherFile = plFileSystem::GetTempFilename(kPatcherExeFilename.AsString().c_str(), s_newPatcherFile);
plFileSystem::Unlink(s_newPatcherFile);
NetCliFileManifestRequest(ManifestCallback, nil, s_manifest);
}
@ -279,7 +272,7 @@ static bool SelfPatcherProc (bool * abort, plLauncherInfo *info) {
si.cb = sizeof(si);
wchar_t cmdline[MAX_PATH];
StrPrintf(cmdline, arrsize(cmdline), L"%s %s", s_newPatcherFile, info->cmdLine);
StrPrintf(cmdline, arrsize(cmdline), L"%s %s", s_newPatcherFile.AsString().ToWchar(), info->cmdLine);
// we have only successfully patched if we actually launch the new version of the patcher
patched = CreateProcessW(