Exemple #1
0
        private static Models.Update CheckForUpdates()
        {
            string source = "https://raw.githubusercontent.com/gilgame/SEWorkbench/master/Src/update.xml";

            string contents = String.Empty;

            try
            {
                using (WebClient client = new WebClient())
                {
                    contents = client.DownloadString(source);
                }
            }
            catch (Exception ex)
            {
                MessageBox.ShowError("Unable to download update.xml: ", ex);
                return(null);
            }

            Models.Update update = new Models.Update();
            try
            {
                if (!String.IsNullOrEmpty(contents))
                {
                    update = (Models.Update)Serialization.Convert.ToObject(contents);

                    Version current = Assembly.GetExecutingAssembly().GetName().Version;

                    Version remote = null;
                    Version.TryParse(update.Version, out remote);

                    int compared = current.CompareTo(remote);
                    if (compared < 0)
                    {
                        update.IsNewer = true;
                    }
                    else
                    {
                        update.IsNewer = false;
                    }
                }
                else
                {
                    update.IsNewer = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.ShowError("Unable to extract update information. Update file may be invalid or currept: ", ex);
                return(null);
            }
            return(update);
        }
Exemple #2
0
        private static Models.Update CheckForUpdates()
        {
            string source = "https://raw.githubusercontent.com/gilgame/SEWorkbench/master/Src/update.xml";

            string contents = String.Empty;
            try
            {
                using (WebClient client = new WebClient())
                {
                    contents = client.DownloadString(source);
                }
            }
            catch (Exception ex)
            {
                MessageBox.ShowError("Unable to download update.xml: ", ex);
                return null;
            }

            Models.Update update = new Models.Update();
            try
            {
                if (!String.IsNullOrEmpty(contents))
                {
                    update = (Models.Update)Serialization.Convert.ToObject(contents);

                    Version current = Assembly.GetExecutingAssembly().GetName().Version;

                    Version remote = null;
                    Version.TryParse(update.Version, out remote);

                    int compared = current.CompareTo(remote);
                    if (compared < 0)
                    {
                        update.IsNewer = true;
                    }
                    else
                    {
                        update.IsNewer = false;
                    }
                }
                else
                {
                    update.IsNewer = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.ShowError("Unable to extract update information. Update file may be invalid or currept: ", ex);
                return null;
            }
            return update;
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            System.AppDomain.CurrentDomain.UnhandledException += Program_UnhandledException;

            if (Configuration.Program.CheckForUpdates)
            {
                Models.Update update = CheckForUpdates();
                if (update != null && update.IsNewer)
                {
                    Views.UpdaterView updater = new Views.UpdaterView();

                    ViewModels.UpdaterViewModel context = (ViewModels.UpdaterViewModel)updater.DataContext;
                    context.Location = update.Location;
                    context.Details  = update.Details;
                    context.CheckSum = update.CheckSum;

                    if (updater.ShowDialog() == true)
                    {
                        string temp    = context.ExtractedPath;
                        string working = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

                        UpdateProgram(temp, working);

                        return;
                    }
                }
            }

            if (args.Length > 1 && args[0].ToLower() == "--pid")
            {
                Process parent = Process.GetProcessById(Configuration.Convert.ToInteger(args[1]));
                if (parent != null)
                {
                    parent.Kill();
                }
            }

            string path = Configuration.Program.SEPath;

            if (!SandboxIsCopied(path))
            {
                if (!IsAdmin)
                {
                    string message = "SE Workbench needs to copy the sandbox files. Make sure Space Engineers and Steam are closed and then press OK to continue.";
                    MessageBox.ShowMessage(message);

                    Restart(true);
                }

                if (!ValidPath(path))
                {
                    path = GetSandboxPath();
                }

                bool success = CopySandbox(path);
                if (success)
                {
                    Configuration.Program.SEPath = path;

                    Restart();
                }
                else
                {
                    string message = String.Format("Workbench was unable to copy sandbox (path: {0}) and may not function properly.", path);
                    MessageBox.ShowMessage(message);
                }
            }

            Views.SplashScreenView splash = new Views.SplashScreenView();
            splash.Show();

            Interop.Engine.Initialize();
            Interop.Decompiler.LoadClasses();

            splash.Close();

            StartApp();
        }