Skip to content

Commit

Permalink
Major speedups
Browse files Browse the repository at this point in the history
  • Loading branch information
simontime committed Oct 5, 2018
1 parent a3ff22c commit 4ca983e
Show file tree
Hide file tree
Showing 41 changed files with 492 additions and 525 deletions.
142 changes: 71 additions & 71 deletions Form1.Designer.cs

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

29 changes: 18 additions & 11 deletions Form1.cs
Expand Up @@ -6,6 +6,7 @@
using System.Media;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using VGAudio.Formats;
Expand Down Expand Up @@ -34,6 +35,18 @@ public Form1()
InitializeComponent();
}

public bool CheckExtension(string Target, string Extension)
{
if (Regex.Match(Extension, $"(?i){Target}").Success)
{
return true;
}
else
{
return false;
}
}

private string[] GetTitleMeta(string TitleID)
{
var Info = new string[]
Expand Down Expand Up @@ -119,7 +132,8 @@ string ExpEnv(string In)

Input = Xci.SecurePartition.OpenFile
(
Xci.SecurePartition.Files.OrderByDescending(s => s.Size)
Xci.SecurePartition.Files
.OrderByDescending(s => s.Size)
.FirstOrDefault()
);
}
Expand Down Expand Up @@ -197,14 +211,7 @@ string ExpEnv(string In)
)
);

var Files = new string[Rom.Files.Count];

for (int i = 0; i < Rom.Files.Count; i++)
{
Files[i] = Rom.Files[i].FullPath.Substring(1);
}

IO.PopulateTreeView(treeView1, Files, '/');
IO.PopulateTreeView(treeView1.Nodes, Rom.RootDir);
}
catch (Exception)
{
Expand Down Expand Up @@ -273,7 +280,7 @@ private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs

var Ext = Name.Split('.')[Name.Count(c => c == '.')].ToUpper();

if (Ext == "BFSTM")
if (CheckExtension(Ext, "bfstm"))
{
try
{
Expand All @@ -297,7 +304,7 @@ private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs
{
}
}
else if (Ext == "WAV")
else if (CheckExtension(Ext, "bfstm"))
{
try
{
Expand Down
41 changes: 17 additions & 24 deletions IO.cs
@@ -1,36 +1,29 @@
using LibHac;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace SwitchExplorer
{
internal class IO
{
// Source: https://stackoverflow.com/a/19332770
public static void PopulateTreeView(TreeView treeView, string[] paths, char pathSeparator)
// Thanks to Alex Barney for providing this code!
public static void PopulateTreeView(TreeNodeCollection nodes, RomfsDir root)
{
TreeNode lastNode = null;
string subPathAgg;
foreach (string path in paths)
RomfsFile fileNode = root.FirstFile;

while (fileNode != null)
{
nodes.Add(fileNode.FullPath, fileNode.Name);
fileNode = fileNode.NextSibling;
}

RomfsDir dirNode = root.FirstChild;

while (dirNode != null)
{
subPathAgg = string.Empty;
foreach (string subPath in path.Split(pathSeparator))
{
subPathAgg += subPath + pathSeparator;
TreeNode[] nodes = treeView.Nodes.Find(subPathAgg, true);
if (nodes.Length == 0)
if (lastNode == null)
lastNode = treeView.Nodes.Add(subPathAgg, subPath);
else
lastNode = lastNode.Nodes.Add(subPathAgg, subPath);
else
lastNode = nodes[0];
}
lastNode = null;
TreeNode newNode = nodes.Add(dirNode.FullPath, dirNode.Name);
PopulateTreeView(newNode.Nodes, dirNode);
dirNode = dirNode.NextSibling;
}
}
}
}
}
2 changes: 1 addition & 1 deletion LibHac/Aes128CtrStream.cs
Expand Up @@ -157,7 +157,7 @@ public override int Read(byte[] buffer, int offset, int count)
{
ValidateSize(count);

var bytesRead = base.Read(_tempBuffer, 0, count);
int bytesRead = base.Read(_tempBuffer, 0, count);
if (bytesRead == 0) return 0;

return _decryptor.TransformBlock(_tempBuffer, 0, bytesRead, buffer, offset);
Expand Down
4 changes: 2 additions & 2 deletions LibHac/Aes128CtrTransform.cs
Expand Up @@ -42,7 +42,7 @@ public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, b
if (inputCount > _maxSize)
throw new ArgumentException($"{nameof(inputCount)} cannot be greater than {_maxSize}");

var blockCount = Util.DivideByRoundUp(inputCount, BlockSizeBytes);
int blockCount = Util.DivideByRoundUp(inputCount, BlockSizeBytes);

FillDecryptedCounter(blockCount);

Expand Down Expand Up @@ -76,7 +76,7 @@ private void XorArrays(byte[] inputBuffer, int inputOffset, byte[] outputBuffer,
{
var inputVec = new Vector<byte>(inputBuffer, inputOffset + i);
var xorVec = new Vector<byte>(xor, i);
var outputVec = inputVec ^ xorVec;
Vector<byte> outputVec = inputVec ^ xorVec;
outputVec.CopyTo(outputBuffer, outputOffset + i);
}
}
Expand Down
8 changes: 4 additions & 4 deletions LibHac/Bktr.cs
Expand Up @@ -52,7 +52,7 @@ public Bktr(Stream patchRomfs, Stream baseRomfs, NcaSection section)

private RelocationEntry GetRelocationEntry(long offset)
{
var index = RelocationOffsets.BinarySearch(offset);
int index = RelocationOffsets.BinarySearch(offset);
if (index < 0) index = ~index - 1;
return RelocationEntries[index];
}
Expand All @@ -63,12 +63,12 @@ public override int Read(byte[] buffer, int offset, int count)
if (remaining <= 0) return 0;
if (remaining < count) count = (int)remaining;

var toOutput = count;
int toOutput = count;
int pos = 0;

while (toOutput > 0)
{
var remainInEntry = CurrentEntry.VirtOffsetEnd - Position;
long remainInEntry = CurrentEntry.VirtOffsetEnd - Position;
int toRead = (int)Math.Min(toOutput, remainInEntry);
ReadCurrent(buffer, pos, toRead);
pos += toRead;
Expand Down Expand Up @@ -97,7 +97,7 @@ private void UpdateSourceStreamPositions()
// At end of virtual stream
if (CurrentEntry == null) return;

var entryOffset = Position - CurrentEntry.VirtOffset;
long entryOffset = Position - CurrentEntry.VirtOffset;

if (CurrentEntry.IsPatch)
{
Expand Down
6 changes: 3 additions & 3 deletions LibHac/BktrCryptoStream.cs
Expand Up @@ -30,7 +30,7 @@ public BktrCryptoStream(Stream baseStream, byte[] key, long offset, long length,
SubsectionBlock = new SubsectionBlock(reader);
}

foreach (var bucket in SubsectionBlock.Buckets)
foreach (SubsectionBucket bucket in SubsectionBlock.Buckets)
{
SubsectionEntries.AddRange(bucket.Entries);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public override long Position
public override int Read(byte[] buffer, int offset, int count)
{
int totalBytesRead = 0;
var outPos = offset;
int outPos = offset;

while (count > 0)
{
Expand All @@ -94,7 +94,7 @@ public override int Read(byte[] buffer, int offset, int count)

private SubsectionEntry GetSubsectionEntry(long offset)
{
var index = SubsectionOffsets.BinarySearch(offset);
int index = SubsectionOffsets.BinarySearch(offset);
if (index < 0) index = ~index - 1;
return SubsectionEntries[index];
}
Expand Down

0 comments on commit 4ca983e

Please sign in to comment.