Beispiel #1
0
        private void ShowServerBrowserWindow()
        {
            if (serverBrowserWindow == null || !serverBrowserWindow.IsActive)
            {
                serverBrowserWindow = new Server_Browser.MainWindow(new Procedure(delegate
                {
                    // Has the server browser window requested that the program be closed?
                    if (serverBrowserWindow.CloseProgram == true)
                    {
                        Close();
                        return;
                    }

                    Show();
                    canOpenDemo      = true;
                    serverWindowOpen = false;
                }));
            }

            try
            {
                canOpenDemo      = false;
                serverWindowOpen = true;
                Hide();
                serverBrowserWindow.Show();
            }
            catch (Exception ex)
            {
                serverBrowserWindow.Close();
                Show();
                canOpenDemo      = true;
                serverWindowOpen = false;
                Common.Message(this, "Server Browser window error.", ex, MessageWindow.Flags.Error);
            }
        }
        private void uiAnalyseButton_Click(object sender, RoutedEventArgs e)
        {
            Demo demo = uiDemoListView.GetSelectedDemo();

            Debug.Assert(demo != null);

            AnalysisWindow window = AnalysisWindowFactory.CreateAnalysisWindow(demo);

            window.Owner = this;
            canOpenDemo  = false;

            try
            {
                window.ShowDialog();
            }
            catch (Exception ex)
            {
                window.Close();
                Common.Message(this, "Analysis window error.", ex, MessageWindow.Flags.Error);
            }
            finally
            {
                canOpenDemo = true;
            }
        }
Beispiel #3
0
 public void Error(String errorMessage, Exception ex)
 {
     Dispatcher.Invoke(DispatcherPriority.Normal, new Procedure(() =>
     {
         Common.Message(this, errorMessage, ex, MessageWindow.Flags.Error);
     }));
 }
        /// <summary>
        /// Purpose: so background threads can correctly display a modal error window.
        /// </summary>
        public void Error(String errorMessage, Exception ex, Boolean continueAbort, Procedure <MessageWindow.Result> setResult)
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, new Procedure(() =>
            {
                MessageWindow.Flags flags = MessageWindow.Flags.Error;

                if (continueAbort)
                {
                    flags |= MessageWindow.Flags.ContinueAbort;
                }

                Common.Message(this, errorMessage, ex, flags, setResult);
            }));
        }
        private void uiHlswAssociateCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                Config.AddHlswProtocolAssociation();
            }
            catch (UnauthorizedAccessException)
            {
                Common.Message(this, "Can't associate with the HLSW protocol, your Windows user account is not authorized to write registry keys. Try running this program as an administrator.");
                uiHlswAssociateCheckBox.IsChecked = false;
            }

            Config.Settings.AssociateWithHlswProtocol = (Boolean)uiHlswAssociateCheckBox.IsChecked;
        }
        private void uiDemAssociateCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            // handle *.dem file association
            try
            {
                Config.AssociateWithDemFiles();
            }
            catch (UnauthorizedAccessException)
            {
                Common.Message(this, "Can't associate with *.dem files, your Windows user account is not authorized to write registry keys. Try running this program as an administrator.");
                uiDemAssociateCheckBox.IsChecked = false;
            }

            Config.Settings.AssociateWithDemFiles = (Boolean)uiDemAssociateCheckBox.IsChecked;
        }
        private void uiViewLogs_Click(object sender, RoutedEventArgs e)
        {
            String logsFolder = System.IO.Path.Combine(Config.ProgramDataPath, "logs");

            if (!System.IO.Directory.Exists(logsFolder))
            {
                Common.Message("No log files found.");
                return;
            }

            try
            {
                Process.Start(logsFolder);
            }
            catch (Exception)
            {
                // don't care about errors
            }
        }
        private void uiRemoveButton_Click(object sender, RoutedEventArgs e)
        {
            // get selected game
            GameListItem gameListItem = (GameListItem)uiGameComboBox.SelectedItem;

            if (gameListItem == null)
            {
                Common.Message(this, "Select a game first.");
                return;
            }

            // get selected map
            MapListItem map = (MapListItem)uiMapListView.SelectedItem;

            if (map == null)
            {
                Common.Message(this, "Select a map first.");
                return;
            }

            // make sure map isn't built-in
            if (map.BuiltIn)
            {
                return;
            }

            // confirmation window
            if (Common.Message(this, "Are you sure you want to remove the select map from the map pool? The corresponding BSP file and any associated WAD files will be deleted.", null, MessageWindow.Flags.YesNo) != MessageWindow.Result.Yes)
            {
                return;
            }

            // delete the checksum folder and all contents
            //String engine = (game.Engine == Demo.EngineEnum.Source ? "source" : "goldsrc");
            String engine         = "goldsrc";
            String checksumFolder = Config.ProgramDataPath + String.Format("\\maps\\{0}\\{1}\\{2}", engine, gameListItem.Game.Folder, map.Checksum);

            Directory.Delete(checksumFolder, true);

            // update UI
            RefreshMapListView();
        }
        private void uiMapPoolMenuItem_Click(object sender, RoutedEventArgs e)
        {
            MapPoolWindow window = new MapPoolWindow();

            window.Owner = this;

            try
            {
                canOpenDemo = false;
                window.ShowDialog();
            }
            catch (Exception ex)
            {
                window.Close();
                Common.Message(this, "Map pool window error.", ex, MessageWindow.Flags.Error);
            }
            finally
            {
                canOpenDemo = true;
            }
        }
Beispiel #10
0
        private void ShowPreferencesWindow()
        {
            PreferencesWindow window = new PreferencesWindow();

            window.Owner = this;

            try
            {
                canOpenDemo = false;
                window.ShowDialog();
            }
            catch (Exception ex)
            {
                window.Close();
                Common.Message(this, "Preferences window error.", ex, MessageWindow.Flags.Error);
            }
            finally
            {
                canOpenDemo = true;
            }
        }
Beispiel #11
0
        private void Window_Activated(object sender, EventArgs e)
        {
            if (hasActivated)
            {
                return;
            }

            hasActivated = true;

            // if running for the first time, prompt the user to setup their Steam account details
            if (Program.FirstRun)
            {
                Common.Message(this, Config.ProgramName + " is running for the first time. Please ensure the detected Steam path and the selected Steam account folder are correct.");
                ShowPreferencesWindow(true);
            }

            // start auto update thread
            if (Config.Settings.AutoUpdate)
            {
                updateCheck = new UpdateCheck((IUpdateCheck)this);
            }

            // check for a file/server address in the command line arguments (file/protocol association)
            String[] commandLineArgs = Environment.GetCommandLineArgs();

            if (commandLineArgs.Length > 1)
            {
                if (commandLineArgs[1].StartsWith("hlsw://"))
                {
                    if (OpenServer(commandLineArgs[1]))
                    {
                        return; // stop now, don't go to last folder/file
                    }
                }
                else
                {
                    String fullPath = System.IO.Path.GetFullPath(commandLineArgs[1]);

                    if (System.IO.File.Exists(fullPath))
                    {
                        if (OpenDemo(fullPath))
                        {
                            return; // stop now, don't go to last folder/file
                        }
                    }
                }
            }

            // open last folder/file
            if (System.IO.Directory.Exists(Config.Settings.LastPath))
            {
                String lastFileName = Config.Settings.LastPath + "\\" + Config.Settings.LastFileName;

                if (System.IO.File.Exists(lastFileName))
                {
                    OpenDemo(lastFileName);
                }
                else
                {
                    uiExplorerTreeView.CurrentFolderPath = Config.Settings.LastPath;
                }
            }
        }
Beispiel #12
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();
        }
        private void uiAddButton_Click(object sender, RoutedEventArgs e)
        {
            // get selected game
            GameListItem gameListItem = (GameListItem)uiGameComboBox.SelectedItem;

            if (gameListItem == null)
            {
                Common.Message(this, "Select a game first.");
                return;
            }

            // open file dialog
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();

            dialog.Title            = "Add Map";
            dialog.Filter           = "BSP files (*.bsp)|*.bsp";
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            String mapFileName = System.IO.Path.GetFileName(dialog.FileName);

            // calculate checksum
            UInt32 checksum = 0;

            try
            {
                checksum = HalfLifeMapChecksum.Calculate(dialog.FileName);
            }
            catch (Exception ex)
            {
                Common.Message(this, String.Format("Error calculate map checksum for map \"{0}\"", mapFileName), ex, MessageWindow.Flags.Error);
                return;
            }

            // see if map is built-in
            if (gameListItem.Game.BuiltInMapExists(checksum, System.IO.Path.GetFileNameWithoutExtension(mapFileName)))
            {
                Common.Message(this, String.Format("The map \"{0}\" with the checksum \"{1}\" is a built-in map. It does not need to be added to the map pool.", mapFileName, checksum));
                return;
            }

            // see if the game map folder already exists
            //String engine = (game.Engine == Demo.EngineEnum.Source ? "source" : "goldsrc");
            String engine        = "goldsrc";
            String gameMapFolder = Config.ProgramDataPath + String.Format("\\maps\\{0}\\{1}", engine, gameListItem.Game.Folder);

            if (!Directory.Exists(gameMapFolder))
            {
                Directory.CreateDirectory(gameMapFolder);
            }

            // see if the checksum folder already exists
            String checksumFolder = gameMapFolder + "\\" + String.Format("{0}", checksum);

            if (!Directory.Exists(checksumFolder))
            {
                Directory.CreateDirectory(checksumFolder);
            }

            // see if the map already exists
            String mapFullPath = checksumFolder + "\\" + mapFileName;

            if (File.Exists(mapFullPath))
            {
                Common.Message(this, String.Format("The map \"{0}\" with the checksum \"{1}\" already exists.", mapFileName, checksum));
                return;
            }

            // copy the map over
            File.Copy(dialog.FileName, mapFullPath);

            // update UI and inform the user of success
            RefreshMapListView();
            Common.Message(this, String.Format("Successfully added the map \"{0}\" with the checksum \"{1}\" to the map pool.", mapFileName, checksum));
        }
Beispiel #14
0
        protected void CheckMapVersion()
        {
            // FIXME:
            // not really needed, just don't call this
            // remove me when source map checksum stuff is figured out
            if (Demo.Engine == Demo.Engines.Source)
            {
                return;
            }

            // see if the game has a config file
            // FIXME: engine name - assuming goldsrc for now (see above)
            Game game = GameManager.Find(Demo);

            if (game == null || game.HasConfig == false)
            {
                // can't determine what maps are built-in for the game - can't handle map versions
                return;
            }

            // see if the map is built-in
            if (game.BuiltInMapExists(Demo.MapChecksum, Demo.MapName))
            {
                // ok, suitable map found
                return;
            }

            // see if the map already exists in the game's "maps" folder
            String mapDestinationPath     = gameFullPath + "\\maps";
            String mapDestinationFileName = mapDestinationPath + "\\" + Demo.MapName + ".bsp";

            if (File.Exists(mapDestinationFileName))
            {
                if (HalfLifeMapChecksum.Calculate(mapDestinationFileName) == Demo.MapChecksum)
                {
                    // ok, suitable map found
                    return;
                }
            }

            // see if we have a map in the map pool matching the checksum
            String mapSourcePath     = Config.ProgramDataPath + "\\maps\\goldsrc\\" + String.Format("{0}\\{1}", Demo.GameFolderName, Demo.MapChecksum);
            String mapSourceFileName = mapSourcePath + "\\" + Demo.MapName + ".bsp";

            if (!File.Exists(mapSourceFileName))
            {
                DownloadMapWindow downloadMapWindow = new DownloadMapWindow(Demo.MapName, Config.MapsUrl + "goldsrc/" + String.Format("{0}/{1}_{2}.zip", Demo.GameFolderName, Demo.MapChecksum, Demo.MapName), mapSourcePath + "\\" + Demo.MapName + ".zip");
                downloadMapWindow.Owner = Owner;

                if (downloadMapWindow.ShowDialog() == false)
                {
                    // can't find a suitable map
                    if (Common.Message(Owner, String.Format("Can't find a version of \"{0}\" with a matching checksum \"{1}\" for this demo. Continue with playback anyway?", Demo.MapName, Demo.MapChecksum), null, MessageWindow.Flags.ContinueAbort) != MessageWindow.Result.Continue)
                    {
                        throw new AbortLaunchException();
                    }

                    return;
                }
            }

            // first make sure the desination "maps" folder exists (create it if it doesn't)
            if (!Directory.Exists(mapDestinationPath))
            {
                Directory.CreateDirectory(mapDestinationPath);
            }

            // if original map exists, rename to *.bak (if that exists, just delete it)
            String backupDestinationFileName = Path.ChangeExtension(mapDestinationFileName, ".bak");

            if (File.Exists(mapDestinationFileName))
            {
                if (File.Exists(backupDestinationFileName))
                {
                    File.Delete(backupDestinationFileName);
                }

                File.Move(mapDestinationFileName, backupDestinationFileName);
                FileOperationList.Add(new FileMoveOperation(backupDestinationFileName, mapDestinationFileName));
            }

            // copy old version of map
            File.Copy(mapSourceFileName, mapDestinationFileName);
            FileOperationList.Add(new FileDeleteOperation(mapDestinationFileName));

            // copy any wad files (if they don't already exist)
            DirectoryInfo directoryInfo = new DirectoryInfo(mapSourcePath);

            foreach (FileInfo fi in directoryInfo.GetFiles("*.wad", SearchOption.TopDirectoryOnly))
            {
                // wad destination = demo destination
                String wadDestinationFileName = gameFullPath + "\\" + fi.Name;

                if (!File.Exists(wadDestinationFileName))
                {
                    File.Copy(fi.FullName, wadDestinationFileName);
                }
            }
        }
Beispiel #15
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);
        }
Beispiel #16
0
        public void SetCurrentPath(String path, String demoNameToSelect)
        {
            // really should refresh the demo list

            /*if (path == currentPath)
             * {
             *  SelectDemo(demoNameToSelect);
             *  return;
             * }*/

            this.demoNameToSelect = demoNameToSelect;

            // clear control
            demoCollection.Clear();

            // abort all running threads from thread pool
            foreach (Thread t in threadPool)
            {
                Common.AbortThread(t);
            }

            // check that directory exists, that path isn't blank
            if (path == "" || !Directory.Exists(path))
            {
                return;
            }

            currentPath = path;

            // search folder for *.dem files
            DirectoryInfo directoryInfo = new DirectoryInfo(path);

            threadPoolFull  = false;
            threadPoolCount = 0;
            FileInfo[] files = null;

            try
            {
                files = directoryInfo.GetFiles("*.dem", SearchOption.TopDirectoryOnly);
            }
            catch (UnauthorizedAccessException)
            {
                return;
            }

            foreach (FileInfo fi in files)
            {
                Thread thread;

                try
                {
                    Demo demo = DemoFactory.CreateDemo(fi.FullName);
                    thread = demo.Read((IMainWindow)((Grid)Parent).Parent, (IDemoListView)this);
                }
                catch (Exception ex)
                {
                    /*
                     * Only show an error message here if the user explicitly opened this demo.
                     * The only errors that should be happening are if the demo isn't a valid HL/Source engine demo or if there's some problem opening the file.
                     *
                     * Any errors that occur in the demo reading thread are always shown (the thread handles this).
                     */
                    if (String.Equals(System.IO.Path.GetFileNameWithoutExtension(fi.Name), demoNameToSelect))
                    {
                        Common.Message((Window)((Grid)Parent).Parent, "Error loading demo file \"" + fi.FullName + "\"", ex, MessageWindow.Flags.Error);
                    }

                    // don't add it to the thread pool
                    continue;
                }

                threadPool.Add(thread);
                threadPoolCount++;
            }

            threadPoolFull = true;
        }
Beispiel #17
0
 private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
 {
     Common.LogException(e.Exception);
     Common.Message(null, "Unhandled exception.", e.Exception, MessageWindow.Flags.Error);
 }