Beispiel #1
0
        /// <summary>
        /// Converts the given texture dictionary to a field texture archive, and returns a new texture dictionary filled with dummy textures for each texture in the given texture dictionary.
        /// </summary>
        /// <param name="textureDictionary"></param>
        /// <param name="archiveFilePath"></param>
        /// <returns></returns>
        public static TextureDictionary ConvertToFieldTextureArchive(TextureDictionary textureDictionary, string archiveFilePath, bool usePS4Format = false)
        {
            var archiveBuilder = new ArchiveBuilder();

            // Create bgTexArcData00.txt
            var fieldTextureArchiveDataInfoStream = new MemoryStream();

            using (var streamWriter = new StreamWriter(fieldTextureArchiveDataInfoStream, Encoding.Default, 4096, true))
            {
                streamWriter.WriteLine("1,");
                streamWriter.WriteLine($"{textureDictionary.Count},");
            }

            archiveBuilder.AddFile("bgTexArcData00.txt", fieldTextureArchiveDataInfoStream);

            // Convert textures
            foreach (var texture in textureDictionary.Textures)
            {
                var textureInfo      = TextureInfo.GetTextureInfo(texture);
                var texturePixelData = TextureUtilities.GetPixelData(texture);

                // Create field texture & save it
                Stream textureStream = new MemoryStream();
                if (!usePS4Format)
                {
                    var fieldTexture = new FieldTexturePS3(textureInfo.PixelFormat, ( byte )textureInfo.MipMapCount, ( short )textureInfo.Width,
                                                           ( short )textureInfo.Height, texturePixelData);
                    fieldTexture.Save(textureStream);
                }
                else
                {
                    var fieldTexture = new GNFTexture(textureInfo.PixelFormat, ( byte )textureInfo.MipMapCount, ( short )textureInfo.Width,
                                                      ( short )textureInfo.Height, texturePixelData, false);
                    fieldTexture.Save(textureStream);
                }

                archiveBuilder.AddFile(texture.Name, textureStream);
            }

            // Finally build archive file
            archiveBuilder.BuildFile(archiveFilePath);

            // Dummy out textures in texture dictionary
            var newTextureDictionary = new TextureDictionary(textureDictionary.Version);

            foreach (var texture in textureDictionary.Textures)
            {
                newTextureDictionary.Add(Texture.CreateDefaultTexture(texture.Name));
            }

            return(newTextureDictionary);
        }
Beispiel #2
0
        protected override void InitializeCore()
        {
            RegisterExportHandler <Archive>((path) => Data.Save(path));
            RegisterReplaceHandler <Archive>((path) => new Archive(path));
            RegisterAddHandler <Stream>((path) => Nodes.Add(DataViewNodeFactory.Create(path)));
            RegisterModelUpdateHandler(() =>
            {
                var builder = new ArchiveBuilder();

                foreach (DataViewNode node in Nodes)
                {
                    builder.AddFile(node.Text, ModuleExportUtilities.CreateStream(node.Data));
                }

                return(builder.Build());
            });
        }
Beispiel #3
0
        protected override void InitializeCore()
        {
            RegisterExportHandler <Archive>((path) => Data.Save(path));
            RegisterReplaceHandler <Archive>((path) => new Archive(path));
            RegisterAddHandler <Stream>((path) => AddChildNode(DataViewNodeFactory.Create(path)));
            RegisterModelUpdateHandler(() =>
            {
                var builder = new ArchiveBuilder();

                foreach (DataViewNode node in Nodes)
                {
                    builder.AddFile(node.Text, ModuleExportUtilities.CreateStream(node.Data));
                }

                return(builder.Build());
            });
            RegisterCustomHandler("Export", "All", () =>
            {
                var dialog = new VistaFolderBrowserDialog();
                {
                    if (dialog.ShowDialog() != true)
                    {
                        return;
                    }

                    foreach (DataViewNode node in Nodes)
                    {
                        // Hack for field texture archives: prefer DDS output format
                        Type type = null;
                        if (node.DataType == typeof(FieldTexturePS3) || node.DataType == typeof(GNFTexture))
                        {
                            type = typeof(DDSStream);
                        }

                        node.Export(Path.Combine(dialog.SelectedPath, node.Text), type);
                    }
                }
            });
        }
Beispiel #4
0
        public void BuildArchive()
        {
            using var builder = new ArchiveBuilder();
            foreach (var fileName in Directory.EnumerateFiles(@"C:\DOS\16\KEEN4"))
            {
                builder.AddFile(fileName, Path.GetFileName(fileName));
            }

            using var outputStream = new MemoryStream();
            builder.Write(outputStream);

            outputStream.Position = 0;
            using var reader      = new ArchiveFile(outputStream);
            foreach (var fileName in Directory.EnumerateFiles(@"C:\DOS\16\KEEN4"))
            {
                using (var f = File.OpenRead(fileName))
                    using (var a = reader.OpenItem(Path.GetFileName(fileName)))
                    {
                        Assert.IsTrue(StreamsEqual(f, a));
                    }
            }
        }
Beispiel #5
0
        public static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: aeonpack <AeonConfig> <PackageName>");
                return(1);
            }

            var archiveBuilder = new ArchiveBuilder();

            var config = AeonConfiguration.Load(args[0]);

            archiveBuilder.AddFile(GetArchiveConfigStream(config), "Archive.AeonConfig");

            int isoIndex = 1;

            foreach (var drive in config.Drives)
            {
                var driveConfig = drive.Value;
                if (!string.IsNullOrEmpty(driveConfig.HostPath))
                {
                    int hostPathLength = driveConfig.HostPath.Length;
                    if (!driveConfig.HostPath.EndsWith('\\') && !driveConfig.HostPath.EndsWith('/'))
                    {
                        hostPathLength++;
                    }

                    var drivePrefix = drive.Key.ToUpperInvariant() + ":\\";

                    foreach (var sourceFileName in Directory.EnumerateFiles(driveConfig.HostPath, "*", SearchOption.AllDirectories))
                    {
                        var destPath = getArchivePath(sourceFileName);
                        if (destPath != null)
                        {
                            Console.WriteLine($"Adding {sourceFileName} => {destPath}...");
                            archiveBuilder.AddFile(sourceFileName, destPath);
                        }
                    }

                    string getArchivePath(string srcPath)
                    {
                        var relativePath = srcPath.Substring(hostPathLength).Trim('\\', '/');
                        var pathParts    = relativePath.Split(Path.DirectorySeparatorChar);

                        if (!pathParts.All(Valid83PathRegex.IsMatch))
                        {
                            return(null);
                        }

                        return(drivePrefix + relativePath.ToUpperInvariant());
                    }
                }
                else if (!string.IsNullOrWhiteSpace(drive.Value.ImagePath))
                {
                    archiveBuilder.AddFile(drive.Value.ImagePath, $"Image{isoIndex}.iso");
                    isoIndex++;
                }
                else
                {
                    throw new InvalidDataException();
                }
            }

            Console.WriteLine($"Writing {args[1]}...");
            using var outputStream = File.Create(args[1]);
            Console.CursorVisible  = false;
            archiveBuilder.Write(outputStream, new BuilderProgress(archiveBuilder.DataCount));
            Console.CursorVisible = true;

            return(0);
        }