Exemplo n.º 1
0
        public static void SaveResource(Resource resource, string outputPath, ResourceFormat format, int version = -1)
        {
            var file = new FileStream(outputPath, FileMode.Create, FileAccess.Write);

            switch (format)
            {
            case ResourceFormat.LSX:
            {
                using (var writer = new LSXWriter(file))
                {
                    writer.PrettyPrint = true;
                    writer.Write(resource);
                }
                break;
            }

            case ResourceFormat.LSB:
            {
                using (var writer = new LSBWriter(file))
                {
                    writer.Write(resource);
                }
                break;
            }

            case ResourceFormat.LSF:
            {
                uint lsfVersion;
                if (version == -1)
                {
                    // Write in V2 format for D:OS EE compatibility
                    lsfVersion = FileVersion.VerChunkedCompress;
                }
                else
                {
                    lsfVersion = (uint)version;
                }

                using (var writer = new LSFWriter(file, lsfVersion))
                {
                    writer.Write(resource);
                }
                break;
            }

            default:
                throw new ArgumentException("Invalid resource format");
            }
        }
Exemplo n.º 2
0
        public static void SaveResource(Resource resource, string outputPath, ResourceFormat format, FileVersion version = 0x0)
        {
            FileManager.TryToCreateDirectory(outputPath);

            using (var file = new FileStream(outputPath, FileMode.Create, FileAccess.Write))
            {
                switch (format)
                {
                case ResourceFormat.LSX:
                {
                    var writer = new LSXWriter(file);
                    writer.PrettyPrint = true;
                    writer.Write(resource);
                    break;
                }

                case ResourceFormat.LSB:
                {
                    var writer = new LSBWriter(file);
                    writer.Write(resource);
                    break;
                }

                case ResourceFormat.LSF:
                {
                    // Write in V2 format for D:OS EE compatibility
                    FileVersion lsfVersion = version == 0x0 ? FileVersion.VerChunkedCompress : version;

                    var writer = new LSFWriter(file, lsfVersion);
                    writer.Write(resource);
                    break;
                }

                case ResourceFormat.LSJ:
                {
                    var writer = new LSJWriter(file);
                    writer.PrettyPrint = true;
                    writer.Write(resource);
                    break;
                }

                default:
                    throw new ArgumentException("Invalid resource format");
                }
            }
        }