2021-08-01 15:12:22 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2021-08-01 00:36:37 -04:00
|
|
|
|
using System.IO;
|
2021-08-01 15:12:22 -04:00
|
|
|
|
using System.Text.RegularExpressions;
|
2021-08-01 00:36:37 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using PatcherUtils;
|
2021-08-01 15:12:22 -04:00
|
|
|
|
using PatchGenerator.Extensions;
|
2021-08-01 00:36:37 -04:00
|
|
|
|
|
|
|
|
|
namespace PatchGenerator
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
|
|
|
|
private string compareFolder = "";
|
|
|
|
|
private string targetFolder = "";
|
2021-08-01 15:12:22 -04:00
|
|
|
|
private string outputFolderName = "";
|
2021-08-06 20:36:11 -04:00
|
|
|
|
public bool AutoZip { get; set; } = true;
|
2021-08-01 15:12:22 -04:00
|
|
|
|
|
2021-08-01 00:36:37 -04:00
|
|
|
|
private Stopwatch stopwatch = new Stopwatch();
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetStopWatchTime()
|
|
|
|
|
{
|
|
|
|
|
return $"Hours: {stopwatch.Elapsed.Hours} - Mins: {stopwatch.Elapsed.Minutes} - Secs: {stopwatch.Elapsed.Seconds} - MilliSecs: {stopwatch.Elapsed.Milliseconds}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool FileDropCheck(DragEventArgs args, ref string str)
|
|
|
|
|
{
|
|
|
|
|
if (!args.Data.GetDataPresent(DataFormats.FileDrop))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string[] paths = (string[])args.Data.GetData(DataFormats.FileDrop);
|
|
|
|
|
|
|
|
|
|
if (paths.Length != 1) return false;
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(paths[0]))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
str = paths[0];
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CompareLabel_Drop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (FileDropCheck(e, ref compareFolder))
|
|
|
|
|
{
|
|
|
|
|
CompareLabel.Content = $"Compare Folder:\n{compareFolder}";
|
|
|
|
|
CompareLabel.BorderBrush = Brushes.DarkCyan;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Dropped File/s could not be used. Make sure you only drop one folder.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TargetLabel_Drop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(FileDropCheck(e, ref targetFolder))
|
|
|
|
|
{
|
|
|
|
|
TargetLabel.Content = $"Target Folder:\n{targetFolder}";
|
|
|
|
|
TargetLabel.BorderBrush = Brushes.DarkCyan;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Dropped File/s could not be used. Make sure you only drop one folder.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-01 15:12:22 -04:00
|
|
|
|
private void GeneratePatches(string patchBase)
|
2021-08-01 00:36:37 -04:00
|
|
|
|
{
|
|
|
|
|
//create temp data
|
2021-08-01 15:12:22 -04:00
|
|
|
|
GenProgressBar.DispatcherSetIndetermination(true);
|
|
|
|
|
GenProgressMessageLabel.DispaatcherSetContent("Extracting temp data ...");
|
2021-08-01 00:36:37 -04:00
|
|
|
|
|
2021-08-01 15:12:22 -04:00
|
|
|
|
LazyOperations.CleanupTempDir();
|
2021-08-01 00:36:37 -04:00
|
|
|
|
LazyOperations.PrepTempDir();
|
|
|
|
|
|
2021-08-01 15:12:22 -04:00
|
|
|
|
GenProgressBar.DispatcherSetIndetermination(false);
|
2021-08-01 00:36:37 -04:00
|
|
|
|
|
|
|
|
|
//generate patches
|
2021-08-01 15:12:22 -04:00
|
|
|
|
FileCompare bc = new FileCompare(targetFolder, compareFolder, patchBase);
|
2021-08-01 00:36:37 -04:00
|
|
|
|
|
|
|
|
|
bc.ProgressChanged += Bc_ProgressChanged;
|
|
|
|
|
|
|
|
|
|
if (!bc.CompareAll())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Failed to generate diffs.", ":(", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-01 15:12:22 -04:00
|
|
|
|
//Copy patch client to output folder
|
|
|
|
|
File.Copy(LazyOperations.PatcherClientPath, $"{outputFolderName}\\patcher.exe", true);
|
2021-08-01 00:36:37 -04:00
|
|
|
|
|
2021-08-01 15:12:22 -04:00
|
|
|
|
//compress patch output folder to 7z file
|
2021-08-06 20:36:11 -04:00
|
|
|
|
if (AutoZip)
|
|
|
|
|
{
|
|
|
|
|
LazyOperations.StartZipProcess(outputFolderName, $"{outputFolderName}.7z".FromCwd());
|
|
|
|
|
}
|
2021-08-01 00:36:37 -04:00
|
|
|
|
|
2021-08-01 15:12:22 -04:00
|
|
|
|
GenProgressBar.DispatcherSetValue(100);
|
|
|
|
|
GenProgressMessageLabel.DispaatcherSetContent("Done");
|
2021-08-01 00:36:37 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Bc_ProgressChanged(object Sender, int Progress, int Total, int Percent, string Message = "", params LineItem[] AdditionalLineItems)
|
|
|
|
|
{
|
|
|
|
|
string additionalInfo = "";
|
2021-08-01 15:12:22 -04:00
|
|
|
|
foreach (LineItem item in AdditionalLineItems)
|
2021-08-01 00:36:37 -04:00
|
|
|
|
{
|
|
|
|
|
additionalInfo += $"{item.ItemText}: {item.ItemValue}\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-08-01 15:12:22 -04:00
|
|
|
|
GenProgressBar.DispatcherSetValue(Percent);
|
2021-08-01 00:36:37 -04:00
|
|
|
|
|
2021-08-01 15:12:22 -04:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(Message))
|
|
|
|
|
{
|
|
|
|
|
GenProgressMessageLabel.DispaatcherSetContent(Message);
|
|
|
|
|
}
|
2021-08-01 00:36:37 -04:00
|
|
|
|
|
2021-08-01 15:12:22 -04:00
|
|
|
|
GenProgressInfoLabel.DispaatcherSetContent($"[{Progress}/{Total}]");
|
|
|
|
|
|
|
|
|
|
AdditionalInfoBlock.DispatcherSetText(additionalInfo);
|
2021-08-01 00:36:37 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GenButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
GenButton.IsEnabled = false;
|
2021-08-01 15:12:22 -04:00
|
|
|
|
CompareLabel.IsEnabled = false;
|
|
|
|
|
TargetLabel.IsEnabled = false;
|
|
|
|
|
FileNameBox.IsEnabled = false;
|
2021-08-06 20:36:11 -04:00
|
|
|
|
AutoZip_checkBox.IsEnabled = false;
|
2021-08-01 15:12:22 -04:00
|
|
|
|
|
|
|
|
|
string InfoNeededMessage = "You must set the following: ";
|
|
|
|
|
bool infoNeeded = false;
|
|
|
|
|
|
|
|
|
|
if(string.IsNullOrWhiteSpace(FileNameBox.Text))
|
|
|
|
|
{
|
|
|
|
|
InfoNeededMessage += "\n[Output File Name]";
|
|
|
|
|
FileNameBox.BorderBrush = Brushes.Red;
|
|
|
|
|
infoNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(string.IsNullOrWhiteSpace(compareFolder))
|
|
|
|
|
{
|
|
|
|
|
InfoNeededMessage += "\n[COMPARE Folder]";
|
|
|
|
|
CompareLabel.BorderBrush = Brushes.Red;
|
|
|
|
|
infoNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(string.IsNullOrWhiteSpace(targetFolder))
|
|
|
|
|
{
|
|
|
|
|
InfoNeededMessage += "\n[TARGET Folder]";
|
|
|
|
|
TargetLabel.BorderBrush = Brushes.Red;
|
|
|
|
|
infoNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (infoNeeded)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(InfoNeededMessage, "Info Required", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
|
|
GenButton.IsEnabled = true;
|
|
|
|
|
CompareLabel.IsEnabled = true;
|
|
|
|
|
TargetLabel.IsEnabled = true;
|
|
|
|
|
FileNameBox.IsEnabled = true;
|
2021-08-06 20:36:11 -04:00
|
|
|
|
AutoZip_checkBox.IsEnabled = true;
|
2021-08-01 15:12:22 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetEndingInfo(string info)
|
|
|
|
|
{
|
|
|
|
|
GenButton.DispatcherSetEnabled(true);
|
|
|
|
|
CompareLabel.DispatcherSetEnabled(true);
|
|
|
|
|
TargetLabel.DispatcherSetEnabled(true);
|
|
|
|
|
FileNameBox.DispatcherSetEnabled(true);
|
2021-08-06 20:36:11 -04:00
|
|
|
|
AutoZip_checkBox.DispatcherSetEnabled(true);
|
2021-08-01 15:12:22 -04:00
|
|
|
|
|
|
|
|
|
GenProgressMessageLabel.DispaatcherSetContent("");
|
|
|
|
|
GenProgressInfoLabel.DispaatcherSetContent(info);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-01 00:36:37 -04:00
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
stopwatch.Reset();
|
|
|
|
|
stopwatch.Start();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-08-01 15:12:22 -04:00
|
|
|
|
GeneratePatches(Path.Combine(outputFolderName.FromCwd(), LazyOperations.PatchFolder));
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
SetEndingInfo($"Patches Generated in: {GetStopWatchTime()}");
|
2021-08-01 00:36:37 -04:00
|
|
|
|
}
|
2021-08-01 15:12:22 -04:00
|
|
|
|
catch(Exception ex)
|
2021-08-01 00:36:37 -04:00
|
|
|
|
{
|
|
|
|
|
stopwatch.Stop();
|
2021-08-01 15:12:22 -04:00
|
|
|
|
SetEndingInfo(ex.Message);
|
2021-08-01 00:36:37 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-08-01 15:12:22 -04:00
|
|
|
|
|
|
|
|
|
private void FileNameBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
FileNameBox.BorderBrush = Brushes.Gainsboro;
|
|
|
|
|
|
|
|
|
|
if (outputFolderName == FileNameBox.Text) return;
|
|
|
|
|
|
|
|
|
|
outputFolderName = Regex.Replace(FileNameBox.Text, "[^A-Za-z0-9.\\-_]", "");
|
|
|
|
|
|
|
|
|
|
FileNameBox.Text = outputFolderName;
|
|
|
|
|
}
|
2021-08-01 00:36:37 -04:00
|
|
|
|
}
|
|
|
|
|
}
|