コード例 #1
0
        public TitleMountDialog(Dictionary <NcaFormatType, List <Tuple <SwitchFsNca, int> > > indexed, SwitchFsNca mainNca)
        {
            InitializeComponent();
            Indexed = indexed;
            MainNca = mainNca;

            bool hasPatch = false;

            foreach (Tuple <SwitchFsNca, int> t in Indexed.Values.SelectMany(i => i))
            {
                NcaFsHeader section = t.Item1.Nca.Header.GetFsHeader(t.Item2);
                if (section.IsPatchSection())
                {
                    hasPatch = true;
                    break;
                }
            }

            if (Indexed.ContainsKey(NcaFormatType.Romfs) || hasPatch)
            {
                ComboBox.Items.Add(MountType.Romfs);
            }
            if (Indexed.ContainsKey(NcaFormatType.Pfs0))
            {
                ComboBox.Items.Add(MountType.Exefs);
            }
        }
コード例 #2
0
        private void MountClicked(object sender, RoutedEventArgs e)
        {
            if (ComboBox.SelectedItem == null)
            {
                return;
            }

            MountType     mountType   = (MountType)ComboBox.SelectedItem;
            NcaFormatType sectionType = NcaFormatType.Romfs;

            switch (mountType)
            {
            case MountType.Exefs:
                sectionType = NcaFormatType.Pfs0;
                break;

            case MountType.Romfs:
                sectionType = NcaFormatType.Romfs;
                break;
            }
            List <IFileSystem> filesystems = new List <IFileSystem>();
            IEnumerable <Tuple <SwitchFsNca, int> > list = Indexed[sectionType];

            TaskManagerPage.Current.Queue.Submit(new RunTask("Opening filesystems to mount...", new Task(() =>
            {
                foreach (Tuple <SwitchFsNca, int> t in list)
                {
                    SwitchFsNca nca     = t.Item1;
                    NcaFsHeader section = t.Item1.Nca.Header.GetFsHeader(t.Item2);
                    int index           = t.Item2;

                    /*IStorage inStorage = nca.OpenStorage(index, IntegrityCheckLevel.ErrorOnInvalid);
                     * IFile outFile = new LocalFile("./tmp.bin", OpenMode.Write | OpenMode.AllowAppend);
                     * IStorage outStorage = outFile.AsStorage();
                     * inStorage.GetSize(out long size);
                     * long buffLen = 0x10000;
                     * for (int i = 0; i < (int)Math.Min(Math.Ceiling((double)size / buffLen), 5); i++)
                     * {
                     *  long off = i * buffLen;
                     *  long left = size - off;
                     *  long toRead = Math.Min(buffLen, left);
                     *
                     *  byte[] buff = new byte[toRead];
                     *
                     *  inStorage.Read(off, buff);
                     *  outStorage.Write(off, buff);
                     * }
                     * //inStorage.Dispose();
                     * outFile.Dispose();*/

                    filesystems.Add(nca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid));
                }
                filesystems.Reverse();
                LayeredFileSystem fs = new LayeredFileSystem(filesystems);
                string typeString    = sectionType.ToString();
                MountService.Mount(new MountableFileSystem(fs, $"Mounted {mountType.ToString().ToLower()}", typeString, OpenMode.Read));
            })));
        }
コード例 #3
0
        private void MountClicked(object sender, RoutedEventArgs e)
        {
            List <Title> selected = new List <Title>();

            foreach (TitleElement info in ListView.Items)
            {
                if (info.Selected)
                {
                    selected.Add(info.Title);
                }
            }

            List <Title> orderedTitles = Element.OrderTitlesByBest();

            Title baseTitle = orderedTitles.FirstOrDefault(t => t.Metadata.Type == TitleType.Application);

            if (baseTitle == null && orderedTitles.Count == 1)
            {
                baseTitle = orderedTitles.First();
            }

            if (!IsMountable(baseTitle, selected))
            {
                MessageBox.Show("The base game isn't available, so the patch cannot be mounted.");
                return;
            }

            Dictionary <NcaFormatType, List <Tuple <SwitchFsNca, int> > > indexed = new Dictionary <NcaFormatType, List <Tuple <SwitchFsNca, int> > >();

            foreach (Title title in selected)
            {
                SwitchFsNca nca = title.MainNca;
                if (nca.Nca.Header.ContentType != ContentType.Meta)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (!nca.Nca.Header.IsSectionEnabled(i))
                        {
                            continue;
                        }
                        NcaFsHeader section = nca.Nca.Header.GetFsHeader(i);
                        if (!indexed.ContainsKey(section.FormatType))
                        {
                            indexed[section.FormatType] = new List <Tuple <SwitchFsNca, int> >();
                        }
                        indexed[section.FormatType].Add(new Tuple <SwitchFsNca, int>(nca, i));
                    }
                }
            }
            Window window = new TitleMountDialog(indexed, baseTitle.MainNca)
            {
                Owner = Window.GetWindow(this)
            };

            window.ShowDialog();
        }
コード例 #4
0
        private void ExtractClicked(object sender, RoutedEventArgs e)
        {
            MountType     mountType   = (MountType)ComboBox.SelectedItem;
            NcaFormatType sectionType = NcaFormatType.Romfs;

            switch (mountType)
            {
            case MountType.Exefs:
                sectionType = NcaFormatType.Pfs0;
                break;

            case MountType.Romfs:
                sectionType = NcaFormatType.Romfs;
                break;
            }

            IEnumerable <Tuple <SwitchFsNca, int> > list = Indexed[sectionType];
            string path = Path.Text;

            TaskManagerPage.Current.Queue.Submit(new RunTask("Opening filesystems to extract...", new Task(() =>
            {
                List <IFileSystem> filesystems = new List <IFileSystem>();
                foreach (Tuple <SwitchFsNca, int> t in list)
                {
                    SwitchFsNca nca     = t.Item1;
                    NcaFsHeader section = t.Item1.Nca.Header.GetFsHeader(t.Item2);
                    int index           = t.Item2;

                    filesystems.Add(nca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid));
                }
                filesystems.Reverse();

                LayeredFileSystem lfs      = new LayeredFileSystem(filesystems);
                ExtractFileSystemTask task = new ExtractFileSystemTask($"Extracting {sectionType}...", lfs, path);

                Dispatcher.InvokeAsync(() =>
                {
                    ProgressView view = new ProgressView(new List <ProgressTask>()
                    {
                        task
                    });
                    NavigationWindow window = new NavigationWindow
                    {
                        ShowsNavigationUI = false // get rid of the t r a s h
                    };
                    window.Navigate(view);

                    TaskManagerPage.Current.Queue.Submit(task);

                    window.Owner = Window.GetWindow(this);
                    window.ShowDialog();
                });
            })));
        }
コード例 #5
0
ファイル: Extensions.cs プロジェクト: SIMOMEGA/HACGUI
        public static void MatchupBaseNca(this IEnumerable <SwitchFsNca> ncas)
        {
            PseudoFileSystem ps = ncas.MakeFs();
            SwitchFs         fs = SwitchFs.OpenNcaDirectory(HACGUIKeyset.Keyset, ps);

            foreach (KeyValuePair <ulong, LibHac.Application> kv in fs.Applications)
            {
                ulong tid = kv.Key;
                LibHac.Application app = kv.Value;

                if (app.Patch != null && app.Main != null)
                {
                    foreach (SwitchFsNca nca in app.Patch.Ncas)
                    {
                        ContentType type    = nca.Nca.Header.ContentType;
                        SwitchFsNca baseNca = app.Main.Ncas.Where(n => n.Nca.Header.ContentType == type).FirstOrDefault();
                        if (baseNca != null)
                        {
                            bool hasPatch = false;
                            for (int i = 0; i < 4; i++)
                            {
                                Nca n = nca.Nca;
                                if (n.CanOpenSection(i))
                                {
                                    NcaFsHeader section = n.Header.GetFsHeader(i);
                                    if (section.IsPatchSection())
                                    {
                                        hasPatch = true;
                                        break;
                                    }
                                }
                            }
                            if (hasPatch)
                            {
                                ncas.Where(n => n.Filename == nca.Filename.Replace("/", "")).First().BaseNca = baseNca.Nca; // set original NCA, not new parsed one
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
        private void MountClicked(object sender, RoutedEventArgs e)
        {
            MountType     mountType   = (MountType)ComboBox.SelectedItem;
            NcaFormatType sectionType = NcaFormatType.Romfs;

            switch (mountType)
            {
            case MountType.Exefs:
                sectionType = NcaFormatType.Pfs0;
                break;

            case MountType.Romfs:
                sectionType = NcaFormatType.Romfs;
                break;
            }
            List <IFileSystem> filesystems = new List <IFileSystem>();
            IEnumerable <Tuple <SwitchFsNca, int> > list = Indexed[sectionType];

            TaskManagerPage.Current.Queue.Submit(new RunTask("Opening filesystems to mount...", new Task(() =>
            {
                foreach (Tuple <SwitchFsNca, int> t in list)
                {
                    SwitchFsNca nca     = t.Item1;
                    NcaFsHeader section = t.Item1.Nca.Header.GetFsHeader(t.Item2);
                    int index           = t.Item2;

                    if (section.IsPatchSection())
                    {
                        MainNca.BaseNca = nca.Nca;
                    }

                    filesystems.Add(nca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid));
                }
                filesystems.Reverse();
                LayeredFileSystem fs = new LayeredFileSystem(filesystems);
                string typeString    = sectionType.ToString();
                MountService.Mount(new MountableFileSystem(fs, $"Mounted {mountType.ToString().ToLower()}", typeString, OpenMode.Read));
            })));
        }