void RunUpdateCheck()
        {
            if (!metaSettings.AutoUpdate)
            {
                return;
            }

            var requiredInstaller = ZenithUpdates.InstallerVer;

            if (metaSettings.InstallerVer != requiredInstaller)
            {
                Console.WriteLine("Important update found for installer, updating...");
                ZenithUpdates.UpdateInstaller();
                metaSettings.InstallerVer = requiredInstaller;
                metaSettings.SaveConfig();
            }

            string ver;

            try
            {
                ver = ZenithUpdates.GetLatestVersion();
            }
            catch { return; }
            if (ver != metaSettings.VersionName)
            {
                Console.WriteLine("Found Update! Current: " + metaSettings.VersionName + " Latest: " + ver);
                try
                {
                    Dispatcher.InvokeAsync(() => windowTabs.UpdaterProgress = UpdateProgress.Downloading).Wait();
                    Stream data;
                    if (Environment.Is64BitOperatingSystem)
                    {
                        data = ZenithUpdates.DownloadAssetData(ZenithUpdates.DataAssetName64);
                    }
                    else
                    {
                        data = ZenithUpdates.DownloadAssetData(ZenithUpdates.DataAssetName32);
                    }
                    var dest = File.OpenWrite(ZenithUpdates.DefaultUpdatePackagePath);
                    data.CopyTo(dest);
                    data.Close();
                    dest.Close();
                    Dispatcher.InvokeAsync(() => windowTabs.UpdaterProgress = UpdateProgress.Downloaded).Wait();
                }
                catch (Exception e)
                {
                    Dispatcher.InvokeAsync(() => windowTabs.UpdaterProgress = UpdateProgress.NotDownloading).Wait();
                    MessageBox.Show("Couldn't download and save update package", "Update failed");
                }
            }
        }
示例#2
0
        static void SilentInstall()
        {
            Stream data;

            if (Environment.Is64BitOperatingSystem)
            {
                data = ZenithUpdates.DownloadAssetData(ZenithUpdates.DataAssetName64);
            }
            else
            {
                data = ZenithUpdates.DownloadAssetData(ZenithUpdates.DataAssetName32);
            }
            ZenithUpdates.InstallFromStream(data);
            data.Close();
            FinalizeInstall();
        }
示例#3
0
        static void UpdateFromPackage(string path)
        {
            if (!File.Exists(path))
            {
                if (!Silent)
                {
                    MessageBox.Show("Could not install update, update package file missing", "Update failed");
                }
                return;
            }
            var f = File.OpenRead(path);

            ZenithUpdates.KillAllProcesses();
            ZenithUpdates.InstallFromStream(f);
            f.Close();
            File.Delete(path);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Task.Run(() =>
            {
#if !DEBUG
                try
                {
#endif
                Stream data;
                if (Environment.Is64BitOperatingSystem)
                {
                    data = ZenithUpdates.DownloadAssetDataProgressive(ZenithUpdates.DataAssetName64, ProgressCallbac);
                }
                else
                {
                    data = ZenithUpdates.DownloadAssetDataProgressive(ZenithUpdates.DataAssetName32, ProgressCallbac);
                }
                Dispatcher.Invoke(() =>
                {
                    dlProgress.Visibility = Visibility.Collapsed;
                });
                Dispatcher.Invoke(() => progressText.Content = "Installing...");
                ZenithUpdates.InstallFromStream(data);
                data.Close();
                Program.FinalizeInstall();
                Dispatcher.Invoke(() => Close());
#if !DEBUG
            }
                     catch (Exception ex)
            {
                exception = ex;
                Dispatcher.Invoke(() => Close());
            }
#endif
            });
        }
 private void updateDownloaded_MouseDown(object sender, MouseButtonEventArgs e)
 {
     ZenithUpdates.KillAllProcesses();
     Process.Start(ZenithUpdates.InstallerPath, "update -Reopen");
     Close();
 }
示例#6
0
        static void Main(string[] args)
        {
#if !DEBUG
            try
            {
#endif
            ZenithUpdates.KillAllProcesses();

            bool reopen      = false;
            string reopenArg = "";

            if (args.Length == 0)
            {
                reopen = true;
                NormalInstall();
            }
            else
            {
                string command = args[0];

                if (!new[] { "install", "update", "uninstall" }.Contains(command))
                {
                    Console.WriteLine("Invalid command " + command);
                    return;
                }

                string packagePath = ZenithUpdates.DefaultUpdatePackagePath;

                for (int i = 1; i < args.Length; i++)
                {
                    if (args[i] == "-Silent")
                    {
                        Silent = true;
                    }
                    if (args[i] == "-PackagePath")
                    {
                        if (command != "update")
                        {
                            Console.WriteLine("-PackagePath flag only allowed on update command");
                            return;
                        }
                        i++;
                        if (i == args.Length)
                        {
                            Console.WriteLine("path expected after -PackagePath");
                            return;
                        }
                        packagePath = args[i];
                    }
                    if (args[i] == "-ReopenArg")
                    {
                        if (command == "uninstall")
                        {
                            Console.WriteLine("-ReopenArg flag not allowed on uninstall command");
                            return;
                        }
                        i++;
                        if (i == args.Length)
                        {
                            Console.WriteLine("argument expected after -ReopenArg");
                            return;
                        }
                        reopenArg = args[i];
                    }
                    if (args[i] == "-Reopen")
                    {
                        if (command == "uninstall")
                        {
                            Console.WriteLine("-Reopen flag not allowed on uninstall command");
                            return;
                        }
                        reopen = true;
                    }
                }

                if (command == "install")
                {
                    if (Silent)
                    {
                        SilentInstall();
                    }
                    else
                    {
                        NormalInstall();
                    }
                }
                if (command == "update")
                {
                    UpdateFromPackage(packagePath);
                    ZenithUpdates.WriteVersionSettings(ZenithUpdates.GetLatestVersion(), true, true);
                }
                if (command == "uninstall")
                {
                    ZenithUpdates.DeleteStartShortcut();
                    ZenithUpdates.DeleteDesktopShortcut();
                    ZenithUpdates.DeleteProgramFolder();
                    if (!Silent)
                    {
                        MessageBox.Show("Successfully uninstalled " + ZenithUpdates.ProgramName + "!");
                    }
                }
            }

            if (reopen)
            {
                string exePath = Path.Combine(ZenithUpdates.InstallPath, ZenithUpdates.ExeName);
                if (reopenArg == "")
                {
                    Process.Start(new ProcessStartInfo()
                    {
                        FileName         = exePath,
                        WorkingDirectory = Path.GetDirectoryName(exePath)
                    });
                }
                else
                {
                    Process.Start(new ProcessStartInfo()
                    {
                        FileName         = exePath,
                        WorkingDirectory = Path.GetDirectoryName(exePath),
                        Arguments        = "\"" + reopenArg + "\""
                    });
                }
            }
#if !DEBUG
        }

        catch (Exception e)
        {
            if (!Silent)
            {
                string msg = e.Message + "\n" + e.Data + "\n";
                msg += e.StackTrace;
                MessageBox.Show(msg, ZenithUpdates.ProgramName + " installer has crashed!");
            }
        }
#endif
        }