Exemple #1
0
 private static void WadIosNamingStuff(bool wad, string temp, string id, string version, string ios, bool NoOut, string output, string realout)
 {
     if (wad == true)
     {
         if (!File.Exists(Path.Combine(temp, id + "v" + version + ".wad")))
         {
             Console.WriteLine("ERROR: Can't find WAD");
             Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it.");
             Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_FILE_ERR_01");
             Environment.Exit(0x00003E81);
             return;
         }
         if (ios != "" && NoOut == true)
         {
             int index = realout.LastIndexOf("\\") > realout.LastIndexOf("/") ? realout.LastIndexOf("\\") : realout.LastIndexOf("/");
             if (File.Exists(realout.Substring(0, index + 1) + ios))
             {
                 File.Delete(realout.Substring(0, index + 1) + ios);
             }
             File.Move(Path.Combine(temp, id + "v" + version + ".wad"), realout.Substring(0, index + 1) + ios);
         }
         else if (ios == "" && NoOut == true)
         {
             if (File.Exists(realout + ".wad"))
             {
                 File.Delete(realout + ".wad");
             }
             File.Move(Path.Combine(temp, id + "v" + version + ".wad"), realout + ".wad");
         }
         else
         {
             if (File.Exists(realout))
             {
                 File.Delete(realout);
             }
             File.Move(Path.Combine(temp, id + "v" + version + ".wad"), realout);
         }
         DeleteADir.DeleteDirectory(temp);
     }
     else if (ios != "")
     {
         if (output.Substring(output.Length - 1, 1) == "\\" || output.Substring(output.Length - 1, 1) == "/")
         {
             output = output.Substring(output.Length - 1, 1);
         }
         if (File.Exists(Path.Combine(output, id + "v" + version + ".wad")))
         {
             if (File.Exists(Path.Combine(output, ios)))
             {
                 File.Delete(Path.Combine(output, ios));
             }
             File.Move(Path.Combine(output, id + "v" + version + ".wad"), Path.Combine(output, ios));
         }
     }
 }
Exemple #2
0
        private static void Install()
        {
            try
            {
                if (BeQuiet.quiet > 1)
                {
                    Console.WriteLine("Installing Sharpii...");
                }
                if (BeQuiet.quiet > 1)
                {
                    Console.WriteLine("Adding Variables");
                }
                Environment.SetEnvironmentVariable("PATH", Path.Combine(Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine), ";", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Sharpii"), EnvironmentVariableTarget.Machine);

                if (BeQuiet.quiet > 1)
                {
                    Console.WriteLine("Creating Directory");
                }
                if (Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Sharpii")))
                {
                    DeleteADir.DeleteDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Sharpii"));
                }
                Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Sharpii"));

                if (BeQuiet.quiet > 1)
                {
                    Console.WriteLine("Copying Files");
                }
                File.Copy(AppDomain.CurrentDomain.BaseDirectory, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Sharpii\\Sharpii.exe");
                if (File.Exists(Path.Combine(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory), "libWiiSharp.dll")))
                {
                    File.Copy(Path.Combine(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory), "libWiiSharp.dll"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Sharpii", "libWiiSharp.dll"));
                }
                if (File.Exists(Path.Combine(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory), "WadInstaller.dll")))
                {
                    File.Copy(Path.Combine(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory), "WadInstaller.dll"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Sharpii", "WadInstaller.dll"));
                }

                if (BeQuiet.quiet > 1)
                {
                    Console.WriteLine("Sharpii was successfully installed to: {0}", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Sharpii\\");
                    Console.WriteLine("You can now use Sharpii in any directory!");
                    Console.WriteLine("\nNOTE: You may need to restart your computer for this to take effect");
                }
                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine("An unknown error occured, please try again\n\nERROR DETAILS: {0}", ex.Message);
                Environment.Exit(0x00003E82);
                return;
            }
        }
Exemple #3
0
        private static void Editor(string[] args, bool edit)
        {
            //Setting up variables
            string input = args[2];
            string output = args[3];
            string id = "";
            int ios = -1;
            string title = "";
            string lwrid = "";
            bool fake = false;
            string sound = "";
            string banner = "";
            string icon = "";
            string app = "";

            //Check if file/folder exists
            if (edit == true)
                if (File.Exists(input) == false)
                {
                    Console.WriteLine("ERROR: Unable to open file: {0}", input);
                    Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it.");
                    Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01");
                    Environment.Exit(0x00003E81);
                    return;
                }
            if (edit == false)
                if (Directory.Exists(input) == false)
                {
                    Console.WriteLine("ERROR: Unable to open folder: {0}", input);
                    Console.WriteLine("Either the folder doesn't exist, or Sharpii doesn't have permission to open it.");
                    Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FOLDER_ERR_01");
                    Environment.Exit(0x00003E94);
                    return;
                }

            for (int i = 1; i < args.Length; i++)
            {
                switch (args[i].ToUpper())
                {
                    case "-F":
                        fake = true;
                        break;
                    case "-ID":
                        if (i + 1 >= args.Length)
                        {
                            Console.WriteLine("ERROR: No ID set");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_ID_01");
                            Environment.Exit(0x00003E8E);
                            return;
                        }
                        id = args[i + 1];
                        if (id.Length < 4)
                        {
                            Console.WriteLine("ERROR: ID too short");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_SHORT_ID_01");
                            Environment.Exit(0x00003E97);
                            return;
                        }
                        id = id.Substring(0, 4);
                        break;
                    case "-TYPE":
                        if (i + 1 >= args.Length)
                        {
                            Console.WriteLine("ERROR: No type set");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_TYPE_01");
                            Environment.Exit(0x00003E98);
                            return;
                        }
                        lwrid = args[i + 1].ToUpper();
                        if (lwrid != "CHANNEL" && lwrid != "DLC" && lwrid != "GAMECHANNEL" && lwrid != "HIDDENCHANNELS" && lwrid != "SYSTEMCHANNELS" && lwrid != "SYSTEMTITLES")
                        {
                            Console.WriteLine("ERROR: Unknown WAD type: {0}", args[i + 1]);
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_UNKNOWN_TYPE_01");
                            Environment.Exit(0x00003E99);
                            return;
                        }
                        break;
                    case "-IOS":
                        if (i + 1 >= args.Length)
                        {
                            Console.WriteLine("ERROR: No type set");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_TYPE_01");
                            Environment.Exit(0x00003E98);
                            return;
                        }
                        if (!int.TryParse(args[i + 1], out ios))
                        {
                            Console.WriteLine("Invalid slot {0}...", args[i + 1]);
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_INVALID_SLOT_01");
                            Environment.Exit(0x00003E8A);
                            return;
                        }
                        if (ios < 0 || ios > 255)
                        {
                            Console.WriteLine("Invalid slot {0}...", ios);
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_INVALID_SLOT_01");
                            Environment.Exit(0x00003E8A);
                            return;
                        }
                        break;
                    case "-TITLE":
                        if (i + 1 >= args.Length)
                        {
                            Console.WriteLine("ERROR: No title set");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_TITLE_01");
                            Environment.Exit(0x00003E95);
                            return;
                        }
                        title = args[i + 1];
                        break;
                    case "-SOUND":
                        if (i + 1 >= args.Length)
                        {
                            Console.WriteLine("ERROR: No sound set");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_SOUND_01");
                            Environment.Exit(0x00003E9A);
                            return;
                        }
                        sound = args[i + 1];
                        if (File.Exists(sound) == false)
                        {
                            Console.WriteLine("ERROR: Unable to find sound wad");
                            Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it.");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01");
                            Environment.Exit(0x00003E81);
                            return;
                        }
                        break;
                    case "-BANNER":
                        if (i + 1 >= args.Length)
                        {
                            Console.WriteLine("ERROR: No banner set");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_BANNER_01");
                            Environment.Exit(0x00003E9B);
                            return;
                        }
                        banner = args[i + 1];
                        if (File.Exists(banner) == false)
                        {
                            Console.WriteLine("ERROR: Unable to find banner wad");
                            Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it.");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01");
                            Environment.Exit(0x00003E81);
                            return;
                        }
                        break;
                    case "-ICON":
                        if (i + 1 >= args.Length)
                        {
                            Console.WriteLine("ERROR: No sound set");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_SOUND_01");
                            Environment.Exit(0x00003E9A);
                            return;
                        }
                        icon = args[i + 1];
                        if (File.Exists(icon) == false)
                        {
                            Console.WriteLine("ERROR: Unable to find icon wad");
                            Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it.");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01");
                            Environment.Exit(0x00003E81);
                            return;
                        }
                        break;
                    case "-DOL":
                        if (i + 1 >= args.Length)
                        {
                            Console.WriteLine("ERROR: No dol set");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_DOL_01");
                            Environment.Exit(0x00003E84);
                            return;
                        }
                        app = args[i + 1];
                        if (File.Exists(app) == false)
                        {
                            Console.WriteLine("ERROR: Unable to find dol wad/file");
                            Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it.");
                            Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01");
                            Environment.Exit(0x00003E81);
                            return;
                        }
                        break;
                }
            }

            //Run main part, and check for exceptions
            try
            {
                WAD wad = new WAD();

                if (edit == true)
                {
                    if (BeQuiet.quiet > 2)
                        Console.Write("Loading file...");
                    wad.LoadFile(input);
                }
                else
                {
                    if (BeQuiet.quiet > 2)
                        Console.Write("Loading folder...");
                    wad.CreateNew(input);
                }

                if (BeQuiet.quiet > 2)
                    Console.Write("Done!\n");

                if (sound != "" || banner != "" || icon != "" || app != "")
                {
                    string temp = Path.GetTempPath() + "Sharpii.tmp";
                    if (Directory.Exists(temp) == true)
                        DeleteADir.DeleteDirectory(temp);

                    Directory.CreateDirectory(temp);

                    wad.Unpack(Path.Combine(temp, "main"));
                    U8 u = new U8();
                    u.LoadFile(Path.Combine(temp, "main", "00000000.app"));
                    u.Extract(Path.Combine(temp, "main", "00000000"));

                    WAD twad = new WAD();

                    if (sound != "")
                    {
                        if (BeQuiet.quiet > 2)
                            Console.Write("Grabbing sound...");

                        twad.LoadFile(sound);
                        twad.Unpack(Path.Combine(temp + "sound"));
                        U8 tu = new U8();
                        tu.LoadFile(Path.Combine(temp, "sound", "00000000.app"));
                        tu.Extract(Path.Combine(temp, "sound", "00000000"));

                        File.Copy(Path.Combine(temp, "sound", "00000000", "meta", "sound.bin"), Path.Combine(temp, "main", "00000000", "meta", "sound.bin"), true);

                        if (BeQuiet.quiet > 2)
                            Console.Write("Done!\n");
                    }
                    if (banner != "")
                    {
                        if (BeQuiet.quiet > 2)
                            Console.Write("Grabbing banner...");

                        twad.LoadFile(banner);
                        twad.Unpack(Path.Combine(temp, "banner"));
                        U8 tu = new U8();
                        tu.LoadFile(Path.Combine(temp, "banner", "00000000.app"));
                        tu.Extract(Path.Combine(temp, "banner", "00000000"));

                        File.Copy(Path.Combine(temp, "banner", "00000000", "meta", "banner.bin"), Path.Combine(temp, "main", "00000000", "meta", "banner.bin"), true);

                        if (BeQuiet.quiet > 2)
                            Console.Write("Done!\n");
                    }
                    if (icon != "")
                    {
                        if (BeQuiet.quiet > 2)
                            Console.Write("Grabbing icon...");

                        twad.LoadFile(icon);
                        twad.Unpack(Path.Combine(temp, "icon"));
                        U8 tu = new U8();
                        tu.LoadFile(Path.Combine(temp, "icon", "00000000.app"));
                        tu.Extract(Path.Combine(temp, "icon", "00000000"));

                        File.Copy(Path.Combine(temp, "icon", "00000000", "meta", "icon.bin"), Path.Combine(temp, "main", "00000000", "meta", "icon.bin"), true);

                        if (BeQuiet.quiet > 2)
                            Console.Write("Done!\n");
                    }
                    if (app != "")
                    {
                        if (BeQuiet.quiet > 2)
                            Console.Write("Grabbing dol...");

                        if (app.Substring(app.Length - 4, 4) == ".dol")
                        {
                            Directory.CreateDirectory(Path.Combine(temp, "dol"));
                            File.Copy(app, Path.Combine(temp, "dol", "00000001.app"));
                        }
                        else
                        {
                            twad.LoadFile(app);
                            twad.Unpack(Path.Combine(temp, "dol"));
                        }

                        File.Copy(Path.Combine(temp, "dol", "00000001.app"), Path.Combine(temp, "main", "00000001.app"), true);

                        if (BeQuiet.quiet > 2)
                            Console.Write("Done!\n");
                    }
                    u.ReplaceFile(1, Path.Combine(temp, "main", "00000000", "meta", "banner.bin"));
                    u.ReplaceFile(2, Path.Combine(temp, "main", "00000000", "meta", "icon.bin"));
                    u.ReplaceFile(3, Path.Combine(temp, "main", "00000000", "meta", "sound.bin"));
                    u.Save(Path.Combine(temp, "main", "00000000.app"));
                    DeleteADir.DeleteDirectory(Path.Combine(temp, "main", "00000000"));
                    wad.CreateNew(Path.Combine(temp, "main"));
                    DeleteADir.DeleteDirectory(temp);
                }

                if (BeQuiet.quiet > 2 && fake == true)
                    Console.WriteLine("FakeSigning WAD");
                wad.FakeSign = fake;

                if (id != "" || lwrid != "")
                {
                    if (id != "")
                    {
                        if (BeQuiet.quiet > 2)
                            Console.WriteLine("Changing channel ID to: {0}", id);
                    }
                    else
                    {
                        id = wad.UpperTitleID;
                    }

                    if (lwrid != "")
                    {
                        if (BeQuiet.quiet > 2)
                            Console.WriteLine("Changing channel type to: {0}", lwrid);
                    }
                    else
                    {
                        lwrid = "CHANNEL";
                    }

                    if (lwrid == "CHANNEL")
                        wad.ChangeTitleID(LowerTitleID.Channel, id);
                    else if (lwrid == "DLC")
                        wad.ChangeTitleID(LowerTitleID.DLC, id);
                    else if (lwrid == "GAMECHANNEL")
                        wad.ChangeTitleID(LowerTitleID.GameChannel, id);
                    else if (lwrid == "HIDDENCHANNELS")
                        wad.ChangeTitleID(LowerTitleID.HiddenChannels, id);
                    else if (lwrid == "SYSTEMCHANNELS")
                        wad.ChangeTitleID(LowerTitleID.SystemChannels, id);
                    else if (lwrid == "SYSTEMTITLES")
                        wad.ChangeTitleID(LowerTitleID.SystemTitles, id);
                }
                if (ios > -1)
                {
                    if (BeQuiet.quiet > 2)
                        Console.WriteLine("Changing startup IOS to: {0}", ios);
                    wad.ChangeStartupIOS(ios);
                }
                if (title != "")
                {
                    if (BeQuiet.quiet > 2)
                        Console.WriteLine("Changing channel title to: {0}", title);
                    wad.ChangeChannelTitles(title);
                }

                if (BeQuiet.quiet > 2)
                    Console.Write("Saving file...");

                if (output.Substring(output.Length - 4, 4).ToUpper() != ".WAD")
                    output = output + ".wad";

                wad.Save(output);

                if (BeQuiet.quiet > 2)
                    Console.Write("Done!\n");

                if (BeQuiet.quiet > 1)
                    Console.WriteLine("Operation completed succesfully!");
            }
            catch (Exception ex)
            {
                if (ex.Message == "Index was outside the bounds of the array.")
                {
                    Console.WriteLine("You need to have all the required .app files, a tmd file, a tik file, and a cert file to do this.");
                    Console.WriteLine("");
                    Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_MISSING_FILES_01");
                    ExceptionListRan = 1;
                    Environment.Exit(0x00003E9D);
                }
                if (ExceptionListRan == 0)
                {
                    Console.WriteLine("An unknown error occured, please try again");
                    Console.WriteLine("");
                    Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
                    Console.WriteLine("Error: SHARPII_NET_CORE_WAD_UNKNOWN_01");
                    Environment.Exit(0x00003E82);
                }  
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                help();
                Environment.Exit(0);
            }

            if (!File.Exists(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + Path.DirectorySeparatorChar + "libWiiSharp.dll"))
            {
                Console.WriteLine("ERROR: libWiiSharp.dll not found");
                Console.WriteLine("This should not appear on the .Net Core port.");
                Console.WriteLine("If you see this, report how you got here on https://github.com/TheShadowEevee/Sharpii-NetCore/issues.");
                Console.WriteLine("Error: SHARPII_NET_CORE_MAIN_MISSING_DLL_LIBWIISHARP_01");
                Environment.Exit(0x00003E8F);
            }

            for (int i = 1; i < args.Length; i++)
            {
                switch (args[i].ToUpper())
                {
                case "-QUIET":
                    BeQuiet.quiet = 1;
                    break;

                case "-Q":
                    BeQuiet.quiet = 1;
                    break;

                case "-LOTS":
                    BeQuiet.quiet = 3;
                    break;

                case "-NOLOG":
                    Logging.log = 0;
                    break;
                }
            }

            string Function     = args[0].ToUpper();
            bool   gotSomewhere = false;

            if (Function == "-H" || Function == "-HELP" || Function == "H" || Function == "HELP")
            {
                help();
                gotSomewhere = true;
            }

            if (Function == "BNS")
            {
                BNS_Stuff.BNS(args);
                gotSomewhere = true;
            }

            if (Function == "WAD")
            {
                WAD_Stuff.WAD(args);
                gotSomewhere = true;
            }

            if (Function == "TPL")
            {
                TPL_Stuff.TPL(args);
                gotSomewhere = true;
            }

            if (Function == "U8")
            {
                U8_Stuff.U8(args);
                gotSomewhere = true;
            }

            if (Function == "IOS")
            {
                IOS_Stuff.IOS(args);
                gotSomewhere = true;
            }

            if (Function == "NUS" || Function == "NUSD")
            {
                NUS_Stuff.NUS(args);
                gotSomewhere = true;
            }

            if (Function == "SENDDOL" || Function == "SENDOL")
            {
                HBC_Stuff.SendDol(args);
                gotSomewhere = true;
            }

            if (Function == "SENDWAD")
            {
                bool cont = HBC_Stuff.SendWad_Check(args);
                if (cont == true)
                {
                    HBC_Stuff.SendWad(args);
                }
                gotSomewhere = true;
            }

            if (Function == "INSTALL")
            {
                Install();
                gotSomewhere = true;
            }

            if (Function == "UNINSTALL")
            {
                Uninstall();
                gotSomewhere = true;
            }

            if (Function == "ERRORS")
            {
                ERROR_Stuff.ERROR(args);
                gotSomewhere = true;
            }

            if (Function == "EXITCODES")
            {
                ERRORCODE_Stuff.ERRORCODE(args);
                gotSomewhere = true;
            }

            if (Function == "WHICH CAME FIRST" || Function == "WHICH CAME FIRST?" ||
                (Function == "WHICH" && args[1].ToUpper() == "CAME" && args[2].Substring(0, 5).ToUpper() == "FIRST"))
            {
                InconspicuousNotEasterEggThingamajig();
                gotSomewhere = true;
            }



            if (gotSomewhere == false)
            {
                //If tuser gets here, they entered something wrong
                Console.WriteLine("ERROR: The argument {0} is invalid", args[0]);
                Console.WriteLine("Error: SHARPII_NET_CORE_MAIN_INVALID_ARG_01");
                Environment.Exit(0x00003E90);
            }

            string temp = Path.GetTempPath() + "Sharpii.tmp";

            if (Directory.Exists(temp) == true)
            {
                DeleteADir.DeleteDirectory(temp);
            }

            Environment.Exit(0);
        }
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Help();
                Environment.Exit(0);
            }

            for (int i = 1; i < args.Length; i++)
            {
                switch (args[i].ToUpper())
                {
                case "-QUIET":
                    BeQuiet.quiet = 1;
                    break;

                case "-Q":
                    BeQuiet.quiet = 1;
                    break;

                case "-LOTS":
                    BeQuiet.quiet = 3;
                    break;
                }
            }

            string Function     = args[0].ToUpper();
            bool   gotSomewhere = false;

            if (Function == "-H" || Function == "-HELP" || Function == "H" || Function == "HELP")
            {
                Help();
                gotSomewhere = true;
            }

            if (Function == "BNS")
            {
                BNS_Stuff.BNS(args);
                gotSomewhere = true;
            }

            if (Function == "WAD")
            {
                WAD_Stuff.WAD(args);
                gotSomewhere = true;
            }

            if (Function == "TPL")
            {
                TPL_Stuff.TPL(args);
                gotSomewhere = true;
            }

            if (Function == "U8")
            {
                U8_Stuff.U8(args);
                gotSomewhere = true;
            }

            if (Function == "IOS")
            {
                IOS_Stuff.IOS(args);
                gotSomewhere = true;
            }

            if (Function == "NUS" || Function == "NUSD")
            {
                NUS_Stuff.NUS(args, false);
                gotSomewhere = true;
            }

            if (Function == "SENDDOL" || Function == "SENDOL")
            {
                HBC_Stuff.SendDol(args);
                gotSomewhere = true;
            }

            if (Function == "SENDWAD")
            {
                bool cont = HBC_Stuff.SendWad_Check(args);
                if (cont == true)
                {
                    HBC_Stuff.SendWad(args);
                }
                gotSomewhere = true;
            }

            if (Function == "ERRORS")
            {
                ERROR_Stuff.ERROR(args);
                gotSomewhere = true;
            }

            if (Function == "EXITCODES")
            {
                ERRORCODE_Stuff.ERRORCODE(args);
                gotSomewhere = true;
            }

            if (gotSomewhere == false)
            {
                //If the user gets here, they entered something wrong
                Console.WriteLine("ERROR: The argument {0} is invalid", args[0]);
                Console.WriteLine("Error: SHARPII_NET_CORE_MAIN_INVALID_ARG");
                if (OperatingSystem.Windows())
                {
                    Environment.Exit(0x00003E90);
                }
                else
                {
                    Environment.Exit(0x00000012);
                }
                return;
            }

            string temp = Path.GetTempPath() + "Sharpii.tmp";

            if (Directory.Exists(temp) == true)
            {
                DeleteADir.DeleteDirectory(temp);
            }

            Environment.Exit(0);
        }
        public static void NUS(string[] args, bool SecondRun)
        {
            if (args.Length < 2)
            {
                NUS_help();
                return;
            }
            if (args[1].ToUpper() == "-H" || args[1].ToUpper() == "-HELP")
            {
                NUS_help();
                return;
            }

            //Set up variables
            string           id      = "";
            string           content = "";
            string           version = "";
            int              intver  = -1;
            string           output  = "";
            bool             local   = false;
            List <StoreType> store   = new List <StoreType>();
            bool             entered = false;
            bool             wad     = false;
            bool             NoOut   = false;
            string           ios     = "";
            string           temp    = Path.GetTempPath() + "Sharpii.tmp";
            bool             ContinueWithoutTicket = false;

            //Remove need for CETK
            if (SecondRun == true)
            {
                ContinueWithoutTicket = true;
            }

            //Get arguments
            for (int i = 1; i < args.Length; i++)
            {
                switch (args[i].ToUpper())
                {
                case "-ALL":
                    store.Add(StoreType.All);
                    entered = true;
                    break;

                case "-WAD":
                    store.Add(StoreType.WAD);
                    entered = true;
                    break;

                case "-ENCRYPT":
                    store.Add(StoreType.EncryptedContent);
                    entered = true;
                    break;

                case "-ENCRYPTED":
                    store.Add(StoreType.EncryptedContent);
                    entered = true;
                    break;

                case "-DECRYPT":
                    store.Add(StoreType.DecryptedContent);
                    entered = true;
                    break;

                case "-DECRYPTED":
                    store.Add(StoreType.DecryptedContent);
                    entered = true;
                    break;

                case "-LOCAL":
                    local = true;
                    break;

                case "-V":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No version set");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_VERSION");
                        if (OperatingSystem.Windows())
                        {
                            Environment.Exit(0x00003E8B);
                        }
                        else
                        {
                            Environment.Exit(0x0000000D);
                        }
                        return;
                    }
                    version = args[i + 1];
                    if (version.ToUpper() == "LATEST")
                    {
                        break;
                    }
                    if (!int.TryParse(version, out intver))
                    {
                        Console.WriteLine("Invalid version {0}...", args[i + 1]);
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_INVALID_VERSION");
                        if (OperatingSystem.Windows())
                        {
                            Environment.Exit(0x00003E8C);
                        }
                        else
                        {
                            Environment.Exit(0x0000000E);
                        }
                        return;
                    }
                    if (intver < 0 || intver > 65535)
                    {
                        Console.WriteLine("Invalid version {0}...", version);
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_INVALID_VERSION");
                        if (OperatingSystem.Windows())
                        {
                            Environment.Exit(0x00003E8C);
                        }
                        else
                        {
                            Environment.Exit(0x0000000E);
                        }
                        return;
                    }
                    break;

                case "-VERSION":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No version set");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_VERSION");
                        if (OperatingSystem.Windows())
                        {
                            Environment.Exit(0x00003E8B);
                        }
                        else
                        {
                            Environment.Exit(0x0000000D);
                        }
                        return;
                    }
                    version = args[i + 1];
                    if (version.ToUpper() == "LATEST")
                    {
                        break;
                    }
                    if (!int.TryParse(version, out intver))
                    {
                        Console.WriteLine("Invalid version {0}...", args[i + 1]);
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_INVALID_VERSION");
                        if (OperatingSystem.Windows())
                        {
                            Environment.Exit(0x00003E8C);
                        }
                        else
                        {
                            Environment.Exit(0x0000000E);
                        }
                        return;
                    }
                    if (intver < 0 || intver > 65535)
                    {
                        Console.WriteLine("Invalid version {0}...", version);
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_INVALID_VERSION");
                        if (OperatingSystem.Windows())
                        {
                            Environment.Exit(0x00003E8C);
                        }
                        else
                        {
                            Environment.Exit(0x0000000E);
                        }
                        return;
                    }
                    break;

                case "-O":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No output set");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_OUTPUT");
                        if (OperatingSystem.Windows())
                        {
                            Environment.Exit(0x00003E8D);
                        }
                        else
                        {
                            Environment.Exit(0x0000000F);
                        }
                        return;
                    }
                    output = args[i + 1];
                    break;

                case "-ID":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No ID specified");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_ID");
                        if (OperatingSystem.Windows())
                        {
                            Environment.Exit(0x00003E8E);
                        }
                        else
                        {
                            Environment.Exit(0x00000010);
                        }
                        return;
                    }
                    id = args[i + 1];
                    id = id.ToUpper();
                    break;

                case "-IOS":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No IOS specified");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_IOS");
                        if (OperatingSystem.Windows())
                        {
                            Environment.Exit(0x00003E86);
                        }
                        else
                        {
                            Environment.Exit(0x00000008);
                        }
                        return;
                    }
                    id = "00000001000000" + Convert.ToInt32(args[i + 1]).ToString("X2");
                    break;

                case "-SINGLE":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No ID specified");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_ID");
                        if (OperatingSystem.Windows())
                        {
                            Environment.Exit(0x00003E8E);
                        }
                        else
                        {
                            Environment.Exit(0x00000010);
                        }
                        return;
                    }
                    content = args[i + 1];
                    break;

                case "-S":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No ID specified");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_ID");
                        if (OperatingSystem.Windows())
                        {
                            Environment.Exit(0x00003E8E);
                        }
                        else
                        {
                            Environment.Exit(0x00000010);
                        }
                        return;
                    }
                    content = args[i + 1];
                    break;
                }
            }

            //Error checking & stuff
            if (id == "")
            {
                Console.WriteLine("ERROR: No ID specified");
                Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_ID");
                if (OperatingSystem.Windows())
                {
                    Environment.Exit(0x00003E8E);
                }
                else
                {
                    Environment.Exit(0x00000010);
                }
                return;
            }

            if (version == "")
            {
                if (BeQuiet.quiet > 2)
                {
                    Console.WriteLine("No version specified, using latest", version);
                }
                version = "LATEST";
            }

            try
            {
                if (version.ToUpper() == "LATEST")
                {
                    //Grab the TMD and get the latest version
                    NusClient grabtmd = new NusClient();
                    TMD       tmd     = grabtmd.DownloadTMD(id, "");
                    version = tmd.TitleVersion.ToString();
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "Title ID must be 16 characters long!")
                {
                    Console.WriteLine("");
                    Console.WriteLine("The ID needs to be 16 Characters.");
                    Console.WriteLine("");
                    Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_BAD_ID");
                    Console.WriteLine("");
                    if (OperatingSystem.Windows())
                    {
                        Environment.Exit(0x00003E9C);
                    }
                    else
                    {
                        Environment.Exit(0x0000001E);
                    }
                    return;
                }
                if (ex.Message == "The remote server returned an error: (404) Not Found.")
                {
                    Console.WriteLine("");
                    Console.WriteLine("The remote server returned a 404 error. Check your Title ID.");
                    Console.WriteLine("");
                    Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_REMOTE_404");
                    Console.WriteLine("");
                    if (OperatingSystem.Windows())
                    {
                        Environment.Exit(0x00003E9E);
                    }
                    else
                    {
                        Environment.Exit(0x00000020);
                    }
                    return;
                }
                if (ExceptionListRan == 0)
                {
                    Console.WriteLine("An unknown error occured, please try again");
                    Console.WriteLine("");
                    Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
                    Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_UNKNOWN");
                    if (OperatingSystem.Windows())
                    {
                        Environment.Exit(0x00003E82);
                    }
                    else
                    {
                        Environment.Exit(0x00000004);
                    }
                    return;
                }
            }
            if (BeQuiet.quiet > 2)
            {
                Console.WriteLine("Found latest version: v{0}", version);
            }

            if (entered == false) //Will only be false if no store type argument was given
            {
                store.Add(StoreType.All);
                if (BeQuiet.quiet > 2)
                {
                    Console.WriteLine("No store type specified, using all");
                }
            }

            if (id.Length == 16 && Convert.ToInt32(id.Substring(14, 2), 16) >= 3 && Convert.ToInt32(id.Substring(14, 2), 16) <= 255 && id.Substring(0, 14) == "00000001000000")
            {
                ios = "IOS" + Convert.ToInt32(id.Substring(14, 2), 16) + "-64-" + version + ".wad";
            }

            if ((((output.Length >= 4 && output.Substring(output.Length - 4, 4).ToUpper() == ".WAD") || output == "") && Array.IndexOf(store.ToArray(), StoreType.WAD) != -1 && store.ToArray().Length == 1) || (output == "" && ios != "" && Array.IndexOf(store.ToArray(), StoreType.WAD) != -1 && store.ToArray().Length == 1))
            {
                wad = true;
                if (Directory.Exists(temp) == true)
                {
                    DeleteADir.DeleteDirectory(temp);
                }

                Directory.CreateDirectory(temp);
            }

            if (output == "")
            {
                NoOut  = true;
                output = ios == "" ? id + "v" + version : ios[0..^ 4];
Exemple #7
0
        public static void NUS(string[] args)
        {
            if (args.Length < 2)
            {
                NUS_help();
                return;
            }
            if (args[1].ToUpper() == "-H" || args[1].ToUpper() == "-HELP")
            {
                NUS_help();
                return;
            }

            //Set up variables
            string           id      = "";
            string           content = "";
            string           version = "";
            int              intver  = -1;
            string           output  = "";
            bool             local   = false;
            List <StoreType> store   = new List <StoreType>();
            bool             entered = false;
            bool             wad     = false;
            bool             NoOut   = false;
            string           ios     = "";
            string           temp    = Path.GetTempPath() + "Sharpii.tmp";

            //Get arguments
            for (int i = 1; i < args.Length; i++)
            {
                switch (args[i].ToUpper())
                {
                case "-ALL":
                    store.Add(StoreType.All);
                    entered = true;
                    break;

                case "-WAD":
                    store.Add(StoreType.WAD);
                    entered = true;
                    break;

                case "-ENCRYPT":
                    store.Add(StoreType.EncryptedContent);
                    entered = true;
                    break;

                case "-ENCRYPTED":
                    store.Add(StoreType.EncryptedContent);
                    entered = true;
                    break;

                case "-DECRYPT":
                    store.Add(StoreType.DecryptedContent);
                    entered = true;
                    break;

                case "-DECRYPTED":
                    store.Add(StoreType.DecryptedContent);
                    entered = true;
                    break;

                case "-LOCAL":
                    local = true;
                    break;

                case "-V":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No version set");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_VERSION_01");
                        Environment.Exit(0x00003E8B);
                        return;
                    }
                    version = args[i + 1];
                    if (version.ToUpper() == "LATEST")
                    {
                        break;
                    }
                    if (!int.TryParse(version, out intver))
                    {
                        Console.WriteLine("Invalid version {0}...", args[i + 1]);
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_INVALID_VERSION_01");
                        Environment.Exit(0x00003E8C);
                        return;
                    }
                    if (intver < 0 || intver > 65535)
                    {
                        Console.WriteLine("Invalid version {0}...", version);
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_INVALID_VERSION_01");
                        Environment.Exit(0x00003E8C);
                        return;
                    }
                    break;

                case "-VERSION":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No version set");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_VERSION_01");
                        Environment.Exit(0x00003E8B);
                        return;
                    }
                    version = args[i + 1];
                    if (version.ToUpper() == "LATEST")
                    {
                        break;
                    }
                    if (!int.TryParse(version, out intver))
                    {
                        Console.WriteLine("Invalid version {0}...", args[i + 1]);
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_INVALID_VERSION_01");
                        Environment.Exit(0x00003E8C);
                        return;
                    }
                    if (intver < 0 || intver > 65535)
                    {
                        Console.WriteLine("Invalid version {0}...", version);
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_INVALID_VERSION_01");
                        Environment.Exit(0x00003E8C);
                        return;
                    }
                    break;

                case "-O":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No output set");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_OUTPUT_01");
                        Environment.Exit(0x00003E8D);
                        return;
                    }
                    output = args[i + 1];
                    break;

                case "-ID":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No ID specified");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_ID_01");
                        Environment.Exit(0x00003E8E);
                        return;
                    }
                    id = args[i + 1];
                    break;

                case "-IOS":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No IOS specified");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_IOS_01");
                        Environment.Exit(0x00003E86);
                        return;
                    }
                    id = "00000001000000" + Convert.ToInt32(args[i + 1]).ToString("X2");
                    break;

                case "-SINGLE":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No ID specified");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_ID_01");
                        Environment.Exit(0x00003E8E);
                        return;
                    }
                    content = args[i + 1];
                    break;

                case "-S":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("ERROR: No ID specified");
                        Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_ID_01");
                        Environment.Exit(0x00003E8E);
                        return;
                    }
                    content = args[i + 1];
                    break;
                }
            }

            //Error checking & stuff
            if (id == "")
            {
                Console.WriteLine("ERROR: No ID specified");
                Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_NO_ID_01");
                Environment.Exit(0x00003E8E);
                return;
            }

            if (version == "")
            {
                if (BeQuiet.quiet > 2)
                {
                    Console.WriteLine("No version specified, using latest", version);
                }
                version = "LATEST";
            }

            try
            {
                if (version.ToUpper() == "LATEST")
                {
                    //Grab the TMD and get the latest version
                    NusClient grabtmd = new NusClient();
                    TMD       tmd     = grabtmd.DownloadTMD(id, "");
                    version = tmd.TitleVersion.ToString();
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "Title ID must be 16 characters long!")
                {
                    Console.WriteLine("");
                    Console.WriteLine("The ID needs to be 16 Characters.");
                    Console.WriteLine("");
                    Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_BAD_ID_01");
                    Console.WriteLine("");
                    Environment.Exit(0x00003E9C);
                    return;
                }
                if (ex.Message == "The remote server returned an error: (404) Not Found.")
                {
                    Console.WriteLine("");
                    Console.WriteLine("The ID is not a valid title ID");
                    Console.WriteLine("");
                    Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_BAD_ID_01");
                    Console.WriteLine("");
                    Environment.Exit(0x00003E9C);
                    return;
                }
            }
            if (BeQuiet.quiet > 2)
            {
                Console.WriteLine("Found latest version: v{0}", version);
            }

            if (entered == false) //Will only be false if no store type argument was given
            {
                store.Add(StoreType.All);
                if (BeQuiet.quiet > 2)
                {
                    Console.WriteLine("No store type specified, using all");
                }
            }

            if (id.Length == 16 && Convert.ToInt32(id.Substring(14, 2), 16) >= 3 && Convert.ToInt32(id.Substring(14, 2), 16) <= 255 && id.Substring(0, 14) == "00000001000000")
            {
                ios = "IOS" + Convert.ToInt32(id.Substring(14, 2), 16) + "-64-" + version + ".wad";
            }

            if ((((output.Length >= 4 && output.Substring(output.Length - 4, 4).ToUpper() == ".WAD") || output == "") && Array.IndexOf(store.ToArray(), StoreType.WAD) != -1 && store.ToArray().Length == 1) || (output == "" && ios != "" && Array.IndexOf(store.ToArray(), StoreType.WAD) != -1 && store.ToArray().Length == 1))
            {
                wad = true;
                if (Directory.Exists(temp) == true)
                {
                    DeleteADir.DeleteDirectory(temp);
                }

                Directory.CreateDirectory(temp);
            }

            if (output == "")
            {
                NoOut  = true;
                output = ios == "" ? id + "v" + version : ios.Substring(0, ios.Length - 4);
                if (BeQuiet.quiet > 2)
                {
                    Console.WriteLine("No output specified, using {0}", output);
                }
            }

            //Main part, catches random/unexpected exceptions
            try
            {
                NusClient nus = new NusClient();

                if (local == true)
                {
                    if (BeQuiet.quiet > 2)
                    {
                        Console.WriteLine("Using local files if present...");
                    }
                    nus.UseLocalFiles = true;
                }


                if (content != "")
                {
                    if (BeQuiet.quiet > 1)
                    {
                        Console.Write("Downloading content...");
                    }

                    nus.DownloadSingleContent(id, version, content, output);

                    if (BeQuiet.quiet > 1)
                    {
                        Console.Write("Done!\n");
                    }
                }
                else
                {
                    if (BeQuiet.quiet > 1)
                    {
                        Console.Write("Downloading title...");
                    }

                    string realout = output;
                    if (wad == true)
                    {
                        output = temp;
                    }

                    nus.DownloadTitle(id, version, output, store.ToArray());

                    WadIosNamingStuff(wad, temp, id, version, ios, NoOut, output, realout);

                    if (BeQuiet.quiet > 1)
                    {
                        Console.Write("Done!\n");
                    }
                }

                if (BeQuiet.quiet > 1)
                {
                    Console.WriteLine("Operation completed succesfully!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("An unknown error occured, please try again");
                Console.WriteLine("");
                Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
                Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_UNKNOWN_01");
                Environment.Exit(0x00003E82);
                return;
            }

            return;
        }