private static void PopulateFromFolder(DiscUtils.Iso9660.CDBuilder builder, DirectoryInfo di, string basePath) { foreach (FileInfo file in di.GetFiles()) { builder.AddFile(file.FullName.Substring(basePath.Length), file.FullName); } foreach (DirectoryInfo dir in di.GetDirectories()) { PopulateFromFolder(builder, dir, basePath); } }
/// <summary> /// Starts the thread creating the ISO file /// </summary> public void bgCreator_DoWork(object sender, DoWorkEventArgs e) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { DriveInfo driveInfo = new DriveInfo(System.IO.Path.GetPathRoot(SourceDriveName)); if (driveInfo.IsReady) { DiscUtils.Iso9660.CDBuilder builder = new DiscUtils.Iso9660.CDBuilder(); builder.UseJoliet = true; builder.VolumeIdentifier = driveInfo.VolumeLabel; DirectoryInfo di = new DirectoryInfo(SourceDriveName); PopulateFromFolder(builder, di, di.FullName); builder.Build(PathToIso); } } catch (Exception ex) { if (OnMessage != null) { EventIsoArgs eArgs = new EventIsoArgs("Error while creating the image: " + ex.Message); OnMessage(eArgs); } } finally { CloseAll(); if (OnFinish != null) { EventIsoArgs eArgs = new EventIsoArgs(stopWatch.Elapsed); OnFinish(eArgs); } } }