コード例 #1
0
        static void Main(string[] args)
        {
            var           config        = new Options();
            ConsoleWriter consoleWriter = new ConsoleWriter();

            Console.CancelKeyPress += OnCancel;
            Console.CursorVisible   = false;

            Interaction.SetInteraction(new ConsoleInteraction(config, consoleWriter));

            var    parser         = new Parser(new ParserSettings(Console.Error));
            string invokedCommand = null;

            if (!parser.ParseArguments(args, config, (v, s) => { invokedCommand = v; }))
            {
                Environment.Exit(Parser.DefaultExitCodeFail);
            }

            switch (invokedCommand)
            {
            case "createiso":
                IsoBuilder isoBuilder = new IsoBuilder();
                isoBuilder.CreateIso(cancellationTokenSource.Token).Wait();
                break;

            case "crypt":
                IsoCryptoClass cryptoClass = new IsoCryptoClass();
                cryptoClass.Process(cancellationTokenSource.Token).Wait();
                break;

            case "createird":
                IrdCreator creator = IrdCreator.Create();
                creator.CreateIRD(cancellationTokenSource.Token).Wait();
                break;
            }
        }
コード例 #2
0
        public async Task <bool> CreateIso(CancellationToken cancellation)
        {
            try
            {
                // Get the JB directory
                Path = await Interaction.Instance.GetJBDirectory();

                if (string.IsNullOrEmpty(Path))
                {
                    return(false);
                }

                if (!IsValidDirectory(Path))
                {
                    Interaction.Instance.ShowMessageDialog(Resources.NotAValidJBDirectory);
                    return(false);
                }

                if (!Path.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture)))
                {
                    Path += System.IO.Path.DirectorySeparatorChar;
                }

                // Get the resulting iso filename
                string savePath = await Interaction.Instance.GetSaveIsoPath();

                if (string.IsNullOrEmpty(savePath))
                {
                    return(false);
                }

                IrdFile irdFile;
                try
                {
                    string irdPath = await Interaction.Instance.GetIrdFile();

                    if (string.IsNullOrEmpty(irdPath))
                    {
                        return(false);
                    }
                    irdFile = IrdFile.Load(irdPath);
                }
                catch (FileLoadException e)
                {
                    Interaction.Instance.ReportMessage(e.Message);
                    return(false);
                }

                if (!CheckParams(irdFile))
                {
                    return(false);
                }

                if (!(await ValidateOrGetUpdate(irdFile, cancellation)))
                {
                    return(false);
                }

                Interaction.Instance.TaskBegin();

                randomData2 = MakeData2Random(irdFile.Data2);

                // Okay, got that figured out, now we have to parse the partition table
                // and get the regions
                Interaction.Instance.ReportMessage("Parsing IRD file");
                ParseTableOfContents(irdFile);
                cdBuilder.TotalLength = ((LastContentSector + 1) * Utilities.SectorSize) + irdFile.Footer.Length;

                bool isValidFile;

                Interaction.Instance.SetProgressMaximum((int)(LastContentSector - FirstContentSector));
                Interaction.Instance.ReportMessage("Checking files...");
                await AddFiles(cancellation);

                Interaction.Instance.ReportProgress(0); // Reset progress

                IsoCryptoClass icc = new IsoCryptoClass();
                try
                {
                    icc.AnalyseISOBuilder(this);
                }
                catch (Exception e)
                {
                    Interaction.Instance.ReportMessage(e.Message);
                    return(false);
                }

                // Verify that the IRD and choosen game directory are the same
                if (irdFile.GameID != icc.GameID)
                {
                    Interaction.Instance.ReportMessage("This IRD file is not valid for this JB directory");
                    return(false);
                }

                Interaction.Instance.ReportProgress(0);
                Interaction.Instance.ReportMessage("Validating files...");
                using (Stream s = Build())
                {
                    Interaction.Instance.SetProgressMaximum(FilesEndSector - FilesStartSector);
                    bool validFiles = await TaskEx.Run(() => CheckFiles(cancellation, irdFile));

                    if (!validFiles)
                    {
                        if (cancellation.IsCancellationRequested)
                        {
                            return(false);
                        }

                        // Ask if the user wants to continue
                        Interaction.Instance.ReportMessage("Invalid hashes found, will continue anyway.");
                    }
                    if (cancellation.IsCancellationRequested)
                    {
                        return(false);
                    }

                    Interaction.Instance.ReportProgress(0);
                    Interaction.Instance.ReportMessage(string.Format("Creating ISO '{0}...'", savePath));

                    // Fix regions to write (skip header, and make last region shorter
                    icc.Regions.First().Start   = (uint)FirstContentSector;
                    icc.Regions.First().Length -= (uint)FirstContentSector;
                    icc.Regions.Last().Length   = (uint)(LastContentSector - icc.Regions.Last().Start) + 1;

                    // Skip partition tables and all, we write those ourselves
                    s.Seek(FirstContentSector * Utilities.SectorSize, SeekOrigin.Begin);

                    using (FileStream fs = new FileStream(savePath, FileMode.Create, FileAccess.ReadWrite))
                    {
                        WriteHeader(fs, irdFile, randomData2, cancellation);
                        if (cancellation.IsCancellationRequested)
                        {
                            return(false);
                        }
                        fs.Seek(FirstContentSector * Utilities.SectorSize, SeekOrigin.Begin);
                        isValidFile = await icc.DoWork(s, fs, cancellation, true, irdFile);

                        if (cancellation.IsCancellationRequested)
                        {
                            return(false);
                        }
                        WriteFooter(fs, irdFile, isValidFile, cancellation);
                        if (cancellation.IsCancellationRequested)
                        {
                            return(false);
                        }

                        if (!isValidFile)
                        {
                            Interaction.Instance.SetProgressError();
                        }
                    }
                }
                Interaction.Instance.ReportMessage(
                    string.Format("All complete, resulting ISO {0} the original.",
                                  isValidFile ? "MATCHES" : "DOES NOT MATCH"));
            }
            catch (PS3BuilderException)
            {
                Interaction.Instance.TaskComplete();
                Interaction.Instance.ReportMessage("Create ISO aborted due to previous errors.");
                return(false);
            }
            catch (Exception e)
            {
                Interaction.Instance.TaskComplete();
                Interaction.Instance.ReportMessage(e.Message);
                return(false);
            }

            Interaction.Instance.TaskComplete();
            return(true);
        }