public string FormateVolumeFolder(Volume volume) { var name = string.IsNullOrWhiteSpace(volume.Name) ? AppConfig.VolumePrefix : volume.Name; name = DirectoryHelpers.MakeValidPath(name); return(volume.Number.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0') + " " + name); }
public string FormateChapterFolder(Chapter chapter) { var name = string.IsNullOrWhiteSpace(chapter.Name) ? AppConfig.ChapterPrefix : chapter.Name; name = DirectoryHelpers.MakeValidPath(name); return(chapter.Number.ToString(CultureInfo.InvariantCulture).PadLeft(chapter.Number % 1 == 0 ? 4 : 6, '0') + " " + name); }
/// <summary> /// Упаковка всех томов. /// </summary> /// <param name="message">Папка манги.</param> public static List <string> CompressVolumes(string message) { var files = new List <string>(); message = DirectoryHelpers.MakeValidPath(message) + Path.DirectorySeparatorChar; if (!Directory.Exists(message)) { return(files); } #warning Проверка не учитывает возможность переопределения папки в настройках типа манги. // Нельзя сжимать папку со всей мангой. if (message.Trim(Path.DirectorySeparatorChar) == AppConfig.DownloadFolder.Trim(Path.DirectorySeparatorChar)) { return(files); } Log.AddFormat("Compression: Start {0}.", message); var volumes = Directory.GetDirectories(message); foreach (var volume in volumes) { var acr = string.Concat(message, GetFolderName(volume), ArchiveFormat); files = AddToArchive(acr, volume); DeleteCompressedFiles(files, volume); } Log.AddFormat("Compression: End {0}.", message); return(files); }
/// <summary> /// Упаковка всех глав. /// </summary> /// <param name="message">Папка манги.</param> public static List <string> CompressChapters(string message) { var files = new List <string>(); message = DirectoryHelpers.MakeValidPath(message) + Path.DirectorySeparatorChar; if (!Directory.Exists(message)) { return(files); } // Нельзя сжимать папку со всей мангой. if (message.Trim(Path.DirectorySeparatorChar) == AppConfig.DownloadFolder.Trim(Path.DirectorySeparatorChar)) { return(files); } Log.AddFormat("Compression: Start {0}.", message); var volumes = Directory.GetDirectories(message); foreach (var volume in volumes) { var chapters = Directory.GetDirectories(volume); foreach (var chapter in chapters) { var acr = string.Concat(volume, Path.DirectorySeparatorChar, GetFolderName(chapter), ArchiveFormat); files = AddToArchive(acr, chapter); DeleteCompressedFiles(files, chapter); } } Log.AddFormat("Compression: End {0}.", message); return(files); }
private static void DeleteCompressedFiles(List <string> files, string folder) { foreach (var file in files) { File.Delete(file); } DirectoryHelpers.DeleteEmptyFolder(folder); }
private static IEnumerable <string> CopyDirectory(string sourceFolder, string destFolder) { try { var result = new List <string>(); if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } var files = Directory.GetFiles(sourceFolder); foreach (var file in files) { var name = Path.GetFileName(file); var dest = Path.Combine(destFolder, name); File.Copy(file, dest); result.Add(file); } var folders = Directory.GetDirectories(sourceFolder); foreach (var folder in folders) { if (DirectoryHelpers.Equals(folder, destFolder)) { continue; } var name = Path.GetFileName(folder); var dest = Path.Combine(destFolder, name); result.AddRange(CopyDirectory(folder, dest)); } return(result); } catch (System.Exception e) { throw new CopyDirectoryFailed("Не удалось скопировать файл или папку. См InnerException.", sourceFolder, destFolder, e); } }
public override async Task BeforeSave(ChangeTrackerArgs args) { if (!DirectoryHelpers.ValidateSettingPath(this.Folder)) { throw new DirectoryNotFoundException($"Не найдена папка {this.Folder}, папка должна существовать."); } if (!args.IsNewEntity) { using (var context = Repository.GetEntityContext()) { var folderState = args.GetPropertyState <string>(nameof(Folder)); if (folderState.IsChanged) { var mangaFolders = await context.Get <IManga>().Select(m => m.Folder).ToListAsync().ConfigureAwait(false); mangaFolders = mangaFolders.Select(DirectoryHelpers.GetAbsoluteFolderPath).ToList(); var settingAbsoluteFolderPath = DirectoryHelpers.GetAbsoluteFolderPath(this.Folder); if (mangaFolders.Any(f => DirectoryHelpers.Equals(f, settingAbsoluteFolderPath) || DirectoryHelpers.IsSubfolder(f, settingAbsoluteFolderPath))) { throw new MangaSettingSaveValidationException($"Папка {this.Folder} используется мангой.", this); } } var uriState = args.GetPropertyState <Uri>(nameof(MainUri)); if (folderState.IsChanged || uriState.IsChanged) { if (!args.CanAddEntities) { var debugMessage = $"Manga settings {MangaName}({Manga:D}) changed:"; if (folderState.IsChanged) { debugMessage += $" folder changed from '{folderState.OldValue}' to '{folderState.Value}'"; } if (uriState.IsChanged) { debugMessage += $" uri changed from '{uriState.OldValue}' to '{uriState.Value}'"; } Log.Add(debugMessage); } // Changed manga will be added to session. if (args.CanAddEntities) { if (uriState.IsChanged && Login != null && Equals(Login.MainUri, uriState.OldValue) && !Equals(Login.MainUri, uriState.Value)) { Login.MainUri = MainUri; } var mangas = await context.Get <IManga>().Where(m => m.Setting == this).ToListAsync().ConfigureAwait(false); foreach (var manga in mangas) { if (uriState.IsChanged) { manga.Uri = new Uri(manga.Uri.OriginalString.Replace(uriState.OldValue.GetLeftPart(UriPartial.Authority), uriState.Value.GetLeftPart(UriPartial.Authority))); } if (folderState.IsChanged) { manga.RefreshFolder(); } await context.AddToTransaction(manga).ConfigureAwait(false); } } } } } await base.BeforeSave(args).ConfigureAwait(false); }