public void ReplaceHostFile(string[] args) { string newPath = ""; foreach (var argument in args) { if (argument.Contains("-newPath")) { newPath = argument.Substring(10, (argument.Length - 11)).Replace("%20", " "); if (!FileModification.FileExists(newPath)) { newPath = ""; } } } if (newPath == "") { Console.WriteLine("No valid path for new system file was given."); if (!_unitTestSetup) { Console.ReadKey(); Environment.Exit(1); } } string hostContent = FileModification.ReadFile(newPath); FileModification.WriteFile(GetHostFileLocation(), hostContent); if (!_unitTestSetup) { Environment.Exit(0); } }
public int UpdateHostFile(string hostFileContent) { string newHostFilePath = $"{ConfigurationPath}\\tempHostFile"; FileModification.WriteFile(newHostFilePath, hostFileContent); return(Execute($"-replaceHostFile -newPath='{newHostFilePath.Replace(" ", "%20")}'")); }
public void SaveConfiguration(CurrentUserConfiguration configuration, string password) { var jsonConfiguration = JsonConvert.SerializeObject(configuration); string encryptedConfiguration = EncryptingHelper.Encrypt(jsonConfiguration, password); FileModification.WriteFile(ConfigurationPath, encryptedConfiguration); }
public void CreateNewHostFile() { if (!HostFileExists()) { try { FileModification.WriteFile(GetHostFileLocation(), "#Host-file created by BackOnTrack"); if (!_unitTestSetup) { Environment.Exit(0); } } catch (Exception e) { Console.WriteLine($"The following error occured: [\"{e}\"]{Environment.NewLine}{e.Message}"); if (!_unitTestSetup) { Console.ReadKey(); Environment.Exit(1); } } } else { Console.WriteLine($"System file \"{GetHostFileLocation()}\" exists already"); if (!_unitTestSetup) { Console.ReadKey(); Environment.Exit(1); } } }
private void SaveUserConfiguration(CurrentUserConfiguration userConfiguration) { var jsonConfiguration = JsonConvert.SerializeObject(userConfiguration); string encryptedConfiguration = EncryptingHelper.Encrypt(jsonConfiguration, _configurationPassword); FileModification.CreateFolderIfNotExists($"{_programSettingsPath}\\.backOnTrack"); FileModification.WriteFile(GetProxyUserConfigurationPath(), encryptedConfiguration); }
public void LoadingEntriesFromEmptyHostFileShouldPutZeroEntriesIntoTheHostEntryList() { //Arrange DoSetupWithUnlockingAndBasicHostFileWithUcosl(); FileModification.WriteFile(NewHostFileTwoLocation, ""); //Act _ucosl.AddAllLinesFromHostFileIntoEntryList(); //Arrange _ucosl.GetHostEntries().Count.Should().Be(0); }
public void CheckHostFileWasReplaced() { //Arrange string newHostFileLocation = $"{TempFolder.Name}{@"\hosts"}"; _systemLevelModification = new SystemLevelModification(true, newHostFileLocation); string newHostFileTwoLocation = $"{TempFolder.Name}{@"\hosts2"}"; FileModification.WriteFile(newHostFileTwoLocation, "#Test"); //Act _systemLevelModification.CreateNewHostFile(); string hostFileContentBefore = FileModification.ReadFile(newHostFileLocation); _systemLevelModification.ReplaceHostFile(new string[] { $"-newPath={newHostFileTwoLocation.Replace(" ", "%20")}" }); string hostFileContentAfter = FileModification.ReadFile(newHostFileLocation); //Assert hostFileContentAfter.Should().NotBe(hostFileContentBefore); }
public void NotActiveBackOnTrackEntriesShouldGetRemovedFromHostEntryList() { //Arrange DoSetupWithUnlockingAndBasicHostFileWithUcosl(); FileModification.WriteFile(NewHostFileTwoLocation, "#Test" + Environment.NewLine + "127.0.0.1 manuelweb.at #BackOnTrackEntry"); var hostEntries = _ucosl.GetHostEntries(); _ucosl.AddAllLinesFromHostFileIntoEntryList(); _ucosl.AddMissingEntriesIntoEntryList(Application.UI.MainView.UserConfiguration); //Act int hostEntriesBeforeRemovingNotActiveOnes = hostEntries.Count; _ucosl.RemoveNotActiveEntriesFromEntryList(Application.UI.MainView.UserConfiguration); int hostEntriesAfterRemovingNotActiveOnes = hostEntries.Count; //Assert hostEntriesBeforeRemovingNotActiveOnes.Should().Be(2); hostEntriesAfterRemovingNotActiveOnes.Should().Be(1); }
private void SaveConfiguration(CurrentProgramConfiguration config) { var jsonConfiguration = JsonConvert.SerializeObject(config); FileModification.WriteFile(ConfigurationPath, jsonConfiguration); }
public void CreateHostFileWithSampleContent() { FileModification.WriteFile(NewHostFileTwoLocation, "#Test" + Environment.NewLine + "127.0.0.1 facebook.com"); }