Beispiel #1
0
        public static VirtualFileSystemEntry ToVirtualFileSystemEntry(this CDReader isoFileSystem, string path)
        {
            if (isoFileSystem.FileExists(path))
            {
                var fileName = Path.GetFileName(path);
                if (fileName.EndsWith(";1"))
                {
                    fileName = fileName.Substring(0, fileName.Length - 2);
                }

                return(new VirtualFile(null, isoFileSystem.OpenFile(path, FileMode.Open), fileName));
            }
            else
            {
                var directory = new VirtualDirectory(null, Path.GetFileName(path));

                foreach (var file in isoFileSystem.GetFiles(path))
                {
                    var entry = ToVirtualFileSystemEntry(isoFileSystem, file);
                    entry.MoveTo(directory);
                }

                foreach (var subDirectory in isoFileSystem.GetDirectories(path))
                {
                    var entry = ToVirtualFileSystemEntry(isoFileSystem, subDirectory);
                    entry.MoveTo(directory);
                }

                return(directory);
            }
        }
Beispiel #2
0
        private IEnumerable <string> ListFiles(string dirPath)
        {
            var fileList = new List <string>();

            foreach (var subDir in _cd.GetDirectories(dirPath))
            {
                fileList.AddRange(_cd.GetFiles(subDir));
                fileList.AddRange(ListFiles(subDir));
            }

            return(fileList);
        }
 private void Recursive_CreateDirs(CDReader cd, string dir, Stream fileStreamFrom, Stream fileStreamTo)
 {
     foreach (string directory in cd.GetDirectories(dir))
     {
         Directory.CreateDirectory(TempPath + @"\" + directory);
         if (cd.GetDirectoryInfo(directory).GetFiles().Length > 0)
         {
             foreach (string file in cd.GetFiles(directory))
             {
                 fileStreamFrom = cd.OpenFile(file, FileMode.Open);
                 fileStreamTo   = File.Open(TempPath + @"\" + file, FileMode.OpenOrCreate);
                 fileStreamFrom.CopyTo(fileStreamTo);
                 fileStreamFrom.Close();
                 fileStreamTo.Close();
             }
         }
         if (cd.GetDirectories(directory).Length > 0)
         {
             Recursive_CreateDirs(cd, directory, fileStreamFrom, fileStreamTo);
         }
     }
 }
Beispiel #4
0
        private void CloneCdDirectory(string dir, CDReader cdr, CDBuilder cdb)
        {
            foreach (string fileName in cdr.GetFiles(dir))
            {
                if (fileName == "\\reactos\\unattend.inf")
                    continue;

                var stream = cdr.OpenFile(fileName, FileMode.Open);
                cdb.AddFile(fileName.Remove(0, 1), stream);
                stream.Close();
            }
            foreach (string dirName in cdr.GetDirectories(dir))
            {
                CloneCdDirectory(dirName, cdr, cdb);
            }
        }
Beispiel #5
0
        static public void ExtractIso(string isoPath, string targetDir)
        {
            using (FileStream isoStream = File.Open(isoPath, FileMode.Open, System.IO.FileAccess.Read))
            {
                CDReader       cd   = new CDReader(isoStream, true);
                Stack <string> dirs = new Stack <string>(20);
                string         root = @"\";
                dirs.Push(root);
                while (dirs.Count > 0)
                {
                    string currentDir = dirs.Pop();
                    Debug.WriteLine($"Scanning directory {currentDir}");
                    string tempPathDirectory = Pathy.Combine(targetDir, currentDir);
                    Directory.CreateDirectory(tempPathDirectory);
                    string[] subDirs = cd.GetDirectories(currentDir);
                    try
                    {
                        string[] files = cd.GetFiles(currentDir);
                        foreach (string file in files)
                        {
                            string normalizedFileName = file.Remove(file.Length - 2);
                            string onIsoPath          = Pathy.Combine(currentDir, file);
                            string newPath            = Pathy.Combine(targetDir, normalizedFileName);
                            Debug.WriteLine($"Copying from {onIsoPath} to {newPath}");
                            using (var fileStream = File.Create(newPath))
                            {
                                using (var gameFileStream = cd.OpenFile(file, FileMode.Open))
                                {
                                    gameFileStream.CopyTo(fileStream);
                                }
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        Debug.WriteLine(err);
                        Debug.WriteLine($"Error ({err.Message}) in {currentDir}");
                        throw;
                    }

                    foreach (string str in subDirs)
                    {
                        dirs.Push(str);
                    }
                }
            }
        }
Beispiel #6
0
        private void ExtractISO_Directory(CDReader cd, string outputFolder, string cd_path)
        {
            var real_directory = string.Format("{0}/{1}", outputFolder, cd_path);

            if (!Directory.Exists(real_directory))
            {
                Directory.CreateDirectory(real_directory);
            }

            var cd_directories = cd.GetDirectories(cd_path);

            foreach (var cd_directory in cd_directories)
            {
                ExtractISO_Directory(cd, outputFolder, cd_directory);
            }

            var cd_files = cd.GetFiles(cd_path);

            foreach (var cd_file in cd_files)
            {
                var fileStream = cd.OpenFile(cd_file, FileMode.Open);

                var attributes = cd.GetAttributes(cd_file);


                var real_file = string.Format("{0}/{1}", outputFolder, cd_file);

                Log($"extracting {cd_file} to {real_file}");

                using (var writerStream = File.OpenWrite(real_file))
                {
                    var max_chunk = 1024;
                    var buffer    = new byte[max_chunk];

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

                fileStream.Dispose();
            }
        }
Beispiel #7
0
        private void GenerateFileList(CDReader iso, string directory, List <string> fileList)
        {
            foreach (var file in iso.GetFiles(directory))
            {
                if (file[0] == '\\')
                {
                    fileList.Add(file.Substring(1, file.Length - 1)); // ISOs reasonably use \ as their root and derive all paths from it, but this causes problems later on when we try to use the ISO paths to build NTFS paths
                }
                else
                {
                    fileList.Add(file);
                }
            }

            foreach (var dir in iso.GetDirectories(directory))
            {
                GenerateFileList(iso, dir, fileList);
            }
        }
        // Recursive function that reads all the directories in an .iso file.
        public void recurse_iso(string[] directories, CDReader cd, string iso)
        {
            foreach (var d in directories)
            {
                foreach (var f in cd.GetFiles(d))
                {
                    var index    = f.LastIndexOf('\\');
                    var filename = f.Substring(index + 1, f.Length - index - 1);
                    foreach (var item in search_terms)
                    {
                        if (filename.ToLower().Contains(item))
                        {
                            file_list.Add(new File_Info(iso + f, filename));
                        }
                    }
                }

                var dir = cd.GetDirectories(d);
                recurse_iso(dir, cd, iso);
            }
        }
        // Function that reads .iso files without extracting the file.
        public void read_iso(string iso)
        {
            using (var isoStream = File.Open(iso, FileMode.Open))
            {
                foreach (var item in search_terms)
                {
                    if (iso.ToLower().Contains(item))
                    {
                        var index    = iso.LastIndexOf('\\');
                        var filename = iso.Substring(index + 1, iso.Length - index - 1);
                        file_list.Add(new File_Info(iso, filename));
                        return;
                    }
                }

                var cd   = new CDReader(isoStream, true);
                var root = cd.Root.FullName.ToString();
                var dir  = cd.GetDirectories(root);
                recurse_iso(dir, cd, iso);
            }
        }
Beispiel #10
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="ApplicationException"></exception>
        public void ExtractBin(string cueFileName)
        {
            if (!Directory.Exists(Directory.GetCurrentDirectory() + @"\" + _outFileNameBase))
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\" + _outFileNameBase);
            }
            var save_dir = Directory.GetCurrentDirectory() + @"\" + _outFileNameBase;

            try
            {
                CueFile cueFile;
                try
                {
                    cueFileName = Path.ChangeExtension(cueFileName, CueExtension);
                    cueFile     = new CueFile(cueFileName);
                }
                catch (Exception e)
                {
                    throw new ApplicationException($"Could not read CUE {cueFileName}:\n{e.Message}");
                }

                Stream binStream;
                try
                {
                    File.Copy(cueFile.BinFileName, save_dir + @"\" + _outFileNameBase + ".bin");
                    binStream = File.OpenRead(cueFile.BinFileName);
                }
                catch (Exception e)
                {
                    throw new ApplicationException($"Could not open BIN {cueFile.BinFileName}: {e.Message}");
                }

                Console.WriteLine(Environment.NewLine + "Writing tracks:");
                foreach (Track curTrack in cueFile.TrackList)
                {
                    Console.WriteLine(curTrack.Modes);
                    Console.WriteLine(curTrack.FileExtension);
                    Console.WriteLine(cueFile.TrackList.Count);
                    // Include track number when more than 1 track.

                    if (cueFile.TrackList.Count > 1)
                    {
                        _outFileName =
                            $"{_outFileNameBase}{curTrack.TrackNumber:00}.{curTrack.FileExtension.ToString().ToLower()}";
                    }
                    else
                    {
                        _outFileName = $"{_outFileNameBase}.{curTrack.FileExtension.ToString().ToLower()}";
                    }
                    curTrack.Write(binStream, _outFileName);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("discutils");
            using (FileStream isoStream = File.OpenRead(_outFileName))
            {
                CDReader cd = new CDReader(isoStream, false);
                Console.WriteLine(cd.Root.FullName);

                string[] files   = cd.GetFiles(cd.Root.FullName);
                string[] dirs    = cd.GetDirectories(cd.Root.FullName);
                bool     mrgdone = false;

                foreach (string c in files)
                {
                    Console.WriteLine(c);
                    if (c == @"\SLUS_014.11;1")
                    {
                        FileStream   fs  = File.Create(save_dir + @"\SLUS_014.11");
                        SparseStream isf = cd.OpenFile(c, FileMode.Open);
                        byte[]       dat = new byte[isf.Length];

                        int result = AsyncContext.Run(() => isf.ReadAsync(dat, 0, (int)isf.Length));

                        Task task = Task.Run(async() => { await fs.WriteAsync(dat, 0, dat.Length); });
                        task.Wait();
                        fs.Close();
                    }

                    foreach (string e in cd.GetFiles("\\DATA"))
                    {
                        Console.WriteLine(e);
                        if (e == @"\DATA\WA_MRG.MRG;1" && !mrgdone)
                        {
                            FileStream   fs     = File.Create(save_dir + @"\WA_MRG.MRG");
                            SparseStream isf    = cd.OpenFile(e, FileMode.Open);
                            byte[]       dat    = new byte[isf.Length];
                            int          result = AsyncContext.Run(() => isf.ReadAsync(dat, 0, (int)isf.Length));
                            Task         task   = Task.Run(async() => { await fs.WriteAsync(dat, 0, dat.Length); });
                            task.Wait();
                            mrgdone = true;
                            fs.Close();
                            break;
                        }
                    }

                    Static.SlusPath = save_dir + @"\SLUS_014.11";
                    Static.WaPath   = save_dir + @"\WA_MRG.MRG";
                    Static.IsoPath  = save_dir + @"\" + _outFileNameBase + ".bin";
                }
                isoStream.Close();
                File.Delete(_outFileName);
            }
        }