public static FilesStorage CreateByCatalogName(string catalogName, bool skipEx = true) { FilesStorage filesStorage = new FilesStorage(catalogName); foreach (var fileName in Directory.GetFiles(catalogName, "*", SearchOption.AllDirectories)) { try { var body = File.ReadAllBytes(fileName); filesStorage.FilesByName.Add(fileName, body); } catch { if (skipEx) { Console.WriteLine($"Ошибка чтения файла (файл пропущен): {fileName}"); } else { throw; } } } return(filesStorage); }
private static void HandleEncrypt() { var path = ReadPath(); var key = ReadKey(); var filesStorage = FilesStorage.CreateByCatalogName(path); var json = JsonSerializer.Serialize(filesStorage); var byteJson = Encoding.Default.GetBytes(json); var EncryptedByteJson = Securer.VisinerTransform(byteJson, key, WorkMode.ENCRYPT); File.WriteAllBytesAsync(STORAGE_PATH, EncryptedByteJson); filesStorage.DeleteCatalog(); }