Skip to content

Commit

Permalink
Add new pak extract / pack tool
Browse files Browse the repository at this point in the history
  • Loading branch information
IntelOrca committed Feb 9, 2024
1 parent 77b64e1 commit 6795ae0
Show file tree
Hide file tree
Showing 4 changed files with 439 additions and 0 deletions.
200 changes: 200 additions & 0 deletions src/peggleedit/Forms/PakToolForm.Designer.cs

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

105 changes: 105 additions & 0 deletions src/peggleedit/Forms/PakToolForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using IntelOrca.PeggleEdit.Tools.Pack;

namespace IntelOrca.PeggleEdit.Designer.Forms
{
public partial class PakToolForm : Form
{
public PakToolForm()
{
InitializeComponent();
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
AutoResize();
}

protected override void OnResize(EventArgs e)
{
base.OnResize(e);
AutoResize();
}

private void AutoResize()
{
ClientSize = new Size(ClientSize.Width, tableLayoutPanel1.Height);
}

private void btnPakBrowse_Click(object sender, EventArgs e)
{
using (var dialog = new SaveFileDialog())
{
dialog.Filter = ".pak Files (*.pak)|*.pak";
if (dialog.ShowDialog() == DialogResult.OK)
{
txtPakLocation.Text = dialog.FileName;
}
}
}

private void btnExtractBrowse_Click(object sender, EventArgs e)
{
using (var dialog = new FolderBrowserDialog())
{
if (dialog.ShowDialog() == DialogResult.OK)
{
txtExtractLocation.Text = dialog.SelectedPath;
}
}
}

private void btnExtract_Click(object sender, EventArgs e)
{
var pakLocation = txtPakLocation.Text.Trim();
var extractLocation = txtExtractLocation.Text.Trim();
try
{
var pak = new PakCollection(pakLocation);
pak.Export(extractLocation);
}
catch (Exception ex)
{
ShowError(ex);
}
}

private void btnPack_Click(object sender, EventArgs e)
{
var pakLocation = txtPakLocation.Text.Trim();
var extractLocation = txtExtractLocation.Text.Trim();
try
{
var pak = new PakCollection();
Import(pak, extractLocation, "");
pak.Save(pakLocation);
}
catch (Exception ex)
{
ShowError(ex);
}
}

private void Import(PakCollection pak, string absolute, string relative)
{
foreach (var f in Directory.GetFiles(absolute))
{
pak.ImportFile(relative, f);
}
foreach (var d in Directory.GetDirectories(absolute))
{
var folderName = Path.GetFileName(d);
Import(pak, d, Path.Combine(relative, folderName));
}
}

private void ShowError(Exception ex)
{
MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Loading

0 comments on commit 6795ae0

Please sign in to comment.