0
0
mirror of https://github.com/sp-tarkov/patcher.git synced 2025-02-12 17:10:46 -05:00

its 1am idk man, I did some things. Patch Generator WIP

This commit is contained in:
IsWaffle 2021-12-25 01:17:01 -05:00
parent f57abbb64a
commit 455125576a
33 changed files with 691 additions and 55 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
/Patcher/_port/Patcher/PatchGenerator/Resources/PatchClient.exe filter=lfs diff=lfs merge=lfs -text

View File

@ -58,8 +58,7 @@ namespace PatcherUtils
if(File.Exists(decodedPath))
{
File.Delete(SourceFilePath);
File.Move(decodedPath, SourceFilePath);
File.Move(decodedPath, SourceFilePath, true);
}
}

View File

@ -2,6 +2,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>

View File

@ -1,5 +1,4 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;
using System;

View File

@ -10,7 +10,7 @@ namespace PatchClient.ViewModels
{
public ICommand CloseCommand => ReactiveCommand.Create(() =>
{
if(Application.Current.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktopApp)
if (Application.Current.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktopApp)
{
desktopApp.MainWindow.Close();
}

View File

@ -1,5 +1,4 @@
using Avalonia;
using ReactiveUI;
using ReactiveUI;
namespace PatchClient.ViewModels
{

View File

@ -1,12 +1,12 @@
using Avalonia;
using PatchClient.Models;
using PatcherUtils;
using ReactiveUI;
using Splat;
using System;
using ReactiveUI;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
namespace PatchClient.ViewModels
{
@ -63,7 +63,7 @@ namespace PatchClient.ViewModels
foreach (LineItem item in AdditionalLineItems)
{
if(initLineItemProgress)
if (initLineItemProgress)
{
if (item.ItemValue <= 0) continue;

View File

@ -1,9 +1,5 @@
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using PatchClient.Models;
using ReactiveUI;
namespace PatchClient.ViewModels
{

View File

@ -1,4 +1,3 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

View File

@ -1,4 +1,3 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

View File

@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="using:PatchGenerator.CustomControls">
<Design.PreviewWith>
<Border Padding="20" Background="{StaticResource AKI_Background_Light}">
<Border Padding="10" Background="{StaticResource AKI_Background_Light}">
<!-- Add Controls for Previewer Here -->
<StackPanel Background="{StaticResource AKI_Background_Light}" Spacing="15" Margin="10">
<cc:TitleBar Title="Title Bar Text"/>
@ -12,18 +12,49 @@
<ProgressBar Value="40"/>
<Separator Height="1"/>
<ProgressBar Value="60" Classes="done"/>
<Button Content="Press Me :)"/>
<CheckBox Content="Check .. Me Out! ba-dum-tss"/>
<TextBox Text="Some Text Here" />
</StackPanel>
</Border>
</Design.PreviewWith>
<!-- Add Styles Here -->
<!-- TitleBar Styles -->
<Style Selector="cc|TitleBar">
<Setter Property="Background" Value="{StaticResource AKI_Background_Dark}"/>
<Setter Property="Foreground" Value="{StaticResource AKI_Foreground_Light}"/>
<Setter Property="XButtonForeground" Value="{StaticResource AKI_Brush_DarkGrayBlue}"/>
</Style>
<!-- TextBox Styles -->
<!-- SourceRef: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Fluent/Controls/TextBox.xaml -->
<Style Selector="TextBox">
<Setter Property="Background" Value="{StaticResource AKI_Brush_DarkGrayBlue}"/>
<Setter Property="FontWeight" Value="SemiBold"/>
</Style>
<Style Selector="TextBox:focus">
<Setter Property="Foreground" Value="Black"/>
</Style>
<Style Selector="TextBox:pointerover /template/ Border#PART_BorderElement">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="DimGray"/>
</Style>
<Style Selector="TextBox:focus /template/ TextBlock#PART_Watermark, TextBox:focus /template/ TextBlock#PART_FloatingWatermark">
<Setter Property="Foreground" Value="Black"/>
</Style>
<Style Selector="TextBox:focus /template/ Border#PART_BorderElement">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{StaticResource AKI_Brush_Yellow}"/>
</Style>
<!-- Label Styles -->
<!-- SourceRef: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Fluent/Controls/Label.xaml -->
<Style Selector="Label">
<Setter Property="Foreground" Value="{StaticResource AKI_Foreground_Light}"/>
</Style>
@ -36,6 +67,8 @@
<Setter Property="Foreground" Value="DimGray"/>
</Style>
<!-- ProgressBar Styles -->
<!-- SourceRef: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Fluent/Controls/ProgressBar.xaml -->
<Style Selector="ProgressBar">
<Setter Property="Foreground" Value="{StaticResource AKI_Brush_Yellow}"/>
</Style>
@ -65,7 +98,40 @@
</Style.Animations>
</Style>
<!-- Seperator Styles -->
<!-- SourceRef: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Fluent/Controls/Separator.xaml -->
<Style Selector="Separator">
<Setter Property="Background" Value="{StaticResource AKI_Background_Dark}"/>
</Style>
<!-- Button Styles -->
<!-- SourceRef: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Fluent/Controls/Button.xaml -->
<Style Selector="Button">
<Setter Property="Background" Value="{StaticResource AKI_Brush_DarkGrayBlue}"/>
<Setter Property="Foreground" Value="{StaticResource AKI_Background_Dark}"/>
</Style>
<Style Selector="Button:pointerover">
<Setter Property="FontWeight" Value="SemiBold"/>
</Style>
<Style Selector="Button:pressed /template/ ContentPresenter">
<Setter Property="Background" Value="{StaticResource AKI_Brush_Yellow}"/>
</Style>
<!-- Checkbox styles -->
<!-- SourceRef: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Fluent/Controls/CheckBox.xaml -->
<Style Selector="CheckBox:checked">
<Setter Property="FontWeight" Value="SemiBold"/>
</Style>
<Style Selector="CheckBox:checked /template/ Border#NormalRectangle">
<Setter Property="Background" Value="{StaticResource AKI_Brush_DarkGrayBlue}"/>
<Setter Property="BorderBrush" Value="{StaticResource AKI_Brush_Yellow}"/>
</Style>
<Style Selector="CheckBox:checked /template/ Path#CheckGlyph">
<Setter Property="Fill" Value="{StaticResource AKI_Brush_Yellow}"/>
</Style>
</Styles>

View File

@ -0,0 +1,24 @@
using Avalonia;
using Avalonia.Controls;
namespace PatchGenerator.AttachedProperties
{
/// <summary>
/// Just a random boolean value for you to attach and use to any control.
/// </summary>
public class RandomBoolAttProp : AvaloniaObject
{
public static readonly AttachedProperty<bool> RandomBoolProperty =
AvaloniaProperty.RegisterAttached<RandomBoolAttProp, Control, bool>("RandomBool");
public static bool GetRandomBool(Control control)
{
return control.GetValue(RandomBoolProperty);
}
public static void SetRandomBool(Control control, bool value)
{
control.SetValue(RandomBoolProperty, value);
}
}
}

View File

@ -0,0 +1,38 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="PatchGenerator.CustomControls.FolderSelector"
DragDrop.AllowDrop="True"
Background="Transparent"
>
<UserControl.Styles>
<Style Selector="Border">
<Setter Property="BorderBrush" Value="{StaticResource AKI_Background_Dark}"/>
<Setter Property="BorderThickness" Value="2"/>
</Style>
<Style Selector="Border.folderSelected">
<Setter Property="BorderBrush" Value="{StaticResource AKI_Brush_Yellow}"/>
</Style>
<Style Selector="TextBlock.folderSelected">
<Setter Property="Foreground" Value="{StaticResource AKI_Brush_Yellow}"/>
</Style>
</UserControl.Styles>
<Border Classes.folderSelected="{Binding FolderSelected, RelativeSource={
RelativeSource AncestorType=UserControl}}">
<TextBlock Text="{Binding FolderPath, RelativeSource={
RelativeSource AncestorType=UserControl}}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Classes.folderSelected="{Binding FolderSelected, RelativeSource={
RelativeSource AncestorType=UserControl}}"
TextWrapping="Wrap"
/>
</Border>
</UserControl>

View File

@ -0,0 +1,69 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using System.IO;
using System.Linq;
namespace PatchGenerator.CustomControls
{
public partial class FolderSelector : UserControl
{
public FolderSelector()
{
InitializeComponent();
AddHandler(DragDrop.DropEvent, Drop);
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
private void Drop(object sender, DragEventArgs e)
{
if (e.Data.Contains(DataFormats.FileNames))
{
string[] filePaths = e.Data.GetFileNames().ToArray();
if (filePaths.Length == 1)
{
DirectoryInfo folder = new DirectoryInfo(filePaths[0]);
if (folder.Exists)
{
FolderPath = filePaths[0];
FolderSelected = true;
return;
}
FolderPath = "Dropped object must be a folder";
FolderSelected = false;
return;
}
FolderPath = "Cannot drop multiple files";
FolderSelected = false;
}
}
private static readonly StyledProperty<bool> FolderSelectedProperty =
AvaloniaProperty.Register<FolderSelector, bool>(nameof(FolderSelected));
private bool FolderSelected
{
get => GetValue(FolderSelectedProperty);
set => SetValue(FolderSelectedProperty, value);
}
public static readonly StyledProperty<string> FolderPathProperty =
AvaloniaProperty.Register<FolderSelector, string>(nameof(FolderPath));
public string FolderPath
{
get => GetValue(FolderPathProperty);
set => SetValue(FolderPathProperty, value);
}
}
}

View File

@ -0,0 +1,16 @@
using Avalonia.Media;
using System.Collections.Generic;
namespace PatchGenerator.Helpers
{
public static class PatchItemDefinitions
{
public static Dictionary<string, IBrush> Colors = new Dictionary<string, IBrush>()
{
{"delta", Brushes.MediumPurple },
{"new", Brushes.Green },
{"del", Brushes.IndianRed },
{"exists", Brushes.DimGray }
};
}
}

View File

@ -0,0 +1,61 @@
namespace PatchGenerator.Models
{
public class GenStartupArgs
{
public bool ReadyToRun => OutputFolderName != "" && SourceFolderPath != "" && TargetFolderPath != "";
public string OutputFolderName { get; private set; } = "";
public string SourceFolderPath { get; private set; } = "";
public string TargetFolderPath { get; private set; } = "";
public bool AutoZip { get; private set; } = true;
protected GenStartupArgs(string OutputFolderName, string SourceFolderPath, string TargetFolderPath, bool AutoZip)
{
this.OutputFolderName = OutputFolderName;
this.SourceFolderPath = SourceFolderPath;
this.TargetFolderPath = TargetFolderPath;
this.AutoZip = AutoZip;
}
public static GenStartupArgs Parse(string[] Args)
{
if (Args == null || Args.Length == 0) return null;
string outputFolderPath = "";
string sourceFolderPath = "";
string targetFolderPath = "";
bool autoZip = true;
foreach (string arg in Args)
{
if (arg.Split("::").Length != 2) return null;
var argSplit = arg.Split("::");
switch (argSplit[0])
{
case "OutputFolderName":
{
outputFolderPath = argSplit[1];
break;
}
case "SourceFolderPath":
{
sourceFolderPath = argSplit[1];
break;
}
case "TargetFolderPath":
{
targetFolderPath = argSplit[1];
break;
}
case "AutoZip":
{
autoZip = bool.Parse(argSplit[1]);
break;
}
}
}
return new GenStartupArgs(outputFolderPath, sourceFolderPath, targetFolderPath, autoZip);
}
}
}

View File

@ -0,0 +1,66 @@
using ReactiveUI;
using System.IO;
namespace PatchGenerator.Models
{
public class PatchGenInfo : ReactiveObject
{
private void UpdateReadyToRun()
{
if (Directory.Exists(SourceFolderPath) && Directory.Exists(TargetFolderPath) && PatchName != "")
{
ReadyToRun = true;
return;
}
ReadyToRun = false;
}
private string _PatchName = "";
public string PatchName
{
get => _PatchName;
set
{
this.RaiseAndSetIfChanged(ref _PatchName, value);
UpdateReadyToRun();
}
}
private string _SourceFolderPath = "";
public string SourceFolderPath
{
get => _SourceFolderPath;
set
{
this.RaiseAndSetIfChanged(ref _SourceFolderPath, value);
UpdateReadyToRun();
}
}
private string _TargetFolderPath = "";
public string TargetFolderPath
{
get => _TargetFolderPath;
set
{
this.RaiseAndSetIfChanged(ref _TargetFolderPath, value);
UpdateReadyToRun();
}
}
private bool _AutoZip = true;
public bool AutoZip
{
get => _AutoZip;
set => this.RaiseAndSetIfChanged(ref _AutoZip, value);
}
private bool _ReadyToRun = false;
public bool ReadyToRun
{
get => _ReadyToRun;
set => this.RaiseAndSetIfChanged(ref _ReadyToRun, value);
}
}
}

View File

@ -0,0 +1,40 @@
using Avalonia.Media;
using PatchGenerator.Helpers;
using ReactiveUI;
using System.Linq;
namespace PatchGenerator.Models
{
public class PatchItem : ReactiveObject
{
private string _Name = "";
public string Name
{
get => _Name;
set => this.RaiseAndSetIfChanged(ref _Name, value);
}
private IBrush _Color;
public IBrush Color
{
get => _Color;
set => this.RaiseAndSetIfChanged(ref _Color, value);
}
public PatchItem(string Name)
{
this.Name = Name.Replace(".new", "").Replace(".delta", "").Replace(".del", "");
IBrush color;
if (PatchItemDefinitions.Colors.TryGetValue(Name.Split('.').Last(), out color))
{
Color = color;
}
else
{
Color = PatchItemDefinitions.Colors["exists"];
}
}
}
}

View File

@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\PatcherUtils\PatcherUtils.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Aki.Common">
<HintPath>References\Aki.Common.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
<AvaloniaResource Remove="Assets\Styles.axaml" />
<None Remove=".gitignore" />
<None Remove="Resources\7za.exe" />
<None Remove="Resources\xdelta3.exe" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\7za.exe" />
<EmbeddedResource Include="Resources\xdelta3.exe" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.11" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.11" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.11" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.11" />
</ItemGroup>
<ItemGroup>
<Compile Update="CustomControls\TitleBar.axaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
</ItemGroup>
</Project>

View File

@ -2,6 +2,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Nullable>enable</Nullable>
</PropertyGroup>
@ -19,6 +20,15 @@
<AvaloniaResource Include="Assets\**" />
<AvaloniaResource Remove="Assets\Styles.axaml" />
<None Remove=".gitignore" />
<None Remove="Resources\7za.exe" />
<None Remove="Resources\PatchClient.exe" />
<None Remove="Resources\xdelta3.exe" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\7za.exe" />
<EmbeddedResource Include="Resources\PatchClient.exe" />
<EmbeddedResource Include="Resources\xdelta3.exe" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.11" />
@ -32,7 +42,4 @@
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,4 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;
using System;

Binary file not shown.

Binary file not shown.

View File

@ -1,12 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PatchGenerator.Models;
using Splat;
namespace PatchGenerator.ViewModels
{
public class OptionsViewModel : ViewModelBase
{
public PatchGenInfo GenerationInfo { get; set; } = new PatchGenInfo();
private ViewNavigator navigator => Locator.Current.GetService<ViewNavigator>();
public OptionsViewModel(GenStartupArgs genArgs = null)
{
if (genArgs != null)
{
//TODO - parse/check startup args and start patching
return;
}
GenerationInfo.SourceFolderPath = "Drop SOURCE folder here";
GenerationInfo.TargetFolderPath = "Drop TARGET folder here";
}
public void GeneratePatches()
{
navigator.SelectedViewModel = new PatchGenerationViewModel(GenerationInfo);
}
}
}

View File

@ -1,6 +1,12 @@
using System;
using Avalonia.Media;
using PatcherUtils;
using PatchGenerator.Helpers;
using PatchGenerator.Models;
using ReactiveUI;
using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;
@ -8,5 +14,92 @@ namespace PatchGenerator.ViewModels
{
public class PatchGenerationViewModel : ViewModelBase
{
private bool _AutoScroll = true;
public bool AutoScroll
{
get => _AutoScroll;
set => this.RaiseAndSetIfChanged(ref _AutoScroll, value);
}
private string _ProgressMessage;
public string ProgressMessage
{
get => _ProgressMessage;
set => this.RaiseAndSetIfChanged(ref _ProgressMessage, value);
}
private int _PatchPercent;
public int PatchPercent
{
get => _PatchPercent;
set => this.RaiseAndSetIfChanged(ref _PatchPercent, value);
}
public ObservableCollection<PatchItem> PatchItemCollection { get; set; } = new ObservableCollection<PatchItem>();
public ObservableCollection<PatchItem> PatchItemLegendCollection { get; set; } = new ObservableCollection<PatchItem>();
private Stopwatch patchGenStopwatch = new Stopwatch();
private readonly PatchGenInfo generationInfo;
public PatchGenerationViewModel(PatchGenInfo GenerationInfo)
{
generationInfo = GenerationInfo;
foreach (KeyValuePair<string, IBrush> pair in PatchItemDefinitions.Colors)
{
PatchItemLegendCollection.Add(new PatchItem("")
{
Name = pair.Key,
Color = pair.Value,
});
}
GeneratePatches();
}
public void GeneratePatches()
{
Task.Run(() =>
{
//Slight delay to avoid some weird race condition in avalonia core, seems to be a bug, but also maybe I'm just stupid, idk -waffle
System.Threading.Thread.Sleep(200);
string outputFolder = Path.Join(LazyOperations.PatchFolder, generationInfo.PatchName);
PatchHelper patcher = new PatchHelper(generationInfo.SourceFolderPath, generationInfo.TargetFolderPath, outputFolder);
patcher.ProgressChanged += Patcher_ProgressChanged;
patchGenStopwatch.Start();
patcher.GeneratePatches();
patchGenStopwatch.Stop();
StringBuilder sb = new StringBuilder()
.Append("Patches Generated in ")
.Append($"{patchGenStopwatch.Elapsed.Hours} hr/s ")
.Append($"{patchGenStopwatch.Elapsed.Minutes} min/s ")
.Append($"{patchGenStopwatch.Elapsed.Seconds} sec/s");
ProgressMessage = sb.ToString();
//TODO - need to fix this. Wrong folder, and need to copy client to output
if (generationInfo.AutoZip)
{
LazyOperations.StartZipProcess(outputFolder, $"{outputFolder}.zip");
}
});
}
private void Patcher_ProgressChanged(object Sender, int Progress, int Total, int Percent, string Message = "", params LineItem[] AdditionalLineItems)
{
ProgressMessage = $"{Progress}/{Total}";
PatchPercent = Percent;
PatchItemCollection.Add(new PatchItem(Message));
}
}
}

View File

@ -1,7 +1,4 @@
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Text;
namespace PatchGenerator.ViewModels
{

View File

@ -2,9 +2,33 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:cc="using:PatchGenerator.CustomControls"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="PatchGenerator.Views.OptionsView">
<Grid>
<Grid ColumnDefinitions="2*,10,2*" RowDefinitions="*,10, AUTO, 10, AUTO" Margin="10">
<cc:FolderSelector FolderPath="{Binding GenerationInfo.SourceFolderPath, Mode=TwoWay}"/>
<cc:FolderSelector Grid.Column="2"
FolderPath="{Binding GenerationInfo.TargetFolderPath, Mode=TwoWay}"/>
<TextBox Text="{Binding GenerationInfo.PatchName}"
Grid.Row="2" Grid.ColumnSpan="3"
Watermark="Output Folder Name"
/>
<CheckBox Content="Zip Generated Files" Grid.Row="4"
IsChecked="{Binding GenerationInfo.AutoZip}"/>
<Button Content="Generate Patches" Grid.ColumnSpan="3" Grid.Row="4"
HorizontalAlignment="Right"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
FontSize="15"
FontWeight="SemiBold"
Height="50"
Width="200"
Command="{Binding GeneratePatches}"
IsEnabled="{Binding GenerationInfo.ReadyToRun}"
/>
</Grid>
</UserControl>

View File

@ -1,4 +1,3 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

View File

@ -2,7 +2,71 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:model="using:PatchGenerator.Models"
xmlns:cc="using:PatchGenerator.CustomControls"
xmlns:att="using:PatchGenerator.AttachedProperties"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="PatchGenerator.Views.PatchGenerationView">
Welcome to Avalonia!
<UserControl.Styles>
<StyleInclude Source="/Assets/Styles.axaml"/>
</UserControl.Styles>
<Grid RowDefinitions="AUTO,*,AUTO,AUTO,AUTO">
<ItemsControl Items="{Binding PatchItemLegendCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Grid.Column="1"
HorizontalAlignment="Center"
Margin="10"
Spacing="30"
/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type model:PatchItem}">
<StackPanel Orientation="Horizontal" Spacing="5">
<Rectangle Fill="{Binding Color}" Height="10" Width="10"/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1"
ScrollChanged="scrollChanged"
att:RandomBoolAttProp.RandomBool="{Binding AutoScroll}"
>
<ItemsControl Items="{Binding PatchItemCollection}"
Background="Transparent"
>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type model:PatchItem}">
<TextBlock Text="{Binding Name}"
TextWrapping="Wrap"
Foreground="{Binding Color}"
/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<ProgressBar Grid.Row="2" Value="{Binding PatchPercent}" Margin="10"/>
<Grid ColumnDefinitions="AUTO,*,AUTO" Grid.Row="3" Margin="10 0">
<Label Content="{Binding ProgressMessage}"/>
<Label Content="{Binding PatchPercent, StringFormat={}{0}%}" Grid.Column="2"/>
</Grid>
<CheckBox Content="AutoScroll" Grid.Row="4" HorizontalAlignment="Right" Margin="10"
IsChecked="{Binding AutoScroll}"/>
</Grid>
</UserControl>

View File

@ -1,6 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using PatchGenerator.AttachedProperties;
namespace PatchGenerator.Views
{
@ -15,5 +15,18 @@ namespace PatchGenerator.Views
{
AvaloniaXamlLoader.Load(this);
}
public void scrollChanged(object sender, ScrollChangedEventArgs e)
{
if (sender is ScrollViewer scrollViewer)
{
bool autoScroll = scrollViewer.GetValue(RandomBoolAttProp.RandomBoolProperty);
if (autoScroll)
{
scrollViewer.ScrollToEnd();
}
}
}
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using System.IO;
using System.Reflection;
@ -67,9 +66,9 @@ namespace PatcherUtils
/// </summary>
public static void PrepTempDir()
{
foreach(string resource in Assembly.GetExecutingAssembly().GetManifestResourceNames())
foreach (string resource in Assembly.GetExecutingAssembly().GetManifestResourceNames())
{
switch(resource)
switch (resource)
{
case string a when a.EndsWith(SevenZExe):
{
@ -108,7 +107,7 @@ namespace PatcherUtils
{
DirectoryInfo dir = new DirectoryInfo(TempDir);
if(dir.Exists)
if (dir.Exists)
{
dir.Delete(true);
}

View File

@ -97,10 +97,9 @@ namespace PatcherUtils
})
.WaitForExit();
if(File.Exists(decodedPath))
if (File.Exists(decodedPath))
{
File.Delete(SourceFilePath);
File.Move(decodedPath, SourceFilePath);
File.Move(decodedPath, SourceFilePath, true);
}
}
@ -116,7 +115,7 @@ namespace PatcherUtils
string deltaPath = GetDeltaPath(SourceFilePath, SourceFolder, "delta");
Directory.CreateDirectory(deltaPath.Replace(sourceFileInfo.Name+".delta", ""));
Directory.CreateDirectory(deltaPath.Replace(sourceFileInfo.Name + ".delta", ""));
//TODO - don't hardcode FileName
@ -140,7 +139,7 @@ namespace PatcherUtils
string deltaPath = GetDeltaPath(SourceFile, SourceFolder, "del");
Directory.CreateDirectory(deltaPath.Replace(sourceFileInfo.Name+".del", ""));
Directory.CreateDirectory(deltaPath.Replace(sourceFileInfo.Name + ".del", ""));
File.Create(deltaPath);
}
@ -156,7 +155,7 @@ namespace PatcherUtils
string deltaPath = GetDeltaPath(TargetFile, TargetFolder, "new");
Directory.CreateDirectory(deltaPath.Replace(targetSourceInfo.Name+".new", ""));
Directory.CreateDirectory(deltaPath.Replace(targetSourceInfo.Name + ".new", ""));
targetSourceInfo.CopyTo(deltaPath, true);
}
@ -180,6 +179,9 @@ namespace PatcherUtils
return false;
}
LazyOperations.CleanupTempDir();
LazyOperations.PrepTempDir();
List<FileInfo> SourceFiles = sourceDir.GetFiles("*", SearchOption.AllDirectories).ToList();
fileCountTotal = SourceFiles.Count;
@ -206,15 +208,18 @@ namespace PatcherUtils
newCount++;
filesProcessed++;
RaiseProgressChanged(filesProcessed, fileCountTotal, targetFile.Name, AdditionalInfo.ToArray());
RaiseProgressChanged(filesProcessed, fileCountTotal, $"{targetFile.FullName.Replace(TargetFolder, "...")}.new", AdditionalInfo.ToArray());
continue;
}
string extension = "";
//if a matching source file was found, check the file hashes and get the delta.
if(!CompareFileHashes(sourceFile.FullName, targetFile.FullName))
if (!CompareFileHashes(sourceFile.FullName, targetFile.FullName))
{
CreateDelta(sourceFile.FullName, targetFile.FullName);
extension = ".delta";
deltaCount++;
}
@ -225,7 +230,7 @@ namespace PatcherUtils
AdditionalInfo[0].ItemValue = deltaCount;
AdditionalInfo[1].ItemValue = newCount;
RaiseProgressChanged(filesProcessed, fileCountTotal, targetFile.Name, AdditionalInfo.ToArray());
RaiseProgressChanged(filesProcessed, fileCountTotal, $"{targetFile.FullName.Replace(TargetFolder, "...")}{extension}", AdditionalInfo.ToArray());
}
//Any remaining source files do not exist in the target folder and can be removed.
@ -243,7 +248,7 @@ namespace PatcherUtils
AdditionalInfo[2].ItemValue = delCount;
filesProcessed++;
RaiseProgressChanged(filesProcessed, fileCountTotal, "", AdditionalInfo.ToArray());
RaiseProgressChanged(filesProcessed, fileCountTotal, $"{delFile.FullName.Replace(SourceFolder, "...")}.del", AdditionalInfo.ToArray());
}
return true;
@ -290,14 +295,14 @@ namespace PatcherUtils
foreach (FileInfo deltaFile in deltaDir.GetFiles("*", SearchOption.AllDirectories))
{
switch(deltaFile.Extension)
switch (deltaFile.Extension)
{
case ".delta":
{
//apply delta
FileInfo sourceFile = SourceFiles.Find(f => f.FullName.Replace(sourceDir.FullName, "") == deltaFile.FullName.Replace(deltaDir.FullName, "").Replace(".delta", ""));
if(sourceFile == null)
if (sourceFile == null)
{
return $"Failed to find matching source file for '{deltaFile.FullName}'";
}
@ -310,7 +315,7 @@ namespace PatcherUtils
}
case ".new":
{
if(newCount == 2 || newCount == 1 || newCount == 0)
if (newCount == 2 || newCount == 1 || newCount == 0)
{
}
@ -318,7 +323,7 @@ namespace PatcherUtils
//copy new file
string destination = Path.Join(sourceDir.FullName, deltaFile.FullName.Replace(deltaDir.FullName, "").Replace(".new", ""));
File.Copy(deltaFile.FullName, destination);
File.Copy(deltaFile.FullName, destination, true);
newCount--;