Files
PCK-Studio/PCK-Studio/Forms/Skins-And-Textures/AdvancedOptions.cs
MayNL 22d1983ee3 Renamed PCK "Properties" to "Parameters"
there's a lot of things with this name scheme in this program so definitely possible i missed something.
2026-04-01 19:35:03 -04:00

85 lines
2.8 KiB
C#

using DiscordRPC;
using OMI;
using OMI.Formats.Pck;
using OMI.Workers.Pck;
using PckStudio.Core.Extensions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
namespace PckStudio.Popups
{
public partial class AdvancedOptions : MetroFramework.Forms.MetroForm
{
public bool IsLittleEndian
{
set
{
_endianness = value ? ByteOrder.LittleEndian : ByteOrder.BigEndian;
}
}
private readonly PckFile _pckFile;
private ByteOrder _endianness;
public AdvancedOptions(PckFile pckFile)
{
InitializeComponent();
_pckFile = pckFile;
propertyTreeview.Nodes.Clear();
propertyTreeview.Nodes.AddRange(_pckFile.GetParameterList().Select(s => new TreeNode(s)).ToArray());
}
private void applyButton_Click(object sender, EventArgs e)
{
if (fileTypeComboBox.SelectedIndex >= 0 && fileTypeComboBox.SelectedIndex <= 13)
{
applyBulkProperties(_pckFile.GetAssets(), fileTypeComboBox.SelectedIndex - 1);
DialogResult = DialogResult.OK;
return;
}
MessageBox.Show(this, "Please select a filetype before applying");
}
private void applyBulkProperties(IReadOnlyCollection<PckAsset> assets, int index)
{
foreach (PckAsset asset in assets)
{
if (asset.Type == PckAssetType.TexturePackInfoFile ||
asset.Type == PckAssetType.SkinDataFile)
{
try
{
PckFile subPCK = asset.GetData(new PckFileReader(_endianness));
applyBulkProperties(subPCK.GetAssets(), index);
asset.SetData(new PckFileWriter(subPCK, _endianness));
}
catch (OverflowException ex)
{
Debug.WriteLine(ex.Message);
}
}
if (index == -1 || (Enum.IsDefined(typeof(PckAssetType), index) && (int)asset.Type == index))
{
asset.AddParameter(propertyKeyTextBox.Text, propertyValueTextBox.Text);
}
}
if (Enum.IsDefined(typeof(PckAssetType), index))
{
MessageBox.Show(this, $"Data added to {(PckAssetType)index} entries");
return;
}
MessageBox.Show(this, "Data added to all entries");
}
private void treeMeta_AfterSelect(object sender, TreeViewEventArgs e)
{
propertyKeyTextBox.Text = propertyTreeview.SelectedNode.Text;
}
}
}