private static void Main(string[] args) { // Changes the CurrentCulture of the current thread to the invariant // culture. Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; try { bool full_scan = true; bool text_mode = false; int parent_id = -1; // Source URL is where we will get the media from string sourceUrl = UpdateUrl; // Patch URL is the html page we will use for the patcher string patchUrl = PatchHtml; string masterServer = null; bool exit_after_patch = false; string commandArgs = ""; for (int i = 0; i < args.Length; ++i) { switch (args[i]) { case "--version": Console.WriteLine(MVUpdate.Version); return; case "--parent_id": Debug.Assert(i + 1 < args.Length); parent_id = int.Parse(args[++i]); break; case "--partial": full_scan = false; break; case "--text_mode": text_mode = true; break; case "--update_url": Debug.Assert(i + 1 < args.Length); sourceUrl = args[++i]; break; case "--patch_url": case "--patcher_url": Debug.Assert(i + 1 < args.Length); patchUrl = args[++i]; break; case "--master": Debug.Assert(i + 1 < args.Length); masterServer = args[++i]; break; case "--exit": exit_after_patch = true; break; default: // An argument that we don't understand.. just pass it through // If there is a second part to the option pass that here too commandArgs += args[i] + " "; if (i + 1 < args.Length && args[i + 1].Length > 2 && !args[i + 1].StartsWith("--")) commandArgs += "\"" + args[++i] + "\" "; break; } } if (parent_id > 0) WaitForExit(parent_id); if (text_mode) { Updater updater = new Updater(); updater.FullScan = full_scan; updater.BaseDirectory = "./"; updater.UpdateUrl = sourceUrl; updater.SetupLog(PatchLogFile); updater.UpdateStarted += MVUpdate.HandleUpdateStarted; updater.UpdateCompleted += MVUpdate.HandleUpdateCompleted; updater.FileFetchStarted += MVUpdate.HandleFileFetchStarted; updater.FileFetchEnded += MVUpdate.HandleFileFetchEnded; updater.FileRemoved += MVUpdate.HandleFileRemoved; // Start the thread Thread updaterThread = new Thread(new ThreadStart(updater.Update)); updaterThread.Name = "Resource Loader"; updaterThread.Start(); updaterThread.Join(); } else { UpdateForm dialog = new UpdateForm(); Updater updater = dialog.Updater; updater.FullScan = full_scan; updater.BaseDirectory = "./"; updater.UpdateUrl = sourceUrl; updater.SetupLog(PatchLogFile); // this will start the update, since the html calls the OnLoaded, which calls StartUpdate dialog.Initialize(patchUrl, true); // dialog.StartUpdate(); // Patcher is run from the MultiverseClient\bin directory DialogResult rv = dialog.ShowDialog(); if (rv == DialogResult.Abort || rv == DialogResult.Cancel) return; } // Ok, we finished patching - write the version and launch the client WriteVersionFile(VersionFile); // Check to see if we should just exit now. if (exit_after_patch) // In this case, we don't want to launch the client. They can launch it // manually if they need to, but since we don't want to screw up the // extended command options, we should just exit. return; string currentDir = Directory.GetCurrentDirectory(); string firstCommandArgs = "--update_url " + sourceUrl; if (masterServer != null) firstCommandArgs += " --master " + masterServer; // Prepend the firstCommandArgs to the commandArgs commandArgs = firstCommandArgs + " " + commandArgs; ProcessStartInfo psi = new ProcessStartInfo("MultiverseClient.exe", commandArgs); psi.WorkingDirectory = currentDir + "\\bin"; Process.Start(psi); } catch (Exception ex) { // Check the latest manifest file // call the existing global exception handler Console.WriteLine(ex.ToString()); Debug.Assert(false, "Caught exception while updating client"); } finally { GC.Collect(); // Kernel.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1); // this.WindowState = FormWindowState.Normal; // this.Show(); } }
public bool UpdateWorldAssets(string worldRepository, string patchUrl, string updateUrl, bool fullScan) { Updater updater = new Updater(); log.InfoFormat("Base Directory: {0}", worldRepository); UpdateForm dialog = new UpdateForm(); dialog.Updater.FullScan = fullScan; dialog.Updater.BaseDirectory = worldRepository; dialog.Updater.UpdateUrl = updateUrl; dialog.Updater.SetupLog(PatchLogFile); dialog.Initialize(patchUrl, true); // dialog.StartUpdate(); bool needUpdate = dialog.Updater.CheckVersion(); if (!needUpdate) { dialog.Updater.CloseLog(); return true; } System.Windows.Forms.DialogResult rv = System.Windows.Forms.DialogResult.Abort; rv = dialog.ShowDialog(); dialog.Updater.CloseLog(); if (rv == System.Windows.Forms.DialogResult.Abort || rv == System.Windows.Forms.DialogResult.Cancel) { if (dialog.Updater.Error != null) // We encountered an error patching log.Error(dialog.Updater.Error); return false; } if (dialog.Updater.Error != null) { // We encounterd an error patching log.Error(dialog.Updater.Error); return false; } // Ok, we finished patching - write the version and launch the client // WriteVersionFile(VersionFile); return true; }