Пример #1
0
        internal static void Mainp(string[] args)
        {
            bool log = false;

            Console.Title = ISOTP.program.ProductName + " " + ISOTP.ActualVersion;
            var  patch      = new PatchFile();
            bool encrypt    = false,
                 batch      = false,
                 authorSet  = false,
                 verSet     = false,
                 changeSet  = false,
                 creditSet  = false,
                 otherSet   = false;
            string output   = "output.kh2patch";
            string logtouse = "none";

            for (int i = 0; i < args.Length; ++i)
            {
                switch (args[i].ToLowerInvariant())
                {
                case "-xeeynamo":
                    DoXeey = true;
                    ISOTP.WriteWarning("Using Xeeynamo's encryption!");
                    break;

                case "-batch":
                    batch = true;
                    break;

                case "-log":
                    log = true;
                    break;

#if DEBUG
                case "-decrypted":
                    if (encrypt)
                    {
                        encrypt = false;
                        Console.WriteLine("Writing in decrypted mode!");
                    }
                    break;
#endif
                case "-hashverskip":
                    hvs = true;
                    break;

                case "-version":
                    if (!uint.TryParse(args[++i].Trim(), out patch.Version))
                    {
                        patch.Version = 1;
                    }
                    else
                    {
                        verSet = true;
                    }
                    break;

                case "-author":
                    patch.Author = args[++i];
                    authorSet    = true;
                    break;

                case "-other":
                    patch.OtherInfo = args[++i];
                    otherSet        = true;
                    break;

                case "-uselog":
                    logtouse = args[++i];
                    uselog   = true;
                    break;

                case "-changelog":
                    patch.AddChange(args[++i]);
                    break;

                case "-skipchangelog":
                    changeSet = true;
                    break;

                case "-fastpatch":
                    patch.fast_patch = true;
                    break;

                case "-credits":
                    patch.AddCredit(args[++i]);
                    break;

                case "-skipcredits":
                    creditSet = true;
                    break;

                case "-uiswitch":
                    UISwitch = true;
                    break;

                case "-newui":
                case "-newinterface":
                    oldui = false;
                    break;

                case "-output":
                    output = args[++i];
                    if (!output.EndsWith(".kh2patch", StringComparison.InvariantCultureIgnoreCase))
                    {
                        output += ".kh2patch";
                    }
                    break;
                }
            }
            //TODO MENU
            if (log)
            {
                var filestream   = new FileStream("log.log", FileMode.Create);
                var streamwriter = new StreamWriter(filestream);
                streamwriter.AutoFlush = true;
                Console.SetOut(streamwriter);
                Console.SetError(streamwriter);
            }
            if (!batch)
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write("{0}\nVersion {1}", ISOTP.program.ProductName, ISOTP.ActualVersion);
                Console.ResetColor();
        #if PRIVATE
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("\nPRIVATE RELEASE\n");
                Console.ResetColor();
        #else
        #if DEBUG
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.Write("\nDEVELOPER RELEASE\n");
                Console.ResetColor();
        #else
                Console.Write("\nPUBLIC RELEASE\n");
        #endif
        #endif
                Console.ForegroundColor = ConsoleColor.DarkMagenta;
                Console.Write("\nProgrammed by {0}\nhttp://www.govanify.com\nhttp://www.twitter.com/GovanifY\nSoftware under GPL 2 license, for more info, use the command -license",
                              ISOTP.program.CompanyName);
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write(
                    "\n\nThis tool is able to create patches for the software KH2FM_Toolkit.\nIt can add files using the internal compression of the game \nKingdom Hearts 2(Final Mix), relink files to others, recreate\nthe iso without size limits and without corruption.\nThis patch system is the best ever made for this game atm.\n");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("\nPress enter to run using the file:");
                Console.ResetColor();
                Console.Write(" {0}", output);

                if (!batch)
                {
                    Console.ReadLine();
                }
            }
            if (uselog)
            {
                logfile = new System.IO.StreamReader(logtouse);
            }
            HashList.HashList.loadHashPairs(printInfo: true);
            if (!authorSet)
            {
                Console.Write("Enter author's name: ");
                if (!uselog)
                {
                    patch.Author = Console.ReadLine().Trim();
                }
                else
                {
                    patch.Author = logfile.ReadLine().Trim();
                }
            }
            if (!verSet)
            {
                Console.Write("Enter revision number: ");
                if (!uselog)
                {
                    while (!uint.TryParse(Console.ReadLine().Trim(), out patch.Version))
                    {
                        ISOTP.WriteWarning("\nInvalid number! ");
                    }
                }
                else
                {
                    while (!uint.TryParse(logfile.ReadLine().Trim(), out patch.Version))
                    {
                        ISOTP.WriteWarning("\nInvalid number! ");
                    }
                }
            }
            if (!changeSet)
            {
                Console.WriteLine("Enter changelog lines here (leave blank to continue):");
                do
                {
                    string inp;
                    if (!uselog)
                    {
                        inp = Console.ReadLine();
                    }
                    else
                    {
                        inp = logfile.ReadLine();
                    }
                    if (inp.Length == 0)
                    {
                        break;
                    }
                    patch.AddChange(inp);
                } while (true);
            }
            if (!creditSet)
            {
                Console.WriteLine("Enter credits here (leave blank to continue):");
                do
                {
                    string inp;
                    if (!uselog)
                    {
                        inp = Console.ReadLine();
                    }
                    else
                    {
                        inp = logfile.ReadLine();
                    }
                    if (inp.Length == 0)
                    {
                        break;
                    }
                    patch.AddCredit(inp);
                } while (true);
            }
            if (!otherSet)
            {
                Console.Write("Other information (leave blank to continue): ");
                string inp2 = "";
                bool   flag = false;
                do
                {
                    string inp;
                    if (!uselog)
                    {
                        inp = Console.ReadLine();
                    }
                    else
                    {
                        inp = logfile.ReadLine();
                    }
                    if (inp.Length == 0)
                    {
                        break;
                    }
                    if (flag)
                    {
                        inp2 += "\n" + inp;
                    }
                    else
                    {
                        inp2 += inp;
                    }
                    flag = true;
                } while (true);
                patch.OtherInfo = inp2;
            }
#if DEBUG
            Console.WriteLine("Filenames may be formatted as text (msg/jp/lk.bar) or hash (0x030b45da).");
#endif
            do
            {
                var file = new PatchFile.FileEntry();
                Console.Write("\nEnter filename: ");
                string name, rel;
                //Target file
                file.Hash = GetFileAsInput(out name, out otherSet);
                if (otherSet)
                {
                    break;
                }
                Console.WriteLine("  Using \"{0}\" for {1:X8}", name, file.Hash);
                //Relink
                Console.Write("Relink to this filename(ex: 000al.idx) [Blank for none]: ");
                file.Relink = GetFileHashAsInput(out rel);
                if (file.Relink == 0)
                {
                    try
                    {
                        file.Data = File.Open(name, FileMode.Open, FileAccess.Read, FileShare.Read);
                    }
                    catch (Exception e)
                    {
                        ISOTP.WriteWarning("Failed opening the file: " + e.Message);
                        continue;
                    }
                    file.name = Path.GetFileName(name);
                    if (file.Data.Length > int.MaxValue || file.Data.Length < 10)
                    {
                        ISOTP.WriteWarning("Too {0} to compress. Press enter.",
                                           (file.Data.Length < 10 ? "small" : "big"));
                        //Do this so the line count is the same whether we can compress or not.
                        Console.ReadLine();
                    }
                    else
                    {
                        //Compress
                        Console.Write("Compress this file? [Y/n] ");
                        file.IsCompressed = GetYesNoInput();
                    }
                }
                else
                {
                    Console.WriteLine("  Using \"{0}\" for {1:X8}", rel, file.Relink);
                }
                //Parent
                Console.Write("Parent compressed file [Leave blank for KH2]: ");
                file.ParentHash = GetFileHashAsInput(out rel);
                if (rel.Equals("KH2", StringComparison.InvariantCultureIgnoreCase))
                {
                    file.ParentHash = 0;
                }
                else if (rel.Equals("OVL", StringComparison.InvariantCultureIgnoreCase))
                {
                    file.ParentHash = 1;
                }
                else if (rel.Equals("ISO", StringComparison.InvariantCultureIgnoreCase))
                {
                    file.ParentHash = 2;
                }
                else
                {
                    switch (file.ParentHash)
                    {
                    case 0:
                        rel = "KH2";
                        break;

                    case 1:
                        rel = "OVL";
                        break;

                    case 2:
                        rel = "ISO";
                        break;
                    }
                }
                Console.WriteLine("  Using \"{0}\" for {1:X8}", rel, file.ParentHash);
                //IsNew
                Console.Write("Should this file be added if he's not in the game? [y/N] ");
                file.IsNewFile = GetYesNoInput();
                patch.Files.Add(file);
            } while (true);
            try
            {
                //TODO Compress(buffer>magic>Compress>Write to output). Files are already compressed, I need to look at this later
                using (FileStream fs = File.Open(output, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    if (encrypt)
                    {
                        patch.Write(fs);
                    }
                    else
                    {
                        patch.WriteDecrypted(fs);
                    }
                    if (batch)
                    {
                        Environment.Exit(0);
                    }
                }
            }
            catch (Exception e)
            {
                ISOTP.WriteWarning("Failed to save file: " + e.Message);
                ISOTP.WriteWarning(e.StackTrace);
                try
                {
                    File.Delete("output.kh2patch");
                }
                catch (Exception z)
                {
                    ISOTP.WriteWarning("Failed to delete file: " + z.Message);
                }
            }
            if (!batch)
            {
                Console.Write("Press enter to exit...");
                Console.ReadLine();
                Environment.Exit(0);
            }
        }
Пример #2
0
        internal static void Mainp(string[] args)
        {
            bool log = false;

            Console.Title = ISOTP.program.ProductName + " " + ISOTP.ActualVersion;
            var patch = new PatchFile();
            bool encrypt = false,
                batch = false,
                authorSet = false,
                verSet = false,
                changeSet = false,
                creditSet = false,
                otherSet = false;
            string output = "output.kh2patch";
            string logtouse = "none";
            for (int i = 0; i < args.Length; ++i)
            {
                switch (args[i].ToLowerInvariant())
                {
                    case "-xeeynamo":
                        DoXeey = true;
                        ISOTP.WriteWarning("Using Xeeynamo's encryption!");
                        break;
                    case "-batch":
                        batch = true;
                        break;
                    case "-log":
                        log = true;
                        break;
            #if DEBUG
                    case "-decrypted":
                        if (encrypt)
                        {
                            encrypt = false;
                            Console.WriteLine("Writing in decrypted mode!");
                        }
                        break;
            #endif
                    case "-hashverskip":
                        hvs = true;
                        break;
                    case "-version":
                        if (!uint.TryParse(args[++i].Trim(), out patch.Version))
                        {
                            patch.Version = 1;
                        }
                        else
                        {
                            verSet = true;
                        }
                        break;
                    case "-author":
                        patch.Author = args[++i];
                        authorSet = true;
                        break;
                    case "-other":
                        patch.OtherInfo = args[++i];
                        otherSet = true;
                        break;
                    case "-uselog":
                        logtouse = args[++i];
                        uselog = true;
                        break;
                    case "-changelog":
                        patch.AddChange(args[++i]);
                        break;
                    case "-skipchangelog":
                        changeSet = true;
                        break;
                    case "-fastpatch":
                        patch.fast_patch = true;
                        break;
                    case "-credits":
                        patch.AddCredit(args[++i]);
                        break;
                    case "-skipcredits":
                        creditSet = true;
                        break;
                    case "-uiswitch":
                        UISwitch = true;
                        break;
                    case "-newui":
                    case "-newinterface":
                        oldui =false;
                        break;
                    case "-output":
                        output = args[++i];
                        if (!output.EndsWith(".kh2patch", StringComparison.InvariantCultureIgnoreCase))
                        {
                            output += ".kh2patch";
                        }
                        break;
                }
            }
            //TODO MENU
            if (log)
            {
                var filestream = new FileStream("log.log", FileMode.Create);
                var streamwriter = new StreamWriter(filestream);
                streamwriter.AutoFlush = true;
                Console.SetOut(streamwriter);
                Console.SetError(streamwriter);
            }
            if (!batch)
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                    Console.Write("{0}\nVersion {1}", ISOTP.program.ProductName, ISOTP.ActualVersion);
                    Console.ResetColor();
            #if PRIVATE
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("\nPRIVATE RELEASE\n");
                    Console.ResetColor();
            #else
            #if DEBUG
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.Write("\nDEVELOPER RELEASE\n");
                    Console.ResetColor();
            #else

                    Console.Write("\nPUBLIC RELEASE\n");
            #endif
            #endif
                Console.ForegroundColor = ConsoleColor.DarkMagenta;
                Console.Write("\nProgrammed by {0}\nhttp://www.govanify.com\nhttp://www.twitter.com/GovanifY\nSoftware under GPL 2 license, for more info, use the command -license",
                    ISOTP.program.CompanyName);
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write(
                    "\n\nThis tool is able to create patches for the software KH2FM_Toolkit.\nIt can add files using the internal compression of the game \nKingdom Hearts 2(Final Mix), relink files to others, recreate\nthe iso without size limits and without corruption.\nThis patch system is the best ever made for this game atm.\n");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("\nPress enter to run using the file:");
                Console.ResetColor();
                Console.Write(" {0}", output);

                if (!batch)
                {
                    Console.ReadLine();
                }
            }
            if (uselog) {logfile = new System.IO.StreamReader(logtouse);}
            HashList.HashList.loadHashPairs(printInfo: true);
            if (!authorSet)
            {
                Console.Write("Enter author's name: ");
                if (!uselog) { patch.Author = Console.ReadLine().Trim(); } else { patch.Author = logfile.ReadLine().Trim(); }
            }
            if (!verSet)
            {
                Console.Write("Enter revision number: ");
                if (!uselog)
                {
                    while (!uint.TryParse(Console.ReadLine().Trim(), out patch.Version))
                    {
                        ISOTP.WriteWarning("\nInvalid number! ");
                    }
                }
                else
                {
                    while (!uint.TryParse(logfile.ReadLine().Trim(), out patch.Version))
                    {
                        ISOTP.WriteWarning("\nInvalid number! ");
                    }
                }
            }
            if (!changeSet)
            {
                Console.WriteLine("Enter changelog lines here (leave blank to continue):");
                do
                {
                    string inp;
                    if (!uselog) { inp = Console.ReadLine(); } else { inp = logfile.ReadLine(); }
                    if (inp.Length == 0)
                    {
                        break;
                    }
                    patch.AddChange(inp);
                } while (true);
            }
            if (!creditSet)
            {
                Console.WriteLine("Enter credits here (leave blank to continue):");
                do
                {
                    string inp;
                    if (!uselog) { inp = Console.ReadLine(); } else { inp = logfile.ReadLine(); }
                    if (inp.Length == 0)
                    {
                        break;
                    }
                    patch.AddCredit(inp);
                } while (true);
            }
            if (!otherSet)
            {
                Console.Write("Other information (leave blank to continue): ");
                string inp2 = "";
                bool flag = false;
                do
                {
                    string inp;
                    if (!uselog) { inp = Console.ReadLine(); } else { inp = logfile.ReadLine(); }
                    if (inp.Length == 0)
                    {
                        break;
                    }
                    if (flag)
                    {
                        inp2 += "\n" + inp;
                    }
                    else
                    {
                        inp2 += inp;
                    }
                    flag = true;
                } while (true);
                patch.OtherInfo = inp2;
            }
            #if DEBUG
            Console.WriteLine("Filenames may be formatted as text (msg/jp/lk.bar) or hash (0x030b45da).");
            #endif
            do
            {
                var file = new PatchFile.FileEntry();
                Console.Write("\nEnter filename: ");
                string name, rel;
                //Target file
                file.Hash = GetFileAsInput(out name, out otherSet);
                if (otherSet)
                {
                    break;
                }
                Console.WriteLine("  Using \"{0}\" for {1:X8}", name, file.Hash);
                //Relink
                Console.Write("Relink to this filename(ex: 000al.idx) [Blank for none]: ");
                file.Relink = GetFileHashAsInput(out rel);
                if (file.Relink == 0)
                {
                    try
                    {
                        file.Data = File.Open(name, FileMode.Open, FileAccess.Read, FileShare.Read);
                    }
                    catch (Exception e)
                    {
                        ISOTP.WriteWarning("Failed opening the file: " + e.Message);
                        continue;
                    }
                    file.name = Path.GetFileName(name);
                    if (file.Data.Length > int.MaxValue || file.Data.Length < 10)
                    {
                        ISOTP.WriteWarning("Too {0} to compress. Press enter.",
                            (file.Data.Length < 10 ? "small" : "big"));
                        //Do this so the line count is the same whether we can compress or not.
                        Console.ReadLine();
                    }
                    else
                    {
                        //Compress
                        Console.Write("Compress this file? [Y/n] ");
                        file.IsCompressed = GetYesNoInput();
                    }
                }
                else
                {
                    Console.WriteLine("  Using \"{0}\" for {1:X8}", rel, file.Relink);
                }
                //Parent
                Console.Write("Parent compressed file [Leave blank for KH2]: ");
                file.ParentHash = GetFileHashAsInput(out rel);
                if (rel.Equals("KH2", StringComparison.InvariantCultureIgnoreCase))
                {
                    file.ParentHash = 0;
                }
                else if (rel.Equals("OVL", StringComparison.InvariantCultureIgnoreCase))
                {
                    file.ParentHash = 1;
                }
                else if (rel.Equals("ISO", StringComparison.InvariantCultureIgnoreCase))
                {
                    file.ParentHash = 2;
                }
                else
                {
                    switch (file.ParentHash)
                    {
                        case 0:
                            rel = "KH2";
                            break;
                        case 1:
                            rel = "OVL";
                            break;
                        case 2:
                            rel = "ISO";
                            break;
                    }
                }
                Console.WriteLine("  Using \"{0}\" for {1:X8}", rel, file.ParentHash);
                //IsNew
                Console.Write("Should this file be added if he's not in the game? [y/N] ");
                file.IsNewFile = GetYesNoInput();
                patch.Files.Add(file);
            } while (true);
            try
            {
                //TODO Compress(buffer>magic>Compress>Write to output). Files are already compressed, I need to look at this later
                using (FileStream fs = File.Open(output, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    if (encrypt)
                    {
                        patch.Write(fs);
                    }
                    else
                    {
                        patch.WriteDecrypted(fs);
                    }
                    if (batch) {Environment.Exit(0);}
                }
            }
            catch (Exception e)
            {
                ISOTP.WriteWarning("Failed to save file: " + e.Message);
                ISOTP.WriteWarning(e.StackTrace);
                try
                {
                    File.Delete("output.kh2patch");
                }
                catch (Exception z)
                {
                    ISOTP.WriteWarning("Failed to delete file: " + z.Message);
                }
            }
            if (!batch)
            {
                Console.Write("Press enter to exit...");
                Console.ReadLine();
                Environment.Exit(0);
            }
        }