예제 #1
0
 void GetUpgradePermissionView_Shown(object sender, EventArgs e)
 {
     if (UACControl.IsVistaOrHigher() && !UACControl.IsAdmin())
     {
         UACControl.AddShieldToButton(updateButton);
     }
 }
예제 #2
0
        private void DoWork()
        {
            try
            {
                if (_checkForUpdates)
                {
                    Logger.Current.Write(LogInfoLevel.Info, "Checking for updates...");
                    View.Invoke(() =>
                    {
                        View.Title   = "Checking for updates...";
                        View.Details = "Checking for updates...";
                    });

                    AvailableUpdates availableUpdates = UpdateChecker.CheckForUpdate(Game.Current);

                    if ((availableUpdates.Framework != null || availableUpdates.Game != null) && GetUpdatePermission())
                    {
                        Logger.Current.Write(LogInfoLevel.Info, "Updates found, restarting elevated...");

                        if (!UACControl.IsVistaOrHigher() && !UACControl.IsAdmin())
                        {
                            //pre vista you can't elevate, so we have to bail out with an error here.
                            ViewFactory.Current.CreateView <IMessage>().Show("Updating requires administrator access", "Administrator accesss required");
                            _workerThread = null;
                            View.Invoke(CloseView);
                            return;
                        }

                        UACControl.RestartElevated(Resources.GamesManagerBootArguments(
                                                       availableUpdates.Game != null ? availableUpdates.Game.Url : string.Empty,
                                                       availableUpdates.Game != null ? availableUpdates.Game.MD5 : string.Empty,
                                                       availableUpdates.Framework != null ? availableUpdates.Framework.Url : string.Empty,
                                                       availableUpdates.Framework != null ? availableUpdates.Framework.MD5 : string.Empty));
                        return;
                    }
                }

                Launch();
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                _workerThread = null;
                View.Invoke(() => Program.ShowUnhandledError(ex));
            }
        }
예제 #3
0
        static int RunMain()
        {
            CommandLineParser commandLine;

            if (FileSystem.Current.FileExists(Resources.ParamsOverrideFile))
            {
                using (var stream = FileSystem.Current.GetFile(Resources.ParamsOverrideFile).OpenStream(FileMode.Open))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        commandLine = new CommandLineParser(reader.ReadToEnd().Split(), false);
                    }
                }
            }
            else
            {
                commandLine = new CommandLineParser(Environment.GetCommandLineArgs());
            }

            Resources.InitGameDirectory(commandLine[Resources.GamesManagerArguments.GameDirOverrideArgument]);

            Application.ThreadException += Application_ThreadException;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Game game = new Game(FileSystem.Combine(Resources.GameBaseDir, Resources.GameConfig));

            if (game.ErrorCollection.Count > 0)
            {
                ViewFactory.Current.CreateView <IMessage>().Show("Game configuration invalid " + game.ErrorCollection[0], "Game configuration invalid");
                return(-1);
            }
            Game.Current = game;

            Resources.InitUserDirectory(Game.Current.Uid, commandLine[Resources.GamesManagerArguments.UserDirOverrideArgument] != null);
            Logger.Current = new Logger(Path.Combine(Resources.GameUserDir, "GamesManagerLog.txt"));


            if (commandLine[Resources.GamesManagerArguments.RegisterArgument] != null)
            {
                Logger.Current.Write(LogInfoLevel.Info, "Registering game...");
                if (!UACControl.IsAdmin())
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Registering requires administrator access");
                    ViewFactory.Current.CreateView <IMessage>().Show("Registering requires administrator access", "Administrator access required");
                    return(-1);
                }

                var installer = new GameRegistrar(true, Game.Current);
                return(installer.Start() == LongRunningTaskResult.Completed ? 0: -1);
            }
            else if (commandLine[Resources.GamesManagerArguments.DeregisterArgument] != null)
            {
                Logger.Current.Write(LogInfoLevel.Info, "Deregistering game...");
                if (!UACControl.IsAdmin())
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Deregistering requires administrator access");
                    ViewFactory.Current.CreateView <IMessage>().Show("Deregistering requires administrator access", "Administrator access required");
                    return(-1);
                }

                var uninstaller = new GameRegistrar(false, Game.Current);
                return(uninstaller.Start() == LongRunningTaskResult.Completed ? 0 : -1);
            }
            else if (commandLine[Resources.GamesManagerArguments.UpdateFrameworkArgument] != null || commandLine[Resources.GamesManagerArguments.UpdateGameArgument] != null)
            {
                Logger.Current.Write(LogInfoLevel.Info, "Updating game/framework...");

                if (commandLine[Resources.GamesManagerArguments.UpdateFrameworkArgument] != null &&
                    commandLine[Resources.GamesManagerArguments.FrameworkUpdateHashArgument] == null)
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Framework update MD5 hash argument missing");
                    ViewFactory.Current.CreateView <IMessage>().Show("Framework update MD5 hash argument missing", "Missing argument");
                    return(-1);
                }

                if (commandLine[Resources.GamesManagerArguments.UpdateGameArgument] != null &&
                    commandLine[Resources.GamesManagerArguments.GameUpdateHashArgument] == null)
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Game update MD5 hash argument missing");
                    ViewFactory.Current.CreateView <IMessage>().Show("Game update MD5 hash argument missing", "Missing argument");
                    return(-1);
                }

                if (!UACControl.IsAdmin())
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Updating requires administrator access");
                    ViewFactory.Current.CreateView <IMessage>().Show("Updating requires administrator access", "Administrator access required");
                    return(-1);
                }

                var presenter = new UpdateGamePresenter(
                    commandLine[Resources.GamesManagerArguments.UpdateGameArgument],
                    commandLine[Resources.GamesManagerArguments.GameUpdateHashArgument],
                    commandLine[Resources.GamesManagerArguments.UpdateFrameworkArgument],
                    commandLine[Resources.GamesManagerArguments.FrameworkUpdateHashArgument]);
                presenter.ShowView();
                Application.Run(presenter.View as Form);

                Process.Start(Resources.FrameworkUpdaterExecutable, Resources.GamesManagerBootArguments(string.Empty, string.Empty, string.Empty, string.Empty));
            }
            else
            {
                Logger.Current.Write(LogInfoLevel.Info, "Launching game...");
                var presenter = new LaunchGamePresenter(commandLine[Resources.GamesManagerArguments.NoUpdateCheckArgument] == null);
                presenter.ShowView();
                Application.Run(presenter.View as Form);
            }

            return(0);
        }