Skip to content

Commit

Permalink
Rework of FileBuffers, option to add files to the ISO, and logging of…
Browse files Browse the repository at this point in the history
… command process outputs
  • Loading branch information
bgsamm committed Dec 12, 2021
1 parent a7beaea commit 0ab4dac
Show file tree
Hide file tree
Showing 15 changed files with 264 additions and 205 deletions.
22 changes: 19 additions & 3 deletions PBRHex Setup/PBRHex Setup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,14 @@
"PrerequisitesLocation" = "2:1"
"Url" = "8:"
"ComponentsUrl" = "8:"
"Items"
{
"{EDC2488A-8267-493A-A98E-7D9C3B36CDF3}:.NETFramework,Version=v4.7.2"
{
"Name" = "8:Microsoft .NET Framework 4.7.2 (x86 and x64)"
"ProductCode" = "8:.NETFramework,Version=v4.7.2"
}
}
}
}
"Release"
Expand All @@ -848,6 +856,14 @@
"PrerequisitesLocation" = "2:1"
"Url" = "8:"
"ComponentsUrl" = "8:"
"Items"
{
"{EDC2488A-8267-493A-A98E-7D9C3B36CDF3}:.NETFramework,Version=v4.7.2"
{
"Name" = "8:Microsoft .NET Framework 4.7.2 (x86 and x64)"
"ProductCode" = "8:.NETFramework,Version=v4.7.2"
}
}
}
}
}
Expand Down Expand Up @@ -3125,15 +3141,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:PBRHex"
"ProductCode" = "8:{F862B141-98A2-4B8F-A0AC-27BF24540CA4}"
"PackageCode" = "8:{814D39E3-EF1C-4664-A38F-2F514E651F08}"
"ProductCode" = "8:{474EBDA2-7043-4C36-9B60-AC8E24CC2659}"
"PackageCode" = "8:{2D7468B5-FAF1-45C3-B01F-C5E61CC1E8DD}"
"UpgradeCode" = "8:{D48A0932-A217-4C66-91CB-5BF77D165DBB}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.0.0"
"ProductVersion" = "8:1.0.3"
"Manufacturer" = "8:PBRHex"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down
5 changes: 3 additions & 2 deletions PBRHex/Commands/FsysCommands/CreateFileCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public CreateFileCommand(IFsysEditor editor, FSYS fsys) {
}

public override bool Execute() {
var file = FileUtils.CreateFile($@"{Program.TempDir}\temp", 0x10);
File = FSYS.AddFile(file);
string path = $@"{Program.TempDir}\temp";
FileUtils.CreateFile(path, 0x10);
File = FSYS.AddFile(path);
Editor.AddFile(File);
return false;
}
Expand Down
5 changes: 1 addition & 4 deletions PBRHex/Files/DOL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ public static class DOL
private static FileBuffer Main;

public static void Initialize() {
Main = new FileBuffer($@"{Program.ISODir}\sys\main.dol")
{
WorkingDir = FileUtils.CreateWorkspace($@"{Program.ISODir}\sys\main.dol")
};
Main = new FileBuffer($@"{Program.ISODir}\sys\main.dol");
Comments = new Dictionary<uint, string>();
string path = $@"{Program.UserDir}\comments.txt";
if(File.Exists(path)) {
Expand Down
44 changes: 19 additions & 25 deletions PBRHex/Files/FSYS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ namespace PBRHex.Files
{
public class FSYS : FileBuffer
{
public List<FileBuffer> Files { get; private set; }
public int FileCount => Files.Count;
public string ExtractedDir { get; set; }
public readonly List<FileBuffer> Files;

public FSYS(string path, FileBuffer[] files) : base(path) {
Files = new List<FileBuffer>(files.Length);
Files.AddRange(files);
public FSYS(string path) : base(path) {
Files = new List<FileBuffer>(FileUtils.DecompressFSYS(Path));
}

public FileBuffer GetFile(int id) {
Expand All @@ -23,37 +21,33 @@ public FileBuffer GetFile(int id) {
return null;
}

//public FileBuffer AddFile() {
// string outpath = $@"{ExtractedDir}\(null)_{Files.Count.ToString("X8").ToLower()}";
// FileUtils.CreateFile(outpath, 800);
// var file = new FileBuffer(outpath) { WorkingDir = ExtractedDir };
// Files.Add(file);
// return file;
//}

//public FileBuffer AddFile(string inpath) {
// string outpath = $@"{ExtractedDir}\(null)_{Files.Count.ToString("X8").ToLower()}";
// FileUtils.CopyFile(inpath, outpath);
// var file = new FileBuffer(outpath) { WorkingDir = ExtractedDir };
// Files.Add(file);
// return file;
//}
public FileBuffer AddFile(string inpath) {
string outpath = $@"{WorkingDir}\files\(null)_{Files.Count:x8}{System.IO.Path.GetExtension(inpath)}";
FileUtils.CopyFile(inpath, outpath);
var newFile = new FileBuffer(outpath, $@"{WorkingDir}\files");
newFile.ID = FileUtils.GenerateFileID(this, newFile);
Files.Add(newFile);
return newFile;
}

/// <summary>
/// Copies the supplied file into the archive, returning the newly created file.
/// </summary>
public FileBuffer AddFile(FileBuffer file) {
string path = $@"{ExtractedDir}\(null)_{Files.Count.ToString("X8").ToLower()}";
var newFile = FileUtils.CreateFile(path, file.GetBufferCopy());
newFile.WorkingDir = ExtractedDir;
newFile.ID = file.ID;
string path = $@"{WorkingDir}\files\(null)_{Files.Count:x8}";
FileUtils.CreateFile(path, file.GetBufferCopy());
var newFile = new FileBuffer(path, $@"{WorkingDir}\files");
if(file.ID != 0)
newFile.ID = file.ID;
else
newFile.ID = FileUtils.GenerateFileID(this, newFile);
Files.Add(newFile);
return newFile;
}

public void RemoveFile(int id) {
var file = GetFile(id);
FileUtils.DeleteFile($@"{ExtractedDir}\{file.Name}");
FileUtils.DeleteFile($@"{WorkingDir}\files\{file.Name}");
Files.Remove(file);
}
}
Expand Down
22 changes: 16 additions & 6 deletions PBRHex/Files/FileBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class FileBuffer
public LabelType[] LabelMap => MakeLabelMap();
public ReadOnlyLabelDict Labels => new ReadOnlyLabelDict(LabelDict);

public readonly Tape<Command> EditHistory;
public readonly Tape<int> LocationHistory;
public Tape<Command> EditHistory { get; private set; }
public Tape<int> LocationHistory { get; private set; }
public int SaveHead;

protected byte[] Buffer { get; set; }
Expand All @@ -32,7 +32,7 @@ public class FileBuffer
/// <summary>
/// The full path of the item.
/// </summary>
public readonly string Path;
public string Path { get; private set; }
/// <summary>
/// The path to the containing directory of the item.
/// </summary>
Expand All @@ -42,7 +42,7 @@ public class FileBuffer
/// <summary>
/// The path to the file's working directory when editing.
/// </summary>
public string WorkingDir { get; set; }
public string WorkingDir { get; private set; }
public string WorkingPath => $@"{WorkingDir}\{Name}";

private string Key => Extension == "" ?
Expand All @@ -61,9 +61,19 @@ static FileBuffer() {
LoadMetadata();
}

public FileBuffer(string filepath) {
Path = System.IO.Path.GetFullPath(filepath);
public FileBuffer(string path) {
Path = System.IO.Path.GetFullPath(path);
WorkingDir = FileUtils.CreateWorkspace(Path);
Initialize();
}

public FileBuffer(string path, string workspace) {
Path = System.IO.Path.GetFullPath(path);
WorkingDir = workspace;
Initialize();
}

private void Initialize() {
Buffer = File.ReadAllBytes(Path);

LocationHistory = new Tape<int>();
Expand Down
29 changes: 18 additions & 11 deletions PBRHex/Files/GTX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,35 @@

namespace PBRHex.Files
{
public class GTX : FileBuffer
public class GTX
{
public int ID => Buffer.ID;

public readonly int Width;
public readonly int Height;
public readonly ImageEncoding Encoding;
public readonly PaletteFormat PaletteEncoding;

private readonly int ImageAddress;
private readonly int PaletteAddress;
private readonly FileBuffer Buffer;

public GTX(FileBuffer buffer) {
Buffer = buffer;

public GTX(string path) : base(path) {
Width = ReadShort(0);
Height = ReadShort(2);
Encoding = (ImageEncoding)ReadInt(8);
PaletteEncoding = (PaletteFormat)ReadInt(0xC);
Width = Buffer.ReadShort(0);
Height = Buffer.ReadShort(2);
Encoding = (ImageEncoding)Buffer.ReadInt(8);
PaletteEncoding = (PaletteFormat)Buffer.ReadInt(0xC);

ImageAddress = ReadInt(0x28);
PaletteAddress = ReadInt(0x48);
ImageAddress = Buffer.ReadInt(0x28);
PaletteAddress = Buffer.ReadInt(0x48);
}

public int GetImageDataSize() {
if(PaletteAddress > 0)
return Width * Height;
return ReadInt(0x4c);
return Buffer.ReadInt(0x4c);
}

public Color GetPixel(int x, int y) {
Expand All @@ -41,14 +46,16 @@ public Color GetPixel(int x, int y) {
block_x * block_height * block_width +
(y % block_height) * block_width +
(x % block_width);
return GetColorFromPalette(ReadByte(ImageAddress + idx));
return GetColorFromPalette(Buffer.ReadByte(ImageAddress + idx));
}

public Color GetColorFromPalette(int index) {
if(PaletteEncoding != PaletteFormat.RGB5A3)
throw new NotImplementedException();
int rgb5a3 = ReadShort(PaletteAddress + index * 2);
int rgb5a3 = Buffer.ReadShort(PaletteAddress + index * 2);
return ImageUtils.RGB5A3toColor(rgb5a3);
}

public static explicit operator GTX(FileBuffer file) => new GTX(file);
}
}
34 changes: 31 additions & 3 deletions PBRHex/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0ab4dac

Please sign in to comment.