private bool SaveFile() { try { FileInfoExtensions .MakeFileTemporaryWritable( _fullPathResolver.Resolve(".gitattributes"), x => { GitAttributesFile = _NO_TRANSLATE_GitAttributesText.GetText(); if (!GitAttributesFile.EndsWith(Environment.NewLine)) { GitAttributesFile += Environment.NewLine; } File.WriteAllBytes(x, GitModule.SystemEncoding.GetBytes(GitAttributesFile)); }); return(true); } catch (Exception ex) { MessageBox.Show(this, _cannotAccessGitattributes.Text + Environment.NewLine + ex.Message, _cannotAccessGitattributesCaption.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }
private bool SaveFile() { try { FileInfoExtensions .MakeFileTemporaryWritable( Module.WorkingDir + ".gitattributes", x => { this.GitAttributesFile = _NO_TRANSLATE_GitAttributesText.GetText(); if (!this.GitAttributesFile.EndsWith(Environment.NewLine)) { this.GitAttributesFile += Environment.NewLine; } File.WriteAllBytes(x, GitModule.SystemEncoding.GetBytes(this.GitAttributesFile)); }); return(true); } catch (Exception ex) { MessageBox.Show(this, _cannotAccessGitattributes.Text + Environment.NewLine + ex.Message, _cannotAccessGitattributesCaption.Text); return(false); } }
private bool SaveGitIgnore() { if (!HasUnsavedChanges()) { return(false); } try { FileInfoExtensions .MakeFileTemporaryWritable( ExcludeFile, x => { var fileContent = _NO_TRANSLATE_GitIgnoreEdit.GetText(); if (!fileContent.EndsWith(Environment.NewLine)) { fileContent += Environment.NewLine; } File.WriteAllBytes(x, GitModule.SystemEncoding.GetBytes(fileContent)); _originalGitIgnoreFileContent = fileContent; }); return(true); } catch (Exception ex) { MessageBox.Show(this, _dialogModel.CannotAccessFile + Environment.NewLine + ex.Message, _dialogModel.CannotAccessFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }
private void AddToIngoreClick(object sender, EventArgs e) { try { FileInfoExtensions .MakeFileTemporaryWritable(Settings.WorkingDir + ".gitignore", x => { var gitIgnoreFile = new StringBuilder(); gitIgnoreFile.Append(Environment.NewLine); gitIgnoreFile.Append(FilePattern.Text); using (TextWriter tw = new StreamWriter(x, true, Settings.Encoding)) { tw.Write(gitIgnoreFile); } }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } Close(); }
private bool SaveFile() { try { FileInfoExtensions .MakeFileTemporaryWritable( _fullPathResolver.Resolve(".mailmap"), x => { this.MailMapFile = _NO_TRANSLATE_MailMapText.GetText(); if (!this.MailMapFile.EndsWith(Environment.NewLine)) { this.MailMapFile += Environment.NewLine; } File.WriteAllBytes(x, GitModule.SystemEncoding.GetBytes(this.MailMapFile)); }); UICommands.RepoChangedNotifier.Notify(); return(true); } catch (Exception ex) { MessageBox.Show(this, _cannotAccessMailmap.Text + Environment.NewLine + ex.Message, _cannotAccessMailmapCaption.Text); return(false); } }
private void AddToIngoreClick(object sender, EventArgs e) { try { FileInfoExtensions .MakeFileTemporaryWritable(Settings.WorkingDir + ".gitignore", x => { var gitIgnoreFileAddition = new StringBuilder(); gitIgnoreFileAddition.Append(FilePattern.Text); gitIgnoreFileAddition.Append(Environment.NewLine); if (File.Exists(Settings.WorkingDir + ".gitignore")) { if (!File.ReadAllText(Settings.WorkingDir + ".gitignore", Settings.SystemEncoding).EndsWith(Environment.NewLine)) { gitIgnoreFileAddition.Insert(0, Environment.NewLine); } } using (TextWriter tw = new StreamWriter(x, true, Settings.SystemEncoding)) { tw.Write(gitIgnoreFileAddition); } }); } catch (Exception ex) { MessageBox.Show(this, ex.ToString()); } Close(); }
private bool SaveGitIgnore() { if (!HasUnsavedChanges()) { return(false); } try { FileInfoExtensions .MakeFileTemporaryWritable( Module.WorkingDir + ".gitignore", x => { var fileContent = _NO_TRANSLATE_GitIgnoreEdit.GetText(); if (!fileContent.EndsWith(Environment.NewLine)) { fileContent += Environment.NewLine; } File.WriteAllBytes(x, GitModule.SystemEncoding.GetBytes(fileContent)); _originalGitIgnoreFileContent = fileContent; }); return(true); } catch (Exception ex) { MessageBox.Show(this, _cannotAccessGitignore.Text + Environment.NewLine + ex.Message, _cannotAccessGitignoreCaption.Text); return(false); } }
private bool SaveFile() { try { FileInfoExtensions .MakeFileTemporaryWritable( GitModule.CurrentWorkingDir + ".mailmap", x => { this.MailMapFile = _NO_TRANSLATE_MailMapText.GetText(); if (!this.MailMapFile.EndsWith(Environment.NewLine)) { this.MailMapFile += Environment.NewLine; } File.WriteAllBytes(x, Settings.SystemEncoding.GetBytes(this.MailMapFile)); }); return(true); } catch (Exception ex) { MessageBox.Show(this, _cannotAccessMailmap.Text + Environment.NewLine + ex.Message, _cannotAccessMailmapCaption.Text); return(false); } }
public void Save(string fileName) { try { FileInfoExtensions.MakeFileTemporaryWritable(fileName, x => File.WriteAllText(fileName, GetAsString(), GetEncoding())); } catch (Exception ex) { ExceptionUtils.ShowException(ex, false); } }
private void SaveClick(object sender, EventArgs e) { FileInfoExtensions .MakeFileTemporaryWritable( Settings.WorkingDir + ".mailmap", x => { // Enter a newline to work around a wierd bug // that causes the first line to include 3 extra bytes. (encoding marker??) MailMapFile = Environment.NewLine + _NO_TRANSLATE_MailMapText.GetText().Trim(); using (TextWriter tw = new StreamWriter(x, false, Settings.Encoding)) tw.Write(MailMapFile); Close(); }); }
private void SaveGitIgnore(bool closeAfterSave) { try { FileInfoExtensions .MakeFileTemporaryWritable( Settings.WorkingDir + ".gitignore", x => { this.GitIgnoreFile = _NO_TRANSLATE_GitIgnoreEdit.GetText(); File.WriteAllBytes(x, Settings.Encoding.GetBytes(this.GitIgnoreFile)); }); } catch (Exception ex) { MessageBox.Show(this, _cannotAccessGitignore.Text + Environment.NewLine + ex.Message, _cannotAccessGitignoreCaption.Text); } Close(); }
private void SaveClick(object sender, EventArgs e) { try { FileInfoExtensions .MakeFileTemporaryWritable( Settings.WorkingDir + ".mailmap", x => { this.MailMapFile = _NO_TRANSLATE_MailMapText.GetText(); File.WriteAllBytes(x, Settings.Encoding.GetBytes(this.MailMapFile)); }); } catch (Exception ex) { MessageBox.Show(this, _cannotAccessMailmap.Text + Environment.NewLine + ex.Message, _cannotAccessMailmapCaption.Text); } Close(); }
private void AddToIngoreClick(object sender, EventArgs e) { var patterns = GetCurrentPatterns().ToArray(); if (patterns.Length == 0) { Close(); return; } try { var fileName = Module.WorkingDir + ".gitignore"; FileInfoExtensions.MakeFileTemporaryWritable(fileName, x => { var gitIgnoreFileAddition = new StringBuilder(); if (File.Exists(fileName) && !File.ReadAllText(fileName, GitModule.SystemEncoding).EndsWith(Environment.NewLine)) { gitIgnoreFileAddition.Append(Environment.NewLine); } foreach (var pattern in patterns) { gitIgnoreFileAddition.Append(pattern); gitIgnoreFileAddition.Append(Environment.NewLine); } using (TextWriter tw = new StreamWriter(x, true, GitModule.SystemEncoding)) { tw.Write(gitIgnoreFileAddition); } }); } catch (Exception ex) { MessageBox.Show(this, ex.ToString()); } Close(); }
public void Save(string fileName) { var configFileContent = new StringBuilder(); foreach (var section in ConfigSections) { //Skip empty sections if (section.Keys.Count == 0) { continue; } configFileContent.Append(section.ToString()); configFileContent.Append(Environment.NewLine); foreach (var key in section.Keys) { foreach (var value in key.Value) { configFileContent.AppendLine(string.Concat("\t", key.Key, " = ", EscapeValue(value))); } } } try { FileInfoExtensions .MakeFileTemporaryWritable(fileName, x => File.WriteAllText(fileName, configFileContent.ToString(), GetEncoding())); } catch (Exception ex) { ExceptionUtils.ShowException(ex, false); } }
private void SaveClick(object sender, EventArgs e) { try { FileInfoExtensions .MakeFileTemporaryWritable( Settings.WorkingDir + ".gitignore", x => { // Enter a newline to work around a wierd bug // that causes the first line to include 3 extra bytes. (encoding marker??) GitIgnoreFile = Environment.NewLine + _NO_TRANSLATE_GitIgnoreEdit.GetText().Trim(); using (var tw = new StreamWriter(x, false, Settings.Encoding)) { tw.Write(GitIgnoreFile); } Close(); }); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void Save() { var configFileContent = new StringBuilder(); foreach (var section in _sections) { //Skip empty sections if (section.Keys.Count == 0) { continue; } configFileContent.AppendLine(section.ToString()); foreach (var key in section.Keys) { foreach (var value in key.Value) { configFileContent.AppendLine(string.Concat("\t", key.Key, " = ", EscapeString(value))); } } } try { FileInfoExtensions .MakeFileTemporaryWritable(_fileName, x => File.WriteAllText(_fileName, configFileContent.ToString(), Settings.Encoding)); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture) { Int64 fileSize = System.Convert.ToInt64(value); return(FileInfoExtensions.GetHumanReadableSizeString(fileSize, 0)); }
public void WhenIsNull_ThenThrowException() { Assert.Throws <ArgumentNullException>(() => FileInfoExtensions.RenameExtension(null, ".txt")); }
public void WhenIsNull_ThenThrowException() { Assert.Throws <ArgumentNullException>(() => FileInfoExtensions.GetNextAvailableFileName(null)); }
public void WhenSourceIsNull_ThenThrowException() { Assert.Throws <ArgumentNullException>(() => FileInfoExtensions.DeleteLines(null, new List <int>(), @"C:\Test.txt")); }
public void WhenSourceIsNull_ThenThrowException() { Assert.Throws <ArgumentNullException>(() => FileInfoExtensions.ReplaceLines(null, new Dictionary <int, string>(), @"C:\Test.txt")); }
public void WhenIsNull_ThenThrowException() { Assert.Throws <ArgumentNullException>(() => FileInfoExtensions.GetExtension(null)); }
public void IsTestFileReturnsFalseIfFileInfoIsNull() { var candidate = FileInfoExtensions.IsTestFile(null, this.mockConfigManager.Object); Assert.IsFalse(candidate); }