private void Window_Drop(object sender, DragEventArgs e) { string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false); if (s.Length != 1) { return; } OpenDemo(Common.SanitisePath(s[0])); }
/// <summary> /// Reads the program configuration from the configuration file, if it exists. Otherwise, default values and information from the registry are used. /// </summary> /// <returns>True if the config file exists, False if it doesn't.</returns> public static Boolean Read() { ProgramDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + ProgramName; ProgramExeFullPath = Common.SanitisePath(Environment.GetCommandLineArgs()[0]); #if DEBUG // Use the working directory when debugging. This is due to the Express edition of VS2008's limited debugging options. // The working directory should be set to the bin sub-directory (e.g. trunk\bin). ProgramPath = Environment.CurrentDirectory; #else ProgramPath = Path.GetDirectoryName(ProgramExeFullPath); #endif Settings = null; Boolean result = true; String configFullPath = ProgramDataPath + "\\" + fileName; if (File.Exists(configFullPath)) { // deserialize try { using (StreamReader stream = new StreamReader(configFullPath)) { Serializer serializer = new Serializer(typeof(ProgramSettings)); Settings = (ProgramSettings)serializer.Deserialize(stream); } } catch (Exception ex) { // Assume the file has been corrupted by the user or some other external influence. Log the exception as a warning, delete the file and use default config values. Common.LogException(ex, true); File.Delete(configFullPath); Settings = null; } } if (Settings == null) { Settings = new ProgramSettings(); result = false; ReadFromRegistry(); } return(result); }
private void uiOpenMenuItem_Click(object sender, RoutedEventArgs e) { // open file dialog Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog(); dialog.Title = "Open Demo"; dialog.Filter = "Demo files (*.dem)|*.dem"; dialog.RestoreDirectory = true; canOpenDemo = false; if (dialog.ShowDialog(this) == false) { canOpenDemo = true; return; } // open demo canOpenDemo = true; OpenDemo(Common.SanitisePath(dialog.FileName)); }
private void uiOpenMenuItem_Click(object sender, RoutedEventArgs e) { // open file dialog System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog(); dialog.Title = "Open Demo"; dialog.Filter = "Demo files (*.dem)|*.dem"; dialog.InitialDirectory = CurrentPath; dialog.RestoreDirectory = true; canOpenDemo = false; if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { canOpenDemo = true; return; } // open demo canOpenDemo = true; OpenDemo(Common.SanitisePath(dialog.FileName)); }
/// <summary> /// Reads as much useful information as possible from the registry, such as Steam and Half-Life's install paths. /// </summary> private static void ReadFromRegistry() { // read SteamExe using (RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Valve\\Steam")) { if (key != null) { Settings.SteamExeFullPath = (string)key.GetValue("SteamExe", ""); if (Settings.SteamExeFullPath == null) { Settings.SteamExeFullPath = ""; } else { Settings.SteamExeFullPath = Common.SanitisePath(Settings.SteamExeFullPath); // this registry value always seems to be lower case. replace steam.exe with Steam.exe Settings.SteamExeFullPath = Settings.SteamExeFullPath.Replace("steam.exe", "Steam.exe"); } } } // check if SteamExe is valid (contains Steam.exe) if (File.Exists(Settings.SteamExeFullPath)) { // Find an account name by enumerating subfolder names in "SteamApps" // use "common" if it exists, otherwise use the first folder that isn't "sourcemods" DirectoryInfo steamAppsDirInfo = new DirectoryInfo(Path.GetDirectoryName(Settings.SteamExeFullPath) + "\\SteamApps"); DirectoryInfo commonDirInfo = Common.FirstOrDefault(steamAppsDirInfo.GetDirectories(), di => di.Name.ToLower() == "common"); if (commonDirInfo != null) { Settings.SteamAccountFolder = commonDirInfo.Name; } else { foreach (DirectoryInfo dirInfo in steamAppsDirInfo.GetDirectories()) { if (dirInfo.Name.ToLower() != "sourcemods") { Settings.SteamAccountFolder = dirInfo.Name; break; } } } } else { // bad steam exe path, make the user enter it manually Settings.SteamExeFullPath = ""; } // read half-life folder path, add hl.exe to it using (RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Valve\\Half-Life")) { if (key != null) { Settings.HlExeFullPath = (String)key.GetValue("InstallPath"); if (Settings.HlExeFullPath == null) { Settings.HlExeFullPath = ""; } else { Common.SanitisePath(Settings.HlExeFullPath); Settings.HlExeFullPath += "\\hl.exe"; if (!File.Exists(Settings.HlExeFullPath)) { // bad hl.exe path, make the user enter it manually Settings.HlExeFullPath = ""; } } } } }
/// <summary> /// Reads as much useful information as possible from the registry, such as Steam and Half-Life's install paths. /// </summary> private static void ReadFromRegistry() { // read SteamExe using (RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Valve\\Steam")) { if (key != null) { Settings.SteamExeFullPath = (string)key.GetValue("SteamExe", ""); if (Settings.SteamExeFullPath == null) { Settings.SteamExeFullPath = ""; } else { Settings.SteamExeFullPath = Common.SanitisePath(Settings.SteamExeFullPath); // this registry value always seems to be lower case. replace steam.exe with Steam.exe Settings.SteamExeFullPath = Settings.SteamExeFullPath.Replace("steam.exe", "Steam.exe"); } } } // check if SteamExe is valid (contains Steam.exe) if (File.Exists(Settings.SteamExeFullPath)) { // Find an account name (first folder in "SteamApps" that isn't "common" or "SourceMods") // "common" created by peggle extreme, left 4 dead etc. DirectoryInfo steamAppsDirInfo = new DirectoryInfo(Path.GetDirectoryName(Settings.SteamExeFullPath) + "\\SteamApps"); foreach (DirectoryInfo dirInfo in steamAppsDirInfo.GetDirectories()) { if (dirInfo.Name.ToLower() != "common" && dirInfo.Name.ToLower() != "sourcemods") { Settings.SteamAccountFolder = dirInfo.Name; break; } } } else { // bad steam exe path, make the user enter it manually Settings.SteamExeFullPath = ""; } // read half-life folder path, add hl.exe to it using (RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Valve\\Half-Life")) { if (key != null) { Settings.HlExeFullPath = (String)key.GetValue("InstallPath"); if (Settings.HlExeFullPath == null) { Settings.HlExeFullPath = ""; } else { Common.SanitisePath(Settings.HlExeFullPath); Settings.HlExeFullPath += "\\hl.exe"; if (!File.Exists(Settings.HlExeFullPath)) { // bad hl.exe path, make the user enter it manually Settings.HlExeFullPath = ""; } } } } }