/
vasiukoff
/
sg
Обзор
Документация
Войти
/
vasiukoff
/
sg
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/ViewModels/AddToIgnore.cs
56 строк
2 KB
leo
refactor: file-system watcher
01 сен 2025, 12:39
01 сен 2025, 12:39
cd80a55
Код
Авторство
О чём код?
using System.ComponentModel.DataAnnotations; using System.IO; using System.Threading.Tasks; namespace SourceGit.ViewModels { public class AddToIgnore : Popup { [Required(ErrorMessage = "Ignore pattern is required!")] public string Pattern { get => _pattern; set => SetProperty(ref _pattern, value, true); } [Required(ErrorMessage = "Storage file is required!!!")] public Models.GitIgnoreFile StorageFile { get; set; } public AddToIgnore(Repository repo, string pattern) { _repo = repo; _pattern = pattern; StorageFile = Models.GitIgnoreFile.Supported[0]; } public override async Task<bool> Sure() { using var lockWatcher = _repo.LockWatcher(); ProgressDescription = "Adding Ignored File(s) ..."; var file = StorageFile.GetFullPath(_repo.FullPath, _repo.GitDir); if (!File.Exists(file)) { await File.WriteAllLinesAsync(file!, [_pattern]); } else { var org = await File.ReadAllTextAsync(file); if (!org.EndsWith('\n')) await File.AppendAllLinesAsync(file, ["", _pattern]); else await File.AppendAllLinesAsync(file, [_pattern]); } _repo.MarkWorkingCopyDirtyManually(); return true; } private readonly Repository _repo; private string _pattern; } }