コード例 #1
0
        static void Main(string[] args)
        {
            DriveInfo discDrive = null;

            foreach (DriveInfo drive in DriveInfo.GetDrives())
            {
                if (drive.DriveType == DriveType.CDRom)
                {
                    discDrive = drive;
                }
            }

            if (discDrive == null)
            {
                Console.WriteLine("No disc drive found!");
                return;
            }
            if (!discDrive.IsReady)
            {
                Console.WriteLine("No disc found? Is a disc inserted?");
                return;
            }

            CDBuilder builder = new CDBuilder();

            builder.UseJoliet        = true;
            builder.VolumeIdentifier = "test";
            builder.VolumeIdentifier = discDrive.VolumeLabel;
            AddFilesRecursively(ref builder, discDrive.RootDirectory.FullName);
            Console.WriteLine("Files added successfully!");

            string outDir = "";

#if RELEASE
            outDir = Path.Combine(Environment.CurrentDirectory, "out");
            if (!Directory.Exists())
            {
                Directory.CreateDirectory(outDir);
            }
            builder.Build(Path.Combine(outDir, $"{ builder.VolumeIdentifier }.iso"));
#else
            outDir = Path.Combine(Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName, "out");
            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }
            builder.Build(Path.Combine(outDir, $"{ builder.VolumeIdentifier }.iso"));
#endif
            Console.WriteLine("ISO file created!");
            Console.ReadKey();
        }
コード例 #2
0
        public void CanWrite()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.False(fs.CanWrite);
        }
コード例 #3
0
        private void BuildSingleDensityArea()
        {
            CDBuilder builder = NewCDBuilderInstance(SINGLE_DENSITY_AREA_LBA_START, SINGLE_DENSITY_AREA_LBA_END);

            byte[] ip0000Data = GDImageUtility.LoadBootstrapInMemory(SingleDensityArea.BootstrapFilePath);
            _singleDensityAreaBootstrapFileName = GDImageUtility.GetBootBinaryFileName(ip0000Data);

            // Handle track02
            List <string> cdda = new List <string>
            {
                _singleDensityAreaAudioTrackPath
            };

            _singleDensityAreaTracks.AddRange(ReadCDDA(cdda));

            // Handle track01
            DirectoryInfo di = new DirectoryInfo(SingleDensityArea.SourceDataDirectory);

            PopulateFromDirectory(builder, di, di.FullName, null, SINGLE_DENSITY_AREA_LBA_END);

            using (BuiltStream isoStream = (BuiltStream)builder.Build())
            {
                _lastProgress = 0;
                WriteDataTrack(true, isoStream, ip0000Data, _singleDensityAreaTracks);
            }
        }
コード例 #4
0
        public void BootImage()
        {
            byte[] memoryStream = new byte[33 * 512];
            for (int i = 0; i < memoryStream.Length; ++i)
            {
                memoryStream[i] = (byte)i;
            }

            CDBuilder builder = new CDBuilder();

            builder.SetBootImage(new MemoryStream(memoryStream), BootDeviceEmulation.HardDisk, 0x543);

            CDReader fs = new CDReader(builder.Build(), false);

            Assert.True(fs.HasBootImage);

            using (Stream bootImg = fs.OpenBootImage())
            {
                Assert.Equal(memoryStream.Length, bootImg.Length);
                for (int i = 0; i < bootImg.Length; ++i)
                {
                    if (memoryStream[i] != bootImg.ReadByte())
                    {
                        Assert.True(false, "Boot image corrupted");
                    }
                }
            }

            Assert.Equal(BootDeviceEmulation.HardDisk, fs.BootEmulation);
            Assert.Equal(0x543, fs.BootLoadSegment);
        }
コード例 #5
0
        public void Parent_Root()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.Null(fs.Root.Parent);
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: bastisk/Folder-To-Iso
        private int BuildIso(DirectoryInfo sourceDirectory, string targetFile)
        {
            CDBuilder builder = new CDBuilder();
            Dictionary <string, string> resultList = new Dictionary <string, string>();

            try
            {
                // Get main folder and put it into results.
                getFileList(sourceDirectory, sourceDirectory).ToList().ForEach(file => resultList.Add(file.Key, file.Value));

                // Now do it for all subfolders

                /*foreach (DirectoryInfo directory in sourceDirectory.GetDirectories())
                 * {
                 *  getFileList(directory, sourceDirectory).ToList().ForEach(file => resultList.Add(file.Key, file.Value));
                 * }*/

                // Finally, add all files collected to the ISO.
                foreach (KeyValuePair <string, string> pair in resultList.ToList())
                {
                    builder.AddFile(pair.Key, pair.Value);
                }

                builder.Build(targetFile);
            } catch (Exception e)
            {
                MessageBox.Show("Error Writing ISO. Check Permissions and Files. " + e.Message);
                return(1);
            }

            return(0);
        }
コード例 #7
0
ファイル: IsoCreator.cs プロジェクト: ymf1/Wexflow
        private bool CreateIso()
        {
            var success = true;

            try
            {
                var       files   = Directory.GetFiles(SrcDir, "*.*", SearchOption.AllDirectories);
                CDBuilder builder = new CDBuilder();
                builder.UseJoliet        = true;
                builder.VolumeIdentifier = VolumeIdentifier;

                foreach (var file in files)
                {
                    var fileIsoPath = file.Replace(SrcDir, string.Empty).TrimStart('\\');
                    builder.AddFile(fileIsoPath, file);
                }

                var isoPath = Path.Combine(Workflow.WorkflowTempFolder, IsoFileName);
                builder.Build(isoPath);

                Files.Add(new FileInf(isoPath, Id));
                InfoFormat("Iso {0} created with success.", isoPath);

                success = true;
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception e)
            {
                ErrorFormat("An error occured while creating {0}: {1}", IsoFileName, e.Message);
            }
            return(success);
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: froize/isoview
        public void AddtoISO(string directory, string isoFile, string sourceName)
        {
            try
            {
                DirectoryInfo rootDirToAdd = new DirectoryInfo(sourceName);
                DirectoryInfo currentDirToAdd = new DirectoryInfo(directory);
                int itemsAdded = 0;
                CDBuilder isoBuilder = new CDBuilder();
                foreach (FileInfo file in currentDirToAdd.GetFiles())
                {
                    string fileOnHdd = file.FullName;
                    string fileOnIso = fileOnHdd.Substring(fileOnHdd.IndexOf(rootDirToAdd.Name) + rootDirToAdd.Name.Length + 1);
                    MessageBox.Show(fileOnIso);
                    isoBuilder.AddFile(fileOnIso, fileOnHdd);
                    itemsAdded++;
                }
                foreach (DirectoryInfo subdir in currentDirToAdd.GetDirectories())
                {
                    itemsAdded++;
                    AddtoISO(subdir.FullName, isoFile, sourceName);
                }

                isoBuilder.Build(isoFile);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

        }
コード例 #9
0
        /**************************************************************************************************************
         * Extract ISO 9660
         *************************************************************************************************************/
        public bool CreateISO9660(string in_sISOPathAndFilename
                                  , string in_sISORootSourceRootDir)
        {
            try
            {
                CDBuilder oISOBuilder = new CDBuilder();
                oISOBuilder.UseJoliet        = true;
                oISOBuilder.VolumeIdentifier = "A_SAMPLE_DISK";
                string sISOPathAndFilename = in_sISOPathAndFilename;

                // Add Files to ISO
                bool bResultAddFiles = AddFilesToISO9660(in_sISORootSourceRootDir
                                                         , ""
                                                         , oISOBuilder
                                                         , false);

                if (bResultAddFiles)
                {
                    // Build the ISO
                    oISOBuilder.Build(sISOPathAndFilename);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception oEx)
            {
                BootmanLog.LogError(LogTextBox, "Error Extracting ISO: " + oEx.Message);
                return(false);
            }
        }
コード例 #10
0
        public override void Build(string inputPath, string outputPath)
        {
            // Use CDBuilder
            CDBuilder isoBuild = new CDBuilder();

            isoBuild.UseJoliet        = true;
            isoBuild.VolumeIdentifier = ISO_Label;

            DirectoryInfo        di    = new DirectoryInfo(inputPath);
            HashSet <FileStream> files = new HashSet <FileStream>();

            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                ISO_Common.Recursive_AddDirs(isoBuild, dir, dir.Name + @"\", files, true);
            }
            foreach (FileInfo file in di.GetFiles())
            {
                ISO_Common.AddFile(isoBuild, file, string.Empty, files, true);
            }

            using (FileStream output = new FileStream(outputPath, FileMode.Create, FileAccess.Write))
                using (Stream input = isoBuild.Build())
                {
                    ISO2PSX.Run(input, output);
                }

            //isoBuild.Build(outputPath);

            foreach (FileStream file in files)
            {
                file.Close();
            }
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        protected override void DoRun()
        {
            DirectoryInfo di = new DirectoryInfo(_srcDir.Value);

            if (!di.Exists)
            {
                Console.WriteLine("The source directory doesn't exist!");
                Environment.Exit(1);
            }

            CDBuilder builder = new CDBuilder();

            if (_volLabelSwitch.IsPresent)
            {
                builder.VolumeIdentifier = _volLabelSwitch.Value;
            }

            if (_bootImage.IsPresent)
            {
                builder.SetBootImage(new FileStream(_bootImage.Value, FileMode.Open, FileAccess.Read), BootDeviceEmulation.NoEmulation, 0);
            }

            PopulateFromFolder(builder, di, di.FullName);

            builder.Build(_isoFileParam.Value);
        }
コード例 #14
0
        public void Equals()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.Equal(fs.GetFileInfo("foo.txt"), fs.GetFileInfo("foo.txt"));
        }
コード例 #15
0
        public void Extension()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.Equal("dir", fs.GetDirectoryInfo("fred.dir").Extension);
            Assert.Equal("", fs.GetDirectoryInfo("fred").Extension);
        }
コード例 #16
0
        public void DirectoryInfo()
        {
            CDBuilder         builder = new CDBuilder();
            CDReader          fs      = new CDReader(builder.Build(), false);
            DiscDirectoryInfo fi      = fs.GetDirectoryInfo(@"SOMEDIR");

            Assert.NotNull(fi);
        }
コード例 #17
0
        public void FileSystemInfo()
        {
            CDBuilder          builder = new CDBuilder();
            CDReader           fs      = new CDReader(builder.Build(), false);
            DiscFileSystemInfo fi      = fs.GetFileSystemInfo(@"SOMEDIR\SOMEFILE");

            Assert.NotNull(fi);
        }
コード例 #18
0
        public void AddFileStream()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"ADIR\AFILE.TXT", new MemoryStream());
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.True(fs.Exists(@"ADIR\AFILE.TXT"));
        }
コード例 #19
0
        public void FullName()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.Equal(@"\", fs.Root.FullName);
            Assert.Equal(@"SOMEDIR\", fs.GetDirectoryInfo(@"SOMEDIR").FullName);
            Assert.Equal(@"SOMEDIR\CHILDDIR\", fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR").FullName);
        }
コード例 #20
0
        public void CreateISO()
        {
            CDBuilder builder = new CDBuilder();

            builder.UseJoliet        = true;
            builder.VolumeIdentifier = "A_SAMPLE_DISK";
            builder.AddFile(@"Folder\Hello.txt", Encoding.ASCII.GetBytes("Hello World!"));
            builder.Build(@"C:\sample.iso");
        }
コード例 #21
0
        public void AddFileBytes()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"ADIR\AFILE.TXT", new byte[] {});
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.True(fs.Exists(@"ADIR\AFILE.TXT"));
        }
コード例 #22
0
        public void Name()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.Equal("foo.txt", fs.GetFileInfo("foo.txt").Name);
            Assert.Equal("foo.txt", fs.GetFileInfo(@"path\foo.txt").Name);
            Assert.Equal("foo.txt", fs.GetFileInfo(@"\foo.txt").Name);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        public void Root()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.NotNull(fs.Root);
            Assert.True(fs.Root.Exists);
            Assert.Empty(fs.Root.Name);
            Assert.Null(fs.Root.Parent);
        }
コード例 #25
0
        public void CreationTimeUtc()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.True(DateTime.UtcNow >= fs.GetFileInfo("foo.txt").CreationTimeUtc);
            Assert.True(DateTime.UtcNow.Subtract(TimeSpan.FromSeconds(10)) <= fs.GetFileInfo("foo.txt").CreationTimeUtc);
        }
コード例 #26
0
        public void SimpleSearch()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"SOMEDIR\CHILDDIR\GCHILDIR\FILE.TXT", new byte[0]);
            CDReader fs = new CDReader(builder.Build(), false);

            DiscDirectoryInfo di = fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR");

            DiscFileInfo[] fis = di.GetFiles("*.*", SearchOption.AllDirectories);
        }
コード例 #27
0
        public void Exists()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"dir\foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.False(fs.GetFileInfo("unknown.txt").Exists);
            Assert.True(fs.GetFileInfo(@"dir\foo.txt").Exists);
            Assert.False(fs.GetFileInfo(@"dir").Exists);
        }
コード例 #28
0
        public void Attributes()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile("foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            DiscFileInfo fi = fs.GetFileInfo("foo.txt");

            // Check default attributes
            Assert.Equal(FileAttributes.ReadOnly, fi.Attributes);
        }
コード例 #29
0
        public void Parent()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"SOMEDIR\ADIR\FILE.TXT", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            DiscFileInfo fi = fs.GetFileInfo(@"SOMEDIR\ADIR\FILE.TXT");

            Assert.Equal(fs.GetDirectoryInfo(@"SOMEDIR\ADIR"), fi.Parent);
            Assert.Equal(fs.GetDirectoryInfo(@"SOMEDIR\ADIR"), fi.Directory);
        }
コード例 #30
0
        public async Task <IActionResult> Upload(Guid uuid)
        {
            var formFile = Request.Form.Files[0];
            var filename = SanitizeFilename(formFile.Name);
            var scope    = Request.Form["scope"][0];
            var size     = Convert.ToInt64(Request.Form["size"][0]);

            if (size > _isoUploadOptions.MaxFileSize)
            {
                throw new Exception($"File exceeds the {_isoUploadOptions.MaxFileSize} byte maximum size.");
            }

            var teamId = await _playerService.GetPrimaryTeamByExerciseIdAsync(uuid, new System.Threading.CancellationToken());

            if (scope == "exercise")
            {
                if (!(await _playerService.CanManageTeamAsync(teamId, new System.Threading.CancellationToken())))
                {
                    throw new InvalidOperationException("You do not have permission to upload public files for this Exercise");
                }
            }

            var destPath = Path.Combine(
                _isoUploadOptions.BasePath,
                uuid.ToString(),
                (scope == "exercise") ? uuid.ToString() : teamId.ToString()
                );

            var destFile = Path.Combine(destPath, filename);

            Directory.CreateDirectory(destPath);

            using (var sourceStream = formFile.OpenReadStream())
            {
                if (filename.ToLower().EndsWith(".iso"))
                {
                    using (var destStream = System.IO.File.Create(destFile))
                    {
                        await sourceStream.CopyToAsync(destStream);
                    }
                }
                else
                {
                    CDBuilder builder = new CDBuilder();
                    builder.UseJoliet        = true;
                    builder.VolumeIdentifier = "PlayerIso";
                    builder.AddFile(filename, sourceStream);
                    builder.Build(destFile + ".iso");
                }
            }

            return(Json("ISO was uploaded"));
        }