/// <summary> /// Asynnchronously checks the files and compares them against the set of standard MD5 checksums /// </summary> /// <param name="theServerInfo">ServerInfo onject of the server to patch for</param> public void PatchClient(ServerInfo theServerInfo) { //cache the ol' server info cachedServerInfo = theServerInfo; if (string.IsNullOrEmpty(SWGANHPAth)) { return; } //get a list of the custom TRE's ServiceMaker myServiceMaker = new ServiceMaker(); LauncherData.LauncherDataClient myClient = myServiceMaker.GetServiceClient(); CustomeTreCallObject theObject = new CustomeTreCallObject { TheClient = myClient, Server = theServerInfo }; myClient.BeginGetCustomTre(theServerInfo.ServerId, new AsyncCallback(FinishedGettingTRE), theObject); if (PatchStepFired != null) { PatchStepFired(this, new PatchingEventArgs(myVariables.GettingCustomTre, true)); } }
private void FinishedGettingTRE(IAsyncResult theResult) { CustomeTreCallObject theObject = theResult.AsyncState as CustomeTreCallObject; List <LauncherData.CustomTre> lstCustomTres = theObject.TheClient.EndGetCustomTre(theResult); if (PatchStepFired != null) { PatchStepFired(this, new PatchingEventArgs(myVariables.Found + " " + lstCustomTres.Count.ToString(), false)); PatchStepFired(this, new PatchingEventArgs(myVariables.CustomServerDir, true)); } //does our directory even exist? if (!Directory.Exists(SWGANHPAth + theObject.Server.SafeFolderName)) { if (PatchStepFired != null) { PatchStepFired(this, new PatchingEventArgs(myVariables.NotFound, false)); } CopyRequiredFiles(theObject.Server); } else { if (PatchStepFired != null) { PatchStepFired(this, new PatchingEventArgs(myVariables.Found, false)); } } if (PatchStepFired != null) { PatchStepFired(this, new PatchingEventArgs(myVariables.ValidatingFiles, true)); } //now to check the files are correctly patched IniFiles myFiles = new IniFiles(SWGANHPAth + "\\swg2uu_live.cfg"); List <KeyValuePair <string, string> > lstStandardFiles = myFiles.GetSectionValuesAsList("SharedFile"); if (PatchStepFired != null) { PatchStepFired(this, new PatchingEventArgs(myVariables.Found + " " + lstStandardFiles.Count.ToString(), false)); } bool blnSuccess = true; foreach (KeyValuePair <string, string> thePair in lstStandardFiles) { //prepare the filename string strFileName = thePair.Value.Substring(1, thePair.Value.Length - 2); //is it a file? if (File.Exists(strFileName)) { using (FileStream fileIn = new FileStream(strFileName, FileMode.Open, FileAccess.Read)) { byte[] arMD5Bytes = hashmd5.ComputeHash(fileIn); //find the file in the Standard List StandardTre theCurrentFile = myUserPreferences.CachedStandardTre.Find(st => st.Filename.Equals(Path.GetFileName(strFileName), StringComparison.InvariantCultureIgnoreCase)); if (theCurrentFile != null) { if (PatchStepFired != null) { PatchStepFired(this, new PatchingEventArgs(myVariables.Validating + " " + Path.GetFileName(strFileName), true)); if (BitConverter.ToString(arMD5Bytes).Replace("-", "") == theCurrentFile.MD5Hash) { PatchStepFired(this, new PatchingEventArgs(myVariables.Passed, false)); } else { PatchStepFired(this, new PatchingEventArgs(myVariables.Failed, false)); //something failed blnSuccess = false; } } } } } } if (PatchFunctionComplete != null) { string strPatchCompleteMessage = myVariables.ClientUpToDate; if (!blnSuccess) { strPatchCompleteMessage = myVariables.ClientOutOfDate + Environment.NewLine + myVariables.PatchFromSWG; } PatchFunctionComplete(this, new PatchFunctionCompleteEventArgs(strPatchCompleteMessage, blnSuccess)); } }