public async Task <bool> Prepare() { try { PackageDownloader.Version ver = null; internalName = null; if (!isDev) { if (!Debugger.IsAttached && !IsSteamFolder) { Status = "Checking for self-upgrade"; var selfUpdater = new SelfUpdater("Zero-K"); selfUpdater.ProgramUpdated += delegate { Process.Start(Application.ExecutablePath, string.Join(" ", Environment.GetCommandLineArgs().Skip(1))); Environment.Exit(0); }; var task = new Task <bool>(() => selfUpdater.CheckForUpdate()); task.Start(); await task; } if (!IsSteamFolder) { downloader.RapidHandling = RapidHandling.SdzNameHash; if (!await downloader.DownloadFile("Checking for chobby update", DownloadType.RAPID, chobbyTag, Progress, 2)) { return(false); } if (!await downloader.DownloadFile("Checking for game update", DownloadType.RAPID, GlobalConst.DefaultZkTag, Progress, 2)) { return(false); } downloader.RapidHandling = RapidHandling.DefaultSdp; ver = downloader.PackageDownloader.GetByTag(chobbyTag); internalName = ver.InternalName; } else { internalName = GetSteamChobby(); ver = downloader.PackageDownloader.GetByInternalName(internalName) ?? downloader.PackageDownloader.GetByTag(chobbyTag); } if (ver == null) { Status = "Rapid package appears to be corrupted, please clear the folder"; return(false); } } else { internalName = "Chobby $VERSION"; } engine = engine ?? GetSteamEngine() ?? QueryDefaultEngine() ?? GlobalConst.DefaultEngineOverride; try { GameAnalytics.ConfigureGameEngineVersion(internalName); GameAnalytics.ConfigureSdkGameEngineVersion(engine); } catch (Exception ex) { Trace.TraceWarning("Game analytics failed to configure version: {0}", ex); } if (!IsSteamFolder) { if (!await downloader.DownloadFile("Downloading engine", DownloadType.ENGINE, engine, Progress, 2)) { return(false); } if (!await downloader.UpdateMissions(Progress)) { Trace.TraceWarning("Mission update has failed"); Status = "Error updating missions"; } } else { ClearSdp(); } downloader.UpdatePublicCommunityInfo(Progress); if (!isDev) { Status = "Reseting configs and deploying AIs"; ConfigVersions.DeployAndResetConfigs(paths, ver); } return(true); } catch (Exception ex) { Trace.TraceError("Unexpected error: {0}", ex); GameAnalytics.AddErrorEvent(EGAErrorSeverity.Error, $"Unexpected error {Status}: {ex}"); Status = "Unexpected error preparing chobby launch: " + ex.Message; return(false); } }
private void OnActivated(object sender, EventArgs e) { SelfUpdater.StartUpdate(this, _patchUrl, _patchHash); }
public NewVersionBar(SelfUpdater selfupdater) { InitializeComponent(); selfupdater.ProgramUpdated += s => { Program.MainWindow.InvokeFunc(() => { Program.NotifySection.AddBar(this); }); }; }
private void MainFrm_Load(object sender, EventArgs e) { SelfUpdater = new SelfUpdater(this); HandleAutoLaunch(); }
public void VersionTest() { var ver = SelfUpdater.CheckLatestVersion(); Assert.AreNotEqual(ver, default); }
/// <summary> /// Loads the application information from the webserver /// </summary> public void LoadApplicationData() { var updater = new SelfUpdater(); this.SelfUpdaterApp = updater.GetApplication(SelfUpdater.UPDATER_APPNAME, SelfUpdater.SUN_UPDATER_ROOTURL); }
public static void Main(string[] args) { try { //Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); Trace.Listeners.Add(new ConsoleTraceListener()); Trace.Listeners.Add(new LogTraceListener()); if (Environment.OSVersion.Platform != PlatformID.Unix) { var ver = GetNetVersionFromRegistry(); if (ver < 378675) { MessageBox.Show("Zero-K launcher needs Microsoft .NET framework 4.5.1\nPlease download and install it first", "Program is unable to run", MessageBoxButtons.OK, MessageBoxIcon.Error); } } Directory.SetCurrentDirectory(StartupPath); SelfUpdater = new SelfUpdater("Zero-K"); // if (Process.GetProcesses().Any(x => x.ProcessName.StartsWith("spring_"))) return; // dont start if started from installer StartupArgs = args; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (!Debugger.IsAttached) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Thread.GetDomain().UnhandledException += UnhandledException; Application.ThreadException += Application_ThreadException; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); } //HttpWebRequest.DefaultCachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); Trace.TraceInformation("Starting with version {0}", SelfUpdater.CurrentVersion); WebRequest.DefaultWebProxy = null; ThreadPool.SetMaxThreads(500, 2000); ServicePointManager.Expect100Continue = false; if (Environment.OSVersion.Platform != PlatformID.Unix && !Conf.UseExternalBrowser) { Utils.SetIeCompatibility(); } //set to current IE version LoadConfig(); var contentDir = !string.IsNullOrEmpty(Conf.DataFolder) ? Conf.DataFolder : StartupPath; if (!Directory.Exists(contentDir) || !SpringPaths.IsDirectoryWritable(contentDir) || pickInitFolder) { var dc = new SelectWritableFolder() { SelectedPath = SpringPaths.GetMySpringDocPath() }; if (dc.ShowDialog() != DialogResult.OK) { return; } contentDir = dc.SelectedPath; } if (Conf.DataFolder != StartupPath) { Conf.DataFolder = contentDir; } else { Conf.DataFolder = null; } if (!SpringPaths.IsDirectoryWritable(StartupPath) || StartupPath.Contains("Local\\Apps")) { MessageBox.Show( string.Format( "Please use the newly created desktop icon to start Zero-K not this one.\r\nZero-K.exe will be moved to {0}", contentDir), "Startup directory is not writable!"); var newTarget = Path.Combine(contentDir, "Zero-K.exe"); if (SelfUpdater.CheckForUpdate(newTarget, true)) { Conf.Save(Path.Combine(contentDir, Config.ConfigFileName)); Process.Start(newTarget); return; } MessageBox.Show("Move failed, please copy Zero-K.exe to a writable folder"); } if (Conf.IsFirstRun) { Utils.CreateDesktopShortcut(); if (Environment.OSVersion.Platform != PlatformID.Unix) { Utils.RegisterProtocol(); } } SpringPaths = new SpringPaths(null, writableFolderOverride: contentDir); SpringPaths.MakeFolders(); SpringPaths.SetEnginePath(Utils.MakePath(SpringPaths.WritableDirectory, "engine", ZkData.GlobalConst.DefaultEngineOverride ?? TasClient.ServerSpringVersion)); // run unitsync as soon as possible so we don't have to spend several minutes doing it on game start // two problems: // 1) unitsync can only be loaded once, even if in a different directory http://msdn.microsoft.com/en-us/library/ms682586.aspx#factors_that_affect_searching // so if we do it in SpringVersionChanged it'll be done at startup for GlobalConst.DefaultEngineOverride, then for no other engine version // 2) unitsync can't be unloaded http://stackoverflow.com/questions/1371877/how-to-unload-the-dll-using-c // also see EngineDownload.cs //SpringPaths.SpringVersionChanged += (s, e) => //{ // //System.Diagnostics.Trace.TraceInformation("SpringPaths version: {0}", SpringPaths.SpringVersion); // //new PlasmaShared.UnitSyncLib.UnitSync(SpringPaths); // //SpringScanner.VerifyUnitSync(); // //if (SpringScanner != null) SpringScanner.Dispose(); // //SpringScanner = new SpringScanner(SpringPaths); // //SpringScanner.Start(); //}; SaveConfig(); try { if (!Debugger.IsAttached) { var wp = ""; foreach (var c in SpringPaths.WritableDirectory.Where(x => (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z'))) { wp += c; } mutex = new Mutex(false, "ZeroKLobby" + wp); if (!mutex.WaitOne(10000, false)) { MessageBox.Show( "Another copy of Zero-K lobby is still running" + "\nMake sure the other lobby is closed (check task manager) before starting new one", "There can be only one lobby running", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } } catch (AbandonedMutexException) { } FriendManager = new FriendManager(); AutoJoinManager = new AutoJoinManager(); EngineConfigurator = new EngineConfigurator(SpringPaths.WritableDirectory); SpringScanner = new SpringScanner(SpringPaths); SpringScanner.LocalResourceAdded += (s, e) => Trace.TraceInformation("New resource found: {0}", e.Item.InternalName); SpringScanner.LocalResourceRemoved += (s, e) => Trace.TraceInformation("Resource removed: {0}", e.Item.InternalName); if (Program.Conf.EnableUnitSyncPrompt && Environment.OSVersion.Platform != PlatformID.Unix) { SpringScanner.UploadUnitsyncData += MicroForms.UnitSyncUploadPrompt.SpringScanner_UploadUnitsyncData; SpringScanner.RetryResourceCheck += MicroForms.UnitSyncRetryPrompt.SpringScanner_RetryGetResourceInfo; } SpringScanner.MapRegistered += (s, e) => Trace.TraceInformation("Map registered: {0}", e.MapName); SpringScanner.ModRegistered += (s, e) => Trace.TraceInformation("Mod registered: {0}", e.Data.Name); Downloader = new PlasmaDownloader.PlasmaDownloader(Conf, SpringScanner, SpringPaths); //rapid Downloader.DownloadAdded += (s, e) => Trace.TraceInformation("Download started: {0}", e.Data.Name); var isLinux = Environment.OSVersion.Platform == PlatformID.Unix; TasClient = new TasClient(string.Format("ZK {0}{1}", SelfUpdater.CurrentVersion, isLinux ? " linux" : "")); SayCommandHandler = new SayCommandHandler(TasClient); ServerImages = new ServerImagesHandler(SpringPaths, TasClient); // log, for debugging TasClient.Connected += (s, e) => Trace.TraceInformation("TASC connected"); TasClient.LoginAccepted += (s, e) => { Trace.TraceInformation("TASC login accepted"); Trace.TraceInformation("Server is using Spring version {0}", TasClient.ServerSpringVersion); if (Environment.OSVersion.Platform == PlatformID.Unix || Conf.UseExternalBrowser) { MainWindow.navigationControl.Path = "battles"; } }; TasClient.LoginDenied += (s, e) => Trace.TraceInformation("TASC login denied"); TasClient.ChannelJoined += (s, e) => { Trace.TraceInformation("TASC channel joined: " + e.Name); }; TasClient.ConnectionLost += (s, e) => Trace.TraceInformation("Connection lost"); // special handling TasClient.PreviewSaid += (s, e) => { var tas = (TasClient)s; User user = null; if (e.Data.UserName != null) { tas.ExistingUsers.TryGetValue(e.Data.UserName, out user); if ((user != null && user.BanMute) || Conf.IgnoredUsers.Contains(e.Data.UserName)) { e.Cancel = true; } } }; TasClient.Extensions.JsonDataReceived += (eventArgs, o) => { var command = o as ProtocolExtension.SiteToLobbyCommand; if (command != null) { MainWindow.navigationControl.Path = command.SpringLink; MainWindow.PopupSelf(); } }; ConnectBar = new ConnectBar(TasClient); ModStore = new ModStore(); ToolTip = new ToolTipHandler(); BrowserInterop = new BrowserInterop(TasClient, Conf); BattleIconManager = new BattleIconManager(); Application.AddMessageFilter(ToolTip); SteamHandler = new ZklSteamHandler(TasClient); SteamHandler.Connect(); MainWindow = new MainWindow(); Application.AddMessageFilter(new ScrollMessageFilter()); if (Conf.StartMinimized) { MainWindow.WindowState = FormWindowState.Minimized; } else { MainWindow.WindowState = FormWindowState.Normal; } MainWindow.Size = new Size(Math.Min(SystemInformation.VirtualScreen.Width - 30, MainWindow.Width), Math.Min(SystemInformation.VirtualScreen.Height - 30, MainWindow.Height)); //in case user have less space than 1024x768 BattleBar = new BattleBar(); NewVersionBar = new NewVersionBar(SelfUpdater); VoteBar = new VoteBar(); PwBar = new PwBar(); //This make the size of every bar constant (only for height). //We wanted to make them constant because the bar get DPI-scaled twice/thrice/multiple-time (especially for reusable bar). //Setting maximum height upon creation will hopefully make sure it is not DPI-scaled multiple time. var votebarSize = new Size(0, VoteBar.Height); // Reference: http://stackoverflow.com/questions/5314041/set-minimum-window-size-in-c-sharp-net var newversionbarSize = new Size(0, NewVersionBar.Height); var battlebarSize = new Size(0, BattleBar.Height); var connectbarSize = new Size(0, ConnectBar.Height); VoteBar.MinimumSize = votebarSize; //fix minimum size forever VoteBar.MaximumSize = votebarSize; //fix maximum size forever NewVersionBar.MinimumSize = newversionbarSize; NewVersionBar.MaximumSize = newversionbarSize; BattleBar.MinimumSize = battlebarSize; BattleBar.MaximumSize = battlebarSize; ConnectBar.MinimumSize = connectbarSize; ConnectBar.MaximumSize = connectbarSize; //End battlebar size hax if (!Debugger.IsAttached && !Conf.DisableAutoUpdate) { Program.SelfUpdater.StartChecking(); } //if (Conf.IsFirstRun) Utils.OpenWeb(GlobalConst.BaseSiteUrl + "/Wiki/LobbyStart", false); // download primary engine & game MainWindow.Paint += GetSpringZK; Downloader.PackageDownloader.MasterManifestDownloaded += GetSpringZK; // Format and display the TimeSpan value. //stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); //Trace.TraceInformation("1 Runtime {0}", elapsedTime); Application.Run(MainWindow); ShutDown(); } catch (Exception ex) { ErrorHandling.HandleException(ex, true); } finally { ShutDown(); } if (ErrorHandling.HasFatalException && !Program.CloseOnNext) { Application.Restart(); } }