예제 #1
0
        private void PopulateFromFolder(CDBuilder builder, DirectoryInfo di, string basePath, string bootBin)
        {
            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())
            {
                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.");
            }
        }
예제 #2
0
 private static void AddFile(CDBuilder isoBuilder, string name, VirtualFile file)
 {
     if (file.StoredInMemory)
     {
         isoBuilder.AddFile(name, file.Open());
     }
     else
     {
         isoBuilder.AddFile(name, file.HostPath);
     }
 }
예제 #3
0
        public static void AddFile(CDBuilder isoBuild, FileInfo file, string sName, HashSet <FileStream> files, bool extendedName)
        {
            var fstream = file.Open(FileMode.Open);

            if (extendedName)
            {
                isoBuild.AddFile(sName + file.Name + ";1", fstream);
            }
            else
            {
                isoBuild.AddFile(sName + file.Name, fstream);
            }
            files.Add(fstream);
        }
예제 #4
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);
        }
        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 static void AddFile(this CDBuilder isoBuilder, string name, VirtualFile file)
        {
            if (!name.EndsWith(";1"))
            {
                name += ";1";
            }

            if (file.StoredInMemory)
            {
                isoBuilder.AddFile(name, file.Open());
            }
            else
            {
                isoBuilder.AddFile(name, file.HostPath);
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
        public async void RunExecute()
        {
            try
            {
                if (!ValidatePaths())
                {
                    return;
                }
                IFilesLoader filesLoader = new FilesLoader();
                CDBuilder    cdBuilder   = new CDBuilder();
                foreach (var(nameInIso, fullName) in filesLoader.GetFiles(SourcePath))
                {
                    cdBuilder.AddFile(nameInIso, fullName);
                }

                IsNotRunning = false;
                await cdBuilder.BuildAsync(DestinationPath,
                                           (current, max) => ProgressValue = current / (double)max * 100);

                ProgressValue = 100;
                IsNotRunning  = true;
                MessageBox.Show("Operation complete");
            }
            catch (Exception exception)
            {
                MessageBox.Show(
                    $"Problem has occurred during processing. Details below:{Environment.NewLine}{exception.Message}");
                IsNotRunning  = true;
                ProgressValue = 0;
            }
        }
예제 #9
0
        public void Length()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"FILE.TXT", new byte[0]);
            builder.AddFile(@"FILE2.TXT", new byte[1]);
            builder.AddFile(@"FILE3.TXT", new byte[10032]);
            builder.AddFile(@"FILE3.TXT;2", new byte[132]);
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.Equal(0, fs.GetFileInfo("FILE.txt").Length);
            Assert.Equal(1, fs.GetFileInfo("FILE2.txt").Length);
            Assert.Equal(10032, fs.GetFileInfo("FILE3.txt;1").Length);
            Assert.Equal(132, fs.GetFileInfo("FILE3.txt;2").Length);
            Assert.Equal(132, fs.GetFileInfo("FILE3.txt").Length);
        }
예제 #10
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);
            }

        }
        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 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);
        }
예제 #13
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");
        }
예제 #14
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"));
        }
예제 #15
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"));
        }
예제 #16
0
        private void BuildIso(ProblemContext context)
        {
            if (context.Flag.Iso.NotEmpty() || context.Flag.Files.IsEmpty())
            {
                return;
            }

            string path = Path.Combine(context.IsoFolder, context.Problem.Id + ".iso");

            try
            {
                var builder = new CDBuilder
                {
                    UseJoliet        = true,
                    VolumeIdentifier = "VOL" + new Random().Next().ToString("X")
                };

                foreach (string file in context.Flag.Files)
                {
                    builder.AddFile(Path.GetFileName(file), file);
                }

                if (context.Spec.Document.NotEmpty())
                {
                    string docpath = Path.Combine(context.ChallengeFolder, context.Spec.Document);
                    if (!File.Exists(docpath))
                    {
                        docpath = Path.Combine(context.IsoFolder, context.Spec.Document);
                    }
                    if (File.Exists(docpath))
                    {
                        builder.AddFile(Path.GetFileName(docpath), docpath);
                    }
                }

                builder.Build(path);

                context.Flag.Iso = Path.GetFileName(path);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, $"Error building iso file for {context.Spec.Title}.");
            }
        }
예제 #17
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);
        }
        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);
        }
예제 #19
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);
        }
예제 #20
0
        public static void PopulateFromFolder(CDBuilder builder, IDirectoryInfo di, string basePath)
        {
            foreach (IFileInfo file in di.GetFiles())
            {
                if (file is VirtualFileInfo)
                {
                    var vfi = file as VirtualFileInfo;
                    builder.AddFile(file.FullName.Substring(basePath.Length), vfi.FileInfo.FullName);
                }
                else
                {
                    builder.AddFile(file.FullName.Substring(basePath.Length), file.FullName);
                }
            }

            foreach (IDirectoryInfo dir in di.GetDirectories())
            {
                PopulateFromFolder(builder, dir, basePath);
            }
        }
        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);
        }
예제 #22
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);
        }
예제 #23
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"));
        }
예제 #24
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);
        }
예제 #25
0
        private static void PopulateFromFolder(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);
            }
        }
예제 #26
0
        public static void MakeRescue(string Directory, string Destination, ProgressBarX progress)
        {
            int       i       = 0;
            CDBuilder builder = new CDBuilder();

            builder.VolumeIdentifier = "SYS_RESCUE_DISK";
            builder.UseJoliet        = true;
            List <string> files = FileHelper.GetFilesRecursive(Directory);

            GUI.UpdateProgress(progress, 0, files.Count);

            using (StreamWriter str = new StreamWriter(Directory + @"\SYSRESCUEINFO.KPAVRSCI", true))
            {
                str.WriteLine("BEGIN SYS_RESC_DISK|" + DateTime.Now.ToString() + "|KAVPROT_ISO_RESCUE|" + Environment.MachineName + "|" + Environment.OSVersion.ToString() + "|" + Environment.UserName);
                foreach (string file in files)
                {
                    i++;
                    try
                    {
                        GUI.UpdateProgress(progress, i, files.Count);
                        builder.AddFile(Path.GetFileName(file), file);
                        str.WriteLine(file);
                        builder.Build(Destination);
                    }
                    catch (Exception ex)
                    {
                        AntiCrash.LogException(ex, 2);
                    }
                    finally
                    {
                    }
                }
                str.WriteLine("END SYS_RESC_DISK " + files.Count);
            }
            builder.AddFile("SYSRESCUEINFO.KPAVRSCI", Directory + @"\SYSRESCUEINFO.KPAVRSCI");

            builder.Build(Destination);
        }
        public void Exists()
        {
            CDBuilder builder = new CDBuilder();

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

            Assert.True(fs.GetDirectoryInfo(@"\").Exists);
            Assert.True(fs.GetDirectoryInfo(@"SOMEDIR").Exists);
            Assert.True(fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR").Exists);
            Assert.True(fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR\").Exists);
            Assert.False(fs.GetDirectoryInfo(@"NONDIR").Exists);
            Assert.False(fs.GetDirectoryInfo(@"SOMEDIR\NONDIR").Exists);
        }
예제 #28
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.");
            }
        }
예제 #29
0
        public void LargeDirectory()
        {
            CDBuilder builder = new CDBuilder();

            builder.UseJoliet = true;

            for (int i = 0; i < 3000; ++i)
            {
                builder.AddFile("FILE" + i + ".TXT", new byte[] { });
            }

            CDReader reader = new CDReader(builder.Build(), true);

            Assert.Equal(3000, reader.Root.GetFiles().Length);
        }
예제 #30
0
        static public void Create(string dir, string isoPath)
        {
            CDBuilder builder = new CDBuilder();

            builder.UseJoliet        = true;
            builder.VolumeIdentifier = "H1_GOG_FILE";
            var files = Directory.EnumerateFiles(dir, "*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                string inIsoPath = file.Substring(dir.Length);
                builder.AddFile(inIsoPath, file);
            }
            builder.Build(isoPath);
        }