Exemplo n.º 1
0
        private void CreateApplications()
        {
            foreach (Title title in Titles.Values.Where(x => x.Metadata.Type >= TitleType.Application))
            {
                Cnmt  meta  = title.Metadata;
                ulong appId = meta.ApplicationTitleId;

                if (!Applications.TryGetValue(appId, out Application app))
                {
                    app = new Application();
                    Applications.Add(appId, app);
                }

                app.AddTitle(title);
            }

            foreach (Application app in Applications.Values)
            {
                SwitchFsNca main  = app.Main?.MainNca;
                SwitchFsNca patch = app.Patch?.MainNca;

                if (main != null && patch != null)
                {
                    patch.BaseNca = main.Nca;
                }
            }
        }
Exemplo n.º 2
0
        private string GetNcaFilename(string name, SwitchFsNca nca)
        {
            if (nca.Nca.Header.ContentType != NcaContentType.Meta || !name.EndsWith(".cnmt.nca"))
            {
                return(Path.GetFileNameWithoutExtension(name));
            }

            return(name.Substring(0, name.Length - ".cnmt.nca".Length));
        }
Exemplo n.º 3
0
        private void OpenAllNcas()
        {
            // Todo: give warning if directories named "*.nca" are found or manually fix the archive bit
            IEnumerable <DirectoryEntry> files = ContentFs.OpenDirectory("/", OpenDirectoryMode.All)
                                                 .EnumerateEntries("*.nca", SearchOptions.RecurseSubdirectories)
                                                 .Where(x => x.Type == DirectoryEntryType.File);

            foreach (DirectoryEntry fileEntry in files)
            {
                SwitchFsNca nca = null;
                try
                {
                    IStorage storage = ContentFs.OpenFile(fileEntry.FullPath, OpenMode.Read).AsStorage();

                    nca = new SwitchFsNca(new Nca(Keyset, storage));

                    nca.NcaId = Path.GetFileNameWithoutExtension(fileEntry.Name);
                    string extension = nca.Nca.Header.ContentType == ContentType.Meta ? ".cnmt.nca" : ".nca";
                    nca.Filename = nca.NcaId + extension;
                }
                catch (MissingKeyException ex)
                {
                    if (ex.Name == null)
                    {
                        Console.WriteLine($"{ex.Message} File:\n{fileEntry}");
                    }
                    else
                    {
                        string name = ex.Type == KeyType.Title ? $"Title key for rights ID {ex.Name}" : ex.Name;
                        Console.WriteLine($"{ex.Message}\nKey: {name}\nFile: {fileEntry}");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex.Message} File: {fileEntry.FullPath}");
                }

                if (nca?.NcaId != null)
                {
                    Ncas.Add(nca.NcaId, nca);
                }
            }
        }