Skip to content

Commit

Permalink
Add a copy of the driver folder
Browse files Browse the repository at this point in the history
  • Loading branch information
JusterZhu committed Dec 31, 2023
1 parent bf7e463 commit 23ce633
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/WPF/GeneralUpdate.Packet/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GeneralUpdate.Packet"
mc:Ignorable="d"
Title="GeneralUpdate.Packet" Height="600" Width="900">
Title="GeneralUpdate.Packet" Height="640" Width="900">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
Expand Down
41 changes: 34 additions & 7 deletions src/WPF/GeneralUpdate.Packet/ViewModels/PacketViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class PacketViewModel : ViewModeBase
{
#region Private Members

private string sourcePath, targetPath, patchPath, infoMessage, url, packetName;
private string sourcePath, targetPath, patchPath, infoMessage, url, packetName, driverDir;
private List<string> _formats, _encodings, _appTypes;
private string _currentFormat, _currentEncoding, _currentAppType, _currentVersion, _currentClientAppKey;
private bool isPublish;
Expand Down Expand Up @@ -49,6 +49,7 @@ internal PacketViewModel()
public bool IsPublish { get => isPublish; set => SetProperty(ref isPublish, value); }
public string Url { get => url; set => SetProperty(ref url, value); }
public string PacketName { get => packetName; set => SetProperty(ref packetName, value); }
public string DriverDir { get => packetName; set => SetProperty(ref driverDir, value); }

public AsyncRelayCommand<string> SelectFolderCommand
{
Expand Down Expand Up @@ -148,7 +149,7 @@ private async Task SelectFolderAction(string value)
var openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = @"D:\";
openFileDialog.Filter = "All files (*.*)|*.*";
if (!openFileDialog.ShowDialog().Value)
if (openFileDialog.ShowDialog() == false)
{
await ShowMessage("Pick options", "No results were selected !");
return;
Expand All @@ -168,6 +169,10 @@ private async Task SelectFolderAction(string value)
case "Patch":
PatchPath = selectedFilePath;
break;

case "Driver":
DriverDir = selectedFilePath;
break;
}
}

Expand All @@ -190,6 +195,7 @@ private async Task BuildPacketCallback()

try
{
CopyDirectory(DriverDir, TargetPath);
await DifferentialCore.Instance.Clean(SourcePath, TargetPath, PatchPath, (sender, args) => { },
String2OperationType(CurrentFormat), String2Encoding(CurrentEncoding), PacketName);
if (IsPublish)
Expand Down Expand Up @@ -315,13 +321,34 @@ await Application.Current.Dispatcher.BeginInvoke(new Action(() =>
}));
}


/// <summary>
/// Check whether the directory contains driver files.
/// Copy all folders containing drivers in the root directory.
/// </summary>
/// <param name="subPath"></param>
/// <returns></returns>
public bool IsDriver(string subPath) => Directory.EnumerateFiles(subPath, "*.inf").Any();
/// <param name="sourceDir"></param>
/// <param name="targetDir"></param>
private void CopyDirectory(string sourceDir, string targetDir)
{
if (string.IsNullOrWhiteSpace(sourceDir) || string.IsNullOrEmpty(targetDir))
return;

if (!Directory.Exists(targetDir))
Directory.CreateDirectory(targetDir);

foreach (var file in Directory.GetFiles(sourceDir))
{
if (Path.GetExtension(file) == ".inf")
{
var targetPath = Path.Combine(targetDir, Path.GetFileName(file));
File.Copy(file, targetPath, true);
}
}

foreach (var directory in Directory.GetDirectories(sourceDir))
{
var targetPath = Path.Combine(targetDir, Path.GetFileName(directory));
CopyDirectory(directory, targetPath);
}
}

#endregion Private Methods
}
Expand Down
10 changes: 8 additions & 2 deletions src/WPF/GeneralUpdate.Packet/Views/PacketView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GeneralUpdate.Packet.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
d:DesignHeight="490" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
Expand All @@ -20,6 +20,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
Expand Down Expand Up @@ -74,7 +75,12 @@
<TextBlock VerticalAlignment="Center" Text="Currnet version :" />
<TextBox Width="400" Height="30" Margin="9,0,3,0" Text="{Binding CurrentVersion}" VerticalContentAlignment="Center" />
</StackPanel>
<StackPanel HorizontalAlignment="Center" Grid.Row="11" Orientation="Horizontal">
<StackPanel Grid.Row="11" Orientation="Horizontal" Height="40" HorizontalAlignment="Center">
<TextBlock VerticalAlignment="Center" Text="Driver dir :" />
<TextBox Width="400" Height="30" Margin="9,0,3,0" Text="{Binding PatchPath}" VerticalContentAlignment="Center" />
<Button Width="110" Height="30" Content="Pick driver" Command="{Binding SelectFolderCommand}" CommandParameter="Driver" />
</StackPanel>
<StackPanel HorizontalAlignment="Center" Grid.Row="12" Orientation="Horizontal">
<Button Margin="5" HorizontalAlignment="Center" Content="Build" Width="110" Height="30" Command="{Binding BuildCommand}" ToolTipService.ToolTip="The binary differential patch package is generated based on the difference between the two versions." />
<CheckBox Margin="10,0,0,0" IsChecked="{Binding IsPublish}" Content="publish" VerticalAlignment="Center" />
</StackPanel>
Expand Down

0 comments on commit 23ce633

Please sign in to comment.