public static bool initalize(App app) { GlobalAppData.patchInformation = null; GlobalAppData.app = app; settingsPath = getUserProfilePath(); if (settings == null) { String f = settingsFile; String d = settingsPath; if (!Directory.Exists(settingsPath)) { DirectoryInfo dInfo = Directory.CreateDirectory(settingsPath); if (!dInfo.Exists) { MessageBox.Show("Failed to create profile directory: " + settingsPath); return(false); } } loadSettings(); return(true); } return(true); }
private static PatchInformation _deserializePatchInformation(String data) { MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); writer.Write(data); writer.Flush(); stream.Position = 0; PatchInformation pi = Serializer.loadFromStream <PatchInformation>(stream); stream.Close(); return(pi); }
public App() : base() { this.ShutdownMode = ShutdownMode.OnLastWindowClose; this.CriticalFailureEvent += (reason) => { MessageBox.Show("Critical failure. Shutting down. \n" + reason); doShutdown(); }; PatchInformation.PatchInformationLoadFailed += (reason) => { MessageBox.Show("Downloading patch information failed: " + reason); doShutdown(); }; GlobalAppData.SettingsLoaded += (settings) => { Task t = PatchInformation.downloadPatchInformation(settings.patcherURI); }; GlobalAppData.initalize(this); }
public Patcher(PatchInformation patchInformation, Settings settings) { this.patchInformation = patchInformation; this.settings = settings; }
public static async Task downloadPatchInformation(String uri) { if (uri == null) { throw new Exception("uri was null"); } using (WebClient wc = new WebClient()) { wc.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) => { if (PatchInformationLoadProgress != null) { PatchInformationLoadProgress(e.ProgressPercentage); } }; wc.DownloadStringCompleted += (object sender, DownloadStringCompletedEventArgs e) => { if (e.Error != null) { if (PatchInformationLoadFailed != null) { PatchInformationLoadFailed(e.Error.ToString()); } return; } String data = e.Result; String signature = Crypto.getSignature(data); if (signature != null) { } else if (signature == null && GlobalAppData.settings.enforceSignature == true) { if (PatchInformationLoadFailed != null) { PatchInformationLoadFailed("Couldn't find required signature."); } return; } PatchInformation pi = _deserializePatchInformation(e.Result); if (PatchInformationLoaded != null) { PatchInformationLoaded(pi); } }; try { try { wc.DownloadStringTaskAsync(uri); } catch (System.Net.WebException) { // this is being handeld in the event handler above already } catch (ArgumentException e) { if (PatchInformationLoadFailed != null) { PatchInformationLoadFailed("Uri is invalid: '" + uri + "'\n" + e.ToString()); } return; } } catch (Exception e) { if (PatchInformationLoadFailed != null) { PatchInformationLoadFailed(e.ToString()); } } } }