Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli into master #8

Merged
merged 17 commits into from
May 10, 2016
Next Next commit
Fix
  • Loading branch information
tomrus88 committed Feb 14, 2016
commit 263447dc85e934f0231b7d136c36c2ef03490452
65 changes: 28 additions & 37 deletions CASCExplorer/CASCViewHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CASCViewHelper
private ExtractProgress extractProgress;
private CASCHandler _casc;
private CASCFolder _root;
private CASCFolder _currentFolder;
private CASCEntrySorter Sorter = new CASCEntrySorter();
private ScanForm scanForm;
private NumberFormatInfo sizeNumberFmt = new NumberFormatInfo()
Expand All @@ -41,11 +42,14 @@ public CASCFolder Root
get { return _root; }
}

public void ExtractFiles(NoFlickerListView filesList)
public CASCFolder CurrentFolder
{
CASCFolder folder = filesList.Tag as CASCFolder;
get { return _currentFolder; }
}

if (folder == null)
public void ExtractFiles(NoFlickerListView filesList)
{
if (_currentFolder == null)
return;

if (!filesList.HasSelection)
Expand All @@ -54,7 +58,7 @@ public void ExtractFiles(NoFlickerListView filesList)
if (extractProgress == null)
extractProgress = new ExtractProgress();

var files = folder.GetFiles(filesList.SelectedIndices.Cast<int>()).ToList();
var files = _currentFolder.GetFiles(filesList.SelectedIndices.Cast<int>()).ToList();
extractProgress.SetExtractData(_casc, files);
extractProgress.ShowDialog();
}
Expand All @@ -76,7 +80,7 @@ await Task.Run(() =>

foreach (var file in installFiles)
{
_casc.ExtractFile(_casc.Encoding.GetEntry(file.MD5).Key, "data\\" + build + "\\install_files", file.Name);
_casc.ExtractFile(_casc.Encoding.GetEntry(file.MD5).Key, Path.Combine("data", build, "install_files"), file.Name);

progress.Report((int)(++numDone / (float)numFiles * 100.0f));
}
Expand Down Expand Up @@ -223,8 +227,9 @@ public void UpdateListView(CASCFolder baseEntry, NoFlickerListView fileList, str
baseEntry.Entries = baseEntry.EntriesMirror.Where(v => v.Value is CASCFolder || (v.Value is CASCFile && wildcard.IsMatch(v.Value.Name))).
OrderBy(v => v.Value, Sorter).ToDictionary(pair => pair.Key, pair => pair.Value);

_currentFolder = baseEntry;

// Update
fileList.Tag = baseEntry;
fileList.VirtualListSize = 0;
fileList.VirtualListSize = baseEntry.Entries.Count;

Expand Down Expand Up @@ -332,15 +337,13 @@ public void SetSort(int column)

public void GetSize(NoFlickerListView fileList)
{
CASCFolder folder = fileList.Tag as CASCFolder;

if (folder == null)
if (_currentFolder == null)
return;

if (!fileList.HasSelection)
return;

var files = folder.GetFiles(fileList.SelectedIndices.Cast<int>());
var files = _currentFolder.GetFiles(fileList.SelectedIndices.Cast<int>());

long size = files.Sum(f => (long)f.GetSize(_casc));

Expand All @@ -349,15 +352,13 @@ public void GetSize(NoFlickerListView fileList)

public void PreviewFile(NoFlickerListView fileList)
{
CASCFolder folder = fileList.Tag as CASCFolder;

if (folder == null)
if (_currentFolder == null)
return;

if (!fileList.HasSingleSelection)
return;

var file = folder.Entries.ElementAt(fileList.SelectedIndex).Value as CASCFile;
var file = _currentFolder.Entries.ElementAt(fileList.SelectedIndex).Value as CASCFile;

var extension = Path.GetExtension(file.Name);

Expand Down Expand Up @@ -427,15 +428,15 @@ private void PreviewBlp(CASCFile file)
}
}

public void CreateListViewItem(RetrieveVirtualItemEventArgs e, CASCFolder folder)
public void CreateListViewItem(RetrieveVirtualItemEventArgs e)
{
if (folder == null)
if (_currentFolder == null)
return;

if (e.ItemIndex < 0 || e.ItemIndex >= folder.Entries.Count)
if (e.ItemIndex < 0 || e.ItemIndex >= _currentFolder.Entries.Count)
return;

ICASCEntry entry = folder.Entries.ElementAt(e.ItemIndex).Value;
ICASCEntry entry = _currentFolder.Entries.ElementAt(e.ItemIndex).Value;

var localeFlags = LocaleFlags.None;
var contentFlags = ContentFlags.None;
Expand All @@ -449,10 +450,7 @@ public void CreateListViewItem(RetrieveVirtualItemEventArgs e, CASCFolder folder
{
var enc = _casc.Encoding.GetEntry(rootInfosLocale.First().MD5);

if (enc != null)
size = enc.Size.ToString("N", sizeNumberFmt);
else
size = "0";
size = enc?.Size.ToString("N", sizeNumberFmt) ?? "0";

foreach (var rootInfo in rootInfosLocale)
{
Expand All @@ -471,10 +469,7 @@ public void CreateListViewItem(RetrieveVirtualItemEventArgs e, CASCFolder folder
{
var enc = _casc.Encoding.GetEntry(installInfos.First().MD5);

if (enc != null)
size = enc.Size.ToString("N", sizeNumberFmt);
else
size = "0";
size = enc?.Size.ToString("N", sizeNumberFmt) ?? "0";

//foreach (var rootInfo in rootInfosLocale)
//{
Expand All @@ -501,17 +496,15 @@ public void CreateListViewItem(RetrieveVirtualItemEventArgs e, CASCFolder folder

public void Cleanup()
{
OnCleanup?.Invoke();

Sorter.CASC = null;

_currentFolder = null;
_root = null;

if (_casc != null)
{
_casc.Clear();
_casc = null;
}
_casc?.Clear();
_casc = null;

OnCleanup?.Invoke();
}

public void Search(NoFlickerListView fileList, SearchForVirtualItemEventArgs e)
Expand All @@ -520,8 +513,6 @@ public void Search(NoFlickerListView fileList, SearchForVirtualItemEventArgs e)
bool searchUp = false;
int SelectedIndex = fileList.SelectedIndex;

CASCFolder folder = fileList.Tag as CASCFolder;

var comparisonType = ignoreCase
? StringComparison.InvariantCultureIgnoreCase
: StringComparison.InvariantCulture;
Expand All @@ -530,7 +521,7 @@ public void Search(NoFlickerListView fileList, SearchForVirtualItemEventArgs e)
{
for (var i = SelectedIndex - 1; i >= 0; --i)
{
var op = folder.Entries.ElementAt(i).Value.Name;
var op = _currentFolder.Entries.ElementAt(i).Value.Name;
if (op.IndexOf(e.Text, comparisonType) != -1)
{
e.Index = i;
Expand All @@ -542,7 +533,7 @@ public void Search(NoFlickerListView fileList, SearchForVirtualItemEventArgs e)
{
for (int i = SelectedIndex + 1; i < fileList.Items.Count; ++i)
{
var op = folder.Entries.ElementAt(i).Value.Name;
var op = _currentFolder.Entries.ElementAt(i).Value.Name;
if (op.IndexOf(e.Text, comparisonType) != -1)
{
e.Index = i;
Expand Down
7 changes: 3 additions & 4 deletions CASCExplorer/DB2Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ public bool HasRow(int index)

public DB2Row GetRow(int index)
{
if (!m_index.ContainsKey(index))
return null;

return m_index[index];
DB2Row row;
m_index.TryGetValue(index, out row);
return row;
}

public IEnumerator<KeyValuePair<int, DB2Row>> GetEnumerator()
Expand Down
7 changes: 3 additions & 4 deletions CASCExplorer/DB3Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ public bool HasRow(int index)

public DB3Row GetRow(int index)
{
if (!m_index.ContainsKey(index))
return null;

return m_index[index];
DB3Row row;
m_index.TryGetValue(index, out row);
return row;
}

public IEnumerator<KeyValuePair<int, DB3Row>> GetEnumerator()
Expand Down
18 changes: 12 additions & 6 deletions CASCExplorer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
viewHelper.SetSort(e.Column);

CASCFolder folder = fileList.Tag as CASCFolder;
CASCFolder folder = viewHelper.CurrentFolder;

if (folder == null)
return;
Expand All @@ -159,7 +159,7 @@ private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)

private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
viewHelper.CreateListViewItem(e, fileList.Tag as CASCFolder);
viewHelper.CreateListViewItem(e);
}

private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
Expand Down Expand Up @@ -190,7 +190,7 @@ private void listView1_KeyDown(object sender, KeyEventArgs e)
private bool NavigateFolder()
{
// Current folder
CASCFolder folder = fileList.Tag as CASCFolder;
CASCFolder folder = viewHelper.CurrentFolder;

if (folder == null)
return false;
Expand Down Expand Up @@ -222,7 +222,7 @@ private void extractToolStripMenuItem_Click(object sender, EventArgs e)
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
extractToolStripMenuItem.Enabled = fileList.HasSelection;
copyNameToolStripMenuItem.Enabled = (fileList.HasSelection && (fileList.Tag as CASCFolder).GetFiles(fileList.SelectedIndices.Cast<int>(), false).Count() > 0) || false;
copyNameToolStripMenuItem.Enabled = (fileList.HasSelection && viewHelper.CurrentFolder.GetFiles(fileList.SelectedIndices.Cast<int>(), false).Count() > 0) || false;
getSizeToolStripMenuItem.Enabled = fileList.HasSelection;
}

Expand All @@ -234,7 +234,7 @@ private void aboutToolStripMenuItem_Click(object sender, EventArgs e)

private void copyNameToolStripMenuItem_Click(object sender, EventArgs e)
{
CASCFolder folder = fileList.Tag as CASCFolder;
CASCFolder folder = viewHelper.CurrentFolder;

if (folder == null)
return;
Expand Down Expand Up @@ -313,6 +313,12 @@ private void contentFlagsToolStripMenuItem_Click(object sender, EventArgs e)
private void Cleanup()
{
fileList.VirtualListSize = 0;

if (folderTree.Nodes.Count > 0)
{
folderTree.Nodes[0].Tag = null;
}

folderTree.Nodes.Clear();

CDNBuildsToolStripMenuItem.Enabled = false;
Expand Down Expand Up @@ -436,7 +442,7 @@ private void exportListfileToolStripMenuItem_Click(object sender, EventArgs e)

private void filterToolStripTextBox_TextChanged(object sender, EventArgs e)
{
viewHelper.UpdateListView(fileList.Tag as CASCFolder, fileList, filterToolStripTextBox.Text);
viewHelper.UpdateListView(viewHelper.CurrentFolder, fileList, filterToolStripTextBox.Text);
}

private void openStorageToolStripButton_Click(object sender, EventArgs e)
Expand Down
5 changes: 1 addition & 4 deletions CascLib/CASCEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ public int GetSize(CASCHandler casc)
{
var encoding = casc.GetEncodingEntry(hash);

if (encoding != null)
return encoding.Size;

return 0;
return encoding?.Size ?? 0;
}

public int CompareTo(ICASCEntry other, int col, CASCHandler casc)
Expand Down
29 changes: 10 additions & 19 deletions CascLib/CASCHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public bool FileExists(string file)
public bool FileExists(ulong hash)
{
var rootInfos = RootHandler.GetAllEntries(hash);
return rootInfos != null && rootInfos.Any();
return rootInfos?.Any() ?? false;
}

public EncodingEntry GetEncodingEntry(ulong hash)
Expand Down Expand Up @@ -214,37 +214,28 @@ public void SaveFileTo(ulong hash, string extractPath, string fullName)

public void Clear()
{
CDNIndex.Clear();
CDNIndex?.Clear();
CDNIndex = null;

foreach (var stream in DataStreams)
stream.Value.Close();

DataStreams.Clear();

EncodingHandler.Clear();
EncodingHandler?.Clear();
EncodingHandler = null;

if (InstallHandler != null)
{
InstallHandler.Clear();
InstallHandler = null;
}
InstallHandler?.Clear();
InstallHandler = null;

if (LocalIndex != null)
{
LocalIndex.Clear();
LocalIndex = null;
}
LocalIndex?.Clear();
LocalIndex = null;

RootHandler.Clear();
RootHandler?.Clear();
RootHandler = null;

if (DownloadHandler != null)
{
DownloadHandler.Clear();
DownloadHandler = null;
}
DownloadHandler?.Clear();
DownloadHandler = null;
}
}
}
2 changes: 1 addition & 1 deletion CascLib/CASCHandlerLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ private CASCHandlerLite(CASCConfig config, LocaleFlags locale, BackgroundWorkerE
}

RootHandler.Clear();
EncodingHandler.Clear();
RootHandler = null;
EncodingHandler.Clear();
EncodingHandler = null;
GC.Collect();

Expand Down
15 changes: 7 additions & 8 deletions CascLib/WowRootHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,16 @@ public override void LoadListFile(string path, BackgroundWorkerEx worker = null)
if (LoadPreHashedListFile("listfile.bin", path, worker))
return;

if (!File.Exists(path))
{
Logger.WriteLine("WowRootHandler: list file missing!");
return;
}

using (var _ = new PerfCounter("WowRootHandler::LoadListFile()"))
{
worker?.ReportProgress(0, "Loading \"listfile\"...");

if (!File.Exists(path))
{
Logger.WriteLine("WowRootHandler: list file missing!");
return;
}

Logger.WriteLine("WowRootHandler: loading file names...");

Dictionary<string, Dictionary<ulong, string>> dirData = new Dictionary<string, Dictionary<ulong, string>>(StringComparer.OrdinalIgnoreCase);
Expand Down Expand Up @@ -437,8 +437,7 @@ public override void Clear()
FileDataStore.Clear();
FileDataStoreReverse.Clear();
UnknownFiles.Clear();
if (Root != null)
Root.Entries.Clear();
Root?.Entries.Clear();
CASCFile.FileNames.Clear();
}

Expand Down