private void ThreadCheckForUpdatesFunction(object checkVersionOnlyParameter) { try { bool checkVersionOnly = (bool)checkVersionOnlyParameter; Result = CheckForUpdatesInternal(checkVersionOnly); } catch (Exception e) { Result = PatchResult.Failed; FailReason = PatchFailReason.FatalException; FailDetails = e.ToString(); } if (Result == PatchResult.AlreadyUpToDate) { comms.Log(Localization.Get(StringId.AppIsUpToDate)); } else if (Result == PatchResult.Success) { comms.Log(Localization.Get(StringId.UpdateAvailable)); } else { comms.Log(comms.FailDetails); } comms.DisposeFileLogger(); IsRunning = false; }
// For self-patching applications only - should be called after Run(true) returns PatchResult.Success // Starts specified self patcher executable with required parameters public bool ApplySelfPatch(string selfPatcherExecutable, string postSelfPatchExecutable = null) { IsRunning = true; Operation = PatchOperation.ApplyingSelfPatch; comms.InitializeFileLogger(); comms.ListenerCallStarted(); try { selfPatcherExecutable = selfPatcherExecutable.Trim(); if (postSelfPatchExecutable != null) { postSelfPatchExecutable = postSelfPatchExecutable.Trim(); } if (!File.Exists(selfPatcherExecutable)) { Result = PatchResult.Failed; FailReason = PatchFailReason.SelfPatcherNotFound; FailDetails = Localization.Get(StringId.E_SelfPatcherDoesNotExist); comms.Log(comms.FailDetails); return(false); } string instructionsPath = comms.CachePath + PatchParameters.SELF_PATCH_INSTRUCTIONS_FILENAME; string completedInstructionsPath = comms.CachePath + PatchParameters.SELF_PATCH_COMPLETED_INSTRUCTIONS_FILENAME; if (!File.Exists(instructionsPath)) { Result = PatchResult.Failed; FailReason = PatchFailReason.Unknown; FailDetails = ""; comms.LogToFile(Localization.Get(StringId.E_XDoesNotExist, instructionsPath)); return(false); } FileInfo selfPatcher = new FileInfo(selfPatcherExecutable); string args = "\"" + instructionsPath + "\" \"" + completedInstructionsPath + "\""; if (!string.IsNullOrEmpty(postSelfPatchExecutable) && File.Exists(postSelfPatchExecutable)) { args += " \"" + postSelfPatchExecutable + "\""; } ProcessStartInfo startInfo = new ProcessStartInfo(selfPatcher.FullName) { Arguments = args, WorkingDirectory = selfPatcher.DirectoryName }; Process.Start(startInfo); Result = PatchResult.Success; } catch (Exception e) { Result = PatchResult.Failed; FailReason = PatchFailReason.FatalException; FailDetails = e.ToString(); comms.LogToFile(e); return(false); } finally { comms.DisposeFileLogger(); IsRunning = false; comms.ListenerCallFinished(); } Process.GetCurrentProcess().Kill(); return(true); }