Exemple #1
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 #2
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 #3
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 #4
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 #5
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 #6
0
        private async Task <IImageState> LoadKtx(Stream fileStream, UPath filePath, IFileManager pluginManager)
        {
            var imgData = new SubStream(fileStream, _header.tableDataOffset, _header.imgDataSize);

            _dataCompressionFormat = Level5Compressor.PeekCompressionMethod(imgData);

            var ktxFile = new MemoryStream();

            Level5Compressor.Decompress(imgData, ktxFile);
            ktxFile.Position = 0;

            var loadResult = await pluginManager.LoadFile(new StreamFile(ktxFile, filePath.GetNameWithoutExtension() + ".ktx"), KtxPluginId);

            if (!loadResult.IsSuccessful)
            {
                throw new InvalidOperationException(loadResult.Message);
            }
            if (!(loadResult.LoadedFileState.PluginState is IImageState))
            {
                throw new InvalidOperationException("The embedded KTX version is not supported.");
            }

            _ktxState = loadResult.LoadedFileState;
            return((IImageState)_ktxState.PluginState);
        }
Exemple #7
0
        public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext)
        {
            var fileStream = await fileSystem.OpenFileAsync(filePath);

            Files = new List <IArchiveFileInfo> {
                _arc.Load(fileStream, filePath.GetNameWithoutExtension())
            };
        }
Exemple #8
0
        public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext)
        {
            var segStream = await fileSystem.OpenFileAsync(filePath);

            var binStream = await fileSystem.OpenFileAsync(filePath.ChangeExtension(".BIN"));

            var sizeName   = filePath.GetDirectory() / filePath.GetNameWithoutExtension() + "SIZE.BIN";
            var sizeStream = fileSystem.FileExists(sizeName) ? await fileSystem.OpenFileAsync(sizeName) : null;

            Files = _arc.Load(segStream, binStream, sizeStream);
        }
Exemple #9
0
        public Task Save(IFileSystem fileSystem, UPath savePath, SaveContext saveContext)
        {
            var segStream = fileSystem.OpenFile(savePath, FileMode.Create, FileAccess.Write);
            var binStream = fileSystem.OpenFile(savePath.ChangeExtension(".BIN"), FileMode.Create, FileAccess.Write);

            var sizeName   = savePath.GetDirectory() / savePath.GetNameWithoutExtension() + "SIZE.BIN";
            var sizeStream = Files.Any(x => x.UsesCompression) ? fileSystem.OpenFile(sizeName, FileMode.Create, FileAccess.Write) : null;

            _arc.Save(segStream, binStream, sizeStream, Files);

            return(Task.CompletedTask);
        }
Exemple #10
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 #11
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 #12
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);
        }