public ApplyDisableIntroAction(GameSetting settings, GameDetectionResult detectionResult, IFileAndFolderRenamer fileRenamer, IPathPatternTranslator pathPatternTranslator) : base(settings) { _detectionResult = detectionResult; _fileRenamer = fileRenamer; _pathPatternTranslator = pathPatternTranslator; }
public GameDetectionResult Execute() { var detectionResult = new GameDetectionResult(_gameSetting.Name); string completeInstallationDirectory = null; var isDetected = false; foreach (var installationDirectory in _installationDirectories) { foreach (var rootDirectory in _gameSetting.PotentialRootFolderNames) { // Validate if game emplacement exists var potentialGameEmplacementPath = $"{installationDirectory}\\{rootDirectory}\\"; if (!Directory.Exists(potentialGameEmplacementPath)) { continue; } // Validate that the folder is the targeted one var isValidated = true; foreach (var rootValidationRule in _gameSetting.ValidationRules) { var rootValidation = new ValidateGameRoot(potentialGameEmplacementPath, rootValidationRule); if (!rootValidation.Execute()) { isValidated = false; } } // If validated store value and break if (isValidated) { completeInstallationDirectory = potentialGameEmplacementPath; isDetected = true; break; } } } // Assign detection value detectionResult.Detected = isDetected; // Assign Installation Path if detected if (detectionResult.Detected && !string.IsNullOrEmpty(completeInstallationDirectory)) { detectionResult.InstallationPath = new DirectoryInfo(completeInstallationDirectory); } // Determine current introduction state if (detectionResult.Detected) { var introStateDetection = new DetectIntroductionState(detectionResult.InstallationPath, _gameSetting.DisablingIntroductionActions); detectionResult.IntroductionState = introStateDetection.Execute(); } // Return result return(detectionResult); }
public void SingleFileToRenameWtComplexNavigation() { //Set constants const string installPath = @"C:\Temp"; const string fileToRename = @"\videos\*\data\second\*\Nvidia.bk2"; //Set dependancies var settings = new GameSetting() { DisablingIntroductionActions = new List <DisableIntroductionAction>() { new DisableIntroductionAction() { Type = DisableActionTypeEnum.FileRename, InitialName = fileToRename, } } }; var gameDetectionResult = new GameDetectionResult("wat") { InstallationPath = new DirectoryInfo(installPath), Detected = true, IntroductionState = IntroductionStateEnum.Enabled }; //Set Mocks var pathPatternTranslatorMock = MockRepository.GenerateMock <IPathPatternTranslator>(); pathPatternTranslatorMock.Expect(x => x.GetPathFromPattern($"{installPath}{fileToRename}")).Return(new[] { @"C:\Temp\videos\sub1\data\second\third1\Nvidia.bk2", @"C:\Temp\videos\sub1\data\second\third2\Nvidia.bk2", @"C:\Temp\videos\sub2\data\second\third3\Nvidia.bk2", @"C:\Temp\videos\sub2\data\second\third4\Nvidia.bk2" }); var fileAndFolderRenamerMock = MockRepository.GenerateMock <IFileAndFolderRenamer>(); fileAndFolderRenamerMock.Expect(x => x.RenameFile(Arg <string> .Is.Equal(@"C:\Temp\videos\sub1\data\second\third1\Nvidia.bk2"), Arg <string> .Is.Equal($@"C:\Temp\videos\sub1\data\second\third1\Nvidia.bk2{GlobalNamesStruct.RenameSuffix}"), Arg <bool> .Is.Anything)); fileAndFolderRenamerMock.Expect(x => x.RenameFile(Arg <string> .Is.Equal(@"C:\Temp\videos\sub1\data\second\third2\Nvidia.bk2"), Arg <string> .Is.Equal($@"C:\Temp\videos\sub1\data\second\third2\Nvidia.bk2{GlobalNamesStruct.RenameSuffix}"), Arg <bool> .Is.Anything)); fileAndFolderRenamerMock.Expect(x => x.RenameFile(Arg <string> .Is.Equal(@"C:\Temp\videos\sub2\data\second\third3\Nvidia.bk2"), Arg <string> .Is.Equal($@"C:\Temp\videos\sub2\data\second\third3\Nvidia.bk2{GlobalNamesStruct.RenameSuffix}"), Arg <bool> .Is.Anything)); fileAndFolderRenamerMock.Expect(x => x.RenameFile(Arg <string> .Is.Equal(@"C:\Temp\videos\sub2\data\second\third4\Nvidia.bk2"), Arg <string> .Is.Equal($@"C:\Temp\videos\sub2\data\second\third4\Nvidia.bk2{GlobalNamesStruct.RenameSuffix}"), Arg <bool> .Is.Anything)); //Run test var businessRule = new ApplyDisableIntroAction(settings, gameDetectionResult, fileAndFolderRenamerMock, pathPatternTranslatorMock); businessRule.Execute(); //Validate pathPatternTranslatorMock.VerifyAllExpectations(); fileAndFolderRenamerMock.VerifyAllExpectations(); }
public void MultipleFilesToRename() { //Set constants const string installPath = @"C:\Temp"; const string fileToRename1 = @"\videos\Nvidia.bk2"; const string fileToRename2 = @"\videos\SubFolder\Intro.bk2"; //Set dependancies var settings = new GameSetting() { DisablingIntroductionActions = new List <DisableIntroductionAction>() { new DisableIntroductionAction() { Type = DisableActionTypeEnum.FileRename, InitialName = fileToRename1, }, new DisableIntroductionAction() { Type = DisableActionTypeEnum.FileRename, InitialName = fileToRename2, } } }; var gameDetectionResult = new GameDetectionResult("wat") { InstallationPath = new DirectoryInfo(installPath), Detected = true, IntroductionState = IntroductionStateEnum.Disabled }; //Set Mocks var fileAndFolderRenamerMock = MockRepository.GenerateMock <IFileAndFolderRenamer>(); fileAndFolderRenamerMock.Expect(x => x.RenameFile(Arg <string> .Is.Equal($"{installPath}{fileToRename1}{GlobalNamesStruct.RenameSuffix}"), Arg <string> .Is.Equal($"{installPath}{fileToRename1}"), Arg <bool> .Is.Equal(false))); fileAndFolderRenamerMock.Expect(x => x.RenameFile(Arg <string> .Is.Equal($"{installPath}{fileToRename2}{GlobalNamesStruct.RenameSuffix}"), Arg <string> .Is.Equal($"{installPath}{fileToRename2}"), Arg <bool> .Is.Equal(false))); var pathPatternTranslatorMock = MockRepository.GenerateMock <IPathPatternTranslator>(); pathPatternTranslatorMock.Expect(x => x.GetPathFromPattern($"{installPath}{fileToRename1}")).Return(new[] { $"{installPath}{fileToRename1}" }); pathPatternTranslatorMock.Expect(x => x.GetPathFromPattern($"{installPath}{fileToRename2}")).Return(new[] { $"{installPath}{fileToRename2}" }); //Run test var businessRule = new ApplyReenableIntroAction(settings, gameDetectionResult, fileAndFolderRenamerMock, pathPatternTranslatorMock); businessRule.Execute(); //Validate fileAndFolderRenamerMock.VerifyAllExpectations(); }
public Game GetGame(GameSetting settings, GameDetectionResult detectionResult) { //TODO: Create local cache of illustrations //Generate illustration var illustration = string.Empty; if (settings.IllustrationPlatform != IllustrationPlatformEnum.Unknown && !string.IsNullOrWhiteSpace(settings.IllustrationId)) { var generateIllustrationAction = new ConstructIllustrationAction(settings.IllustrationPlatform, settings.IllustrationId); illustration = generateIllustrationAction.Execute(); } //Create Game object var game = new Game(settings, detectionResult, illustration); return(game); }