Skip to content

Commit

Permalink
Update VisualGGPK
Browse files Browse the repository at this point in the history
Window_Drop event now works on _workerThread instead of main thread.
This solves the issue of unresponsive window.

Automatically prefixes "ROOT\" with DirectoryPath(var fixedFileName) in HandleDropDirectory()

Add AutoScrollCheckBox
  • Loading branch information
aianlinb authored Dec 25, 2019
1 parent c98ce56 commit f055317
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 38 deletions.
3 changes: 2 additions & 1 deletion VisualGGPK/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
<TextBox x:Name="TextBoxNameHash" Width="100" IsReadOnly="True"/>

<Label x:Name="LabelFileHash" Content="{x:Static Properties:Resources.MainWindow_Label_FileHash}"/>
<TextBox x:Name="TextBoxHash" Width="100" IsReadOnly="True"/>
<TextBox x:Name="TextBoxHash" Width="100" IsReadOnly="True"/>
<CheckBox x:Name="AutoScrollCheckBox" Content="AutoScroll" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10,0,0,0" IsChecked="True"/>
</StackPanel>

<!--different viewers for different types of files-->
Expand Down
97 changes: 60 additions & 37 deletions VisualGGPK/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ private void Output(string msg)
{
TextBoxOutput.Dispatcher.BeginInvoke(new Action(() =>
{
TextBoxOutput.Text += msg;
TextBoxOutput.AppendText(msg);
if (AutoScrollCheckBox.IsChecked.Value)
{
TextBoxOutput.ScrollToEnd();
}
}), null);
}

Expand Down Expand Up @@ -446,7 +450,7 @@ private void ReplaceFileRecord(FileRecord recordToReplace)
if (_content.IsReadOnly)
{
MessageBox.Show(
Settings.Strings["ReplaceItem_Readonly"],
Settings.Strings["ReplaceItem_Readonly"],
Settings.Strings["ReplaceItem_ReadonlyCaption"]);
return;
}
Expand All @@ -455,24 +459,24 @@ private void ReplaceFileRecord(FileRecord recordToReplace)
{
var openFileDialog = new OpenFileDialog
{
FileName = "",
CheckFileExists = true,
FileName = "",
CheckFileExists = true,
CheckPathExists = true
};

if (openFileDialog.ShowDialog() != true) return;
recordToReplace.ReplaceContents(_ggpkPath, openFileDialog.FileName, _content.FreeRoot);
MessageBox.Show(
String.Format(Settings.Strings["ReplaceItem_Successful"], recordToReplace.Name, recordToReplace.RecordBegin.ToString("X")),
Settings.Strings["ReplaceItem_Successful_Caption"],
String.Format(Settings.Strings["ReplaceItem_Successful"], recordToReplace.Name, recordToReplace.RecordBegin.ToString("X")),
Settings.Strings["ReplaceItem_Successful_Caption"],
MessageBoxButton.OK, MessageBoxImage.Information);
UpdateDisplayPanel();
}
catch (Exception ex)
{
MessageBox.Show(
string.Format(Settings.Strings["ReplaceItem_Failed"], ex.Message),
Settings.Strings["Error_Caption"],
string.Format(Settings.Strings["ReplaceItem_Failed"], ex.Message),
Settings.Strings["Error_Caption"],
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
Expand All @@ -487,7 +491,7 @@ private void HandleDropArchive(string archivePath)
if (_content.IsReadOnly)
{
MessageBox.Show(
Settings.Strings["ReplaceItem_Readonly"],
Settings.Strings["ReplaceItem_Readonly"],
Settings.Strings["ReplaceItem_ReadonlyCaption"]);
return;
}
Expand Down Expand Up @@ -544,7 +548,6 @@ private void HandleDropArchive(string archivePath)
OutputLine(string.Format(Settings.Strings["MainWindow_HandleDropDirectory_Failed"], fixedFileName));
continue;
}
OutputLine(string.Format(Settings.Strings["MainWindow_HandleDropDirectory_Replace"], fixedFileName));

using (var reader = item.OpenReader())
{
Expand All @@ -553,6 +556,8 @@ private void HandleDropArchive(string archivePath)

_recordsByPath[fixedFileName].ReplaceContents(_ggpkPath, replacementData, _content.FreeRoot);
}

OutputLine(string.Format(Settings.Strings["MainWindow_HandleDropDirectory_Replace"], fixedFileName));
}
}
}
Expand All @@ -576,9 +581,10 @@ private void HandleDropFile(string fileName)
return;
}

record.ReplaceContents(_ggpkPath, fileName, _content.FreeRoot);

OutputLine(string.Format(Settings.Strings["MainWindow_HandleDropFile_Replace"], record.GetDirectoryPath(), record.Name));

record.ReplaceContents(_ggpkPath, fileName, _content.FreeRoot);
}

/// <summary>
Expand Down Expand Up @@ -606,14 +612,20 @@ private void HandleDropDirectory(string baseDirectory)
foreach (var item in filesToReplace)
{
var fixedFileName = item.Remove(0, baseDirectory.Length - baseDirectoryNameLength);
if (!fixedFileName.StartsWith("ROOT" + Path.DirectorySeparatorChar))
{
fixedFileName = "ROOT" + Path.DirectorySeparatorChar + fixedFileName;
}
if (!_recordsByPath.ContainsKey(fixedFileName))
{
OutputLine(string.Format(Settings.Strings["MainWindow_HandleDropDirectory_Failed"], fixedFileName));
continue;
}
OutputLine(string.Format(Settings.Strings["MainWindow_HandleDropDirectory_Replace"], fixedFileName));

_recordsByPath[fixedFileName].ReplaceContents(_ggpkPath, item, _content.FreeRoot);

OutputLine(string.Format(Settings.Strings["MainWindow_HandleDropDirectory_Replace"], fixedFileName));

}
}

Expand Down Expand Up @@ -717,26 +729,35 @@ private void Window_Drop_1(object sender, DragEventArgs e)
MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
return;

var fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];
if (fileNames == null || fileNames.Length != 1)
{
OutputLine(Settings.Strings["MainWindow_Drop_Failed"]);
return;
}
_workerThread = new Thread(() =>
{
var fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];
if (fileNames == null || fileNames.Length != 1)
{
OutputLine(Settings.Strings["MainWindow_Drop_Failed"]);
return;
}

var extension = Path.GetExtension(fileNames[0]);
if (Directory.Exists(fileNames[0]))
{
HandleDropDirectory(fileNames[0]);
}
else if (!String.IsNullOrEmpty(extension) && extension.Equals(".zip")) // Zip file
{
HandleDropArchive(fileNames[0]);
}
else
{
HandleDropFile(fileNames[0]);
}

OutputLine(Environment.NewLine + "Finished!");

_workerThread = null;
});

if (Directory.Exists(fileNames[0]))
{
HandleDropDirectory(fileNames[0]);
}
var extension = Path.GetExtension(fileNames[0]);
if (!String.IsNullOrEmpty(extension) && extension.Equals(".zip")) // Zip file
{
HandleDropArchive(fileNames[0]);
}
else
{
HandleDropFile(fileNames[0]);
}
_workerThread.Start();
}

private void Window_Closing_1(object sender, CancelEventArgs e)
Expand Down Expand Up @@ -812,17 +833,19 @@ private TreeViewItem CreateLazyTreeViewItem(object o)
item.Items.Add("Loading...");
text = o.ToString();
}
else
throw new Exception("Unknown tree view item type: " + o.GetType());
// create stack panel
var stack = new StackPanel {Orientation = Orientation.Horizontal};
else
throw new Exception("Unknown tree view item type: " + o.GetType());

// create stack panel
var stack = new StackPanel { Orientation = Orientation.Horizontal };
// create Image
var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(
icon.ToBitmap().GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
var img = new Image
{
Source = bitmapSource, Width = 10, Height = 10
Source = bitmapSource,
Width = 10,
Height = 10
};
// Label
var lbl = new Label
Expand Down

0 comments on commit f055317

Please sign in to comment.