Browse Source

Merge pull request #385 from Hoikas/patch-phailure

Fix some plUruLauncher Probz
Branan Purvine-Riley 11 years ago
parent
commit
cc6e92b20a
  1. 23
      Sources/Plasma/Apps/plClient/winmain.cpp
  2. 9
      Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp
  3. 3
      Sources/Plasma/Apps/plUruLauncher/plClientLauncher.h
  4. 45
      Sources/Plasma/Apps/plUruLauncher/winmain.cpp

23
Sources/Plasma/Apps/plClient/winmain.cpp

@ -497,22 +497,18 @@ bool InitPhysX()
return false; return false;
// launch the PhysX installer // launch the PhysX installer
STARTUPINFOW startupInfo; SHELLEXECUTEINFOW info;
PROCESS_INFORMATION processInfo; memset(&info, 0, sizeof(info));
memset(&startupInfo, 0, sizeof(startupInfo)); info.cbSize = sizeof(info);
memset(&processInfo, 0, sizeof(processInfo)); info.lpFile = s_physXSetupExeName;
startupInfo.cb = sizeof(startupInfo); info.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC;
if(!CreateProcessW(NULL, s_physXSetupExeName, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo)) ShellExecuteExW(&info);
{
hsMessageBox("Failed to launch PhysX installer.\nPlease re-run URU to ensure you have the latest version.", "Error", hsMessageBoxNormal);
return false;
}
// let the user know what's going on // let the user know what's going on
HWND waitingDialog = ::CreateDialog(gHInst, MAKEINTRESOURCE(IDD_LOADING), NULL, WaitingForPhysXDialogProc); HWND waitingDialog = ::CreateDialog(gHInst, MAKEINTRESOURCE(IDD_LOADING), NULL, WaitingForPhysXDialogProc);
// run a loop to wait for it to quit, pumping the windows message queue intermittently // run a loop to wait for it to quit, pumping the windows message queue intermittently
DWORD waitRet = WaitForSingleObject(processInfo.hProcess, 100); DWORD waitRet = WaitForSingleObject(info.hProcess, 100);
MSG msg; MSG msg;
while (waitRet == WAIT_TIMEOUT) while (waitRet == WAIT_TIMEOUT)
{ {
@ -521,12 +517,11 @@ bool InitPhysX()
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
} }
waitRet = WaitForSingleObject(processInfo.hProcess, 100); waitRet = WaitForSingleObject(info.hProcess, 100);
} }
// cleanup // cleanup
CloseHandle(processInfo.hThread); CloseHandle(info.hProcess);
CloseHandle(processInfo.hProcess);
::DestroyWindow(waitingDialog); ::DestroyWindow(waitingDialog);
} }
else else

9
Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp

@ -234,6 +234,8 @@ plString plClientLauncher::GetAppArgs() const
ss << " -Image"; ss << " -Image";
if (hsCheckBits(fFlags, kPatchOnly)) if (hsCheckBits(fFlags, kPatchOnly))
ss << " -PatchOnly"; ss << " -PatchOnly";
if (hsCheckBits(fFlags, kSkipLoginDialog))
ss << " -SkipLoginDialog";
return ss.GetString(); return ss.GetString();
} }
@ -429,13 +431,15 @@ void plClientLauncher::ParseArguments()
if (cmdParser.GetBool(arg)) \ if (cmdParser.GetBool(arg)) \
fFlags |= flag; fFlags |= flag;
enum { kArgServerIni, kArgNoSelfPatch, kArgImage, kArgRepairGame, kArgPatchOnly }; enum { kArgServerIni, kArgNoSelfPatch, kArgImage, kArgRepairGame, kArgPatchOnly,
kArgSkipLoginDialog };
const CmdArgDef cmdLineArgs[] = { const CmdArgDef cmdLineArgs[] = {
{ kCmdArgFlagged | kCmdTypeString, L"ServerIni", kArgServerIni }, { kCmdArgFlagged | kCmdTypeString, L"ServerIni", kArgServerIni },
{ kCmdArgFlagged | kCmdTypeBool, L"NoSelfPatch", kArgNoSelfPatch }, { kCmdArgFlagged | kCmdTypeBool, L"NoSelfPatch", kArgNoSelfPatch },
{ kCmdArgFlagged | kCmdTypeBool, L"Image", kArgImage }, { kCmdArgFlagged | kCmdTypeBool, L"Image", kArgImage },
{ kCmdArgFlagged | kCmdTypeBool, L"Repair", kArgRepairGame }, { kCmdArgFlagged | kCmdTypeBool, L"Repair", kArgRepairGame },
{ kCmdArgFlagged | kCmdTypeBool, L"PatchOnly", kArgPatchOnly } { kCmdArgFlagged | kCmdTypeBool, L"PatchOnly", kArgPatchOnly },
{ kCmdArgFlagged | kCmdTypeBool, L"SkipLoginDialog", kArgSkipLoginDialog }
}; };
CCmdParser cmdParser(cmdLineArgs, arrsize(cmdLineArgs)); CCmdParser cmdParser(cmdLineArgs, arrsize(cmdLineArgs));
@ -448,6 +452,7 @@ void plClientLauncher::ParseArguments()
APPLY_FLAG(kArgImage, kClientImage); APPLY_FLAG(kArgImage, kClientImage);
APPLY_FLAG(kArgRepairGame, kRepairGame); APPLY_FLAG(kArgRepairGame, kRepairGame);
APPLY_FLAG(kArgPatchOnly, kPatchOnly); APPLY_FLAG(kArgPatchOnly, kPatchOnly);
APPLY_FLAG(kArgSkipLoginDialog, kSkipLoginDialog);
// last chance setup // last chance setup
if (hsCheckBits(fFlags, kPatchOnly)) if (hsCheckBits(fFlags, kPatchOnly))

3
Sources/Plasma/Apps/plUruLauncher/plClientLauncher.h

@ -63,8 +63,9 @@ private:
{ {
kHaveSelfPatched = 1<<0, kHaveSelfPatched = 1<<0,
kClientImage = 1<<1, kClientImage = 1<<1,
kGameDataOnly = (1<<2), kGameDataOnly = 1<<2,
kPatchOnly = 1<<3, kPatchOnly = 1<<3,
kSkipLoginDialog = 1<<4,
kRepairGame = kHaveSelfPatched | kClientImage | kGameDataOnly, kRepairGame = kHaveSelfPatched | kClientImage | kGameDataOnly,
}; };

45
Sources/Plasma/Apps/plUruLauncher/winmain.cpp

@ -66,26 +66,29 @@ static plClientLauncher s_launcher;
static UINT s_taskbarCreated = RegisterWindowMessageW(L"TaskbarButtonCreated"); static UINT s_taskbarCreated = RegisterWindowMessageW(L"TaskbarButtonCreated");
static ITaskbarList3* s_taskbar = nullptr; static ITaskbarList3* s_taskbar = nullptr;
typedef std::unique_ptr<void, std::function<BOOL(HANDLE)>> handleptr_t;
// =================================================== // ===================================================
/** Create a global patcher mutex that is backwards compatible with eap's */ /** Create a global patcher mutex that is backwards compatible with eap's */
static HANDLE CreatePatcherMutex() static handleptr_t CreatePatcherMutex()
{ {
return CreateMutexW(nullptr, FALSE, plManifest::PatcherExecutable().AsString().ToWchar()); return handleptr_t(CreateMutexW(nullptr, TRUE, plManifest::PatcherExecutable().AsString().ToWchar()),
CloseHandle);
} }
static bool IsPatcherRunning() static bool IsPatcherRunning()
{ {
HANDLE mut = CreatePatcherMutex(); handleptr_t mut = CreatePatcherMutex();
return WaitForSingleObject(mut, 0) != WAIT_OBJECT_0; return WaitForSingleObject(mut.get(), 0) != WAIT_OBJECT_0;
} }
static void WaitForOldPatcher() static void WaitForOldPatcher()
{ {
HANDLE mut = CreatePatcherMutex(); handleptr_t mut = CreatePatcherMutex();
DWORD wait = WaitForSingleObject(mut, 0); DWORD wait = WaitForSingleObject(mut.get(), 0);
while (wait != WAIT_OBJECT_0) // :( :( :( while (wait != WAIT_OBJECT_0) // :( :( :(
wait = WaitForSingleObject(mut, 100); wait = WaitForSingleObject(mut.get(), 100);
Sleep(1000); // :( Sleep(1000); // :(
} }
@ -231,7 +234,7 @@ static void ISetDownloadStatus(const plString& status)
} }
static HANDLE ICreateProcess(const plFileName& exe, const plString& args) static handleptr_t ICreateProcess(const plFileName& exe, const plString& args)
{ {
STARTUPINFOW si; STARTUPINFOW si;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
@ -262,7 +265,7 @@ static HANDLE ICreateProcess(const plFileName& exe, const plString& args)
// So maybe it needs elevation... Or maybe everything arseploded. // So maybe it needs elevation... Or maybe everything arseploded.
if (result != FALSE) { if (result != FALSE) {
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
return pi.hProcess; return handleptr_t(pi.hProcess, CloseHandle);
} else if (GetLastError() == ERROR_ELEVATION_REQUIRED) { } else if (GetLastError() == ERROR_ELEVATION_REQUIRED) {
SHELLEXECUTEINFOW info; SHELLEXECUTEINFOW info;
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
@ -270,9 +273,9 @@ static HANDLE ICreateProcess(const plFileName& exe, const plString& args)
info.lpFile = file.GetData(); info.lpFile = file.GetData();
info.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC; info.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC;
info.lpParameters = args.ToWchar(); info.lpParameters = args.ToWchar();
hsAssert(ShellExecuteExW(&info), "ShellExecuteExW phailed"); ShellExecuteExW(&info);
return info.hProcess; return handleptr_t(info.hProcess, CloseHandle);
} else { } else {
wchar_t* msg = nullptr; wchar_t* msg = nullptr;
FormatMessageW( FormatMessageW(
@ -306,14 +309,13 @@ static bool IInstallRedist(const plFileName& exe)
ss << " /norestart"; // I don't want to image the accusations of viruses and hacking if this happened... ss << " /norestart"; // I don't want to image the accusations of viruses and hacking if this happened...
// Now fire up the process... // Now fire up the process...
HANDLE process = ICreateProcess(exe, ss.GetString()); handleptr_t process = ICreateProcess(exe, ss.GetString());
if (process) { if (process) {
WaitForSingleObject(process, INFINITE); WaitForSingleObject(process.get(), INFINITE);
// Get the exit code so we can indicate success/failure to the redist thread // Get the exit code so we can indicate success/failure to the redist thread
DWORD code = PLASMA_OK; DWORD code = PLASMA_OK;
hsAssert(GetExitCodeProcess(process, &code), "failed to get redist exit code"); GetExitCodeProcess(process.get(), &code);
CloseHandle(process);
return code != PLASMA_PHAILURE; return code != PLASMA_PHAILURE;
} }
@ -329,17 +331,14 @@ static void ILaunchClientExecutable(const plFileName& exe, const plString& args)
// Only launch a client executable if we're given one. If not, that's probably a cue that we're // Only launch a client executable if we're given one. If not, that's probably a cue that we're
// done with some service operation and need to go away. // done with some service operation and need to go away.
if (!exe.AsString().IsEmpty()) { if (!exe.AsString().IsEmpty()) {
HANDLE hEvent = CreateEventW(nullptr, TRUE, FALSE, L"UruPatcherEvent"); handleptr_t hEvent = handleptr_t(CreateEventW(nullptr, TRUE, FALSE, L"UruPatcherEvent"), CloseHandle);
HANDLE process = ICreateProcess(exe, args); handleptr_t process = ICreateProcess(exe, args);
// if this is the real game client, then we need to make sure it gets this event... // if this is the real game client, then we need to make sure it gets this event...
if (plManifest::ClientExecutable().AsString().CompareI(exe.AsString()) == 0) { if (plManifest::ClientExecutable().AsString().CompareI(exe.AsString()) == 0) {
WaitForInputIdle(process, 1000); WaitForInputIdle(process.get(), 1000);
WaitForSingleObject(hEvent, INFINITE); WaitForSingleObject(hEvent.get(), INFINITE);
} }
CloseHandle(process);
CloseHandle(hEvent);
} }
// time to hara-kiri... // time to hara-kiri...
@ -399,7 +398,7 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL
IShowErrorDialog(text.ToWchar()); IShowErrorDialog(text.ToWchar());
return PLASMA_OK; return PLASMA_OK;
} }
HANDLE _onePatcherMut = CreatePatcherMutex(); HANDLE _onePatcherMut = CreatePatcherMutex().release();
// Initialize the network core // Initialize the network core
s_launcher.InitializeNetCore(); s_launcher.InitializeNetCore();

Loading…
Cancel
Save