Beispiel #1
0
        internal static bool ExtractXiso(XisoOptions opts)
        {
            BinaryReader br = null;

            try {
                Abort = false;
                var sw = new Stopwatch();
                sw.Start();
                XisoListAndSize retval;
                UpdateStatus(string.Format("Extracting {0}", opts.Source));
                if (!GetFileListAndSize(opts, out retval, out br))
                {
                    return(false);
                }
                _errorlevel = 0;
                if (ExtractXiso(opts, retval, ref br))
                {
                    if (opts.DeleteIsoOnCompletion)
                    {
                        br.Close();
                        File.Delete(opts.Source);
                    }
                    sw.Stop();
                    UpdateStatus(string.Format("Successfully extracted {0} Files in {1} Folders with a total size of {2}", retval.Files, retval.Folders, Utils.GetSizeReadable(_totalSize)));
                    UpdateOperation(string.Format("Completed extraction after {0:F0} Minute(s) and {1} Seconds", sw.Elapsed.TotalMinutes, sw.Elapsed.Seconds));
                    return(true);
                }
                sw.Stop();
                if (Abort)
                {
                    UpdateStatus("Aborted by user");
                    UpdateOperation(string.Format("Aborted extraction after {0:F0} Minute(s) and {1} Seconds", sw.Elapsed.TotalMinutes, sw.Elapsed.Seconds));
                }

                else if (_errorlevel != 5)
                {
                    UpdateStatus("Extraction failed!");
                    UpdateOperation(string.Format("Extraction failed after {0:F0} Minute(s) and {1} Seconds", sw.Elapsed.TotalMinutes, sw.Elapsed.Seconds));
                }
                return(false);
            }
            finally {
                if (br != null)
                {
                    br.Close();
                }
            }
        }
Beispiel #2
0
        private static bool ExtractXiso(XisoOptions opts, XisoListAndSize retval, ref BinaryReader br)
        {
            _errorlevel = 0;
            if (opts.UseFtp && opts.FtpOpts.IsValid)
            {
                return(ExtractFiles(ref br, ref retval.List, opts.FtpOpts, opts));
            }
            if (opts.UseFtp)
            {
                opts.Target = Path.Combine(Path.GetDirectoryName(opts.Source), Path.GetFileNameWithoutExtension(opts.Source));
            }
            if (opts.GenerateSfv)
            {
                opts.SfvGen = new SfvGenerator(Path.Combine(Path.GetDirectoryName(opts.Source), Path.GetFileNameWithoutExtension(opts.Source)) + ".sfv");
            }
            var space = GetTotalFreeSpace(opts.Target);

            if (space < 0)
            {
                UpdateStatus(string.Format("WARNING: Unable to get Total Free Space got: {0} We'll be extracting anyways...", space));
                space = retval.Size * 100; // There was an error, try to extract anyways
            }
            if (space > retval.Size)
            {
                _totalSize = retval.Size;
                if (!ExtractFiles(ref br, ref retval.List, opts.Target, opts))
                {
                    return(false);
                }
                if (opts.GenerateSfv)
                {
                    opts.SfvGen.Save();
                }
                return(true);
            }
            _errorlevel = 5;
            UpdateStatus(string.Format("Extraction failed! (Not enough space on drive) space needed: {0} Space available: {1}", Utils.GetSizeReadable(retval.Size), Utils.GetSizeReadable(space)));
            return(false);
        }
Beispiel #3
0
        internal static bool ExtractXiso(XisoOptions opts, XisoListAndSize retval)
        {
            var br = new BinaryReader(File.Open(opts.Source, FileMode.Open, FileAccess.Read, FileShare.Read));

            try {
                if (opts.GenerateSfv)
                {
                    opts.SfvGen = new SfvGenerator(Path.Combine(Path.GetDirectoryName(opts.Source), Path.GetFileNameWithoutExtension(opts.Source)) + ".sfv");
                }
                var ret = ExtractXiso(opts, retval, ref br);
                if (!ret || !opts.DeleteIsoOnCompletion)
                {
                    return(ret);
                }
                br.Close();
                File.Delete(opts.Source);
                return(true);
            }
            finally {
                br.Close();
            }
        }
Beispiel #4
0
        internal static bool GetFileListAndSize(XisoOptions opts, out XisoListAndSize retval, out BinaryReader br)
        {
            Abort = false;
            if (opts.GenerateSfv)
            {
                opts.SfvGen = new SfvGenerator(Path.Combine(Path.GetDirectoryName(opts.Source), Path.GetFileNameWithoutExtension(opts.Source)) + ".sfv");
            }
            retval      = new XisoListAndSize();
            br          = null;
            _errorlevel = 1;
            if (!VerifyXiso(opts.Source))
            {
                return(false);
            }
            br = new BinaryReader(File.Open(opts.Source, FileMode.Open, FileAccess.Read, FileShare.Read));
            if (!BinarySeek(ref br, ((_baseOffset + 32) * 2048) + 0x14, 8))
            {
                return(false);
            }
            var data = br.ReadBytes(8);

            UpdateOperation("Grabbing Root sector & offset...");
            uint rootsector;

            _errorlevel = int.MaxValue;
            if (!EndianConverter.Little32(ref data, out rootsector))
            {
                return(false);
            }
            uint rootsize;

            if (!EndianConverter.Little32(ref data, out rootsize, 4))
            {
                return(false);
            }
            UpdateStatus(string.Format("Root sector: {0} (0x{0:X}) Root size: {1} (0x{1:X})", rootsector, rootsize));
            UpdateOperation("Parsing Game Partition FS Table...");
            Parse(ref br, ref retval.List, 0, 0, rootsector);
            _totalProcessed = 0;
            _totalSize      = 0;
            var msg     = "";
            var newlist = new List <XisoTableData>();

            foreach (var entry in retval.List)
            {
                if (opts.ExcludeSysUpdate && entry.Path.IndexOf("$SystemUpdate", StringComparison.CurrentCultureIgnoreCase) != -1 ||
                    entry.Name.IndexOf("$SystemUpdate", StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    continue;
                }
                if (entry.IsFile)
                {
                    if (opts.GenerateFileList)
                    {
                        msg += string.Format("{0}{1} [Offset: 0x{2:X} Size: {3}]{4}", entry.Path, entry.Name, entry.Offset, Utils.GetSizeReadable(entry.Size), Environment.NewLine);
                    }
                    _totalSize += entry.Size;
                    retval.Files++;
                }
                else
                {
                    if (opts.GenerateFileList)
                    {
                        msg += string.Format("{0}{1}\\{2}", entry.Path, entry.Name, Environment.NewLine);
                    }
                    retval.Folders++;
                }
                newlist.Add(entry);
            }
            retval.List = newlist;
            UpdateStatus(string.Format("Parsing Game Partition FS Table done! Total entries found: {0} Files: {1} Folders: {2} Total File size: {3}", retval.List.Count, retval.Files, retval.Folders,
                                       Utils.GetSizeReadable(_totalSize)));
            if (opts.GenerateFileList)
            {
                msg = string.Format("Total entries: {0}{4}Folders: {1}{4}Files: {2}{4}Total Filesize: {5}{4}{3}", retval.List.Count, retval.Folders, retval.Files, msg, Environment.NewLine,
                                    Utils.GetSizeReadable(_totalSize));
                File.WriteAllText(string.Format("{0}\\{1}.txt", Path.GetDirectoryName(opts.Source), Path.GetFileNameWithoutExtension(opts.Source)), msg);
            }
            if (string.IsNullOrEmpty(opts.Target))
            {
                opts.Target = string.Format("{0}\\{1}", Path.GetDirectoryName(opts.Source), Path.GetFileNameWithoutExtension(opts.Source));
            }
            if (opts.Target.EndsWith("\\", StringComparison.Ordinal))
            {
                opts.Target = opts.Target.Substring(0, opts.Target.Length - 1);
            }
            retval.Size = _totalSize;
            return(true);
        }
Beispiel #5
0
 private static bool ExtractFile(ref BinaryReader br, long offset, uint size, string target, XisoOptions xisoOpts)
 {
     _errorlevel = 4;
     if (!BinarySeek(ref br, offset, size))
     {
         UpdateStatus("Seek failure");
         return(false);
     }
     using (var bw = new BinaryWriter(File.Open(target, FileMode.Create, FileAccess.Write, FileShare.None))) {
         _errorlevel = 0;
         UpdateFileProgress(0, 0);
         uint crc = 0;
         for (uint i = 0; i < size;)
         {
             if (Abort)
             {
                 return(false);
             }
             var readsize = Utils.GetSmallest(size - i, ReadWriteBuffer);
             if (!xisoOpts.GenerateSfv)
             {
                 bw.Write(br.ReadBytes((int)readsize));
             }
             else
             {
                 var buf = br.ReadBytes((int)readsize);
                 bw.Write(buf);
                 crc = SfvGenerator.Crc.ComputeChecksum(buf, crc);
             }
             _totalProcessed += readsize;
             i += readsize;
             UpdateFileProgress(((double)i / size) * 100, readsize);
             UpdateIsoProgress(((double)_totalProcessed / _totalSize) * 100);
             if (MultiSize <= 0)
             {
                 continue;
             }
             _multiProcessed += readsize;
             UpdateTotalProgress(((double)_multiProcessed / MultiSize) * 100);
         }
         if (xisoOpts.GenerateSfv)
         {
             xisoOpts.SfvGen.AddFile(target.Replace(xisoOpts.Target, ""), crc);
         }
     }
     return(true);
 }
Beispiel #6
0
 private static bool ExtractFiles(ref BinaryReader br, ref List <XisoTableData> list, string target, XisoOptions xisoOpts)
 {
     _totalProcessed = 0;
     UpdateStatus(string.Format("Extracting files to {0}", target));
     UpdateOperation(string.Format("Extracting files to {0}", target));
     if (list.Count == 0)
     {
         return(false);
     }
     Directory.CreateDirectory(target);
     foreach (var entry in list)
     {
         if (Abort)
         {
             return(false);
         }
         Directory.CreateDirectory(target + entry.Path);
         if (!entry.IsFile)
         {
             Directory.CreateDirectory(target + entry.Path + entry.Name);
             continue;
         }
         UpdateStatus(string.Format("Extracting {0}{1} ({2})", entry.Path, entry.Name, Utils.GetSizeReadable(entry.Size)));
         if (!ExtractFile(ref br, entry.Offset, entry.Size, string.Format("{0}{1}{2}", target, entry.Path, entry.Name), xisoOpts))
         {
             return(false);
         }
     }
     if (xisoOpts.GenerateSfv)
     {
         xisoOpts.SfvGen.Save();
     }
     return(true);
 }
Beispiel #7
0
 private static bool ExtractFiles(ref BinaryReader br, ref List <XisoTableData> list, Xisoftp.FTPSettingsData ftpOpts, XisoOptions xisoOpts)
 {
     _totalProcessed = 0;
     if (list.Count == 0)
     {
         return(false);
     }
     UpdateStatus("Connecting to server...");
     if (!Xisoftp.Connect(ftpOpts.Host, ftpOpts.Port, ftpOpts.DataConnectionType, ftpOpts.User, ftpOpts.Password))
     {
         UpdateStatus(string.Format("Connection failed! Last Error: {0}", Xisoftp.LastError));
         return(false);
     }
     if (!Xisoftp.SetDirectory(ftpOpts.Path))
     {
         UpdateStatus(string.Format("Set Directory Failure! Last Error: {0}", Xisoftp.LastError));
         Xisoftp.Disconnect();
         return(false);
     }
     UpdateStatus(string.Format("Creating Directory: {0}", xisoOpts.Target));
     if (!Xisoftp.CreateDirectory(xisoOpts.Target))
     {
         UpdateStatus(string.Format("Create target Directory Failure! Last Error: {0}", Xisoftp.LastError));
         Xisoftp.Disconnect();
         return(false);
     }
     ftpOpts.Path += xisoOpts.Target;
     UpdateStatus(string.Format("Extracting files to ftp:{0}", ftpOpts.Path));
     UpdateOperation(string.Format("Extracting files to ftp:{0}", ftpOpts.Path));
     foreach (var entry in list)
     {
         if (entry.IsFile)
         {
             continue;
         }
         var dir = ftpOpts.Path + (entry.Path.Substring(1) + entry.Name).Replace("\\", "/");
         UpdateStatus(string.Format("Creating Directory: {0}", dir));
         Xisoftp.CreateDirectory(dir);
     }
     foreach (var entry in list)
     {
         if (Abort)
         {
             return(false);
         }
         if (!entry.IsFile)
         {
             continue;
         }
         if (!Xisoftp.SetDirectory((ftpOpts.Path + entry.Path.Replace("\\", "/")).Replace("//", "/")))
         {
             UpdateStatus(string.Format("Set Directory Failure! Last Error: {0}", Xisoftp.LastError));
             Xisoftp.Disconnect();
             return(false);
         }
         UpdateStatus(string.Format("Extracting {0}{1} ({2})", entry.Path, entry.Name, Utils.GetSizeReadable(entry.Size)));
         if (!Xisoftp.SendFile(entry.Name, ref br, entry.Offset, entry.Size, xisoOpts, entry.Path))
         {
             UpdateStatus(string.Format("Send File Failure! Last Error: {0}", Xisoftp.LastError));
             Xisoftp.Disconnect();
             return(false);
         }
     }
     if (xisoOpts.GenerateSfv)
     {
         xisoOpts.SfvGen.Save();
     }
     return(true);
 }
Beispiel #8
0
 public static bool SendFile(string file, ref BinaryReader src, long offset, long size, XisoOptions xisoOpts, string path)
 {
     if (!Client.IsConnected)
     {
         XisoExtractor.UpdateStatus("FTP Not connected!");
         return(false);
     }
     try {
         using (var stream = Client.OpenWrite(file)) {
             if (src.BaseStream.Position != offset)
             {
                 if (!Seek(ref src, offset, size))
                 {
                     src.Close();
                     XisoExtractor.UpdateStatus("Seek failure!");
                     return(false);
                 }
             }
             else if (src.BaseStream.Length < src.BaseStream.Position + size)
             {
                 src.Close();
                 XisoExtractor.UpdateStatus("Size failure!");
                 return(false);
             }
             long processed = 0;
             XISOStatus.UpdateFTPProgress(processed, size);
             uint crc = 0;
             while (processed < size)
             {
                 if (XisoExtractor.Abort)
                 {
                     return(false);
                 }
                 var sendsize = Utils.GetSmallest(size - processed, BufferSize);
                 var data     = src.ReadBytes((int)sendsize);
                 stream.Write(data, 0, data.Length);
                 if (xisoOpts.GenerateSfv)
                 {
                     crc = SfvGenerator.Crc.ComputeChecksum(data, crc);
                 }
                 processed += sendsize;
                 var handler = ProgressUpdate;
                 if (handler != null)
                 {
                     handler.Invoke(null, new EventArg <long, long, long>(sendsize, processed, size));
                 }
                 XISOStatus.UpdateFTPProgress(processed, size);
             }
             if (xisoOpts.GenerateSfv)
             {
                 xisoOpts.SfvGen.AddFile(Path.Combine(path, file), crc);
             }
         }
     }
     catch (Exception ex) {
         LastError = ex.Message;
         MessageBox.Show(string.Format(Resources.XISOFTPTransferError, file, ex), Resources.FTPTransferErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
     return(true);
 }