Added ISO
This commit is contained in:
		
							
								
								
									
										40
									
								
								Helpers/HelperISO.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								Helpers/HelperISO.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,40 @@ | ||||
| using DiscUtils.Iso9660; | ||||
| using File_Watcher.Models; | ||||
|  | ||||
| namespace File_Watcher.Helpers; | ||||
|  | ||||
| internal static partial class HelperISO | ||||
| { | ||||
|  | ||||
|     private static void DirectoryToISO(ILogger<Worker> logger, string destinationDirectory, bool mapOnly, string directory) | ||||
|     { | ||||
|         byte[] bytes = []; | ||||
|         string relativePath; | ||||
|         string directoryName = Path.GetFileName(directory); | ||||
|         CDBuilder builder = new() { UseJoliet = true, VolumeIdentifier = directoryName.Length < 25 ? directoryName : directoryName[..25] }; | ||||
|         IEnumerable<string> files = Directory.EnumerateFiles(directory, "*", new EnumerationOptions { IgnoreInaccessible = true, RecurseSubdirectories = true }); | ||||
|         foreach (string file in files) | ||||
|         { | ||||
|             relativePath = Path.GetRelativePath(directory, file).Replace(';', '_'); | ||||
|             if (!mapOnly) | ||||
|                 _ = builder.AddFile(relativePath, file); | ||||
|             else | ||||
|                 _ = builder.AddFile(relativePath, bytes); | ||||
|         } | ||||
|         logger.LogInformation(destinationDirectory); | ||||
|         builder.Build(Path.Combine(destinationDirectory, $"{directoryName}.iso")); | ||||
|         logger.LogInformation(directoryName); | ||||
|     } | ||||
|  | ||||
|     internal static bool DirectoryToISO(AppSettings appSettings, ILogger<Worker> logger) | ||||
|     { | ||||
|         IsoConfiguration isoConfiguration = appSettings.IsoConfiguration; | ||||
|         logger.LogInformation(isoConfiguration.SourceDirectory); | ||||
|         bool mapOnly = isoConfiguration.SourceDirectory.Length == 2; | ||||
|         if (!Directory.Exists(isoConfiguration.DestinationDirectory)) | ||||
|             _ = Directory.CreateDirectory(isoConfiguration.DestinationDirectory); | ||||
|         DirectoryToISO(logger, isoConfiguration.DestinationDirectory, mapOnly, isoConfiguration.SourceDirectory); | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user