Skip to content

Commit

Permalink
Entry Names shown in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Crauzer committed Oct 20, 2017
1 parent 8e3f261 commit 3afc6b1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Obsidian/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<Grid>
<DataGrid Height="475" x:Name="datagridWadEntries" Margin="10,10,10,0" AutoGenerateColumns="False" GridLinesVisibility="Vertical" VerticalGridLinesBrush="#7F000000" SelectedCellsChanged="datagridWadEntries_SelectedCellsChanged" BeginningEdit="datagridWadEntries_BeginningEdit">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding XXHash, Converter={StaticResource WadNameConverter}}" IsReadOnly="True"/>
<DataGridTextColumn Header="Name" Binding="{Binding Converter={StaticResource WadNameConverter}}" IsReadOnly="True"/>
<DataGridTextColumn Header="Type" Binding="{Binding Type}" IsReadOnly="True"/>
<DataGridTextColumn Header="Size" Binding="{Binding UncompressedSize, Converter={StaticResource SizeValueConverter}}" IsReadOnly="True"/>
<DataGridTextColumn Header="File Redirection" Binding="{Binding FileRedirection}"/>
Expand Down
16 changes: 8 additions & 8 deletions Obsidian/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class MainWindow : Window
{
public WADFile Wad { get; set; }
public WADEntry CurrentlySelectedEntry { get; set; }
public List<string> StringDictionary { get; set; }
public static List<string> StringDictionary { get; set; }

public MainWindow()
{
Expand All @@ -47,19 +47,19 @@ private void buttonOpenWadFile_Click(object sender, RoutedEventArgs e)
if (dialog.ShowDialog() == true)
{
this.Wad = new WADFile(dialog.FileName);
GenerateWADStrings();

this.buttonSaveWadFile.IsEnabled = true;
this.buttonAddFile.IsEnabled = true;
this.butonAddFileRedirection.IsEnabled = true;
this.CurrentlySelectedEntry = null;
this.datagridWadEntries.ItemsSource = this.Wad.Entries;

GenerateWADStrings();
}
}

private void GenerateWADStrings()
{
this.StringDictionary = new List<string>();
StringDictionary = new List<string>();
foreach (WADEntry wadEntry in this.Wad.Entries.Where(x => x.Type == EntryType.Compressed))
{
byte[] entryData = wadEntry.GetContent(true);
Expand Down Expand Up @@ -87,11 +87,11 @@ private void GenerateWADStrings()
}
});

this.StringDictionary.AddRange(wadEntryStrings);
StringDictionary.AddRange(wadEntryStrings);
}
}

this.StringDictionary.RemoveAll(x => x == null);
StringDictionary.RemoveAll(x => x == null);
}

public IEnumerable<string> GetValueStrings(BINFileValue value)
Expand Down Expand Up @@ -162,7 +162,7 @@ private void datagridWadEntries_SelectedCellsChanged(object sender, SelectedCell
string entryName = "";
using (XXHash64 xxHash = XXHash64.Create())
{
entryName = this.StringDictionary.Find(x =>
entryName = StringDictionary.Find(x =>
BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(x.ToLower())), 0) == (this.datagridWadEntries.SelectedItem as WADEntry).XXHash);
}

Expand Down Expand Up @@ -238,7 +238,7 @@ private void buttonExtract_Click(object sender, RoutedEventArgs e)
string entryName;
using (XXHash64 xxHash = XXHash64.Create())
{
entryName = this.StringDictionary.Find(x => BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(x.ToLower())), 0) == entry.XXHash);
entryName = StringDictionary.Find(x => BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(x.ToLower())), 0) == entry.XXHash);
}

if (entryName == null)
Expand Down
2 changes: 1 addition & 1 deletion Obsidian/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
19 changes: 17 additions & 2 deletions Obsidian/ValueConverters/WadNameConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Fantome.Libraries.League.Helpers.Utilities;
using Fantome.Libraries.League.Helpers.Cryptography;
using Fantome.Libraries.League.Helpers.Utilities;
using Fantome.Libraries.League.IO.WAD;
using System;
using System.Globalization;
using System.Text;
using System.Windows.Data;

namespace Obsidian.ValueConverters
Expand All @@ -9,7 +12,19 @@ public class WadNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Utilities.ByteArrayToHex(BitConverter.GetBytes((ulong)value), true);
string finalName = "";
using (XXHash64 xxHash = XXHash64.Create())
{
finalName = MainWindow.StringDictionary.Find(x =>
BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(x.ToLower())), 0) == (value as WADEntry).XXHash);
}

if (finalName == null)
{
finalName = Utilities.ByteArrayToHex(BitConverter.GetBytes((ulong)(value as WADEntry).XXHash), true);
}

return finalName;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down

0 comments on commit 3afc6b1

Please sign in to comment.