Skip to content

Commit

Permalink
Version 1.0.1: Added BlockSizeComboBox, CompressionLevelLabel and let…
Browse files Browse the repository at this point in the history
… the user continue when detecting a yet unimplemented multifile NDV0 fragment
  • Loading branch information
nicoboss committed Feb 2, 2019
1 parent 8018e7e commit 083c59f
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 69 deletions.
10 changes: 6 additions & 4 deletions CompressFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal class CompressFolder
private readonly RichTextBox DebugOutput;
private readonly string inFolderPath;
private readonly string outFolderPath;
private readonly int ZstdLevel;
private int amountOfBlocks;
private int currentBlockID;
private byte[] nsZipHeader;
Expand All @@ -24,19 +25,20 @@ internal class CompressFolder
private int sizeOfSize;

private CompressFolder(RichTextBox debugOutputArg, string inFolderPathArg, string outFolderPathArg,
int bsArg = 262144)
int bsArg, int ZstdLevelArg)
{
bs = bsArg;
ZstdLevel = ZstdLevelArg;
DebugOutput = debugOutputArg;
inFolderPath = inFolderPathArg;
outFolderPath = outFolderPathArg;
CompressFunct();
}

public static void Compress(RichTextBox debugOutputArg, string inFolderPathArg, string outFolderPathArg,
int bsArg = 262144)
int bsArg, int ZstdLevel)
{
new CompressFolder(debugOutputArg, inFolderPathArg, outFolderPathArg, bsArg);
new CompressFolder(debugOutputArg, inFolderPathArg, outFolderPathArg, bsArg, ZstdLevel);
}

private void CompressFunct()
Expand Down Expand Up @@ -187,7 +189,7 @@ private void CompressBlock(ref byte[] input, ref byte[] output)
using (var memoryStream = new MemoryStream())
using (var compressionStream = new ZstandardStream(memoryStream, CompressionMode.Compress))
{
compressionStream.CompressionLevel = 19;
compressionStream.CompressionLevel = ZstdLevel;
compressionStream.Write(input, 0, input.Length);
compressionStream.Close();
output = memoryStream.ToArray();
Expand Down
154 changes: 98 additions & 56 deletions Frontend.Designer.cs

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

51 changes: 50 additions & 1 deletion Frontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ namespace nsZip
{
public partial class Frontend : Form
{
private int BlockSize = 262144;
private string OutputFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
private bool VerifyWhenCompressing = true;
private int ZstdLevel = 18;

public Frontend()
{
Expand All @@ -23,6 +25,9 @@ public Frontend()
private void Form1_Load(object sender, EventArgs e)
{
MaximumSize = Screen.FromControl(this).WorkingArea.Size;
CompressionLevelComboBox.SelectedIndex = 3;
BlockSizeComboBox.SelectedIndex = 0;
VerifyAfterCompressCheckBox_CheckedChanged(null, null);
}

//To properly fit the Form to if moved to a screen with another resolution
Expand Down Expand Up @@ -205,7 +210,7 @@ private void CompressExtracted(Keyset keyset)
}

TrimDeltaNCA.Process("decrypted", keyset, DebugOutput);
CompressFolder.Compress(DebugOutput, "decrypted", "compressed");
CompressFolder.Compress(DebugOutput, "decrypted", "compressed", BlockSize, ZstdLevel);

if (VerifyWhenCompressing)
{
Expand Down Expand Up @@ -342,6 +347,50 @@ private void VerifyAfterCompressCheckBox_CheckedChanged(object sender, EventArgs
}

VerifyWhenCompressing = VerifyAfterCompressCheckBox.Checked;
DebugOutput.AppendText($"Set VerifyWhenCompressing to {VerifyWhenCompressing}\r\n");
}

private void CompressionLevelComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
switch (CompressionLevelComboBox.SelectedIndex)
{
case 0:
ZstdLevel = 8;
break;
case 1:
ZstdLevel = 12;
break;
case 2:
ZstdLevel = 14;
break;
case 3:
ZstdLevel = 18;
break;
case 4:
ZstdLevel = 22;
break;
default:
throw new NotImplementedException();
}

DebugOutput.AppendText($"Set ZstdLevel to {ZstdLevel}\r\n");
}

private void BlockSizeComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
switch (BlockSizeComboBox.SelectedIndex)
{
case 0:
BlockSize = 262144;
break;
case 1:
BlockSize = 524288;
break;
default:
throw new NotImplementedException();
}

DebugOutput.AppendText($"Set BlockSize to {BlockSize} bytes\r\n");
}
}
}
10 changes: 10 additions & 0 deletions LibHacExtensions/SearchDeltaMatching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;
using LibHac.IO;

namespace nsZip.LibHacExtensions
Expand Down Expand Up @@ -52,6 +53,15 @@ public static byte[] SearchMatching(IStorage fragmentFile, string newBaseFolderP
var fragmentSize = Header.FragmentHeaderSize + Header.FragmentBodySize;
if (fragmentFile.Length < fragmentSize)
{
var dialogResult = MessageBox.Show(
"The currently processing NCA contains a yet unimplemented NDV0 file. I will add support for it in the next few days. Do you want to continue and store it uncompressed - the resulting NSPZ/XCIZ file will be significantly larger then under normal circumstances?",
"Unimplemented NDV0 file detcted! Store uncompressed?", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
if (dialogResult == DialogResult.Yes)
{
return null;
}

throw new InvalidDataException(
$"Delta file is smaller than the header indicates. (0x{fragmentSize} bytes)");
}
Expand Down
5 changes: 3 additions & 2 deletions nsZip.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<UpdateUrl>http://www.nicobosshard.ch/nsZip/</UpdateUrl>
<ApplicationRevision>18</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<ApplicationRevision>21</ApplicationRevision>
<ApplicationVersion>1.0.1.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down Expand Up @@ -161,6 +161,7 @@
<Content Include="nsZip.ico" />
<EmbeddedResource Include="Frontend.resx">
<DependentUpon>Frontend.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
Loading

0 comments on commit 083c59f

Please sign in to comment.