public void GetDirectories()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddDirectory(@"SOMEDIR\CHILD\GCHILD");
            builder.AddDirectory(@"A.DIR");
            CDReader fs = new CDReader(builder.Build(), false);


            Assert.Equal(2, fs.Root.GetDirectories().Length);

            DiscDirectoryInfo someDir = fs.Root.GetDirectories(@"SoMeDir")[0];

            Assert.Equal(1, fs.Root.GetDirectories("SOMEDIR").Length);
            Assert.Equal("SOMEDIR", someDir.Name);

            Assert.Equal(1, someDir.GetDirectories("*.*").Length);
            Assert.Equal("CHILD", someDir.GetDirectories("*.*")[0].Name);
            Assert.Equal(2, someDir.GetDirectories("*.*", SearchOption.AllDirectories).Length);

            Assert.Equal(4, fs.Root.GetDirectories("*.*", SearchOption.AllDirectories).Length);
            Assert.Equal(2, fs.Root.GetDirectories("*.*", SearchOption.TopDirectoryOnly).Length);

            Assert.Equal(1, fs.Root.GetDirectories("*.DIR", SearchOption.AllDirectories).Length);
            Assert.Equal(@"A.DIR\", fs.Root.GetDirectories("*.DIR", SearchOption.AllDirectories)[0].FullName);

            Assert.Equal(1, fs.Root.GetDirectories("GCHILD", SearchOption.AllDirectories).Length);
            Assert.Equal(@"SOMEDIR\CHILD\GCHILD\", fs.Root.GetDirectories("GCHILD", SearchOption.AllDirectories)[0].FullName);
        }
        private void RepackISO_Directory(CDBuilder cd, string rootFolder, string inputFolder)
        {
            var directories = Directory.GetDirectories(inputFolder);

            foreach (var directory in directories)
            {
                var cd_directory  = directory.Replace(rootFolder, string.Empty);
                var directoryInfo = cd.AddDirectory(cd_directory);

                RepackISO_Directory(cd, rootFolder, directory);
            }

            var files = Directory.GetFiles(inputFolder);

            foreach (var file in files)
            {
                byte[] buffer = null;
                using (var readStream = File.OpenRead(file))
                {
                    buffer = new byte[readStream.Length];
                    var max_chunk = 1024;

                    for (var b = 0; b < readStream.Length; b += max_chunk)
                    {
                        var amount = (int)Math.Min(max_chunk, readStream.Length - b);
                        readStream.Read(buffer, b, amount);
                    }
                }

                var cd_file  = file.Replace(rootFolder, string.Empty);
                var fileInfo = cd.AddFile(cd_file, buffer);
            }
        }
        public void CreateIso(string inputPath, string outputPath, string volumeIdentifier)
        {
            _log.Verbose($"Creating ISO from directory {inputPath}");
            var builder = new CDBuilder
            {
                UseJoliet        = true,
                VolumeIdentifier = volumeIdentifier ?? "CAKE_ISO"
            };

            foreach (var entry in Directory.GetFileSystemEntries(inputPath, "*", SearchOption.AllDirectories))
            {
                var fileInfo = new FileInfo(entry);
                if ((fileInfo.Attributes & FileAttributes.Directory) != 0)
                {
                    _log.Verbose($"Creating directory: {Path.GetFullPath(entry).Replace(inputPath, "")}");
                    builder.AddDirectory(Path.GetFullPath(entry).Replace(inputPath, ""));
                }
                else
                {
                    _log.Verbose($"Creating file: {Path.GetFullPath(entry).Replace(inputPath, "")}");
                    builder.AddFile(Path.GetFullPath(entry).Replace(inputPath, ""), entry);
                }
            }
            builder.Build(outputPath);
        }
        public void GetFileSystemInfos()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddDirectory(@"SOMEDIR\CHILD\GCHILD");
            builder.AddDirectory(@"AAA.EXT");
            builder.AddFile(@"FOO.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\CHILD.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\FOO.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\CHILD\GCHILD\BAR.TXT", new byte[10]);
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.Equal(3, fs.Root.GetFileSystemInfos().Length);

            Assert.Equal(1, fs.Root.GetFileSystemInfos("*.EXT").Length);
            Assert.Equal(2, fs.Root.GetFileSystemInfos("*.?XT").Length);
        }
        public void Parent()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddDirectory(@"SOMEDIR");
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.Equal(fs.Root, fs.Root.GetDirectories("SOMEDIR")[0].Parent);
        }
        public void GetFiles()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddDirectory(@"SOMEDIR\CHILD\GCHILD");
            builder.AddDirectory(@"AAA.DIR");
            builder.AddFile(@"FOO.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\CHILD.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\FOO.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\CHILD\GCHILD\BAR.TXT", new byte[10]);
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.Equal(1, fs.Root.GetFiles().Length);
            Assert.Equal("FOO.TXT", fs.Root.GetFiles()[0].FullName);

            Assert.Equal(2, fs.Root.GetDirectories("SOMEDIR")[0].GetFiles("*.TXT").Length);
            Assert.Equal(4, fs.Root.GetFiles("*.TXT", SearchOption.AllDirectories).Length);

            Assert.Equal(0, fs.Root.GetFiles("*.DIR", SearchOption.AllDirectories).Length);
        }
Esempio n. 7
0
 public static void Recursive_AddDirs(CDBuilder isoBuild, DirectoryInfo di, string sName, HashSet <FileStream> files, bool extendedName)
 {
     foreach (DirectoryInfo dir in di.GetDirectories())
     {
         isoBuild.AddDirectory(sName + dir.Name);
         Recursive_AddDirs(isoBuild, dir, sName + dir.Name + @"\", files, extendedName);
     }
     foreach (FileInfo file in di.GetFiles())
     {
         AddFile(isoBuild, file, sName, files, extendedName);
     }
 }
Esempio n. 8
0
 private void AddToBuilderRecursively(CDBuilder isoBuilder, VirtualFileSystemEntry entry, string rootPrefix)
 {
     if (entry.EntryType == VirtualFileSystemEntryType.File)
     {
         AddFile(isoBuilder, entry.FullName.Remove(0, rootPrefix.Length), (( VirtualFile )entry));
     }
     else
     {
         isoBuilder.AddDirectory(entry.FullName.Remove(0, rootPrefix.Length));
         foreach (var directoryEntry in ((VirtualDirectory)entry))
         {
             AddToBuilderRecursively(isoBuilder, directoryEntry, rootPrefix);
         }
     }
 }
Esempio n. 9
0
        private void PopulateFromFolder(CDBuilder builder, DirectoryInfo di, string basePath, string bootBin)
        {
            FileInfo bootBinFile = null;

            FileInfo[] folderFiles = di.GetFiles();
            //Add directory first, so we can set the creation time correctly.
            string localDirPath = di.FullName.Substring(basePath.Length);

            if (localDirPath.Length > 1)
            {
                //Add directory first, so it has the correct creation time.
                BuildDirectoryInfo dir = builder.AddDirectory(localDirPath);
                dir.CreationTime = di.CreationTimeUtc;
            }
            foreach (FileInfo file in folderFiles)
            {
                string filePath = file.FullName.Substring(basePath.Length);
                if (bootBin != null && file.Name.Equals(bootBin, StringComparison.OrdinalIgnoreCase))
                {
                    bootBinFile = file; //Ignore this for now, we want it last
                }
                else
                {
                    builder.AddFile(filePath, file.FullName);
                }
            }

            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                PopulateFromFolder(builder, dir, basePath, null);
            }

            if (bootBinFile != null && bootBin != null)
            {
                builder.AddFile(bootBin, bootBinFile.FullName);
                long sectorSize = RoundUp(bootBinFile.Length, DATA_SECTOR_SIZE);
                builder.LastFileStartSector = (uint)(GD_END_LBA - 150 - (sectorSize / DATA_SECTOR_SIZE));
            }
            else if (bootBin != null)
            {
                //User doesn't know what they're doing and gave us bad data.
                throw new FileNotFoundException("IP.BIN requires the boot file " + bootBin +
                                                " which was not found in the data directory.");
            }
        }
        public void Attributes()
        {
            // Start time rounded down to whole seconds
            DateTime start = DateTime.UtcNow;

            start = new DateTime(start.Year, start.Month, start.Day, start.Hour, start.Minute, start.Second);

            CDBuilder builder = new CDBuilder();

            builder.AddDirectory("Foo");
            CDReader fs  = new CDReader(builder.Build(), false);
            DateTime end = DateTime.UtcNow;

            DiscDirectoryInfo di = fs.GetDirectoryInfo("Foo");

            Assert.Equal(FileAttributes.Directory | FileAttributes.ReadOnly, di.Attributes);
            Assert.True(di.CreationTimeUtc >= start);
            Assert.True(di.CreationTimeUtc <= end);
            Assert.True(di.LastAccessTimeUtc >= start);
            Assert.True(di.LastAccessTimeUtc <= end);
            Assert.True(di.LastWriteTimeUtc >= start);
            Assert.True(di.LastWriteTimeUtc <= end);
        }
Esempio n. 11
0
        private void PopulateFromDirectory(CDBuilder builder, DirectoryInfo di, string basePath, string bootBin, uint endLba)
        {
            FileInfo bootBinFile = null;

            foreach (FileInfo file in di.GetFiles())
            {
                string filePath = file.FullName.Substring(basePath.Length);
                if (bootBin != null && file.Name.Equals(bootBin, StringComparison.OrdinalIgnoreCase))
                {
                    bootBinFile = file; // Ignore this for now, we want it last
                }
                else
                {
                    builder.AddFile(filePath, file.FullName);
                }
            }

            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                string filePath = dir.FullName.Substring(basePath.Length);
                builder.AddDirectory(filePath, dir.FullName); // this will save the original CreationDate of the dir in the ISO
                PopulateFromDirectory(builder, dir, basePath, null, endLba);
            }

            if (bootBinFile != null && bootBin != null)
            {
                builder.AddFile(bootBin, bootBinFile.FullName);
                long sectorSize = GDImageUtility.RoundUp(bootBinFile.Length, DATA_SECTOR_SIZE);
                builder.LastFileStartSector = (uint)(endLba - TRACK_GAP_SECTOR_COUNT - (sectorSize / DATA_SECTOR_SIZE));
            }
            else if (bootBin != null)
            {
                // User doesn't know what they're doing and gave us bad data.
                throw new FileNotFoundException("IP.BIN requires the boot file " + bootBin +
                                                " which was not found in the data directory.");
            }
        }
Esempio n. 12
0
        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 bool AddFilesToISO9660(string in_sDirectoryRead
                                       , string in_sDirectoryISO
                                       , CDBuilder in_oISOBuilder
                                       , bool in_bCreateISOSubDirectory)
        {
            try
            {
                string sDirectoryISO = in_sDirectoryISO.Trim();

                if (System.IO.Directory.Exists(in_sDirectoryRead))
                {
                    // Create new ISO Subdirectory
                    if (in_bCreateISOSubDirectory)
                    {
                        in_oISOBuilder.AddDirectory(sDirectoryISO);
                    }

                    System.IO.DirectoryInfo oDirInfo = new DirectoryInfo(in_sDirectoryRead);

                    // Copy the files and overwrite destination files if they already exist.
                    foreach (FileInfo oFileInfo in oDirInfo.GetFiles())
                    {
                        // Add File to ISO
                        try
                        {
                            if (Properties.Settings.Default.DebugOn)
                            {
                                BootmanLog.LogError(LogTextBox
                                                    , "ISO Create Add: >> " + sDirectoryISO + "\\" + oFileInfo.Name);
                            }

                            in_oISOBuilder.AddFile(sDirectoryISO + "\\" + oFileInfo.Name
                                                   , oFileInfo.FullName);
                        }
                        catch (Exception oEx)
                        {
                            BootmanLog.LogError(LogTextBox
                                                , "Error: " + oEx.Message);

                            throw new Exception("Rethrow - " + oEx.Message);
                        }
                    }

                    foreach (DirectoryInfo oSubDirInfo in oDirInfo.GetDirectories())
                    {
                        string sNewDirRead = oSubDirInfo.FullName;

                        string sNewDirISO = "";
                        if (sDirectoryISO.Length > 0)
                        {
                            sNewDirISO = sDirectoryISO + "\\" + oSubDirInfo.Name;
                        }
                        else
                        {
                            sNewDirISO = oSubDirInfo.Name;
                        }

                        // Recursive call
                        bool bRecusiveCallResult = AddFilesToISO9660(sNewDirRead
                                                                     , sNewDirISO
                                                                     , in_oISOBuilder
                                                                     , true);

                        if (!bRecusiveCallResult)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else
                {
                    Console.WriteLine("Source path does not exist!");
                    return(false);
                }
            }
            catch (Exception oEx)
            {
                BootmanLog.LogError(LogTextBox
                                    , "Error: " + oEx.Message);
                return(false);
            }
        }
        private void Build(string filename)
        {
            if (System.IO.File.Exists(filename))
            {
                System.IO.File.Delete(filename);
            }

            System.Windows.Forms.DialogResult criticalError = System.Windows.Forms.DialogResult.None;

            do
            {
                try
                {
                    this.DisplayName = "Iso Creator Tool: Writing iso...";

                    CDBuilder builder = new CDBuilder();
                    builder.UseJoliet = true;

                    if (!string.IsNullOrWhiteSpace(this.DiscName))
                    {
                        builder.VolumeIdentifier = this.DiscName;
                    }

                    string[] directories = System.IO.Directory.GetDirectories(this.Folder, "*", System.IO.SearchOption.AllDirectories);

                    foreach (string dir in directories)
                    {
                        builder.AddDirectory(dir.Substring(this.Folder.Length + 1));
                    }

                    string[] files = System.IO.Directory.GetFiles(this.Folder, "*", System.IO.SearchOption.AllDirectories);

                    int ix     = 1;
                    int fCount = files.Length;

                    foreach (string file in files)
                    {
                        System.Windows.Forms.DialogResult fileError = System.Windows.Forms.DialogResult.None;

                        this.DisplayName = string.Format("[{0}%] Iso Creator Tool: Writing iso...", Math.Round((100.0 / fCount) * ix, 0).ToString());

                        do
                        {
                            try
                            {
                                builder.AddFile(file.Substring(this.Folder.Length + 1), System.IO.File.OpenRead(file));
                            }
                            catch (Exception exFile)
                            {
                                fileError = System.Windows.Forms.MessageBox.Show(exFile.Message, "Error", System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore, System.Windows.Forms.MessageBoxIcon.Error);
                            }
                        } while (fileError == System.Windows.Forms.DialogResult.Retry);

                        if (fileError == System.Windows.Forms.DialogResult.Abort)
                        {
                            goto Abort;
                        }

                        ix++;
                    }

                    this.DisplayName = "Iso Creator Tool: Finishing iso...";

                    builder.Build(filename);

                    System.Diagnostics.Process.Start("explorer.exe", "/select, \"" + filename + "\"");
                }
                catch (Exception ex)
                {
                    criticalError = System.Windows.Forms.MessageBox.Show(ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.RetryCancel, System.Windows.Forms.MessageBoxIcon.Error);

                    if (System.IO.File.Exists(filename))
                    {
                        System.IO.File.Delete(filename);
                    }
                }
            } while (criticalError == System.Windows.Forms.DialogResult.Retry);

Abort:

            this.DisplayName = "Iso Creator Tool: Finish...";
            this.Working     = false;
        }