Esempio n. 1
0
        public void LoadEntries()
        {
            _contentDictionary = new SortedDictionary <(ulong, NcaContentType), string>();

            foreach (StorageId storageId in Enum.GetValues(typeof(StorageId)))
            {
                string contentDirectory    = null;
                string contentPathString   = null;
                string registeredDirectory = null;

                try
                {
                    contentPathString   = LocationHelper.GetContentRoot(storageId);
                    contentDirectory    = LocationHelper.GetRealPath(_device.FileSystem, contentPathString);
                    registeredDirectory = Path.Combine(contentDirectory, "registered");
                }
                catch (NotSupportedException)
                {
                    continue;
                }

                Directory.CreateDirectory(registeredDirectory);

                LinkedList <LocationEntry> locationList = new LinkedList <LocationEntry>();

                void AddEntry(LocationEntry entry)
                {
                    locationList.AddLast(entry);
                }

                foreach (string directoryPath in Directory.EnumerateDirectories(registeredDirectory))
                {
                    if (Directory.GetFiles(directoryPath).Length > 0)
                    {
                        string ncaName = new DirectoryInfo(directoryPath).Name.Replace(".nca", string.Empty);

                        using (FileStream ncaFile = new FileStream(Directory.GetFiles(directoryPath)[0], FileMode.Open, FileAccess.Read))
                        {
                            Nca nca = new Nca(_device.System.KeySet, ncaFile.AsStorage());

                            string switchPath = contentPathString + ":/" + ncaFile.Name.Replace(contentDirectory, string.Empty).TrimStart(Path.DirectorySeparatorChar);

                            // Change path format to switch's
                            switchPath = switchPath.Replace('\\', '/');

                            LocationEntry entry = new LocationEntry(switchPath,
                                                                    0,
                                                                    (long)nca.Header.TitleId,
                                                                    nca.Header.ContentType);

                            AddEntry(entry);

                            _contentDictionary.Add((nca.Header.TitleId, nca.Header.ContentType), ncaName);
                        }
                    }
                }

                foreach (string filePath in Directory.EnumerateFiles(contentDirectory))
                {
                    if (Path.GetExtension(filePath) == ".nca")
                    {
                        string ncaName = Path.GetFileNameWithoutExtension(filePath);

                        using (FileStream ncaFile = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                        {
                            Nca nca = new Nca(_device.System.KeySet, ncaFile.AsStorage());

                            string switchPath = contentPathString + ":/" + filePath.Replace(contentDirectory, string.Empty).TrimStart(Path.DirectorySeparatorChar);

                            // Change path format to switch's
                            switchPath = switchPath.Replace('\\', '/');

                            LocationEntry entry = new LocationEntry(switchPath,
                                                                    0,
                                                                    (long)nca.Header.TitleId,
                                                                    nca.Header.ContentType);

                            AddEntry(entry);

                            _contentDictionary.Add((nca.Header.TitleId, nca.Header.ContentType), ncaName);
                        }
                    }
                }

                if (_locationEntries.ContainsKey(storageId) && _locationEntries[storageId]?.Count == 0)
                {
                    _locationEntries.Remove(storageId);
                }

                if (!_locationEntries.ContainsKey(storageId))
                {
                    _locationEntries.Add(storageId, locationList);
                }
            }

            TimeManager.Instance.InitializeTimeZone(_device);
        }
Esempio n. 2
0
        public void LoadEntries()
        {
            ContentDictionary = new SortedDictionary <(ulong, ContentType), string>();

            foreach (StorageId StorageId in Enum.GetValues(typeof(StorageId)))
            {
                string ContentDirectory    = null;
                string ContentPathString   = null;
                string RegisteredDirectory = null;

                try
                {
                    ContentPathString   = LocationHelper.GetContentRoot(StorageId);
                    ContentDirectory    = LocationHelper.GetRealPath(Device.FileSystem, ContentPathString);
                    RegisteredDirectory = Path.Combine(ContentDirectory, "registered");
                }
                catch (NotSupportedException NEx)
                {
                    continue;
                }

                Directory.CreateDirectory(RegisteredDirectory);

                LinkedList <LocationEntry> LocationList = new LinkedList <LocationEntry>();

                void AddEntry(LocationEntry Entry)
                {
                    LocationList.AddLast(Entry);
                }

                foreach (string DirectoryPath in Directory.EnumerateDirectories(RegisteredDirectory))
                {
                    if (Directory.GetFiles(DirectoryPath).Length > 0)
                    {
                        string NcaName = new DirectoryInfo(DirectoryPath).Name.Replace(".nca", string.Empty);

                        using (FileStream NcaFile = new FileStream(Directory.GetFiles(DirectoryPath)[0], FileMode.Open, FileAccess.Read))
                        {
                            Nca Nca = new Nca(Device.System.KeySet, NcaFile, false);

                            string SwitchPath = Path.Combine(ContentPathString + ":",
                                                             NcaFile.Name.Replace(ContentDirectory, string.Empty).TrimStart('\\'));

                            // Change path format to switch's
                            SwitchPath = SwitchPath.Replace('\\', '/');

                            LocationEntry Entry = new LocationEntry(SwitchPath,
                                                                    0,
                                                                    (long)Nca.Header.TitleId,
                                                                    Nca.Header.ContentType);

                            AddEntry(Entry);

                            ContentDictionary.Add((Nca.Header.TitleId, Nca.Header.ContentType), NcaName);

                            NcaFile.Close();
                            Nca.Dispose();
                            NcaFile.Dispose();
                        }
                    }
                }

                foreach (string FilePath in Directory.EnumerateFiles(ContentDirectory))
                {
                    if (Path.GetExtension(FilePath) == ".nca")
                    {
                        string NcaName = Path.GetFileNameWithoutExtension(FilePath);

                        using (FileStream NcaFile = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
                        {
                            Nca Nca = new Nca(Device.System.KeySet, NcaFile, false);

                            string SwitchPath = Path.Combine(ContentPathString + ":",
                                                             FilePath.Replace(ContentDirectory, string.Empty).TrimStart('\\'));

                            // Change path format to switch's
                            SwitchPath = SwitchPath.Replace('\\', '/');

                            LocationEntry Entry = new LocationEntry(SwitchPath,
                                                                    0,
                                                                    (long)Nca.Header.TitleId,
                                                                    Nca.Header.ContentType);

                            AddEntry(Entry);

                            ContentDictionary.Add((Nca.Header.TitleId, Nca.Header.ContentType), NcaName);

                            NcaFile.Close();
                            Nca.Dispose();
                            NcaFile.Dispose();
                        }
                    }
                }

                if (LocationEntries.ContainsKey(StorageId) && LocationEntries[StorageId]?.Count == 0)
                {
                    LocationEntries.Remove(StorageId);
                }

                if (!LocationEntries.ContainsKey(StorageId))
                {
                    LocationEntries.Add(StorageId, LocationList);
                }
            }
        }