Ejemplo n.º 1
0
        public void Verify()
        {
            VerifyProgramSettings();
            Debug.Assert(gameFullPath != null);
            VerifyRunningPrograms();
            Debug.Assert(processExeFullPath != null);

            try
            {
                PreLaunch();
            }
            catch (Exception)
            {
                try
                {
                    FileOperationList.Execute();
                }
                catch (Exception)
                {
                    // absorb any post-launch errors in this case, since we're just doing clean up
                }

                throw;
            }
        }
Ejemplo n.º 2
0
        public void LaunchedProcessClosed()
        {
            Procedure action = () =>
            {
                try
                {
                    FileOperationList.Execute();
                }
                catch (Exception)
                {
                    // suppress cleanup errors
                }

                Demo demo = uiDemoListView.GetSelectedDemo();
                if (demo != null && UseHlae(demo))
                {
                    Debug.Assert(launcher as SteamLauncher != null);
                }

                // If the system tray still has a context menu, then connecting must have been cancelled.
                // Don't apply the "close when finished" functionality in this case.
                if (!SystemTrayIcon.HasContextMenuStrip && Config.Settings.PlaybackCloseWhenFinished)
                {
                    SystemTrayIcon.Hide();
                    Close();
                }
                else
                {
                    RestoreFromTray();
                    canOpenDemo = true;
                }
            };

            if (Thread.CurrentThread != Dispatcher.Thread)
            {
                Dispatcher.Invoke(DispatcherPriority.Normal, action);
            }
            else
            {
                action();
            }
        }
Ejemplo n.º 3
0
        private void uiPlayButton_Click(object sender, RoutedEventArgs e)
        {
            Demo demo = uiDemoListView.GetSelectedDemo();

            if (demo == null)
            {
                // shouldn't happen since the button should be disabled, but anyway...
                return;
            }

            // verify paths etc.
            launcher           = LauncherFactory.CreateLauncher(demo);
            launcher.Owner     = this;
            launcher.UseHlae   = UseHlae(demo);
            launcher.Interface = (ILauncher)this;

            try
            {
                launcher.Verify();
            }
            catch (Launcher.AbortLaunchException)
            {
                return;
            }
            catch (ApplicationException ex)
            {
                Common.Message(this, null, ex);
                return;
            }
            catch (Exception ex)
            {
                Common.Message(this, null, ex, MessageWindow.Flags.Error);
                return;
            }

            // make sure source and destination filenames don't match (dickhead insurance)
            if (String.Equals(demo.FileFullPath, launcher.GameFullPath + "\\" + Config.LaunchDemoFileName, StringComparison.CurrentCultureIgnoreCase))
            {
                Common.Message(this, "Source and destination filenames are the same. Rename or move the source file and try again.");
                return;
            }

            // add the demo file path to the file operation manager
            FileOperationList.Add(new FileDeleteOperation(launcher.GameFullPath + "\\" + Config.LaunchDemoFileName));

            // stop the user from being able to open a new demo now
            canOpenDemo = false;

            // write the demo
            ProgressWindow writeDemoProgressWindow = new ProgressWindow()
            {
                Owner = this
            };

            writeDemoProgressWindow.Thread          = demo.Write((IProgressWindow)writeDemoProgressWindow);
            writeDemoProgressWindow.ThreadParameter = launcher.GameFullPath + "\\" + Config.LaunchDemoFileName;
            if (writeDemoProgressWindow.ShowDialog() == false)
            {
                // user aborted writing
                FileOperationList.Execute();
                canOpenDemo = true;
                return;
            }

            // go to tray
            MinimiseToTray();

            // launch the game
            try
            {
                launcher.Run();
            }
            catch (Exception ex)
            {
                RestoreFromTray();
                FileOperationList.Execute();
                canOpenDemo = true;
                Common.Message(this, "Error launching game.", ex, MessageWindow.Flags.Error);
                return;
            }

            SystemTrayIcon.Text = "Looking for " + (launcher.UseHlae ? "HLAE" : "game") + " process...";

            // enable the tray context menu
            TrayContextMenuEnable(true);
        }
Ejemplo n.º 4
0
        static void Main(String[] args)
        {
            // read config.xml
            try
            {
                Config.Read();
            }
            catch (Exception ex)
            {
                Common.Message(null, "Error reading from the configuration file. Try deleting \"config.xml\" from  \"" + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + Config.ProgramName + "\".", ex, MessageWindow.Flags.Error);
                return;
            }

            // look for already running process with same name and path
            Process process = Common.FindProcess(Path.GetFileNameWithoutExtension(Config.ProgramExeFullPath), Config.ProgramExeFullPath, Process.GetCurrentProcess().Id);

            if (process != null)
            {
                // focus on process window
                SetForegroundWindow(process.MainWindowHandle);

                if (args.Length > 0)
                {
                    if (File.Exists(args[0]))
                    {
                        // send command line parameter to existing process
                        try
                        {
                            CreateClientChannel(args[0]);
                        }
                        catch (Exception ex)
                        {
                            Common.Message(null, "Error creating client IPC channel.", ex, MessageWindow.Flags.Error);
                        }
                    }
                }

                // another process already exists, end this one
                return;
            }
            else
            {
                try
                {
                    CreateServerChannel();
                }
                catch (Exception ex)
                {
                    Common.Message(null, "Error creating server IPC channel.", ex, MessageWindow.Flags.Error);
                    return; // quit
                }

                AllowSetForegroundWindow(Process.GetCurrentProcess().Id);
            }

            // read steam.xml
            try
            {
                GameManager.Initialise(Config.ProgramPath + "\\config");
            }
            catch (Exception ex)
            {
                Common.Message(null, "Error reading from \"steam.json\". Reinstalling may fix the problem.", ex, MessageWindow.Flags.Error);
                return;
            }

            // read fileoperationslog.xml
            try
            {
                FileOperationList.Initialise(Config.ProgramDataPath, "fileoperationslog.xml");
                FileOperationList.Execute();
            }
            catch (Exception ex)
            {
                Common.Message(null, "FileOperationList error. Try deleting \"fileoperationslog.xml\" from \"" + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + Config.ProgramName + "\" if the problem persists.", ex, MessageWindow.Flags.Error);
                return;
            }

            // file association
            if (Config.Settings.AssociateWithDemFiles)
            {
                try
                {
                    Config.AssociateWithDemFiles();
                }
                catch (UnauthorizedAccessException)
                {
                    Config.Settings.AssociateWithDemFiles = false;
                }
                catch (Exception ex)
                {
                    Common.Message(null, "Error associating with *.dem files.", ex, MessageWindow.Flags.Error);
                }
            }

            App app = new App();

            app.InitializeComponent();
            app.Run();
        }