Skip to content

Commit 23ce633

Browse files
committed
Add a copy of the driver folder
1 parent bf7e463 commit 23ce633

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

src/WPF/GeneralUpdate.Packet/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:GeneralUpdate.Packet"
77
mc:Ignorable="d"
8-
Title="GeneralUpdate.Packet" Height="600" Width="900">
8+
Title="GeneralUpdate.Packet" Height="640" Width="900">
99
<Grid>
1010
<Grid.RowDefinitions>
1111
<RowDefinition Height="100"></RowDefinition>

src/WPF/GeneralUpdate.Packet/ViewModels/PacketViewModel.cs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class PacketViewModel : ViewModeBase
1717
{
1818
#region Private Members
1919

20-
private string sourcePath, targetPath, patchPath, infoMessage, url, packetName;
20+
private string sourcePath, targetPath, patchPath, infoMessage, url, packetName, driverDir;
2121
private List<string> _formats, _encodings, _appTypes;
2222
private string _currentFormat, _currentEncoding, _currentAppType, _currentVersion, _currentClientAppKey;
2323
private bool isPublish;
@@ -49,6 +49,7 @@ internal PacketViewModel()
4949
public bool IsPublish { get => isPublish; set => SetProperty(ref isPublish, value); }
5050
public string Url { get => url; set => SetProperty(ref url, value); }
5151
public string PacketName { get => packetName; set => SetProperty(ref packetName, value); }
52+
public string DriverDir { get => packetName; set => SetProperty(ref driverDir, value); }
5253

5354
public AsyncRelayCommand<string> SelectFolderCommand
5455
{
@@ -148,7 +149,7 @@ private async Task SelectFolderAction(string value)
148149
var openFileDialog = new OpenFileDialog();
149150
openFileDialog.InitialDirectory = @"D:\";
150151
openFileDialog.Filter = "All files (*.*)|*.*";
151-
if (!openFileDialog.ShowDialog().Value)
152+
if (openFileDialog.ShowDialog() == false)
152153
{
153154
await ShowMessage("Pick options", "No results were selected !");
154155
return;
@@ -168,6 +169,10 @@ private async Task SelectFolderAction(string value)
168169
case "Patch":
169170
PatchPath = selectedFilePath;
170171
break;
172+
173+
case "Driver":
174+
DriverDir = selectedFilePath;
175+
break;
171176
}
172177
}
173178

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

191196
try
192197
{
198+
CopyDirectory(DriverDir, TargetPath);
193199
await DifferentialCore.Instance.Clean(SourcePath, TargetPath, PatchPath, (sender, args) => { },
194200
String2OperationType(CurrentFormat), String2Encoding(CurrentEncoding), PacketName);
195201
if (IsPublish)
@@ -315,13 +321,34 @@ await Application.Current.Dispatcher.BeginInvoke(new Action(() =>
315321
}));
316322
}
317323

318-
319324
/// <summary>
320-
/// Check whether the directory contains driver files.
325+
/// Copy all folders containing drivers in the root directory.
321326
/// </summary>
322-
/// <param name="subPath"></param>
323-
/// <returns></returns>
324-
public bool IsDriver(string subPath) => Directory.EnumerateFiles(subPath, "*.inf").Any();
327+
/// <param name="sourceDir"></param>
328+
/// <param name="targetDir"></param>
329+
private void CopyDirectory(string sourceDir, string targetDir)
330+
{
331+
if (string.IsNullOrWhiteSpace(sourceDir) || string.IsNullOrEmpty(targetDir))
332+
return;
333+
334+
if (!Directory.Exists(targetDir))
335+
Directory.CreateDirectory(targetDir);
336+
337+
foreach (var file in Directory.GetFiles(sourceDir))
338+
{
339+
if (Path.GetExtension(file) == ".inf")
340+
{
341+
var targetPath = Path.Combine(targetDir, Path.GetFileName(file));
342+
File.Copy(file, targetPath, true);
343+
}
344+
}
345+
346+
foreach (var directory in Directory.GetDirectories(sourceDir))
347+
{
348+
var targetPath = Path.Combine(targetDir, Path.GetFileName(directory));
349+
CopyDirectory(directory, targetPath);
350+
}
351+
}
325352

326353
#endregion Private Methods
327354
}

src/WPF/GeneralUpdate.Packet/Views/PacketView.xaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:local="clr-namespace:GeneralUpdate.Packet.Views"
77
mc:Ignorable="d"
8-
d:DesignHeight="450" d:DesignWidth="800">
8+
d:DesignHeight="490" d:DesignWidth="800">
99
<Grid>
1010
<Grid.RowDefinitions>
1111
<RowDefinition />
@@ -20,6 +20,7 @@
2020
<RowDefinition Height="Auto" />
2121
<RowDefinition Height="Auto" />
2222
<RowDefinition Height="Auto" />
23+
<RowDefinition Height="Auto" />
2324
<RowDefinition />
2425
</Grid.RowDefinitions>
2526
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
@@ -74,7 +75,12 @@
7475
<TextBlock VerticalAlignment="Center" Text="Currnet version :" />
7576
<TextBox Width="400" Height="30" Margin="9,0,3,0" Text="{Binding CurrentVersion}" VerticalContentAlignment="Center" />
7677
</StackPanel>
77-
<StackPanel HorizontalAlignment="Center" Grid.Row="11" Orientation="Horizontal">
78+
<StackPanel Grid.Row="11" Orientation="Horizontal" Height="40" HorizontalAlignment="Center">
79+
<TextBlock VerticalAlignment="Center" Text="Driver dir :" />
80+
<TextBox Width="400" Height="30" Margin="9,0,3,0" Text="{Binding PatchPath}" VerticalContentAlignment="Center" />
81+
<Button Width="110" Height="30" Content="Pick driver" Command="{Binding SelectFolderCommand}" CommandParameter="Driver" />
82+
</StackPanel>
83+
<StackPanel HorizontalAlignment="Center" Grid.Row="12" Orientation="Horizontal">
7884
<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." />
7985
<CheckBox Margin="10,0,0,0" IsChecked="{Binding IsPublish}" Content="publish" VerticalAlignment="Center" />
8086
</StackPanel>

0 commit comments

Comments
 (0)