示例#1
0
 protected override void InitializeViewCore()
 {
     foreach (var handle in Data)
     {
         var node = DataNodeFactory.Create(Data.Open(handle, EntryStreamMode.MemoryStream), handle);
         mValueMap[node] = node.Data;
         Add(node);
     }
 }
示例#2
0
        protected override void InitializeViewCore()
        {
            for (int i = 0; i < Data.Count; i++)
            {
                var name = mNameGetter != null?mNameGetter(Data[i]) : $"{DataNodeFactory.GetSpecialName( mType )} #{i}";

                Add(DataNodeFactory.Create <T>(name, Data[i]));
            }
        }
示例#3
0
        protected override void InitializeCore()
        {
            RegisterReplaceHandler <TextureSet>(BinaryFile.Load <TextureSet>);
            RegisterExportHandler <TextureSet>((path) =>
            {
                // Assume it's being exported for F2nd PS3
                if (BinaryFormatUtilities.IsClassic(Data.Format) && path.EndsWith(".txd", StringComparison.OrdinalIgnoreCase))
                {
                    Data.Format     = BinaryFormat.F2nd;
                    Data.Endianness = Endianness.BigEndian;
                }

                // Or reverse
                else if (BinaryFormatUtilities.IsModern(Data.Format) && path.EndsWith(".bin", StringComparison.OrdinalIgnoreCase))
                {
                    Data.Format     = BinaryFormat.DT;
                    Data.Endianness = Endianness.LittleEndian;
                }

                Data.Save(path);
            });
            RegisterImportHandler <Texture>((path) =>
            {
                var texture = TextureEncoder.Encode(path);
                var node    = DataNodeFactory.Create <Texture>(Path.GetFileNameWithoutExtension(path), texture);
                Textures.Add(node);
            });
            RegisterImportHandler <Bitmap>((path) =>
            {
                var texture = TextureEncoder.Encode(path);
                var node    = DataNodeFactory.Create <Texture>(Path.GetFileNameWithoutExtension(path), texture);
                Textures.Add(node);
            });
            RegisterCustomHandler("Export All", () =>
            {
                using (var saveFileDialog = new SaveFileDialog())
                {
                    saveFileDialog.AutoUpgradeEnabled = true;
                    saveFileDialog.CheckPathExists    = true;
                    saveFileDialog.Title    = "Select a folder to export textures to.";
                    saveFileDialog.FileName = "Enter into a directory and press Save";

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        var outputDirectory = Path.GetDirectoryName(saveFileDialog.FileName);
                        foreach (var texture in Data.Textures)
                        {
                            if (!TextureFormatUtilities.IsCompressed(texture.Format) || texture.IsYCbCr)
                            {
                                TextureDecoder.DecodeToPNG(texture, Path.Combine(outputDirectory, texture.Name + ".png"));
                            }
                            else
                            {
                                TextureDecoder.DecodeToDDS(texture, Path.Combine(outputDirectory, texture.Name + ".dds"));
                            }
                        }
                    }
                }
            }, Keys.Control | Keys.Shift | Keys.E);
            RegisterDataUpdateHandler(() =>
            {
                var data        = new TextureSet();
                data.Format     = Format;
                data.Endianness = Endianness;
                data.Textures.AddRange(Textures.Data);
                return(data);
            });
        }
示例#4
0
        protected override void InitializeCore()
        {
            mValueMap = new Dictionary <DataNode, object>();

            if (Data.Flags.HasFlag(BinaryFileFlags.Load))
            {
                mFlags |= DataNodeActionFlags.Replace;
                RegisterReplaceHandler <TArchive>((path) => BinaryFile.Load <TArchive>(path));
            }
            if (Data.Flags.HasFlag(BinaryFileFlags.Save))
            {
                mFlags |= DataNodeActionFlags.Export;
                RegisterExportHandler <TArchive>((path) => Data.Save(path));
            }
            if (Data.CanAdd)
            {
                mFlags |= DataNodeActionFlags.Import | DataNodeActionFlags.Move;
                RegisterImportHandler <Stream>((path) => DataNodeFactory.Create(path));
            }
            if (Data.CanRemove)
            {
                mFlags |= DataNodeActionFlags.Remove;
            }

            RegisterCustomHandler("Export All", () =>
            {
                using (var saveFileDialog = new SaveFileDialog())
                {
                    saveFileDialog.AutoUpgradeEnabled = true;
                    saveFileDialog.CheckPathExists    = true;
                    saveFileDialog.Title    = "Select a folder to export textures to.";
                    saveFileDialog.FileName = "Enter into a directory and press Save";

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                    }
                }
            }, Keys.Control | Keys.Shift | Keys.E);

            RegisterDataUpdateHandler(() =>
            {
                // We're gonna work with the original data always
                foreach (var node in Nodes)
                {
                    Stream stream = null;

                    bool exists;
                    if ((exists = mValueMap.TryGetValue(node, out object value) && !value.Equals(node.Data)) || !exists)
                    {
                        stream = new FormatModuleStream(node.Data, node.Name);
                    }

                    if (stream != null)
                    {
                        Data.Add(node.Name, stream, false, ConflictPolicy.Replace);
                        mValueMap[node] = node.Data;
                    }
                }

                return(Data);
            });
        }