Implement mini repacking (untested)

This commit is contained in:
Kurt
2015-05-05 22:46:57 -07:00
parent 5fe4889423
commit 23a4135c0c
2 changed files with 83 additions and 24 deletions

View File

@@ -32,11 +32,12 @@ private void InitializeComponent()
this.L_DARCMini = new System.Windows.Forms.Label();
this.CHK_PNG = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.PB_Repack = new System.Windows.Forms.Panel();
this.label4 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.CB_Repack = new System.Windows.Forms.ComboBox();
this.PB_BCLIM = new System.Windows.Forms.PictureBox();
this.B_Reset = new System.Windows.Forms.Button();
this.CHK_Delete = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.PB_BCLIM)).BeginInit();
this.SuspendLayout();
//
@@ -78,13 +79,13 @@ private void InitializeComponent()
this.label1.TabIndex = 3;
this.label1.Text = "BCLIM Viewer";
//
// panel1
// PB_Repack
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Location = new System.Drawing.Point(168, 124);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(144, 67);
this.panel1.TabIndex = 5;
this.PB_Repack.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.PB_Repack.Location = new System.Drawing.Point(168, 124);
this.PB_Repack.Name = "PB_Repack";
this.PB_Repack.Size = new System.Drawing.Size(144, 67);
this.PB_Repack.TabIndex = 5;
//
// label4
//
@@ -95,13 +96,13 @@ private void InitializeComponent()
this.label4.TabIndex = 7;
this.label4.Text = "Folder Repack";
//
// comboBox1
// CB_Repack
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(12, 124);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(150, 21);
this.comboBox1.TabIndex = 8;
this.CB_Repack.FormattingEnabled = true;
this.CB_Repack.Location = new System.Drawing.Point(12, 124);
this.CB_Repack.Name = "CB_Repack";
this.CB_Repack.Size = new System.Drawing.Size(150, 21);
this.CB_Repack.TabIndex = 8;
//
// PB_BCLIM
//
@@ -124,16 +125,29 @@ private void InitializeComponent()
this.B_Reset.UseVisualStyleBackColor = true;
this.B_Reset.Click += new System.EventHandler(this.B_Reset_Click);
//
// CHK_Delete
//
this.CHK_Delete.AutoSize = true;
this.CHK_Delete.Checked = true;
this.CHK_Delete.CheckState = System.Windows.Forms.CheckState.Checked;
this.CHK_Delete.Location = new System.Drawing.Point(12, 148);
this.CHK_Delete.Name = "CHK_Delete";
this.CHK_Delete.Size = new System.Drawing.Size(155, 17);
this.CHK_Delete.TabIndex = 10;
this.CHK_Delete.Text = "Delete Folder after Packing";
this.CHK_Delete.UseVisualStyleBackColor = true;
//
// ToolsUI
//
this.AllowDrop = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(324, 362);
this.Controls.Add(this.CHK_Delete);
this.Controls.Add(this.B_Reset);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.CB_Repack);
this.Controls.Add(this.label4);
this.Controls.Add(this.panel1);
this.Controls.Add(this.PB_Repack);
this.Controls.Add(this.label1);
this.Controls.Add(this.CHK_PNG);
this.Controls.Add(this.PB_BCLIM);
@@ -156,10 +170,11 @@ private void InitializeComponent()
private System.Windows.Forms.Label L_DARCMini;
private System.Windows.Forms.CheckBox CHK_PNG;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel PB_Repack;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.ComboBox CB_Repack;
private System.Windows.Forms.PictureBox PB_BCLIM;
private System.Windows.Forms.Button B_Reset;
private System.Windows.Forms.CheckBox CHK_Delete;
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace pk3DS
@@ -16,6 +17,11 @@ public ToolsUI()
PB_BCLIM.DragEnter += tabMain_DragEnter;
PB_BCLIM.DragDrop += tabMain_DragDrop;
CLIMWindow = PB_BCLIM.Size;
CB_Repack.Items.Add("GARC Pack");
CB_Repack.Items.Add("GARC Pack (from Existing)");
CB_Repack.Items.Add("DARC Pack (use filenames)");
CB_Repack.Items.Add("Mini Pack (from Name)");
CB_Repack.SelectedIndex = 0;
}
private void tabMain_DragEnter(object sender, DragEventArgs e)
{
@@ -30,7 +36,7 @@ private void tabMain_DragDrop(object sender, DragEventArgs e)
openARC(path);
else if (sender == PB_BCLIM)
openIMG(path);
else if (sender == panel1)
else if (sender == PB_Repack)
saveARC(path);
}
private void dropHover(object sender, EventArgs e)
@@ -41,11 +47,6 @@ private void dropLeave(object sender, EventArgs e)
{
(sender as Panel).BackColor = Color.Transparent;
}
private void saveARC(string path)
{
int type = comboBox1.SelectedIndex;
Util.Alert("Not implemented." + Environment.NewLine + path);
}
private void openIMG(string path)
{
var img = png2bclim.makeBMP(path, CHK_PNG.Checked);
@@ -99,6 +100,49 @@ private void openARC(string path, bool recursing = false)
Util.Error("File error:" + Environment.NewLine + path, e.ToString());
}
}
private void saveARC(string path)
{
if (Directory.Exists(path)) { Util.Error("Input path is not a Folder", path); return; }
string folderName = Path.GetDirectoryName(path);
string parentName = Directory.GetParent(path).FullName;
int type = CB_Repack.SelectedIndex;
switch (type)
{
case -1: return;
case 0: // GARC Pack
case 1: // GARC Pack Existing
case 2: // DARC Pack
{
Util.Alert("Repacking not implemented." + Environment.NewLine + path);
return;
}
case 3: // Mini Pack
{
string fileName = folderName.Replace("_", "");
if (fileName.Length < 2) { Util.Error("Mini Folder name not valid:", path); return; }
string fileExt = fileName.Substring(fileName.Length - 2);
string fileNum = fileName.Substring(0, fileName.Length - 3); // ignore "."
string[] filesToPack = Directory.GetFiles(path);
byte[][] data = new byte[filesToPack.Length][];
for (int i = 0; i < filesToPack.Length; i++) data[i] = File.ReadAllBytes(filesToPack[i]);
byte[] miniBytes = ARC.packMini(data, fileExt);
string newName = fileNum + "." + fileExt;
File.WriteAllBytes(parentName + newName, miniBytes);
Util.Alert("Mini Folder Repacked!",
String.Format("InFolder: {0}{2}OutFile{1}", folderName, newName, Path.DirectorySeparatorChar));
break;
}
default: Util.Alert("Repacking not implemented." + Environment.NewLine + path);
return;
}
// Delete path after repacking
if (CHK_Delete.Checked)
Directory.Delete(path, true);
}
private void PB_BCLIM_Click(object sender, EventArgs e)
{
if (ModifierKeys == Keys.Control && Util.Prompt(MessageBoxButtons.YesNo, "Copy image to clipboard?") == DialogResult.Yes)