Skip to content

Commit 347baef

Browse files
CopilotJusterZhu
andauthored
Add driver directory packaging to GeneralUpdate.Tool.Avalonia (#10)
* Initial plan * Add driver directory feature to PacketView and PacketViewModel Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com> * Improve error handling for driver file copying Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
1 parent 1d272a4 commit 347baef

3 files changed

Lines changed: 86 additions & 19 deletions

File tree

src/Models/PacketConfigModel.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace GeneralUpdate.Tool.Avalonia.Models;
44

55
public class PacketConfigModel : ObservableObject
66
{
7-
private string _appDirectory, _releaseDirectory, _patchDirectory, _name, _path;
7+
private string _appDirectory, _releaseDirectory, _patchDirectory, _name, _path, _driverDirectory;
88
private PlatformModel _platform;
99
private FormatModel _format;
1010
private EncodingModel _encoding;
@@ -96,4 +96,17 @@ public string Path
9696
OnPropertyChanged(nameof(Path));
9797
}
9898
}
99+
100+
/// <summary>
101+
/// 驱动程序目录
102+
/// </summary>
103+
public string DriverDirectory
104+
{
105+
get => _driverDirectory;
106+
set
107+
{
108+
_driverDirectory = value;
109+
OnPropertyChanged(nameof(DriverDirectory));
110+
}
111+
}
99112
}

src/ViewModels/PacketViewModel.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ private void ResetAction()
9393
ConfigModel.ReleaseDirectory = GetPlatformSpecificPath();
9494
ConfigModel.AppDirectory = GetPlatformSpecificPath();
9595
ConfigModel.PatchDirectory = GetPlatformSpecificPath();
96+
ConfigModel.DriverDirectory = string.Empty;
9697
ConfigModel.Encoding = Encodings.First();
9798
ConfigModel.Format = Formats.First();
9899
}
99100

100-
/// <summary>
101+
/// <summary>
101102
/// Choose a path
102103
/// </summary>
103104
/// <param name="value"></param>
@@ -122,6 +123,10 @@ private async Task SelectFolderAction(string value)
122123
case "Patch":
123124
ConfigModel.PatchDirectory = folder!.Path.LocalPath;
124125
break;
126+
127+
case "Driver":
128+
ConfigModel.DriverDirectory = folder!.Path.LocalPath;
129+
break;
125130
}
126131
}
127132
catch (Exception e)
@@ -141,6 +146,25 @@ await DifferentialCore.Instance.Clean(ConfigModel.AppDirectory,
141146
ConfigModel.ReleaseDirectory,
142147
ConfigModel.PatchDirectory);
143148

149+
// Copy driver files to drivers folder if driver directory is specified
150+
if (!string.IsNullOrWhiteSpace(ConfigModel.DriverDirectory) &&
151+
Directory.Exists(ConfigModel.DriverDirectory))
152+
{
153+
try
154+
{
155+
var driversFolder = Path.Combine(ConfigModel.PatchDirectory, "drivers");
156+
Directory.CreateDirectory(driversFolder);
157+
158+
CopyDriverFiles(ConfigModel.DriverDirectory, driversFolder);
159+
}
160+
catch (Exception ex)
161+
{
162+
Trace.WriteLine($"Failed to copy driver files: {ex.Message}");
163+
await MessageBox.ShowAsync("Failed to copy driver files. Please check the driver directory permissions and available disk space.", "Warning", Buttons.OK);
164+
// Continue with the build process even if driver copying fails
165+
}
166+
}
167+
144168
var directoryInfo = new DirectoryInfo(ConfigModel.PatchDirectory);
145169
var parentDirectory = directoryInfo.Parent!.FullName;
146170
var operationType = ConfigModel.Format.Value;
@@ -211,4 +235,24 @@ private void DeleteDirectoryRecursively(string targetDir)
211235
}
212236
Directory.Delete(targetDir, false);
213237
}
238+
239+
private void CopyDriverFiles(string sourceDir, string targetDir)
240+
{
241+
// Copy all files from source to target
242+
foreach (var file in Directory.GetFiles(sourceDir))
243+
{
244+
var fileName = Path.GetFileName(file);
245+
var destFile = Path.Combine(targetDir, fileName);
246+
File.Copy(file, destFile, true);
247+
}
248+
249+
// Copy all subdirectories and their files recursively
250+
foreach (var dir in Directory.GetDirectories(sourceDir))
251+
{
252+
var dirName = Path.GetFileName(dir);
253+
var destDir = Path.Combine(targetDir, dirName);
254+
Directory.CreateDirectory(destDir);
255+
CopyDriverFiles(dir, destDir);
256+
}
257+
}
214258
}

src/Views/PacketView.axaml

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</i:Interaction.Behaviors>
1515
<Grid RowDefinitions="9*,1*">
1616
<ScrollViewer>
17-
<Grid ColumnDefinitions="1*,4*,1*" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto">
17+
<Grid ColumnDefinitions="1*,4*,1*" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto">
1818
<!-- SourcePath -->
1919
<TextBlock
2020
HorizontalAlignment="Right"
@@ -72,54 +72,64 @@
7272
CommandParameter="Patch" Content="Pick"
7373
Theme="{DynamicResource SolidButton}">
7474
</Button>
75-
<!-- Packet name -->
75+
<!-- Driver path -->
7676
<TextBlock
7777
Grid.Row="3"
7878
HorizontalAlignment="Right"
7979
VerticalAlignment="Center"
80-
Text="PacketName" />
80+
Text="DriverDirectory" />
8181
<TextBox
8282
Grid.Row="3"
8383
Grid.Column="1"
8484
Margin="5"
85-
Text="{Binding ConfigModel.Name, Mode=TwoWay}" />
85+
Text="{Binding ConfigModel.DriverDirectory, Mode=TwoWay}" />
86+
<Button
87+
Grid.Row="3"
88+
Grid.Column="2"
89+
Margin="5"
90+
Classes="Primary"
91+
Command="{Binding SelectFolderCommand}"
92+
CommandParameter="Driver" Content="Pick"
93+
Theme="{DynamicResource SolidButton}">
94+
</Button>
8695
<!-- Packet name -->
8796
<TextBlock
8897
Grid.Row="4"
8998
HorizontalAlignment="Right"
9099
VerticalAlignment="Center"
100+
Text="PacketName" />
101+
<TextBox
102+
Grid.Row="4"
103+
Grid.Column="1"
104+
Margin="5"
105+
Text="{Binding ConfigModel.Name, Mode=TwoWay}" />
106+
<!-- Format -->
107+
<TextBlock
108+
Grid.Row="5"
109+
HorizontalAlignment="Right"
110+
VerticalAlignment="Center"
91111
Text="Format" />
92112
<ComboBox
93-
Grid.Row="4"
113+
Grid.Row="5"
94114
Grid.Column="1"
95115
MinWidth="150"
96116
Margin="5"
97117
ItemsSource="{Binding Formats}"
98118
SelectedItem="{Binding ConfigModel.Format}" />
99119
<!-- encoding -->
100120
<TextBlock
101-
Grid.Row="5"
121+
Grid.Row="6"
102122
HorizontalAlignment="Right"
103123
VerticalAlignment="Center"
104124
Text="Encoding" />
105125
<ComboBox
106-
Grid.Row="5"
126+
Grid.Row="6"
107127
Grid.Column="1"
108128
MinWidth="150"
109129
Margin="5"
110130
ItemsSource="{Binding Encodings}"
111131
SelectedIndex="0"
112132
SelectedItem="{Binding ConfigModel.Encoding}" />
113-
<Button
114-
Grid.Row="6"
115-
Grid.Column="2"
116-
Margin="5"
117-
Classes="Primary"
118-
IsVisible="False"
119-
Command="{Binding SelectFolderCommand}"
120-
CommandParameter="Driver" Content="Pick"
121-
Theme="{DynamicResource SolidButton}">
122-
</Button>
123133
</Grid>
124134
</ScrollViewer>
125135
<StackPanel

0 commit comments

Comments
 (0)