public void CreateEmptyProfileConfigurationIfNotExists() { if (!FileModification.FileExists(GetProxyUserConfigurationPath())) { SaveUserConfiguration(new CurrentUserConfiguration()); } }
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")}'")); }
private void DoUiTestsSetup(string[] settings) { if (!UnitTestSetup) { if (settings.Contains("-uiTesting")) { UiTestSetup = true; foreach (var argument in settings) { if (argument.Contains("-programPath")) { _programSettingsPath = argument.Substring(13, (argument.Length - 13)).Replace("%20", " "); try { FileModification.CreateFolderIfNotExists(_programSettingsPath); } catch (Exception e) { Messages.CreateMessageBox(_programSettingsPath + "=" + e.Message, "Error", true); } FileModification.HostFileLocation = _programSettingsPath + "\\hosts"; } } } } }
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); } } }
public void SaveConfiguration(CurrentUserConfiguration configuration, string password) { var jsonConfiguration = JsonConvert.SerializeObject(configuration); string encryptedConfiguration = EncryptingHelper.Encrypt(jsonConfiguration, password); FileModification.WriteFile(ConfigurationPath, encryptedConfiguration); }
private void DeleteOldPictures() { FileModification.DelteFileIfExists($"{_oldImagePath}.jpg"); FileModification.DelteFileIfExists($"{_oldImagePath}.jpeg"); FileModification.DelteFileIfExists($"{_oldImagePath}.gif"); FileModification.DelteFileIfExists($"{_oldImagePath}.bmp"); FileModification.DelteFileIfExists($"{_oldImagePath}.png"); }
private void SaveUserConfiguration(CurrentUserConfiguration userConfiguration) { var jsonConfiguration = JsonConvert.SerializeObject(userConfiguration); string encryptedConfiguration = EncryptingHelper.Encrypt(jsonConfiguration, _configurationPassword); FileModification.CreateFolderIfNotExists($"{_programSettingsPath}\\.backOnTrack"); FileModification.WriteFile(GetProxyUserConfigurationPath(), encryptedConfiguration); }
static FileModificationInfo Create(FileModification fileModification) { return new FileModificationInfo { ModifiedAt = fileModification.ModifiedAt, ModifiedBy = fileModification.ModifiedBy, ModificationMessage = fileModification.ModificationMessage }; }
public void SetCurrentConfigurationToDefault() { if (!FileModification.FileExists(ConfigurationPath)) { FileModification.CreateFolderIfNotExists(ConfigurationPath.Replace("\\config.settings", "")); } CreateNewConfiguration(); CopyCurrentConfigurationToTempConfig(); }
public ActionCollection(string file, string currentModID, List <FileModification> modifications) { var fileModifications = modifications.Where(m => m.FilePath == file); this.moveAction = fileModifications.LastOrDefault(a => a.ModID != currentModID && a.Type == FileModificationType.Moved); this.replaceAction = fileModifications.LastOrDefault(a => a.ModID != currentModID && a.Type == FileModificationType.Replaced); this.editAction = fileModifications.LastOrDefault(a => a.ModID != currentModID && a.Type == FileModificationType.Edited); this.addAction = fileModifications.LastOrDefault(a => a.ModID != currentModID && a.Type == FileModificationType.Added); this.deleteAction = fileModifications.LastOrDefault(a => a.ModID != currentModID && a.Type == FileModificationType.Deleted); this.lastAction = fileModifications.LastOrDefault(a => a.ModID != currentModID); }
public void SaveCurrentConfiguration() { CopyTempConfigurationToCurrentConfig(); if (!FileModification.FileExists(ConfigurationPath)) { FileModification.CreateFolderIfNotExists(ConfigurationPath.Replace("\\config.settings", "")); } SaveConfiguration(Configuration); CopyCurrentConfigurationToTempConfig(); }
public void LoadingEntriesFromEmptyHostFileShouldPutZeroEntriesIntoTheHostEntryList() { //Arrange DoSetupWithUnlockingAndBasicHostFileWithUcosl(); FileModification.WriteFile(NewHostFileTwoLocation, ""); //Act _ucosl.AddAllLinesFromHostFileIntoEntryList(); //Arrange _ucosl.GetHostEntries().Count.Should().Be(0); }
static FileModificationStatistics CreateHistory(string fileName, IEnumerable<string> fileHistory) { var firstModification = new FileModification(); var editModifications = new List<FileModification>(); var editRegex = new Regex("edit\\son\\s(.+)\\sby\\s(.+)\\@.+\n\n\t(.+)", RegexOptions.Multiline); var addRegex = new Regex("\\sadd\\son\\s(.+)\\sby\\s(.+)\\@.+\n\n\t(.+)", RegexOptions.Multiline); foreach (var historyEntry in fileHistory) { var editMatch = editRegex.Match(historyEntry); if (editMatch.Success) { DateTime editDate; if (DateTime.TryParse(editMatch.Groups[1].Value, out editDate)) { var editedBy = editMatch.Groups[2].Value; var editMessage = editMatch.Groups[3].Value; editModifications.Add(new FileModification { ModifiedAt = editDate, ModificationMessage = editMessage, ModifiedBy = editedBy }); } continue; } var addMatch = addRegex.Match(historyEntry); if (addMatch.Success) { DateTime addDate; if (DateTime.TryParse(addMatch.Groups[1].Value, out addDate)) { var addedBy = addMatch.Groups[2].Value; var addedMessage = addMatch.Groups[3].Value; firstModification = new FileModification { ModifiedAt = addDate, ModificationMessage = addedMessage, ModifiedBy = addedBy }; } } } return new FileModificationStatistics { FileName = fileName, FirstCommit = firstModification, OtherCommits = editModifications }; }
private void SetNewestImagePath() { string imagePath = ""; if (FileModification.FileExists($"{_oldImagePath}.jpg")) { imagePath = $"{_oldImagePath}.jpg"; } else if (FileModification.FileExists($"{_oldImagePath}.jpeg")) { imagePath = $"{_oldImagePath}.jpeg"; } else if (FileModification.FileExists($"{_oldImagePath}.gif")) { imagePath = $"{_oldImagePath}.gif"; } else if (FileModification.FileExists($"{_oldImagePath}.bmp")) { imagePath = $"{_oldImagePath}.bmp"; } else if (FileModification.FileExists($"{_oldImagePath}.png")) { imagePath = $"{_oldImagePath}.png"; } if (imagePath != "") { try { System.Drawing.Image img = System.Drawing.Image.FromFile(imagePath); var bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri(imagePath); bmp.EndInit(); imageToRemind.Source = bmp; } catch (Exception) { //image is broken imageToRemind.Source = null; } } else { //image is not in folder imageToRemind.Source = null; } }
private void AddAllLinesFromHostFileIntoEntryList() { string fileContent = FileModification.ReadFile(FileModification.GetHostFileLocation()); using (StringReader reader = new StringReader(fileContent)) { string line; while ((line = reader.ReadLine()) != null) { HostEntry newEntry = new HostEntry() { Content = line, LineNumber = (CurrentLineNumber + 1), IsEnabled = false }; HostEntries.Add(newEntry); CurrentLineNumber++; } } }
private void SetNewestImagePath() { string imagePath = ""; if (FileModification.FileExists($"{_oldImagePath}.jpg")) { imagePath = $"{_oldImagePath}.jpg"; } else if (FileModification.FileExists($"{_oldImagePath}.jpeg")) { imagePath = $"{_oldImagePath}.jpeg"; } else if (FileModification.FileExists($"{_oldImagePath}.gif")) { imagePath = $"{_oldImagePath}.gif"; } else if (FileModification.FileExists($"{_oldImagePath}.bmp")) { imagePath = $"{_oldImagePath}.bmp"; } else if (FileModification.FileExists($"{_oldImagePath}.png")) { imagePath = $"{_oldImagePath}.png"; } if (imagePath != "") { try { ImageDisplayed.Source = GetImageByStream(imagePath); } catch (Exception) { //image is broken ImageDisplayed.Source = null; } } else { //image is not in folder ImageDisplayed.Source = null; } }
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); }
public void SetCurrentConfigurationFromConfig() { if (FileModification.FileExists(ConfigurationPath)) { string configurationContent = FileModification.ReadFile(ConfigurationPath); if (configurationContent == "") { CreateNewConfiguration(); } else { Configuration = JsonConvert.DeserializeObject <CurrentProgramConfiguration>(configurationContent); } } else { FileModification.CreateFolderIfNotExists(ConfigurationPath.Replace("\\config.settings", "")); CreateNewConfiguration(); } CopyCurrentConfigurationToTempConfig(); }
public void LoadCurrentUserConfiguration() { if (!FileModification.FileExists(GetProxyUserConfigurationPath())) { throw new WebProxyNoProfilesFileException($"WebProxy file \"{GetProxyUserConfigurationPath()}\" does not exist."); } else { string encryptedConfigurationContent = FileModification.ReadFile(GetProxyUserConfigurationPath()); bool fileIsBroken = false; if (encryptedConfigurationContent != "") { try { string configurationContent = EncryptingHelper.Decrypt(encryptedConfigurationContent, _configurationPassword); var configuration = JsonConvert.DeserializeObject <CurrentUserConfiguration>(configurationContent); ApplyUserConfiguration(configuration, false); } catch (Exception) { fileIsBroken = true; } } else { fileIsBroken = true; } if (fileIsBroken) { throw new WebProxyBrokenProfileConfigurationException($"WebProxy file \"{GetProxyUserConfigurationPath()}\" is broken."); } } }
public bool HostFileExists() { return(FileModification.FileExists(FileModification.GetHostFileLocation())); }
private void CopyNewPicture() { string imageExtension = Path.GetExtension(_newImagePath); FileModification.CopyFileFromOnPathToAnother(_newImagePath, $"{_oldImagePath}{imageExtension}"); }
public void CreateHostFileWithSampleContent() { FileModification.WriteFile(NewHostFileTwoLocation, "#Test" + Environment.NewLine + "127.0.0.1 facebook.com"); }
private string GetHostFileContent() { return(FileModification.ReadFile(FileModification.GetHostFileLocation())); }
public bool ConfigurationIsAlreadyCreated() { return(FileModification.FileExists(ConfigurationPath)); }
private void SaveConfiguration(CurrentProgramConfiguration config) { var jsonConfiguration = JsonConvert.SerializeObject(config); FileModification.WriteFile(ConfigurationPath, jsonConfiguration); }
public CurrentUserConfiguration OpenConfiguration(string password) { string encryptedConfigurationContent = FileModification.ReadFile(ConfigurationPath); return(DecryptConfiguration(encryptedConfigurationContent, password)); }