Beispiel #1
0
        /// <summary>
        /// Loads the title info from TMD.
        /// </summary>
        private void LoadTitleFromTMD()
        {
            // Show dialog for opening TMD file...
            OpenFileDialog opentmd = new OpenFileDialog()
            {
                Filter = "TMD Files|*tmd*",
                Title  = "Open TMD"
            };

            if (opentmd.ShowDialog() != DialogResult.Cancel)
            {
                libWiiSharp.TMD tmdLocal = new libWiiSharp.TMD();
                tmdLocal.LoadFile(opentmd.FileName);
                WriteStatus(String.Format("TMD Loaded ({0} blocks)", tmdLocal.GetNandBlocks()));

                titleidbox.Text = tmdLocal.TitleID.ToString("X16");
                WriteStatus("Title ID: " + tmdLocal.TitleID.ToString("X16"));

                titleversion.Text = tmdLocal.TitleVersion.ToString();
                WriteStatus("Version: " + tmdLocal.TitleVersion);

                if (tmdLocal.StartupIOS.ToString("X") != "0")
                {
                    WriteStatus("Requires: IOS" + int.Parse(tmdLocal.StartupIOS.ToString("X").Substring(7, 2).ToString(), System.Globalization.NumberStyles.HexNumber));
                }

                WriteStatus("Content Count: " + tmdLocal.NumOfContents);

                for (int a = 0; a < tmdLocal.Contents.Length; a++)
                {
                    WriteStatus(String.Format("   Content {0}: {1} ({2} bytes)", a, tmdLocal.Contents[a].ContentID.ToString("X8"), tmdLocal.Contents[a].Size.ToString()));
                    WriteStatus(String.Format("    - Index: {0}", tmdLocal.Contents[a].Index.ToString()));
                    WriteStatus(String.Format("    - Type: {0}", tmdLocal.Contents[a].Type.ToString()));
                    WriteStatus(String.Format("    - Hash: {0}...", DisplayBytes(tmdLocal.Contents[a].Hash, String.Empty).Substring(0, 8)));
                }

                WriteStatus("TMD information parsed!");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Loads the title info from TMD.
        /// </summary>
        private void LoadTitleFromTMD()
        {
            // Show dialog for opening TMD file...
            OpenFileDialog opentmd = new OpenFileDialog();
            opentmd.Filter = "TMD Files|*tmd*";
            opentmd.Title = "Open TMD";
            if (opentmd.ShowDialog() != DialogResult.Cancel)
            {
                libWiiSharp.TMD tmdLocal = new libWiiSharp.TMD();
                tmdLocal.LoadFile(opentmd.FileName);
                WriteStatus(String.Format("TMD Loaded ({0} blocks)", tmdLocal.GetNandBlocks()));

                titleidbox.Text = tmdLocal.TitleID.ToString("X16");
                WriteStatus("Title ID: " + tmdLocal.TitleID.ToString("X16"));

                titleversion.Text = tmdLocal.TitleVersion.ToString();
                WriteStatus("Version: " + tmdLocal.TitleVersion);

                if (tmdLocal.StartupIOS.ToString("X") != "0")
                    WriteStatus("Requires: IOS" + int.Parse(tmdLocal.StartupIOS.ToString("X").Substring(7, 2).ToString(), System.Globalization.NumberStyles.HexNumber));
                
                WriteStatus("Content Count: " + tmdLocal.NumOfContents);

                for (int a = 0; a < tmdLocal.Contents.Length; a++)
			    {
                    WriteStatus(String.Format("   Content {0}: {1} ({2} bytes)", a, tmdLocal.Contents[a].ContentID.ToString("X8"), tmdLocal.Contents[a].Size.ToString()));
                    WriteStatus(String.Format("    - Index: {0}", tmdLocal.Contents[a].Index.ToString()));
                    WriteStatus(String.Format("    - Type: {0}", tmdLocal.Contents[a].Type.ToString()));
                    WriteStatus(String.Format("    - Hash: {0}...", DisplayBytes(tmdLocal.Contents[a].Hash, String.Empty).Substring(0, 8)));
                }

                WriteStatus("TMD information parsed!");
            }
        }
Beispiel #3
0
        void ReorganizePreviousFolderStructure(object sender, DoWorkEventArgs e)
        {
            // 0000000000000000v000\* become titles\0000000000000000\v000\*
            Regex TitleDirectoryRegex = new Regex(@"[a-zA-Z0-9]{16}v?([0-9]*)?");

            if (Directory.Exists(Path.Combine(CURRENT_DIR, "titles")) == false)
                Directory.CreateDirectory(Path.Combine(CURRENT_DIR, "titles"));

            string[] directories = Directory.GetDirectories(CURRENT_DIR, "*", SearchOption.TopDirectoryOnly);
            Debug.WriteLine("Dirs: " + directories.Length);
            foreach (string directory in directories)
            {
                Debug.WriteLine("ff: " + directory);
                DirectoryInfo dinfo = new DirectoryInfo(directory);

                // name is XXXXXXXXXXXXXXXXvYYYY
                if (TitleDirectoryRegex.IsMatch(dinfo.Name.ToString()) && dinfo.Name.Contains("v"))
                {
                    string[] title_info = dinfo.Name.Split('v');
                    string titleid_dir = Path.Combine(Path.Combine(CURRENT_DIR, "titles"), title_info[0]);
                    string newfull_dir = Path.Combine(titleid_dir, String.Format("{0}", title_info[1]));

                    if (Directory.Exists(titleid_dir) == false)
                        Directory.CreateDirectory(titleid_dir);

                    if (Directory.Exists(newfull_dir) == false)
                        Directory.CreateDirectory(newfull_dir);

                    string[] files = Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly);
                    foreach (string file in files)
                    {
                        FileInfo titlefile = new FileInfo(file);
                        if (File.Exists(Path.Combine(newfull_dir, titlefile.Name)) == false)
                            titlefile.MoveTo(Path.Combine(newfull_dir, titlefile.Name));
                    }

                    if (dinfo.GetFiles().Length <= 0 && dinfo.GetDirectories().Length <= 0)
                        Directory.Delete(directory);


                }
                else if (TitleDirectoryRegex.IsMatch(dinfo.Name.ToString()))
                {
                    string titleid_dir = Path.Combine(Path.Combine(CURRENT_DIR, "titles"), dinfo.Name.ToString());

                    libWiiSharp.TMD tmdfile = new libWiiSharp.TMD();
                    int count = 0;

                    string[] tmdfiles = Directory.GetFiles(directory, "*tmd*", SearchOption.TopDirectoryOnly);
                    if (tmdfiles.Length > 1)
                        continue; //Too many TMD files ?

                    foreach (string file in tmdfiles)
                    {
                        if (file.Contains("tmd"))
                        {
                            tmdfile.LoadFile(file);
                            count++;
                        }
                    }
                    if (count == 0)
                        continue;

                    string version = tmdfile.TitleVersion.ToString();
                    string newfull_dir = Path.Combine(titleid_dir, String.Format("{0}", version));

                    if (Directory.Exists(titleid_dir) == false)
                        Directory.CreateDirectory(titleid_dir);

                    if (Directory.Exists(newfull_dir) == false)
                        Directory.CreateDirectory(newfull_dir);

                    string[] files = Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly);
                    foreach (string file in files)
                    {
                        FileInfo titlefile = new FileInfo(file);
                        if (File.Exists(Path.Combine(newfull_dir, titlefile.Name)) == false)
                            titlefile.MoveTo(Path.Combine(newfull_dir, titlefile.Name));
                    }

                    if (dinfo.GetFiles().Length <= 0 && dinfo.GetDirectories().Length <= 0)
                        Directory.Delete(directory);

                }
            }

        }
Beispiel #4
0
        private void PatchExternalDownloadDir(string foldPath)
        {
            ShowLog("Patch dir [" + foldPath + "] start...");

            ShowLog("Check file count & size...");


            try
            {    // Load tmd
                var tmdFile = Path.Combine(foldPath, "tmd");
                if (!File.Exists(tmdFile))
                {
                    ShowLog("Not found tmd file!");
                    return;
                }

                libWiiSharp.TMD tmd = new libWiiSharp.TMD();
                tmd.LoadFile(tmdFile);

                List <string> renameList = new List <string>();

                // Check content & size
                for (int i = 0; i < tmd.NumOfContents; ++i)
                {
                    libWiiSharp.TMD_Content content = tmd.Contents[i];

                    var contentId = content.ContentID.ToString("x8");

                    // check content size
                    {
                        FileInfo fi = new FileInfo(Path.Combine(foldPath, contentId));
                        if (!fi.Exists)
                        {
                            throw new Exception("Content [" + contentId + "] not exists!");
                        }
                        if (fi.Length != (long)content.Size)
                        {
                            throw new Exception("Content [" + contentId + "] size error!");
                        }
                    }

                    // check h3 size
                    if (((short)content.Type & 0x02) == 0x02)
                    {
                        FileInfo h3fi = new FileInfo(Path.Combine(foldPath, contentId + ".h3"));
                        if (!h3fi.Exists)
                        {
                            throw new Exception("Content [" + contentId + "] h3 not exists!");
                        }
                        if (!(h3fi.Length == 20 || h3fi.Length == 40))
                        {
                            throw new Exception("Content [" + contentId + "] h3 size error!");
                        }
                    }
                    renameList.Add(contentId);
                }

                // Rename

                // tmd
                RenameFileInDir(foldPath, "tmd", "title.tmd");
                foreach (var i in renameList)
                {
                    RenameFileInDir(foldPath, i, i + ".app");
                }

                ShowLog("Patch dir [" + foldPath + "] finish...");
            }
            catch (Exception ex)
            {
                ShowLog("Fail: " + ex.Message);
            }
        }