Exemple #1
0
        private void OpenAllSaves()
        {
            if (SaveDir == null)
            {
                return;
            }

            string[] files = Fs.GetFileSystemEntries(SaveDir, "*");

            foreach (string file in files)
            {
                Savefile save     = null;
                string   saveName = Path.GetFileNameWithoutExtension(file);

                try
                {
                    IStorage storage = Fs.OpenFile(file, FileMode.Open).AsStorage();

                    string sdPath = "/" + Util.GetRelativePath(file, SaveDir).Replace('\\', '/');
                    var    nax0   = new Nax0(Keyset, storage, sdPath, false);
                    save = new Savefile(Keyset, nax0.BaseStorage, IntegrityCheckLevel.None, true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex.Message} File: {file}");
                }

                if (save != null && saveName != null)
                {
                    Saves[saveName] = save;
                }
            }
        }
Exemple #2
0
        private void OpenAllNcas()
        {
            string[] files = Fs.GetFileSystemEntries(ContentsDir, "*.nca", SearchOption.AllDirectories);

            foreach (string file in files)
            {
                Nca nca = null;
                try
                {
                    bool     isNax0;
                    IStorage storage = OpenSplitNcaStream(Fs, file);
                    if (storage == null)
                    {
                        continue;
                    }

                    using (var reader = new BinaryReader(storage.AsStream(), Encoding.Default, true))
                    {
                        reader.BaseStream.Position = 0x20;
                        isNax0 = reader.ReadUInt32() == 0x3058414E; // NAX0
                        reader.BaseStream.Position = 0;
                    }

                    if (isNax0)
                    {
                        string sdPath = "/" + Util.GetRelativePath(file, ContentsDir).Replace('\\', '/');
                        var    nax0   = new Nax0(Keyset, storage, sdPath, false);
                        nca = new Nca(Keyset, nax0.BaseStorage, false);
                    }
                    else
                    {
                        nca = new Nca(Keyset, storage, false);
                    }

                    nca.NcaId = Path.GetFileNameWithoutExtension(file);
                    string extension = 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{file}");
                    }
                    else
                    {
                        string name = ex.Type == KeyType.Title ? $"Title key for rights ID {ex.Name}" : ex.Name;
                        Console.WriteLine($"{ex.Message}\nKey: {name}\nFile: {file}");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex.Message} File: {file}");
                }

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