static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Updater updte = new Updater(); }
public static void Main(string[] args) { try { if (!args.ToList().Contains("--disable-updates")) { bool msgOk = false; if (Settings.ReadValue("Update", "CheckUpdates") == "True" || Settings.ReadValue("Update", "CheckUpdates") == string.Empty) { msgOk = true; Console.Write("Checking updates..."); var updater = new Updater(Settings.ReadValue("Update", "UpdateUrl")); Settings.WriteValue("Update", "CheckUpdates", "Plugins"); if (MainUpdateRequired(updater)) { Console.WriteLine("Update required!"); updater = new Updater(Settings.ReadValue("Update", "UpdaterUrl")); foreach (var file in updater.GetUpdateFileList()) updater.DownloadFile(file); Process.Start("Update.exe", "--wait-process q2Tool --auto-execute \"q2Tool.exe\""); return; } } if (Settings.ReadValue("Update", "CheckUpdates") == "Plugins") { if(!msgOk) Console.Write("Checking updates..."); var updater = new Updater(Settings.ReadValue("Update", "UpdateUrl")); Settings.WriteValue("Update", "CheckUpdates", "False"); EnableOnlyPlugins(updater); var pluginFiles = updater.GetUpdateFileList(); if (pluginFiles.Count > 0) { Console.Write("Downloading plugins.."); foreach (var plugin in pluginFiles) { Console.Write("."); updater.DownloadFile(plugin); } } Console.WriteLine("OK"); } else { BackgroundUpdateCheck(); } } else { BackgroundUpdateCheck(); } LoadPlugins(); var quake = new Quake(Settings.ReadValue("Game", "Path")) { CFG = Settings.ReadValue("Game", "CFG") }; string server = Settings.ReadValue("Game", "DefaultServer"); for (int i = 0; i < args.Length; i++) { if (args[i] == "+connect") { server = args[++i]; break; } } quake.Run(server); foreach (Plugin plugin in PluginManager.GetPlugins<Plugin>()) { try { plugin.Quake = quake; plugin.GameStart(); } catch (Exception ex) { Console.WriteLine("Plugin {0} could not be loaded: {1}.", plugin.GetType().Name, ex.Message); PluginManager.UnLoadPlugin(plugin); } } } catch (FileNotFoundException ex) { Settings.WriteValue("Update", "CheckUpdates", "True"); Console.WriteLine("O arquivo \"{0}\" não foi encontrado.", ex.FileName); PluginManager.MessageToPlugin<PLog>(ex); } catch (Exception ex) { Settings.WriteValue("Update", "CheckUpdates", "True"); Exception inner = ex.InnerException; Console.WriteLine("Error: {0}", ex.Message); while (inner != null) { Console.WriteLine(inner.Message); inner = inner.InnerException; } PluginManager.MessageToPlugin<PLog>(ex); } }
static bool MainUpdateRequired(Updater updater) { foreach (var module in updater.Modules) { if (module.Name.StartsWith("q2Tool.Plugin.")) { module.Enabled = false; if (module.Enabled && Settings.ReadValue("q2Tool.Plugin", module.Name.Substring(14)) == string.Empty) Settings.WriteValue("q2Tool.Plugin", module.Name.Substring(14), "enabled"); } } return updater.GetUpdateFileList().Count > 0; }
private static void EnableOnlyPlugins(Updater updater) { foreach (var module in updater.Modules) { if (module.Name.StartsWith("q2Tool.Plugin.")) module.Enabled = Settings.ReadValue("q2Tool.Plugin", module.Name.Substring(14)).ToLower() == "enabled"; else module.Enabled = false; } }
static void BackgroundUpdateCheck() { Parallel.Start(() => { try { var updater = new Updater(Settings.ReadValue("Update", "UpdateUrl")); if (MainUpdateRequired(updater)) { Settings.WriteValue("Update", "CheckUpdates", "True"); return; } EnableOnlyPlugins(updater); if (updater.GetUpdateFileList().Count > 0) Settings.WriteValue("Update", "CheckUpdates", "Plugins"); } catch { } }); }
static void Main(string[] args) { try { string waitProcess = null; for (int i = 0; i < args.Length; i++) { if (args[i] == "--wait-process" && i + 1 < args.Length) { waitProcess = args[i + 1]; break; } } if (!string.IsNullOrEmpty(waitProcess)) { var processList = Process.GetProcessesByName(waitProcess); if (processList.Length == 1) { Console.WriteLine("Waiting for {0} to end...", waitProcess); processList[0].WaitForExit(); } } Console.Write("Loading => "); Updater updater = new Updater(Settings.ReadValue("Update", "UpdateUrl")); double lastUpdate = 0; int maxBarSize = Console.WindowWidth - Console.CursorLeft; int updatedFiles = 0; #region Enable Optional Modules foreach (var module in updater.Modules) { string customStatus = Settings.ReadValue(module.Name, "Enabled"); if (!string.IsNullOrEmpty(customStatus)) module.Enabled = bool.Parse(customStatus); } #endregion List<string> updateFiles = updater.GetUpdateFileList(); foreach (string file in updateFiles) { updater.DownloadFile(file); #region Update ProgressBar double atualPercentage = ++updatedFiles / ((double)updateFiles.Count); for (int i = 1; i < (atualPercentage - lastUpdate) * maxBarSize; i++) Console.Write("#"); lastUpdate = atualPercentage; #endregion } Console.Write(new string('#', Console.WindowWidth - Console.CursorLeft)); string autoExecute = null; for(int i = 0; i < args.Length; i++) { if (args[i] == "--auto-execute" && i + 1 < args.Length) { autoExecute = args[i + 1]; break; } } if (!string.IsNullOrEmpty(autoExecute)) { string[] cmd = autoExecute.Split(' '); Process.Start(cmd[0], string.Join(" ", cmd, 1, cmd.Length - 1)); } else { Console.WriteLine("Updated"); Console.ReadKey(); } } catch(Exception ex) { Exception inner = ex.InnerException; Console.WriteLine("Error: {0}", ex.Message); while (inner != null) { Console.WriteLine(inner.Message); inner = inner.InnerException; } Console.ReadKey(); } }