private void BtnNext_Click(object sender, RoutedEventArgs e) { var dir = DirectoryPathBox.Text; var parser = new SFMDirectoryParser(dir, WindowsFileSystem.Instance); var error = parser.Validate(); if (error == SFMDirectoryParserError.NotExists) { MessageBox.Show("The path chosen is not a valid directory.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (error == SFMDirectoryParserError.NotLikely) { if (MessageBox.Show("The directory does not seem like the typical SFM installation. Continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } } _config.Write(new ConfigFile(parser.Path)); var gameinfoHandler = new GameinfoHandler(parser.GameinfoPath, WindowsFileSystem.Instance); var ret = gameinfoHandler.Execute(); /* TODO: maybe display a bit more useful error message including troubleshooting issues */ if (ret == GameinfoHandlerError.FileInvalid) { MessageBox.Show("Failed to add entry to gameinfo.txt", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } SetupWindow.Instance.GoToMainWindow(); }
public bool Save() { var parser = new SFMDirectoryParser(SfmDirectory, WindowsFileSystem.Instance); var error = parser.Validate(); switch (error) { case SFMDirectoryParserError.NotExists: SaveError = "SFM Directory does not exist."; Reset(); return(false); case SFMDirectoryParserError.NotLikely: SaveError = "SFM Directory is not valid."; Reset(); return(false); case SFMDirectoryParserError.Ok: break; default: throw new ArgumentOutOfRangeException(); } _file.SfmDirectoryPath = parser.Path; _config.Write(_file); MainWindow.Instance.RefreshListData(); return(true); }
public void IdentifyInvalidDirectory() { const string baseDir = "C:\\SecretPlace\\"; var fs = new MockFileSystem(); var parser = new SFMDirectoryParser(baseDir, fs); Assert.AreEqual(SFMDirectoryParserError.NotExists, parser.Validate()); }
public void IdentifyNotLikelyDirectory() { const string baseDir = "C:\\AwesomeStuff\\"; var fs = new MockFileSystem(); fs.AddFile(new MockFile(baseDir, MockFileType.Directory)); string[] subDirs = { "Ponies", "NSFWStuff" }; foreach (var d in subDirs) { fs.AddFile(new MockFile(Path.Combine(baseDir, d), MockFileType.Directory)); } var parser = new SFMDirectoryParser(baseDir, fs); Assert.AreEqual(SFMDirectoryParserError.NotLikely, parser.Validate()); }
public void IdentifyCorrectDirectory() { const string baseDir = "C:\\SourceFilmmaker\\game"; var fs = new MockFileSystem(); /* Create a fake default SFM installation */ fs.AddFile(new MockFile(baseDir, MockFileType.Directory)); string[] subDirs = { "bin", "hl2", "left4dead2_movies", "platform", "sdktools", "tf", "tf_movies", "usermod" }; foreach (var d in subDirs) { fs.AddFile(new MockFile(Path.Combine(baseDir, d), MockFileType.Directory)); } var parser = new SFMDirectoryParser(baseDir, fs); Assert.AreEqual(SFMDirectoryParserError.Ok, parser.Validate()); }