mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-17 02:51:27 +00:00
Deprecate plFileUtils and parts of pnUtPath
This commit is contained in:
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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(
|
||||
|
Reference in New Issue
Block a user