internal static void PackToIso(PackToIsoSettings stg) { IsoProgressDialog iso = new IsoProgressDialog(); iso.Run(stg); iso.ShowDialog(); return; /*var fls = Stuff.GetAllFiles(dir); * var drs = Stuff.GetAllDirs(dir); * //generate meta.xml * var mm = GenerateMetaXml(dir); * * using (FileStream fs = new FileStream(path, FileMode.Create)) * { * AppendFileToIso(fs, ".indx\\meta.xml", Encoding.UTF8.GetBytes(mm)); * foreach (var item in fls) * { * if (item.Length > 1024 * 1024 * 10) continue;//10 Mb * * var bb = dir.Filesystem.ReadAllBytes(item.FullName); * var rep = item.FullName.Replace(dir.FullName, "").Trim(new char[] { '\\' }); * AppendFileToIso(fs, rep, bb); * } * }*/ }
internal void Run(PackToIsoSettings stg) { packStg = stg; label1.Text = "Iso image path: " + stg.Path; Text = "iso writing.."; stg.ProgressReport = (now, total) => { float f = now / (float)total; this.Invoke((Action)(() => { progressBar1.Value = (int)Math.Round(f * 100); })); }; stg.AfterPackFinished = () => { Stuff.Info("Pack to iso complete!"); Close(); }; th = new Thread(() => { this.Invoke((Action)(() => { label1.Text = "collecting files.."; })); CDBuilder builder = new CDBuilder(); builder.ProgresReport = stg.ProgressReport; List <IFileInfo> files = new List <IFileInfo>(); foreach (var item in stg.Dirs) { Stuff.GetAllFiles(item, files); } files.AddRange(stg.Files); if (stg.IncludeMeta) { var mm = GenerateMetaXml(files.ToArray(), stg.Root); builder.AddDirectory(".indx"); builder.AddFile(".indx\\meta.xml", Encoding.UTF8.GetBytes(mm)); } builder.VolumeIdentifier = stg.VolumeId; if (stg.BeforePackStart != null) { stg.BeforePackStart(); } foreach (var item in stg.Dirs) { PopulateFromFolder(builder, item, item.FullName); } foreach (var item in stg.Files) { if (item is VirtualFileInfo) { var vfi = item as VirtualFileInfo; builder.AddFile(item.FullName, vfi.FileInfo.FullName); } else { builder.AddFile(item.FullName, item.FullName); } } this.Invoke((Action)(() => { label1.Text = "Building image: " + stg.Path; })); try { builder.Build(stg.Path); if (stg.AfterPackFinished != null) { stg.AfterPackFinished(); } } catch (ThreadAbortException ex) { if (File.Exists(packStg.Path)) { File.Delete(packStg.Path); } } }); th.IsBackground = true; }
private void ToIsoToolStripMenuItem_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count == 0) { return; } List <TagInfo> tags = new List <TagInfo>(); for (int i = 0; i < listView1.SelectedItems.Count; i++) { if (!(listView1.SelectedItems[i].Tag is TagInfo)) { continue; } tags.Add(listView1.SelectedItems[i].Tag as TagInfo); } if (tags.Count == 0) { return; } var vfs = new VirtualFilesystem(); var vdir = new VirtualDirectoryInfo(vfs); //vdir.FullName = "z:\\" + tag.Name; vdir.FullName = "z:\\"; SaveFileDialog sfd = new SaveFileDialog(); sfd.DefaultExt = "iso"; sfd.Filter = "iso images|*.iso"; List <IFileInfo> flss = new List <IFileInfo>(); foreach (var tag in tags) { flss.AddRange(tag.Files); } var gg = flss.GroupBy(z => z.FullName.ToLower()).ToArray(); flss.Clear(); foreach (var item in gg) { flss.Add(item.First()); } var ord = flss.GroupBy(z => z.FullName.ToLower()).ToArray(); var ord2 = flss.GroupBy(z => z.Name.ToLower()).ToArray(); if (ord2.Any(z => z.Count() > 1)) { var fer = ord2.Where(z => z.Count() > 1).Sum(z => z.Count()); Stuff.Warning(fer + " files has same names. Pack impossible"); if (Stuff.Question("Open pack editor?") == DialogResult.Yes) { PackEditor p = new PackEditor(); p.Init(flss); p.MdiParent = mdi.MainForm; p.Show(); } return; } flss = ord.Select(z => z.First()).ToList(); flss = flss.Where(z => z.Length > 0).ToList(); vdir.ChildsFiles.AddRange(flss.Select(z => new VirtualFileInfo(z, vdir) { Directory = vdir })); vfs.Files = vdir.ChildsFiles.OfType <VirtualFileInfo>().ToList(); if (sfd.ShowDialog() == DialogResult.OK) { PackToIsoSettings stg = new PackToIsoSettings(); stg.Dirs.Add(vdir); stg.Path = sfd.FileName; stg.IncludeMeta = true; stg.Root = vdir; stg.AfterPackFinished = () => { Stuff.Info("Pack complete!"); }; if (tags.Count == 1) { stg.VolumeId = tags.First().Name.Replace(' ', '_'); } else { stg.VolumeId = $"Volume[{tags.Count} tags]"; } if (stg.VolumeId.Length > 32) { stg.VolumeId = stg.VolumeId.Substring(0, 32); } Stuff.PackToIso(stg); } }