Skip to content

Commit

Permalink
Adding Shadow support.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed Feb 27, 2016
1 parent 885b252 commit bd9aac5
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 87 deletions.
4 changes: 0 additions & 4 deletions HeroesONE/HeroesONE.csproj
Expand Up @@ -35,10 +35,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FraGag.Compression.Prs, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Dependencies\FraGag.Compression.Prs.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
Expand Down
20 changes: 8 additions & 12 deletions HeroesONE/Program.cs
@@ -1,6 +1,5 @@
using System;
using System.IO;
using FraGag.Compression;
using HeroesONELib;

namespace HeroesONE
Expand All @@ -9,19 +8,19 @@ static class Program
{
static LongOpt[] opts = {
new LongOpt("help", Argument.No, null, 'h'),
new LongOpt("no-compression", Argument.No, null, 'n'),
new LongOpt("pack", Argument.No, null, 'p'),
new LongOpt("unpack", Argument.No, null, 'u')
new LongOpt("unpack", Argument.No, null, 'u'),
new LongOpt("shadow", Argument.No, null, 's')
};

/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
Getopt getopt = new Getopt("KensSharp", args, Getopt.digest(opts), opts);
Getopt getopt = new Getopt("HeroesONE", args, Getopt.digest(opts), opts);
Mode? mode = null;
bool compress = true;
bool shadow = false;
int opt = getopt.getopt();
while (opt != -1)
{
Expand All @@ -36,8 +35,8 @@ static void Main(string[] args)
case 'u':
mode = Mode.Unpack;
break;
case 'n':
compress = false;
case 's':
shadow = true;
break;
}
opt = getopt.getopt();
Expand All @@ -61,10 +60,7 @@ static void Main(string[] args)
Directory.CreateDirectory(dest);
}
foreach (HeroesONEFile.File item in one.Files)
if (!compress)
File.WriteAllBytes(Path.Combine(dest, item.Name), item.Data);
else
File.WriteAllBytes(Path.Combine(dest, item.Name), Prs.Decompress(item.Data));
File.WriteAllBytes(Path.Combine(dest, item.Name), item.Data);
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
break;
Expand All @@ -75,7 +71,7 @@ static void Main(string[] args)
HeroesONEFile ar = new HeroesONEFile();
for (int i = getopt.Optind; i < args.Length - 1; i++)
ar.Files.Add(new HeroesONEFile.File(args[i]));
ar.Save(fn);
ar.Save(fn, shadow);
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
break;
Expand Down
4 changes: 2 additions & 2 deletions HeroesONE/Resources/HelpText.txt
Expand Up @@ -4,5 +4,5 @@ Arguments:
-u, --unpack filename [destination] Extracts filename to destination, or the
current directory.
-p, --pack filenames destination Packs files into the destination archive.
-n, --no-compress Does not compress or decompress files in
the archive.
-s, --shadow Packs the archive with the "Shadow the
Hedgehog" format.
3 changes: 0 additions & 3 deletions HeroesONEEdit/HeroesONEEdit.csproj
Expand Up @@ -33,9 +33,6 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="FraGag.Compression.Prs">
<HintPath>..\Dependencies\FraGag.Compression.Prs.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
Expand Down
28 changes: 16 additions & 12 deletions HeroesONEEdit/MainForm.cs
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Windows.Forms;
using HeroesONELib;
using FraGag.Compression;

namespace HeroesONEEdit
{
Expand All @@ -29,15 +28,20 @@ private void Form1_Load(object sender, EventArgs e)

private void LoadFile(string filename)
{
try
#if !DEBUG
try
{
#endif
file = new HeroesONEFile(filename);
#if !DEBUG
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
return;
}
#endif
shadowModeToolStripMenuItem.Checked = file.IsShadow;
this.filename = filename;
listView1.Items.Clear();
imageList1.Images.Clear();
Expand Down Expand Up @@ -66,15 +70,15 @@ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
if (string.IsNullOrEmpty(filename))
saveAsToolStripMenuItem_Click(sender, e);
else
file.Save(filename);
file.Save(filename, shadowModeToolStripMenuItem.Checked);
}

private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
using (SaveFileDialog a = new SaveFileDialog() { Filter = "ONE Files|*.one|All Files|*.*" })
if (a.ShowDialog() == DialogResult.OK)
{
file.Save(a.FileName);
file.Save(a.FileName, shadowModeToolStripMenuItem.Checked);
this.filename = a.FileName;
}
}
Expand All @@ -87,7 +91,7 @@ private void extractAllToolStripMenuItem_Click(object sender, EventArgs e)
a.SelectedPath = Path.GetDirectoryName(filename);
if (a.ShowDialog(this) == DialogResult.OK)
foreach (HeroesONEFile.File item in file.Files)
File.WriteAllBytes(Path.Combine(a.SelectedPath, item.Name), Prs.Decompress(item.Data));
File.WriteAllBytes(Path.Combine(a.SelectedPath, item.Name), item.Data);
}
}

Expand Down Expand Up @@ -122,7 +126,7 @@ private void extractToolStripMenuItem_Click(object sender, EventArgs e)
FileName = selectedItem.Text
})
if (a.ShowDialog() == DialogResult.OK)
File.WriteAllBytes(a.FileName, Prs.Decompress(file.Files[listView1.Items.IndexOf(selectedItem)].Data));
File.WriteAllBytes(a.FileName, file.Files[listView1.Items.IndexOf(selectedItem)].Data);
}

private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -138,7 +142,7 @@ private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
if (a.ShowDialog() == DialogResult.OK)
{
file.Files[i] = new HeroesONEFile.File(a.FileName);
file.Files[i].Data = Prs.Compress(file.Files[i].Data);
file.Files[i].Data = file.Files[i].Data;
file.Files[i].Name = fn;
}
}
Expand All @@ -157,7 +161,7 @@ private void insertToolStripMenuItem_Click(object sender, EventArgs e)
foreach (string item in a.FileNames)
{
file.Files.Insert(i, new HeroesONEFile.File(item));
file.Files[i].Data = Prs.Compress(file.Files[i].Data);
file.Files[i].Data = file.Files[i].Data;
i++;
}
listView1.Items.Clear();
Expand Down Expand Up @@ -212,7 +216,7 @@ private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
private void listView1_ItemActivate(object sender, EventArgs e)
{
string fp = Path.Combine(Path.GetTempPath(), file.Files[listView1.SelectedIndices[0]].Name);
File.WriteAllBytes(fp, Prs.Decompress(file.Files[listView1.SelectedIndices[0]].Data));
File.WriteAllBytes(fp, file.Files[listView1.SelectedIndices[0]].Data);
System.Diagnostics.Process.Start(fp);
}

Expand Down Expand Up @@ -245,11 +249,11 @@ private void AddFiles(string[] files)
{
found = true;
file.Files[j] = new HeroesONEFile.File(item);
file.Files[j].Data = Prs.Compress(file.Files[j].Data);
file.Files[j].Data = file.Files[j].Data;
}
if (found) continue;
file.Files.Add(new HeroesONEFile.File(item));
file.Files[i].Data = Prs.Compress(file.Files[i].Data);
file.Files[i].Data = file.Files[i].Data;
imageList1.Images.Add(GetIcon(file.Files[i].Name));
listView1.Items.Add(file.Files[i].Name, i);
i++;
Expand All @@ -259,7 +263,7 @@ private void AddFiles(string[] files)
private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
{
string fn = Path.Combine(Path.GetTempPath(), file.Files[listView1.SelectedIndices[0]].Name);
File.WriteAllBytes(fn, Prs.Decompress(file.Files[listView1.SelectedIndices[0]].Data));
File.WriteAllBytes(fn, file.Files[listView1.SelectedIndices[0]].Data);
DoDragDrop(new DataObject(DataFormats.FileDrop, new string[] { fn }), DragDropEffects.All);
}

Expand Down
10 changes: 10 additions & 0 deletions HeroesONEEdit/MainForm.designer.cs

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

0 comments on commit bd9aac5

Please sign in to comment.