Пример #1
0
        private void startDownload(object titleList)
        {
            try
            {
                setControls(false);
                List <string[]>  titles    = (List <string[]>)titleList;
                List <StoreType> storeList = new List <StoreType>();

                if (storeTypes[0])
                {
                    storeList.Add(StoreType.EncryptedContent);
                }
                if (storeTypes[1])
                {
                    storeList.Add(StoreType.DecryptedContent);
                }
                if (storeTypes[2])
                {
                    storeList.Add(StoreType.WAD);
                }

                foreach (string[] thisTitle in titles)
                {
                    try { nusClient.DownloadTitle(thisTitle[0], thisTitle[1], Application.StartupPath + Path.DirectorySeparatorChar + thisTitle[0] + (string.IsNullOrEmpty(thisTitle[1]) ? string.Empty : "v" + thisTitle[1]), storeList.ToArray()); }
                    catch { }
                }
            }
            finally
            {
                this.Invoke(new MethodInvoker(this.uncheckNodes));
                setControls(true);
            }
        }
Пример #2
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;
        }
        private void BuildNand()
        {
            // Deletage to fire current action description
            objectInvoker delegateMethodeLabelLog       = new objectInvoker(this.updateLabelLog);
            objectInvoker delegateMethodeLog            = new objectInvoker(this.updateLog);
            objectInvoker delegateMethodeGlobalProgress = new objectInvoker(this.initGlobalProgress);

            // IOS list
            List <string[]> titleList = new List <string[]>();

            // Temp directory
            string tmpPath = Path.GetTempPath();

            // System Menu and his IOS.
            switch (this.sysMenu)
            {
            case "4.2J":
                // System Menu
                titleList.Add(new string[2] {
                    "0000000100000002", "480"
                });
                // IOS70
                titleList.Add(new string[2] {
                    "0000000100000046", "6944"
                });
                break;

            case "4.2U":
                // System Menu
                titleList.Add(new string[2] {
                    "0000000100000002", "481"
                });
                // IOS70
                titleList.Add(new string[2] {
                    "0000000100000046", "6944"
                });
                break;

            case "4.2E":
                // System Menu
                titleList.Add(new string[2] {
                    "0000000100000002", "482"
                });
                // IOS70
                titleList.Add(new string[2] {
                    "0000000100000046", "6944"
                });
                break;

            case "4.3J":
                // System Menu
                titleList.Add(new string[2] {
                    "0000000100000002", "512"
                });
                // IOS80
                titleList.Add(new string[2] {
                    "0000000100000050", "6944"
                });
                break;

            case "4.3U":
                // System Menu
                titleList.Add(new string[2] {
                    "0000000100000002", "513"
                });
                // IOS80
                titleList.Add(new string[2] {
                    "0000000100000050", "6944"
                });
                break;

            case "4.3E":
                // System Menu
                titleList.Add(new string[2] {
                    "0000000100000002", "514"
                });
                // IOS80
                titleList.Add(new string[2] {
                    "0000000100000050", "6944"
                });
                break;

            default:
                throw new Exception("Invalid System Menu !!");
            }

            // Full list of usefull IOS
            if (this.fullNand)
            {
                // IOS28
                titleList.Add(new string[2] {
                    "000000010000001C", "1807"
                });
                // IOS31
                titleList.Add(new string[2] {
                    "000000010000001F", "3608"
                });
                // IOS33
                titleList.Add(new string[2] {
                    "0000000100000021", "3608"
                });
                // IOS34
                titleList.Add(new string[2] {
                    "0000000100000022", "3608"
                });
                // IOS35
                titleList.Add(new string[2] {
                    "0000000100000023", "3608"
                });
                // IOS36
                titleList.Add(new string[2] {
                    "0000000100000024", "3608"
                });
                // IOS37
                titleList.Add(new string[2] {
                    "0000000100000025", "5663"
                });
                // IOS38
                titleList.Add(new string[2] {
                    "0000000100000026", "4124"
                });
                // IOS53
                titleList.Add(new string[2] {
                    "0000000100000035", "5663"
                });
                // IOS55
                titleList.Add(new string[2] {
                    "0000000100000037", "5663"
                });
                // IOS56
                titleList.Add(new string[2] {
                    "0000000100000038", "5662"
                });
                // IOS57
                titleList.Add(new string[2] {
                    "0000000100000039", "5919"
                });
                // IOS61
                titleList.Add(new string[2] {
                    "000000010000003D", "5662"
                });
            }

            IAsyncResult r = this.BeginInvoke(delegateMethodeGlobalProgress, ((titleList.Count * 2) + 1));

            this.EndInvoke(r);

            delegateMethodeGlobalProgress = new objectInvoker(this.updateGlobalProgress);

            try
            {
                int cptProgress = 0;

                foreach (string[] title in titleList)
                {
                    string currentWadFileName = String.Format("{0}v{1}.wad", title[0], title[1]);

                    if (!isStopRequired)
                    {
                        if (title[0] == "0000000100000002")
                        {
                            this.Invoke(delegateMethodeLabelLog, "Downloading System Menu " + this.sysMenu);
                        }
                        else
                        {
                            this.Invoke(delegateMethodeLabelLog, "Downloading IOS" + Wii.Tools.HexStringToInt(title[0].Substring(8)) + "v" + title[1]);
                        }

                        nusClient.DownloadTitle(title[0], title[1], tmpPath, StoreType.WAD);

                        cptProgress++;
                        this.Invoke(delegateMethodeGlobalProgress, cptProgress);
                    }
                    else
                    {
                        break;
                    }

                    if (!isStopRequired)
                    {
                        this.Invoke(delegateMethodeLabelLog, "Installing Downloaded File");
                        this.Invoke(delegateMethodeLog, "Installing Downloaded File");

                        Wii.WadUnpack.UnpackToNand(tmpPath + currentWadFileName, this.nandPath);
                    }
                    else
                    {
                        break;
                    }

                    if (!isStopRequired)
                    {
                        this.Invoke(delegateMethodeLabelLog, "Delete Temporary Downloaded File");
                        this.Invoke(delegateMethodeLog, "Delete Temporary Downloaded File");

                        File.Delete(tmpPath + currentWadFileName);

                        cptProgress++;
                        this.Invoke(delegateMethodeGlobalProgress, cptProgress);
                    }
                    else
                    {
                        break;
                    }
                }

                if (!isStopRequired)
                {
                    this.Invoke(delegateMethodeLabelLog, "Generate setting.txt");
                    this.Invoke(delegateMethodeLog, "Generate setting.txt");

                    SettingTxt.GenerateFile(this.wiiSerialNumber, this.sysMenu[3].ToString(),
                                            this.nandPath + Path.DirectorySeparatorChar + "title" + Path.DirectorySeparatorChar + "00000001" +
                                            Path.DirectorySeparatorChar + "00000002" + Path.DirectorySeparatorChar + "data");

                    cptProgress++;
                    this.Invoke(delegateMethodeGlobalProgress, cptProgress);
                }

                if (!isStopRequired)
                {
                    this.Invoke(delegateMethodeLabelLog, "Build successfull !");
                    this.Invoke(delegateMethodeLog, "Build successfull !");
                }
                else
                {
                    this.Invoke(delegateMethodeLabelLog, "Build aborted !");
                    this.Invoke(delegateMethodeLog, "Build aborted !");
                }
            }
            catch (Exception ex)
            {
                if (this.IsHandleCreated)
                {
                    this.Invoke(delegateMethodeLabelLog, ex.Message);
                    this.Invoke(delegateMethodeLog, "Build aborted !");
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            finally
            {
                if (this.IsHandleCreated)
                {
                    resetFormInvoker rst = new resetFormInvoker(this.LockUnlockForm);
                    this.Invoke(rst);
                }
            }
        }