Exemple #1
0
        public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext)
        {
            Stream hpiStream;
            Stream hpbStream;

            if (filePath.GetExtensionWithDot() == ".HPI")
            {
                var hpbName = filePath.GetNameWithoutExtension() + ".HPB";

                if (!fileSystem.FileExists(filePath.GetDirectory() / hpbName))
                {
                    throw new FileNotFoundException($"{hpbName} not found.");
                }

                hpiStream = await fileSystem.OpenFileAsync(filePath);

                hpbStream = await fileSystem.OpenFileAsync(filePath.GetDirectory() / hpbName);
            }
            else
            {
                var hpiName = filePath.GetNameWithoutExtension() + ".HPI";

                if (!fileSystem.FileExists(filePath.GetDirectory() / hpiName))
                {
                    throw new FileNotFoundException($"{hpiName} not found.");
                }

                hpiStream = await fileSystem.OpenFileAsync(filePath.GetDirectory() / hpiName);

                hpbStream = await fileSystem.OpenFileAsync(filePath);
            }

            Files = _hpiHpb.Load(hpiStream, hpbStream);
        }
Exemple #2
0
        public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext)
        {
            Stream imgStream;
            Stream ddtStream;

            if (filePath.GetExtensionWithDot() == ".IMG")
            {
                var ddtPath = filePath.GetDirectory() / (filePath.GetNameWithoutExtension() + ".DDT");
                if (!fileSystem.FileExists(ddtPath))
                {
                    throw new FileNotFoundException($"{ddtPath.GetName()} not found.");
                }

                imgStream = await fileSystem.OpenFileAsync(filePath);

                ddtStream = await fileSystem.OpenFileAsync(ddtPath);
            }
            else
            {
                var imgPath = filePath.GetDirectory() / (filePath.GetNameWithoutExtension() + ".IMG");
                if (!fileSystem.FileExists(imgPath))
                {
                    throw new FileNotFoundException($"{imgPath.GetName()} not found.");
                }

                imgStream = await fileSystem.OpenFileAsync(imgPath);

                ddtStream = await fileSystem.OpenFileAsync(filePath);
            }

            Files = _ddtImg.Load(ddtStream, imgStream);
        }
Exemple #3
0
        public void TestExtensions()
        {
            {
                var path = new UPath("/a/b/c/d.txt");
                Assert.Equal(new UPath("/a/b/c"), path.GetDirectory());
                Assert.Equal("d.txt", path.GetName());
                Assert.Equal("d", path.GetNameWithoutExtension());
                Assert.Equal(".txt", path.GetExtensionWithDot());
                var newPath = path.ChangeExtension(".zip");
                Assert.Equal("/a/b/c/d.zip", newPath.FullName);
                Assert.Equal(new UPath("a/b/c/d.txt"), path.ToRelative());
                Assert.Equal(path, path.AssertAbsolute());
                Assert.Throws <ArgumentNullException>(() => new UPath().AssertNotNull());
                Assert.Throws <ArgumentException>(() => new UPath("not_absolute").AssertAbsolute());
            }

            {
                var path = new UPath("d.txt");
                Assert.Equal(UPath.Empty, path.GetDirectory());
                Assert.Equal("d.txt", path.GetName());
                Assert.Equal("d", path.GetNameWithoutExtension());
                Assert.Equal(".txt", path.GetExtensionWithDot());
                var newPath = path.ChangeExtension(".zip");
                Assert.Equal("d.zip", newPath.FullName);
                Assert.Equal(new UPath("d.txt"), path.ToRelative());
            }
        }
Exemple #4
0
        public Task Save(IFileSystem fileSystem, UPath savePath, SaveContext saveContext)
        {
            Stream lstStream;
            Stream arcStream;

            var lstName = $"{savePath.GetNameWithoutExtension()}.irlst";
            var arcName = $"{savePath.GetNameWithoutExtension()}.irarc";

            switch (savePath.GetExtensionWithDot())
            {
            case ".irlst":
                lstStream = fileSystem.OpenFile(savePath.GetDirectory() / lstName, FileMode.Create);
                arcStream = fileSystem.OpenFile(savePath.GetDirectory() / arcName, FileMode.Create);
                break;

            default:
                lstStream = fileSystem.OpenFile(savePath.GetDirectory() / lstName, FileMode.Create);
                arcStream = fileSystem.OpenFile(savePath.GetDirectory() / arcName, FileMode.Create);
                break;
            }

            _irarc.Save(lstStream, arcStream, Files);

            return(Task.CompletedTask);
        }
Exemple #5
0
        public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext)
        {
            Stream incStream;
            Stream datStream;

            if (filePath.GetExtensionWithDot() == ".inc")
            {
                if (!fileSystem.FileExists(filePath.GetDirectory() / "pack.dat"))
                {
                    throw new FileNotFoundException("pack.dat not found.");
                }

                incStream = await fileSystem.OpenFileAsync(filePath);

                datStream = await fileSystem.OpenFileAsync(filePath.GetDirectory() / "pack.dat");
            }
            else
            {
                if (!fileSystem.FileExists(filePath.GetDirectory() / "pack.inc"))
                {
                    throw new FileNotFoundException("pack.inc not found.");
                }

                incStream = await fileSystem.OpenFileAsync(filePath.GetDirectory() / "pack.inc");

                datStream = await fileSystem.OpenFileAsync(filePath);
            }

            Files = _aatri.Load(incStream, datStream, AAPackSupport.GetVersion(loadContext.DialogManager));
        }
Exemple #6
0
        public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext)
        {
            Stream lstStream;
            Stream arcStream;

            if (filePath.GetExtensionWithDot() == ".irlst")
            {
                var arcName = $"{filePath.GetNameWithoutExtension()}.irarc";

                if (!fileSystem.FileExists(filePath.GetDirectory() / arcName))
                {
                    throw new FileNotFoundException($"{ arcName } not found.");
                }

                lstStream = await fileSystem.OpenFileAsync(filePath);

                arcStream = await fileSystem.OpenFileAsync(filePath.GetDirectory() / arcName);
            }
            else
            {
                var lstName = $"{filePath.GetNameWithoutExtension()}.irlst";

                if (!fileSystem.FileExists(filePath.GetDirectory() / lstName))
                {
                    throw new FileNotFoundException($"{lstName} not found.");
                }

                lstStream = await fileSystem.OpenFileAsync(filePath.GetDirectory() / lstName);

                arcStream = await fileSystem.OpenFileAsync(filePath);
            }

            Files = _irarc.Load(lstStream, arcStream);
        }
Exemple #7
0
        public static Platform DeterminePlatform(UPath fileName)
        {
            switch (fileName.GetExtensionWithDot())
            {
            case ".osbctr":
                return(Platform.N3DS);

            default:
                return(Platform.PC);
            }
        }
Exemple #8
0
        public async Task <bool> IdentifyAsync(IFileSystem fileSystem, UPath filePath, IdentifyContext identifyContext)
        {
            filePath = filePath.GetExtensionWithDot() == ".srd" ? filePath : filePath.ChangeExtension(".srd");
            if (!fileSystem.FileExists(filePath))
            {
                return(false);
            }

            var fileStream = await fileSystem.OpenFileAsync(filePath);

            using var br = new BinaryReaderX(fileStream);
            return(br.ReadString(4) == "$CFH");
        }
Exemple #9
0
        public IArchiveFileInfo Add(Stream fileData, UPath filePath)
        {
            // Determine extension hash
            var extensionHash = Regex.IsMatch(filePath.GetExtensionWithDot(), @"\.[\da-fA-F]{8}") ?
                                uint.Parse(filePath.GetExtensionWithDot().Substring(1), NumberStyles.HexNumber) :
                                MtArcSupport.DetermineExtensionHash(filePath.GetExtensionWithDot());

            // Create entry
            IMtEntry entry;

            switch (_platform)
            {
            case MtArcPlatform.Switch:
                entry = new MtEntrySwitch
                {
                    ExtensionHash = extensionHash,
                    FileName      = (filePath.GetDirectory() / filePath.GetNameWithoutExtension()).FullName,
                    decompSize    = (int)fileData.Length
                };
                break;

            case MtArcPlatform.LittleEndian:
            case MtArcPlatform.BigEndian:
                entry = new MtEntry
                {
                    ExtensionHash = extensionHash,
                    FileName      = (filePath.GetDirectory() / filePath.GetNameWithoutExtension()).FullName,
                    decompSize    = (int)fileData.Length,
                };
                break;

            default:
                throw new InvalidOperationException();
            }

            // Create ArchiveFileInfo
            return(CreateAfi(fileData, filePath.FullName, entry, _platform));
        }
Exemple #10
0
        public Task Save(IFileSystem fileSystem, UPath savePath, SaveContext saveContext)
        {
            Stream ltFileStream;
            Stream lpFileStream;

            if (savePath.GetExtensionWithDot() == ".lt")
            {
                ltFileStream = fileSystem.OpenFile(savePath, FileMode.Create, FileAccess.Write);
                lpFileStream = fileSystem.OpenFile(savePath.ChangeExtension(".lp"), FileMode.Create, FileAccess.Write);
            }
            else
            {
                ltFileStream = fileSystem.OpenFile(savePath.ChangeExtension(".lt"), FileMode.Create, FileAccess.Write);
                lpFileStream = fileSystem.OpenFile(savePath, FileMode.Create, FileAccess.Write);
            }

            _img.Save(ltFileStream, lpFileStream, Images[0].ImageInfo);

            return(Task.CompletedTask);
        }
Exemple #11
0
        public Task Save(IFileSystem fileSystem, UPath savePath, SaveContext saveContext)
        {
            Stream srdStream;
            Stream srdvStream;

            if (savePath.GetExtensionWithDot() == ".srd")
            {
                srdStream  = fileSystem.OpenFile(savePath, FileMode.Create, FileAccess.Write);
                srdvStream = fileSystem.OpenFile(savePath.ChangeExtension(".srdv"), FileMode.Create, FileAccess.Write);
            }
            else
            {
                srdStream  = fileSystem.OpenFile(savePath.ChangeExtension(".srd"), FileMode.Create, FileAccess.Write);
                srdvStream = fileSystem.OpenFile(savePath, FileMode.Create, FileAccess.Write);
            }

            _img.Save(srdStream, srdvStream, Images.Select(x => x.ImageInfo).ToArray());

            return(Task.CompletedTask);
        }
Exemple #12
0
        public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext)
        {
            Stream srdStream;
            Stream srdvStream;

            if (filePath.GetExtensionWithDot() == ".srd")
            {
                srdStream = await fileSystem.OpenFileAsync(filePath);

                srdvStream = await fileSystem.OpenFileAsync(filePath.ChangeExtension(".srdv"));
            }
            else
            {
                srdStream = await fileSystem.OpenFileAsync(filePath.ChangeExtension(".srd"));

                srdvStream = await fileSystem.OpenFileAsync(filePath);
            }

            Images = _img.Load(srdStream, srdvStream).Select(x => new KanvasImage(EncodingDefinition, x)).ToArray();
        }
Exemple #13
0
        public Task Save(IFileSystem fileSystem, UPath savePath, SaveContext saveContext)
        {
            Stream idxStream;
            Stream binStream;

            if (savePath.GetExtensionWithDot() == ".idx")
            {
                idxStream = fileSystem.OpenFile(savePath, FileMode.Create, FileAccess.Write);
                binStream = fileSystem.OpenFile(savePath.ChangeExtension(".bin"), FileMode.Create, FileAccess.Write);
            }
            else
            {
                idxStream = fileSystem.OpenFile(savePath.ChangeExtension(".idx"), FileMode.Create, FileAccess.Write);
                binStream = fileSystem.OpenFile(savePath, FileMode.Create, FileAccess.Write);
            }

            _arc.Save(idxStream, binStream, Files);

            return(Task.CompletedTask);
        }
Exemple #14
0
        public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext)
        {
            Stream idxStream;
            Stream binStream;

            if (filePath.GetExtensionWithDot() == ".idx")
            {
                idxStream = await fileSystem.OpenFileAsync(filePath);

                binStream = await fileSystem.OpenFileAsync(filePath.ChangeExtension(".bin"));
            }
            else
            {
                idxStream = await fileSystem.OpenFileAsync(filePath.ChangeExtension(".idx"));

                binStream = await fileSystem.OpenFileAsync(filePath);
            }

            Files = _arc.Load(idxStream, binStream);
        }
Exemple #15
0
        public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext)
        {
            Stream ltFileStream;
            Stream lpFileStream;

            if (filePath.GetExtensionWithDot() == ".lt")
            {
                ltFileStream = await fileSystem.OpenFileAsync(filePath);

                lpFileStream = await fileSystem.OpenFileAsync(filePath.ChangeExtension(".lp"));
            }
            else
            {
                ltFileStream = await fileSystem.OpenFileAsync(filePath.ChangeExtension(".lt"));

                lpFileStream = await fileSystem.OpenFileAsync(filePath);
            }

            Images = new List <IKanvasImage> {
                new KanvasImage(EncodingDefinition, _img.Load(ltFileStream, lpFileStream))
            };
        }
Exemple #16
0
        public Task Save(IFileSystem fileSystem, UPath savePath, SaveContext saveContext)
        {
            Stream incStream;
            Stream datStream;

            switch (savePath.GetExtensionWithDot())
            {
            case ".inc":
                incStream = fileSystem.OpenFile(savePath.GetDirectory() / "pack.inc", FileMode.Create);
                datStream = fileSystem.OpenFile(savePath.GetDirectory() / savePath.GetNameWithoutExtension() + ".dat", FileMode.Create);
                break;

            default:
                incStream = fileSystem.OpenFile(savePath.GetDirectory() / savePath.GetNameWithoutExtension() + ".inc", FileMode.Create);
                datStream = fileSystem.OpenFile(savePath.GetDirectory() / "pack.dat", FileMode.Create);
                break;
            }

            _aatri.Save(incStream, datStream, Files);

            return(Task.CompletedTask);
        }
Exemple #17
0
        public Task Save(IFileSystem fileSystem, UPath savePath, SaveContext saveContext)
        {
            Stream hpiStream;
            Stream hpbStream;

            switch (savePath.GetExtensionWithDot())
            {
            case ".HPI":
                hpiStream = fileSystem.OpenFile(savePath, FileMode.Create);
                hpbStream = fileSystem.OpenFile(savePath.ChangeExtension("HPB"), FileMode.Create);
                break;

            default:
                hpiStream = fileSystem.OpenFile(savePath.ChangeExtension("HPI"), FileMode.Create);
                hpbStream = fileSystem.OpenFile(savePath, FileMode.Create);
                break;
            }

            _hpiHpb.Save(hpiStream, hpbStream, Files);

            return(Task.CompletedTask);
        }
Exemple #18
0
        public Task Save(IFileSystem fileSystem, UPath savePath, SaveContext saveContext)
        {
            Stream imgStream;
            Stream ddtStream;

            switch (savePath.GetExtensionWithDot())
            {
            case ".IMG":
                var ddtPath = savePath.GetDirectory() / (savePath.GetNameWithoutExtension() + ".DDT");
                imgStream = fileSystem.OpenFile(savePath, FileMode.Create);
                ddtStream = fileSystem.OpenFile(ddtPath, FileMode.Create);
                break;

            default:
                var imgPath = savePath.GetDirectory() / (savePath.GetNameWithoutExtension() + ".IMG");
                imgStream = fileSystem.OpenFile(imgPath, FileMode.Create);
                ddtStream = fileSystem.OpenFile(savePath, FileMode.Create);
                break;
            }

            _ddtImg.Save(ddtStream, imgStream, Files);

            return(Task.CompletedTask);
        }