static void Main(string[] args) { // start ticker watch.Start(); // parse commandline arguments ReadCommandLineArguments(args); // create UI if not-headless if (!isHeadless) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // create ui form = new DownloadForm(files); form.FormClosed += OnFormClosed; form.Show(); } // read urls if (!ReadUrlDataFile()) { return; } // start download of patchinfo.txt webClient.DownloadDataCompleted += OnWebClientDownloadDataCompleted; webClient.DownloadDataAsync(new Uri(jsonUrl)); /////////////////////////////////////////////////////////////////////// // mainthread loop while (isRunning) { long tick = watch.ElapsedTicks; double mstick = (double)tick / MSTICKDIVISOR; // handle PatchFile instances returned by workers ProcessQueues(); // update UI if (!isHeadless) { // tick ui if (form != null) { form.Tick(mstick); } // process messages Application.DoEvents(); } // sleep a bit (-> ~60 FPS) Thread.Sleep(16); } /////////////////////////////////////////////////////////////////////// // also stop worker-instances foreach (Worker w in workers) { if (w != null) { w.Stop(); } } // start client in case patching went well if (!abort) { ProcessStartInfo pi = new ProcessStartInfo(); pi.FileName = CLIENTEXEAUTO; pi.Arguments = ""; pi.UseShellExecute = true; pi.WorkingDirectory = CLIENTPATHAUTO; Process process = new Process(); process.StartInfo = pi; process.Start(); } }
static void Main(string[] args) { // start ticker watch.Start(); /////////////////////////////////////////////////////////////////////// // parse commandline arguments and set UpdateFormat. // CLASSIC CLIENT USING CMD ARGS if ((args.Length == 6 || args.Length == 7) && args[1].Contains("UPDATE")) { updateFormat = (args.Length == 6) ? UpdateFormat.Classic6Arg : UpdateFormat.Classic7Arg; ReadCommandLineArgumentsClassic(args); } // OGRE CLIENT else if (args.Length > 0 || File.Exists(DOTNETURLDATAFILE)) { updateFormat = UpdateFormat.DotNet; ReadCommandLineArguments(args); } // CLASSIC CLIENT USING FILE else if (File.Exists(CLASSICURLDATAFILE)) { updateFormat = UpdateFormat.ClassicManual; } /////////////////////////////////////////////////////////////////////// // create UI if not-headless if (!isHeadless) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // create ui form = new DownloadForm(files, languageHandler, jsonFileProgress); form.FormClosed += OnFormClosed; form.Show(); } /////////////////////////////////////////////////////////////////////// // read url data file if necessary switch (updateFormat) { case UpdateFormat.DotNet: if (!ReadUrlDataFile()) { return; } break; case UpdateFormat.Classic6Arg: case UpdateFormat.Classic7Arg: // No need to parse file. break; case UpdateFormat.ClassicManual: if (!ReadUrlDataFileClassic()) { return; } break; case UpdateFormat.None: if (!isHeadless) { MessageBox.Show(String.Format(languageHandler.UrlInfoMissing, DOTNETURLDATAFILE), languageHandler.ErrorText, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; } /////////////////////////////////////////////////////////////////////// // create worker-instances and start them for (int i = 0; i < workers.Length; i++) { workers[i] = new Worker( PATCHERPATH, baseUrl, queue, queueHashed, queueDone, queueErrors); workers[i].Start(); } /////////////////////////////////////////////////////////////////////// // start download of patchinfo.txt if (updateStage != UpdateStage.Abort) { if (!isHeadless) { form.DisplayStatus(String.Format(languageHandler.DownloadingPatch, MaxStages)); } UpdateStage = UpdateStage.DownloadingJson; webClient.DownloadDataCompleted += OnWebClientDownloadDataCompleted; webClient.DownloadProgressChanged += OnWebClientDownloadProgressChanged; webClient.DownloadDataAsync(new Uri(jsonUrl)); } /////////////////////////////////////////////////////////////////////// // mainthread loop long transitionMsTick = 0; while (updateStage != UpdateStage.Finished && updateStage != UpdateStage.Abort) { long tick = watch.ElapsedTicks; double mstick = (double)tick / MSTICKDIVISOR; switch (updateStage) { case UpdateStage.HashingFiles: if (transitionMsTick == 0) { transitionMsTick = (long)mstick; } // handle transition from scanning to downloading if (files.Count > 0 && queue.Count == 0 && mstick - transitionMsTick > MINHASHTRANSITIONTIME) { UpdateStage = UpdateStage.DownloadingFiles; if (!isHeadless) { form.DisplayStatus(String.Format(languageHandler.DownloadInit, MaxStages)); } transitionMsTick = 0; } break; case UpdateStage.DownloadingFiles: // handle PatchFile instances returned by workers ProcessQueues(); break; case UpdateStage.Ngen: ProcessNgen(); break; case UpdateStage.FinishedTransition: if (transitionMsTick == 0 && !isHeadless) { transitionMsTick = (long)mstick; if (clientFilesUpdated) { form.DisplayStatus(languageHandler.ClientWasUpdated); } else { form.DisplayStatus(languageHandler.ClientUpToDate); } } if (mstick - transitionMsTick > MINFINISHTRANSITIONTIME) { UpdateStage = UpdateStage.Finished; } break; default: break; } // update UI if (!isHeadless) { // tick ui if (form != null) { form.Tick(mstick, MaxStages, x64NgenDone, x86NgenDone); } // process messages Application.DoEvents(); } // sleep a bit (-> ~60 FPS) Thread.Sleep(16); } /////////////////////////////////////////////////////////////////////// // also stop worker-instances foreach (Worker w in workers) { if (w != null) { w.Stop(); } } // in case patching went well if (updateStage != UpdateStage.Abort) { // make sure the client executable really exists if (File.Exists(Path.Combine(clientPath, clientExecutable))) { ProcessStartInfo pi; Process process; // start client pi = new ProcessStartInfo(); pi.FileName = clientExecutable; pi.Arguments = ""; pi.UseShellExecute = true; pi.WorkingDirectory = clientPath; process = new Process(); process.StartInfo = pi; process.Start(); } else { MessageBox.Show(languageHandler.ClientExecutableMissing, languageHandler.ErrorText, MessageBoxButtons.OK); } } }