public Form1() { if (File.Exists(RelativePath + "Patcher.manifest")) m_UpdaterManifest = new ManifestFile(File.Open(RelativePath + "Patcher.manifest", FileMode.Open)); else { MessageBox.Show("Couldn't find patcher's manifest - unable to update!"); Environment.Exit(0); } if (File.Exists(RelativePath + "Client.manifest")) m_ClientManifest = new ManifestFile(File.Open(RelativePath + "Client.manifest", FileMode.Open)); else { MessageBox.Show("Couldn't find client's manifest - unable to update!"); Environment.Exit(0); } if (MessageBox.Show("Backup data before updating?", "Backup", MessageBoxButtons.YesNo) == DialogResult.Yes) FileManager.Backup(m_ClientManifest, RelativePath); InitializeComponent(); this.FormClosing += new FormClosingEventHandler(Form1_FormClosing); m_Requester = new Requester("https://dl.dropboxusercontent.com/u/257809956/UpdaterPatchManifest.manifest"); m_Requester.OnFetchedManifest += new FetchedManifestDelegate(m_Requester_OnFetchedManifest); m_Requester.OnTick += new DownloadTickDelegate(m_Requester_OnTick); m_Requester.OnFetchedFile += new FetchedFileDelegate(m_Requester_OnFetchedFile); Logger.OnMessageLogged += new MessageLoggedDelegate(Logger_OnMessageLogged); m_Requester.Initialize(); }
/// <summary> /// The manifest was fetched. /// </summary> /// <param name="Manifest">The patch manifest that was fetched.</param> private void m_Requester_OnFetchedManifest(ManifestFile Manifest) { lock(m_PatchManifest) m_PatchManifest = Manifest; if (!m_PatchingUpdater) { //Versions didn't match, do update. if (m_ClientManifest.Version != m_PatchManifest.Version) { lock(m_ClientManifest) { foreach (PatchFile clPF in m_ClientManifest.PatchFiles) { lock (m_PatchManifest) { foreach (PatchFile pmPF in m_PatchManifest.PatchFiles) { if (NeedToDownloadFile(pmPF, clPF)) { if (!m_PatchDiff.Contains(pmPF)) m_PatchDiff.Add(pmPF); } } } } this.Invoke(new MethodInvoker(() => { PrgFile.Value = 0; })); Directory.CreateDirectory(RelativePath + "Tmp"); m_Requester.FetchFile(m_PatchDiff[0].URL); } } else { DialogResult Diag = MessageBox.Show("Done", "Your client is up to date!\n" + "Would you like to configure the client?", MessageBoxButtons.YesNo); if (Diag == System.Windows.Forms.DialogResult.No) { if (File.Exists(RelativePath + "Project Dollhouse Client.exe")) Process.Start(RelativePath + "Project Dollhouse Client.exe"); } else { } Environment.Exit(0); } } else { //Versions didn't match, do update. if (m_UpdaterManifest.Version != m_PatchManifest.Version) { lock (m_UpdaterManifest) { foreach (PatchFile clPF in m_UpdaterManifest.PatchFiles) { foreach (PatchFile pmPF in m_UpdaterManifest.PatchFiles) { if (NeedToDownloadFile(pmPF, clPF)) { if (!m_PatchDiff.Contains(pmPF)) m_PatchDiff.Add(pmPF); } } } } this.Invoke(new MethodInvoker(() => { PrgFile.Value = 0; })); Directory.CreateDirectory(RelativePath + "Tmp"); m_Requester.FetchFile(m_PatchDiff[0].URL); } else //Versions matched, no need to update this application! { m_PatchingUpdater = false; MessageBox.Show("Patcher was up to date!\n Checking client..."); lock (m_Requester) { //Start updating client! m_Requester = new Requester("https://dl.dropboxusercontent.com/u/257809956/PatchManifest.manifest"); m_Requester.OnFetchedManifest += new FetchedManifestDelegate(m_Requester_OnFetchedManifest); m_Requester.OnTick += new DownloadTickDelegate(m_Requester_OnTick); m_Requester.OnFetchedFile += new FetchedFileDelegate(m_Requester_OnFetchedFile); m_Requester.Initialize(); } } } }