Extract ISO using winrar automatically using C # or batch

I am trying to extract the ISO to a folder with the same name without .iso at the end.

I had a problem with winrar since it does not start the extraction when I start a session starting from a folder with ISO.

UPDATED with response code

private void ExtractISO(string toExtract, string folderName)
    {
        // reads the ISO
        CDReader Reader = new CDReader(File.Open(toExtract, FileMode.Open), true);
        // passes the root directory the folder name and the folder to extract
        ExtractDirectory(Reader.Root, folderName /*+ Path.GetFileNameWithoutExtension(toExtract)*/ + "\\", "");
        // clears reader and frees memory
        Reader.Dispose();
    }

    private void ExtractDirectory(DiscDirectoryInfo Dinfo, string RootPath, string PathinISO)
    {
        if (!string.IsNullOrWhiteSpace(PathinISO))
        {
            PathinISO += "\\" + Dinfo.Name;
        }
        RootPath += "\\" + Dinfo.Name;
        AppendDirectory(RootPath);
        foreach (DiscDirectoryInfo dinfo in Dinfo.GetDirectories())
        {
            ExtractDirectory(dinfo, RootPath, PathinISO);
        }
        foreach (DiscFileInfo finfo in Dinfo.GetFiles())
        {
            using (Stream FileStr = finfo.OpenRead())
            {
                using (FileStream Fs = File.Create(RootPath + "\\" + finfo.Name)) // Here you can Set the BufferSize Also e.g. File.Create(RootPath + "\\" + finfo.Name, 4 * 1024)
                {
                    FileStr.CopyTo(Fs, 4 * 1024); // Buffer Size is 4 * 1024 but you can modify it in your code as per your need
                }
            }
        }
    }

    static void AppendDirectory(string path)
    {
        try
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
        catch (DirectoryNotFoundException Ex)
        {
            AppendDirectory(Path.GetDirectoryName(path));
        }
        catch (PathTooLongException Ex)
        {
            AppendDirectory(Path.GetDirectoryName(path));
        }
    }

The user selects the folder to extract (.ISO) to the table. Then I use it in Process.Start () in the background worker. This is similar to opening the installation software and does not extract the ISO to the desired folder name.

Thanks in advance for your help.

Or, if someone can give me a package to extract the ISO instead and call it from C # passing to Extract, and the folder name, which would also be useful.

thank

+3
source share
4 answers

!

SevenZipSharp .NET DiscUtils ISO...

ClassLibraries ISO !

DiscUtils ISO [ CDReader Class] .

SevenZipSharp, , ClassLibrary Google, !

, Path.GetFileNameWithoutExtension((string)ISOFileName), "ISOFile" iso "ISOFile.iso". .

UPDATE

ISO DiscUtils:

using DiscUtils;
using DiscUtils.Iso9660;

void ExtractISO(string ISOName, string ExtractionPath)
{
    using (FileStream ISOStream = File.Open(ISOName, FileMode.Open))
    {
        CDReader Reader = new CDReader(ISOStream, true, true);
        ExtractDirectory(Reader.Root, ExtractionPath + Path.GetFileNameWithoutExtension(ISOName) + "\\", "");
        Reader.Dispose();
    }
}
void ExtractDirectory(DiscDirectoryInfo Dinfo, string RootPath, string PathinISO)
{
    if (!string.IsNullOrWhiteSpace(PathinISO))
    {
        PathinISO += "\\" + Dinfo.Name;
    }
    RootPath += "\\" + Dinfo.Name;
    AppendDirectory(RootPath);
    foreach (DiscDirectoryInfo dinfo in Dinfo.GetDirectories())
    {
        ExtractDirectory(dinfo, RootPath, PathinISO);
    }
    foreach (DiscFileInfo finfo in Dinfo.GetFiles())
    {
            using (Stream FileStr = finfo.OpenRead())
            {
                using (FileStream Fs = File.Create(RootPath + "\\" + finfo.Name)) // Here you can Set the BufferSize Also e.g. File.Create(RootPath + "\\" + finfo.Name, 4 * 1024)
                {
                    FileStr.CopyTo(Fs, 4 * 1024); // Buffer Size is 4 * 1024 but you can modify it in your code as per your need
                }
            }
    }
}
static void AppendDirectory(string path)
{
    try
    {
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
    }
    catch (DirectoryNotFoundException Ex)
    {
        AppendDirectory(Path.GetDirectoryName(path));
    }
    catch (PathTooLongException Exx)
    {
        AppendDirectory(Path.GetDirectoryName(path));
    }
}

:

ExtractISO(ISOFileName, Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\");

! !

, , ...

!

+10

:

string Desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Process.Start("Winrar.exe", string.Format("x {0} {1}",
   Desktop + "\\test.rar",
   Desktop + "\\SomeFolder"));

test.rar SomeFolder. .rar .iso, .

, , , . , =]

P.S. , YourProcessInfo.WindowStyle ProcessWindowStyle.Hidden.

0

UDF ISO Windows (DISM) , DiscUtils

using DiscUtils;
public static void ReadIsoFile(string sIsoFile, string sDestinationRootPath)
        {
            Stream streamIsoFile = null;
            try
            {
                streamIsoFile = new FileStream(sIsoFile, FileMode.Open);
                DiscUtils.FileSystemInfo[] fsia = FileSystemManager.DetectDefaultFileSystems(streamIsoFile);
                if (fsia.Length < 1)
            {
                MessageBox.Show("No valid disc file system detected.");
            }
            else
            {
                DiscFileSystem dfs = fsia[0].Open(streamIsoFile);                    
                ReadIsoFolder(dfs, @"", sDestinationRootPath);
                return;
            }
        }
        finally
        {
            if (streamIsoFile != null)
            {
                streamIsoFile.Close();
            }
        }
    }

public static void ReadIsoFolder(DiscFileSystem cdReader, string sIsoPath, string sDestinationRootPath)
    {
        try
        {
            string[] saFiles = cdReader.GetFiles(sIsoPath);
            foreach (string sFile in saFiles)
            {
                DiscFileInfo dfiIso = cdReader.GetFileInfo(sFile);
                string sDestinationPath = Path.Combine(sDestinationRootPath, dfiIso.DirectoryName.Substring(0, dfiIso.DirectoryName.Length - 1));
                if (!Directory.Exists(sDestinationPath))
                {
                    Directory.CreateDirectory(sDestinationPath);
                }
                string sDestinationFile = Path.Combine(sDestinationPath, dfiIso.Name);
                SparseStream streamIsoFile = cdReader.OpenFile(sFile, FileMode.Open);
                FileStream fsDest = new FileStream(sDestinationFile, FileMode.Create);
                byte[] baData = new byte[0x4000];
                while (true)
                {
                    int nReadCount = streamIsoFile.Read(baData, 0, baData.Length);
                    if (nReadCount < 1)
                    {
                        break;
                    }
                    else
                    {
                        fsDest.Write(baData, 0, nReadCount);
                    }
                }
                streamIsoFile.Close();
                fsDest.Close();
            }
            string[] saDirectories = cdReader.GetDirectories(sIsoPath);
            foreach (string sDirectory in saDirectories)
            {
                ReadIsoFolder(cdReader, sDirectory, sDestinationRootPath);
            }
            return;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

ISOReader,

http://www.java2s.com/Open-Source/CSharp_Free_CodeDownload/i/isoreader.zip

0

I recently ran into this .iso mining issue. Having tried several methods, 7zip did the job for me, you just need to make sure that the latest version of 7zip is installed on your system. Maybe this will help to try {

            Process cmd = new Process();
            cmd.StartInfo.FileName = "cmd.exe";
            cmd.StartInfo.RedirectStandardInput = true;
            cmd.StartInfo.RedirectStandardOutput = true;
            cmd.StartInfo.CreateNoWindow = false;
            cmd.StartInfo.UseShellExecute = false;
            cmd.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            cmd.Start();

            cmd.StandardInput.WriteLine("C:");
            //Console.WriteLine(cmd.StandardOutput.Read());
            cmd.StandardInput.Flush();

            cmd.StandardInput.WriteLine("cd C:\\\"Program Files\"\\7-Zip\\");
            //Console.WriteLine(cmd.StandardOutput.ReadToEnd());
            cmd.StandardInput.Flush();


            cmd.StandardInput.WriteLine(string.Format("7z x -y -o{0} {1}", source, copyISOLocation.TempIsoPath));
            //Console.WriteLine(cmd.StandardOutput.ReadToEnd());
            cmd.StandardInput.Flush();
            cmd.StandardInput.Close();
            cmd.WaitForExit();
            Console.WriteLine(cmd.StandardOutput.ReadToEnd());
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message + "\n" + e.StackTrace);
            if (e.InnerException != null)
            {
                Console.WriteLine(e.InnerException.Message + "\n" + e.InnerException.StackTrace);
            }
        }
0
source

All Articles