Esempio n. 1
0
        public static string DetectPs2Sku(FileInfo isofile)
        {
            Stream isoStream;

            if (isBinFile(isofile))
            {
                isoStream = new RawCdRomStream(isofile);
            }
            else
            {
                isoStream = isofile.OpenRead();
            }

            if (!CDReader.Detect(isoStream))
            {
                return(null);
            }
            CDReader cdReader = new CDReader(isoStream, false, true);

            if (!cdReader.FileExists("SYSTEM.CNF"))
            {
                cdReader.Dispose();
                isoStream.Dispose();
                return(null);
            }

            SparseStream systemCnfStream = cdReader.OpenFile("SYSTEM.CNF", FileMode.Open, FileAccess.Read);
            StreamReader systemCnfReader = new StreamReader(systemCnfStream, Encoding.ASCII);
            string       boot2           = null;

            while (!systemCnfReader.EndOfStream)
            {
                boot2 = systemCnfReader.ReadLine();
                if (boot2.ToUpperInvariant().StartsWith("BOOT"))
                {
                    break;
                }
            }
            systemCnfReader.Dispose();
            systemCnfStream.Dispose();

            while (boot2.Contains("\\"))
            {
                boot2 = boot2.Substring(1);
            }

            if (boot2.EndsWith(";1"))
            {
                boot2 = boot2.Substring(0, boot2.Length - 2);
            }

            cdReader.Dispose();
            isoStream.Dispose();
            return(boot2);
        }
Esempio n. 2
0
 public override bool DetectROM(string inputPath, out string titleID, out uint regionID)
 {
     regionID = 0;
     using (FileStream isoStream = File.Open(inputPath, FileMode.Open))
     {
         if (!CDReader.Detect(isoStream))
         {
             titleID = null;
             return(false);
         }
         else
         {
             CDReader cd = new CDReader(isoStream, true);
             titleID = null;
             bool confirm = false;
             if (cd.FileExists(@"UMD_DATA.BIN"))
             {
                 using (StreamReader sr = new StreamReader(cd.OpenFile(@"UMD_DATA.BIN", FileMode.Open)))
                 {
                     titleID = sr.ReadLine().Substring(0, 10);
                 }
                 confirm = true;
             }
             cd.Dispose();
             return(confirm);
         }
     }
 }
Esempio n. 3
0
        public void ExtractISO(string toExtract, string folderName)
        {
            CDReader Reader = new CDReader(File.Open(toExtract, FileMode.Open), true);

            ExtractDirectory(Reader.Root, folderName + "\\", "");
            Console.WriteLine(toExtract + " was succesfully extracted.");
            Reader.Dispose();
        }
Esempio n. 4
0
 void ExtractISO(string ISOName, string ExtractionPath)
 {
     using (FileStream ISOStream = File.Open(openFileDialog1.FileName, FileMode.Open))
     {
         CDReader Reader = new CDReader(ISOStream, true, true);
         ExtractDirectory(Reader.Root, ExtractionPath + Path.GetFileNameWithoutExtension(ISOName) + "\\", "");
         Reader.Dispose();
     }
 }
Esempio n. 5
0
        public static string ExtractIso(string isoFile)
        {
            string dstDir = Path.Join(Path.GetTempPath(), Path.GetRandomFileName());

            using (Stream stream = File.OpenRead(isoFile)) {
                CDReader cd = new CDReader(stream, true);
                ExtractIsoDirectory(cd.Root, dstDir);
                cd.Dispose();
            }

            return(dstDir);
        }
Esempio n. 6
0
        private void CloseISO(Command loadISO, Command closeISO)
        {
            cdReader.Dispose();
            isoFileStream.Dispose();

            var filesToRemove = files.Where((file) => file.DiscFile != null);

            foreach (var file in filesToRemove)
            {
                files.Remove(file);
            }

            closeISO.Enabled = false;
            loadISO.Enabled  = true;
        }
Esempio n. 7
0
 public CdIo(string cdPath)
 {
     Path = cdPath;
     try
     {
         File = new FileStream(cdPath, FileMode.Open);
         _cd  = new CDReader(File, true);
     }
     catch (Exception)
     {
         _cd?.Dispose();
         File?.Dispose();
         throw;
     }
 }
Esempio n. 8
0
        void treeView1_NodeMouseClick(object sender,
    TreeNodeMouseClickEventArgs e)
        {
			using (FileStream ISOStream = File.Open(openFileDialog1.FileName, FileMode.Open))
			{
				CDReader Reader = new CDReader(ISOStream, true, true);
                metroListView1.Items.Clear();        
				TreeNode newSelected = e.Node;
				DiscDirectoryInfo nodeDirInfo = (DiscDirectoryInfo)newSelected.Tag;
                BrowseDirectory(Reader.Root, ExtPath + Path.GetFileNameWithoutExtension(ISONameFile) + "\\", "", nodeDirInfo);
                textBox1.Text = nodeDirInfo.FullName;
                currentFolder = nodeDirInfo;
                Reader.Dispose();
			}
			metroListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }
Esempio n. 9
0
        private void PopulateTreeView(string ISOName, string ExtractionPath)
        {
            TreeNode rootNode; ISONameFile = ISOName; ExtPath = ExtractionPath;
            using (FileStream ISOStream = File.Open(openFileDialog1.FileName, FileMode.Open))
			{
				CDReader Reader = new CDReader(ISOStream, true, true);
				DiscDirectoryInfo info = Reader.Root;
				if (info.Exists)
				{
					rootNode = new TreeNode(ISOName);
					rootNode.Tag = info;
					GetDirectories(info.GetDirectories(), rootNode);
					treeView1.Nodes.Add(rootNode);
				}
				Reader.Dispose();
			}
        }
 void ExtractISO(string ISOName, string ExtractionPath)
 {
     using (FileStream ISOStream = File.Open(ISOName, FileMode.Open))
     {
         try
         {
             var Reader = new DiscUtils.Udf.UdfReader(ISOStream);
             ExtractDirectory(Reader.Root, ExtractionPath + "\\", "");
             Reader.Dispose();
         } catch
         {
             CDReader Reader = new CDReader(ISOStream, true, true);
             ExtractDirectory(Reader.Root, ExtractionPath + "\\", "");
             Reader.Dispose();
         }
     }
 }
Esempio n. 11
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (_cd is object)
                    {
                        _cd.Dispose();
                    }

                    if (_isoStream is object)
                    {
                        _isoStream.Dispose();
                    }
                }

                disposedValue = true;
            }
        }
Esempio n. 12
0
        // Extracts the package.rdp from a GEB iso
        public static bool Extract(string isoPath, bool debug)
        {
            try
            {
                // Debug mode only variables
                long   bytesReadTotal   = 0;
                string percentageString = "# Extracting package.rdp - 0%";

                // Initializing virtual ISO disc
                if (debug)
                {
                    Console.WriteLine("# Reading ISO File System...");
                }
                CDReader isoFile = new CDReader(new FileStream(isoPath, FileMode.Open), false);

                if (debug)
                {
                    Console.WriteLine("# Checking ISO Files...");
                }
                // Check if file exists
                if (isoFile.FileExists("\\PSP_GAME\\USRDIR\\package.rdp"))
                {
                    if (debug)
                    {
                        Console.WriteLine("# Initializing Streams and Buffers");
                    }
                    // Initializing Streams and buffers
                    Stream     packageStream = isoFile.OpenFile("\\PSP_GAME\\USRDIR\\package.rdp", FileMode.Open);
                    FileStream outStream     = new FileStream("package.rdp", FileMode.Create, FileAccess.Write);
                    int        bufferLenght  = 2048;
                    byte[]     buffer        = new byte[bufferLenght];

                    if (debug)
                    {
                        Console.Write(percentageString);
                    }
                    // Extract the package.rdp
                    int bytesRead = packageStream.Read(buffer, 0, bufferLenght);
                    bytesReadTotal += bytesRead;
                    while (bytesRead > 0)
                    {
                        outStream.Write(buffer, 0, bytesRead);
                        outStream.Flush();
                        bytesRead       = packageStream.Read(buffer, 0, bufferLenght);
                        bytesReadTotal += bytesRead;
                        if (debug)
                        {
                            int currentPercentage = (int)((bytesReadTotal * 100) / packageStream.Length);
                            if (percentageString != "# Extracting package.rdp - " + currentPercentage + "%")
                            {
                                percentageString = "# Extracting package.rdp - " + currentPercentage + "%";
                                Console.Write("\r" + percentageString);
                            }
                        }
                    }
                    Console.WriteLine("\n# Closing Streams");
                    // Close Streams
                    outStream.Close();
                    packageStream.Close();
                }
                // Iso not valid
                else
                {
                    if (debug)
                    {
                        Console.WriteLine("# Can't find the file \"\\PSP_GAME\\USRDIR\\package.rdp\" into the Iso File System");
                        Console.WriteLine("# Disposing Iso File System");
                    }
                    // Close Virtual Iso
                    isoFile.Dispose();
                    return(false);
                }

                if (debug)
                {
                    Console.WriteLine("# Disposing Iso File System");
                }
                // Close Virtual Iso
                isoFile.Dispose();
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="isoPath"></param>
        /// <param name="debug"></param>
        /// <returns>-2 package.rdp dimension, -1 Iso not valid, 1 inserted</returns>
        public static int Insert(string isoPath, bool debug)
        {
            try
            {
                // Debug mode only variables
                long   bytesReadTotal   = 0;
                string percentageString = "# Inserting package.rdp - 0%";

                // Initializing virtual ISO disc
                if (debug)
                {
                    Console.WriteLine("# Reading ISO File System...");
                }
                FileStream isoStream = new FileStream(isoPath, FileMode.Open, FileAccess.ReadWrite);
                CDReader   isoFile   = new CDReader(isoStream, false);

                if (debug)
                {
                    Console.WriteLine("# Checking ISO Files...");
                }
                // Check if file exists
                if (isoFile.FileExists("\\PSP_GAME\\USRDIR\\package.rdp"))
                {
                    if (debug)
                    {
                        Console.WriteLine("# Initializing Streams and Buffers");
                    }
                    // Initializing Streams and buffers
                    Stream     packageStream = isoFile.OpenFile("\\PSP_GAME\\USRDIR\\package.rdp", FileMode.Open, FileAccess.Read);
                    FileStream inStream      = new FileStream("package.rdp", FileMode.Open, FileAccess.Read);
                    int        bufferLenght  = 2048;
                    byte[]     buffer        = new byte[bufferLenght];

                    if (debug)
                    {
                        Console.WriteLine("# Checking package.rdp files dimensions");
                    }
                    // Checking package.rdp dimensions
                    if (inStream.Length != packageStream.Length)
                    {
                        if (debug)
                        {
                            Console.WriteLine("# The package.rdp has a different dimension from the original one.");
                            Console.WriteLine("# Disposing Iso File System");
                        }
                        // Close Virtual Iso
                        isoFile.Dispose();
                        return(-2);
                    }

                    // Closing useless streams
                    packageStream.Close();
                    packageStream.Dispose();
                    isoFile.Dispose();
                    isoFile = null;

                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    if (debug)
                    {
                        Console.WriteLine("# Initializing injecter...");
                    }

                    byte[] rdpUnique = new byte[0x60];
                    inStream.Seek(0, SeekOrigin.Begin);
                    inStream.Read(rdpUnique, 0, 0x60);
                    inStream.Seek(0, SeekOrigin.Begin);

                    long rdpOffset = localizeRDP(rdpUnique, isoStream);
                    isoStream.Seek(rdpOffset, SeekOrigin.Begin);

                    if (debug)
                    {
                        Console.Write(percentageString);
                    }
                    // Inserting the package.rdp
                    int bytesRead = inStream.Read(buffer, 0, bufferLenght);
                    bytesReadTotal += bytesRead;
                    while (bytesRead > 0)
                    {
                        isoStream.Write(buffer, 0, bytesRead);
                        isoStream.Flush();
                        bytesRead       = inStream.Read(buffer, 0, bufferLenght);
                        bytesReadTotal += bytesRead;
                        if (debug)
                        {
                            int currentPercentage = (int)((bytesReadTotal * 100) / packageStream.Length);
                            if (percentageString != "# Inserting package.rdp - " + currentPercentage + "%")
                            {
                                percentageString = "# Inserting package.rdp - " + currentPercentage + "%";
                                Console.Write("\r" + percentageString);
                            }
                        }
                    }
                    Console.WriteLine("\n# Closing Streams");
                    // Close Streams
                    inStream.Close();
                    isoStream.Close();
                }
                // Iso not valid
                else
                {
                    if (debug)
                    {
                        Console.WriteLine("# Can't find the file \"\\PSP_GAME\\USRDIR\\package.rdp\" into the Iso File System");
                        Console.WriteLine("# Disposing Iso File System");
                    }
                    // Close Virtual Iso
                    isoFile.Dispose();
                    return(-1);
                }
                return(1);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /**************************************************************************************************************
         * ISO Extract
         *************************************************************************************************************/
        public bool ExtractISO(string in_sIsoPathAndFileName
                               , string in_sIsoExtractionRootDir
                               , bool in_bCreateSubdirectory)
        {
            try
            {
                using (FileStream ISOStream = File.Open(in_sIsoPathAndFileName, FileMode.Open))
                {
                    DiscUtils.FileSystemManager oMgr           = new FileSystemManager();
                    DiscUtils.FileSystemInfo[]  oFileInfoItems = oMgr.DetectFileSystems(ISOStream);

                    bool bIsUDF = false;
                    foreach (DiscUtils.FileSystemInfo oInfo in oFileInfoItems)
                    {
                        string sDesc = oInfo.Description;

                        if (sDesc == "OSTA Universal Disk Format (UDF)")
                        {
                            bIsUDF = true;
                        }
                    }

                    string sIsoExtractionPath = "";

                    if (in_bCreateSubdirectory)
                    {
                        // Extract to subdirectory on drive
                        sIsoExtractionPath
                            = Path.Combine(in_sIsoExtractionRootDir, Path.GetFileNameWithoutExtension(in_sIsoPathAndFileName));
                    }
                    else
                    {
                        // Extract to ISO Extraction Root directory
                        sIsoExtractionPath = in_sIsoExtractionRootDir;
                    }

                    if (bIsUDF)
                    {
                        BootmanLog.LogError(LogTextBox, "Processing ISO Extract as ISO-UDF");

                        UdfReader oUDFReader = new UdfReader(ISOStream);
                        ExtractDirectoryISOUDF(oUDFReader.Root
                                               , sIsoExtractionPath
                                               , "");
                        oUDFReader.Dispose();
                        return(true);
                    }
                    else
                    {
                        BootmanLog.LogError(LogTextBox, "Processing ISO Extract as ISO-9660");

                        CDReader oISO9660Reader = new CDReader(ISOStream, true, true);
                        ExtractDirectoryISO9660(oISO9660Reader.Root
                                                , sIsoExtractionPath
                                                , "");
                        oISO9660Reader.Dispose();
                        return(true);
                    }
                }
            }
            catch (Exception oEx)
            {
                BootmanLog.LogError(LogTextBox, "Error Extracting ISO: " + oEx.Message);
                return(false);
            }
        }
Esempio n. 15
0
 public override void Dispose()
 {
     _cd.Dispose();
     File.Dispose();
 }