Rename 'PckEditor' to 'PckAssetBrowserEditor'

This commit is contained in:
miku-666
2025-11-10 04:37:52 +01:00
parent 3478038c95
commit cae8dda315
6 changed files with 54 additions and 130 deletions

View File

@@ -2,7 +2,7 @@
namespace PckStudio.Controls
{
partial class PckEditor
partial class PckAssetBrowserEditor
{
/// <summary>
/// Required designer variable.
@@ -32,7 +32,7 @@ namespace PckStudio.Controls
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.PictureBox logoPictureBox;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PckEditor));
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PckAssetBrowserEditor));
this.pckFileLabel = new MetroFramework.Controls.MetroLabel();
this.labelImageSize = new MetroFramework.Controls.MetroLabel();
this.fileEntryCountLabel = new MetroFramework.Controls.MetroLabel();

View File

@@ -35,24 +35,24 @@ using PckStudio.Internal;
using PckStudio.Popups;
using PckStudio.Properties;
using PckStudio.Json;
using PckStudio.Rendering;
using PckStudio.ModelSupport;
using PckStudio.Core;
using PckStudio.Core.Json;
using PckStudio.Core.Skin;
using PckStudio.Core.Deserializer;
using PckStudio.Core.Serializer;
using PckStudio.Core.Json;
using PckStudio.Core.FileFormats;
using PckStudio.Core.Skin;
using PckStudio.Rendering;
using PckStudio.Core;
using PckStudio.ModelSupport;
using PckStudio.Json;
using PckStudio.Core.IO.PckAudio;
using PckStudio.Core.IO._3DST;
using PckStudio.Core.Misc;
using PckStudio.Core.DLC;
namespace PckStudio.Controls
{
internal partial class PckEditor : EditorControl<PackInfo>
internal partial class PckAssetBrowserEditor : EditorControl<PackInfo>
{
private string _location = string.Empty;
private readonly OMI.ByteOrder _originalEndianness;
@@ -78,15 +78,15 @@ namespace PckStudio.Controls
private readonly Dictionary<PckAssetType, Action<PckAsset>> _pckAssetTypeHandler;
public PckEditor(PackInfo packInfo, ISaveContext<PackInfo> saveContext)
public PckAssetBrowserEditor(PackInfo packInfo, ISaveContext<PackInfo> saveContext)
: base(packInfo, saveContext)
{
InitializeComponent();
_onModifiedChangeDelegate = OnModify;
_originalEndianness = packInfo.Endianness;
_currentEndianness = packInfo.Endianness;
_originalEndianness = packInfo.ByteOrder;
_currentEndianness = packInfo.ByteOrder;
LittleEndianCheckBox.Visible = packInfo.AllowEndianSwap;
LittleEndianCheckBox.Visible = packInfo.AllowByteOrderSwap;
treeViewMain.TreeViewNodeSorter = new PckNodeSorter();
@@ -213,7 +213,7 @@ namespace PckStudio.Controls
if (asset.Size <= 0)
{
Trace.TraceInformation($"[{nameof(PckEditor)}:{nameof(HandleTextureFile)}] '{asset.Filename}' size is 0.");
Trace.TraceInformation($"[{nameof(PckAssetBrowserEditor)}:{nameof(HandleTextureFile)}] '{asset.Filename}' size is 0.");
return;
}

View File

@@ -11,20 +11,21 @@ using OMI.Formats.Languages;
using OMI.Workers.Pck;
using OMI.Workers.GameRule;
using OMI.Workers.Language;
using PckStudio.Properties;
using PckStudio.Forms;
using PckStudio.Forms.Additional_Popups;
using PckStudio.Core.Misc;
using PckStudio.Forms.Features;
using PckStudio.Core.Extensions;
using PckStudio.Popups;
using PckStudio.External.API.Miles;
using PckStudio.Internal.App;
using PckStudio.Interfaces;
using PckStudio.Controls;
using PckStudio.External.API.Miles;
using PckStudio.Forms;
using PckStudio.Forms.Features;
using PckStudio.Forms.Additional_Popups;
using PckStudio.Interfaces;
using PckStudio.Internal;
using PckStudio.Internal.App;
using PckStudio.Popups;
using PckStudio.Properties;
using PckStudio.Core;
using PckStudio.Core.App;
using PckStudio.Core.DLC;
using PckStudio.Core.Extensions;
using PckStudio.Core.Interfaces;
namespace PckStudio
{
@@ -59,9 +60,13 @@ namespace PckStudio
public void LoadPckFromFile(string filepath)
{
Core.Interfaces.IDLCPackage dlcPackage = DLCManager.Default.OpenDLCPackage(filepath);
IDLCPackage dlcPackage = DLCManager.Default.OpenDLCPackage(filepath);
Debug.WriteLine(dlcPackage?.GetDLCPackageType());
AddEditorPage(filepath);
if (dlcPackage is null)
return;
SaveToRecentFiles(filepath);
if (dlcPackage.GetDLCPackageType() == DLCPackageType.Unknown)
AddEditorPage(dlcPackage);
}
internal void OpenNewPckTab(string caption, string identifier, PackInfo packInfo, ISaveContext<PackInfo> saveContext)
@@ -71,92 +76,28 @@ namespace PckStudio
tabControl.SelectTab(openTabPages[identifier]);
return;
}
var editor = new PckEditor(packInfo, saveContext);
var editor = new PckAssetBrowserEditor(packInfo, saveContext);
AddPage(caption, identifier, editor);
}
private void AddEditorPage(string caption, string identifier, PackInfo packInfo, ISaveContext<PackInfo> saveContext = null)
{
saveContext ??= GetDefaultSaveContext("./new.pck", "PCK (Minecraft Console Package)");
var editor = new PckEditor(packInfo, saveContext);
var editor = new PckAssetBrowserEditor(packInfo, saveContext);
AddPage(caption, identifier, editor);
}
private PckFile ReadPck(string filePath, OMI.ByteOrder byteOrder)
private void AddEditorPage(IDLCPackage dlcPackage)
{
var pckReader = new PckFileReader(byteOrder);
return pckReader.FromFile(filePath);
}
private bool TryOpenPck(string filepath, out PackInfo packInfo)
{
if (!File.Exists(filepath) || !filepath.EndsWith(".pck"))
{
packInfo = PackInfo.Empty;
return false;
PackInfo packInfo = PackInfo.Create((dlcPackage as UnknownDLCPackage).PckFile, default, false);
ISaveContext<PackInfo> saveContext = GetDefaultSaveContext("", "PCK (Minecraft Console Package)");
var editor = new PckAssetBrowserEditor(packInfo, saveContext);
TabPage page = AddPage(dlcPackage.Name, dlcPackage.Name, editor);
}
try
{
OMI.ByteOrder byteOrder = OMI.ByteOrder.BigEndian;
PckFile pckFile = ReadPck(filepath, byteOrder);
packInfo = PackInfo.Create(pckFile, byteOrder, true);
return packInfo.IsValid;
}
catch (OverflowException)
{
try
{
// if failed, attempt again in the reverse. THEN throw an error if failed
OMI.ByteOrder byteOrder = OMI.ByteOrder.LittleEndian;
PckFile pckFile = ReadPck(filepath, byteOrder);
packInfo = PackInfo.Create(pckFile, byteOrder, true);
return packInfo.IsValid;
}
catch (OverflowException ex)
{
MessageBox.Show(this, "Failed to open pck", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Debug.WriteLine(ex.Message);
}
}
catch
{
MessageBox.Show(this, "Failed to open pck. There's two common reasons for this:\n" +
"1. The file is audio/music cues PCK file. Please use the specialized editor while inside of a pck file.\n" +
"2. We're aware of an issue where a pck file might fail to load because it contains multiple entries with the same path.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
packInfo = PackInfo.Empty;
return false;
}
private void AddEditorPage(string filepath)
{
if (!File.Exists(filepath) && !filepath.EndsWith(".pck"))
{
Trace.TraceError($"[{nameof(AddEditorPage)}] Invalid filepath({filepath})");
return;
}
if (openTabPages.ContainsKey(filepath))
{
tabControl.SelectTab(openTabPages[filepath]);
return;
}
SaveToRecentFiles(filepath);
if (TryOpenPck(filepath, out PackInfo packInfo))
{
ISaveContext<PackInfo> saveContext = GetDefaultSaveContext(filepath, "PCK (Minecraft Console Package)");
var editor = new PckEditor(packInfo, saveContext);
TabPage page = AddPage(Path.GetFileName(filepath), filepath, editor);
return;
}
MessageBox.Show(string.Format("Failed to load {0}", Path.GetFileName(filepath)), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private static ISaveContext<PackInfo> GetDefaultSaveContext(string filepath, string description)
{
return new DelegatedFileSaveContext<PackInfo>(filepath, false, new FileDialogFilter(description, "*"+Path.GetExtension(filepath)),(packInfo, stream) => new PckFileWriter(packInfo.File, packInfo.Endianness).WriteToStream(stream));
return new DelegatedFileSaveContext<PackInfo>(filepath, false, new FileDialogFilter(description, "*"+Path.GetExtension(filepath)),(packInfo, stream) => new PckFileWriter(packInfo.File, packInfo.ByteOrder).WriteToStream(stream));
}
private TabPage AddPage(string caption, string identifier, Control control)
@@ -434,7 +375,7 @@ namespace PckStudio
if (TryGetCurrentEditor(out IEditor<PackInfo> editor))
{
using AdvancedOptions advanced = new AdvancedOptions(editor.EditorValue.File);
advanced.IsLittleEndian = editor.EditorValue.Endianness == OMI.ByteOrder.LittleEndian;
advanced.IsLittleEndian = editor.EditorValue.ByteOrder == OMI.ByteOrder.LittleEndian;
if (advanced.ShowDialog() == DialogResult.OK)
{
editor.UpdateView();

View File

@@ -146,11 +146,11 @@
<SubType>Form</SubType>
</Compile>
<Compile Include="Controls\PageClosingEventArgs.cs" />
<Compile Include="Controls\PckEditor.cs">
<Compile Include="Controls\PckAssetBrowserEditor.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\PckEditor.Designer.cs">
<DependentUpon>PckEditor.cs</DependentUpon>
<Compile Include="Controls\PckAssetBrowserEditor.Designer.cs">
<DependentUpon>PckAssetBrowserEditor.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Additional-Popups\FilterPrompt.cs">
<SubType>Form</SubType>
@@ -395,8 +395,8 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Controls\PckEditor.resx">
<DependentUpon>PckEditor.cs</DependentUpon>
<EmbeddedResource Include="Controls\PckAssetBrowserEditor.resx">
<DependentUpon>PckAssetBrowserEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Additional-Popups\FilterPrompt.resx">
<DependentUpon>FilterPrompt.cs</DependentUpon>

View File

@@ -8,38 +8,21 @@ namespace PckStudio.Core
public static readonly PackInfo Empty = new PackInfo(default, default, default);
public bool IsValid { get; }
public PckFile File { get; }
public OMI.ByteOrder Endianness { get; }
public OMI.ByteOrder ByteOrder { get; }
//public enum PackType
//{
// Unknown = -1,
// SkinPack,
// TexturePack,
// MashUpPack
//}
public bool AllowByteOrderSwap { get; }
//public PackType Type { get; }
public bool AllowEndianSwap { get; }
public static PackInfo Create(PckFile file, OMI.ByteOrder endianness, bool allowEndianSwap)
public static PackInfo Create(PckFile file, OMI.ByteOrder byteOrder, bool allowByteOrderSwap)
{
return new PackInfo(file, endianness, allowEndianSwap);
return new PackInfo(file, byteOrder, allowByteOrderSwap);
}
private PackInfo(PckFile file, OMI.ByteOrder endianness, bool allowEndianSwap)
private PackInfo(PckFile file, OMI.ByteOrder byteOrder, bool allowByteOrderSwap)
{
File = file;
Endianness = endianness;
AllowEndianSwap = allowEndianSwap;
//Type = GetPackType();
IsValid = file is not null && Enum.IsDefined(typeof(OMI.ByteOrder), endianness); // && Type != PackType.Unknown;
ByteOrder = byteOrder;
AllowByteOrderSwap = allowByteOrderSwap;
IsValid = file is not null && Enum.IsDefined(typeof(OMI.ByteOrder), byteOrder);
}
//private PackType GetPackType()
//{
// return PackType.SkinPack;
//}
}
}