From 199e3630d9b51bcf65dad6334558e523a516b12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=8C=AF=E4=BC=9F?= Date: Tue, 6 Feb 2024 10:03:28 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E4=BA=86?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=20DNS=20=E4=BF=AE=E6=94=B9=E7=9A=84?= =?UTF-8?q?=20UI=20(#12)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 完善了自定义 DNS 修改的 UI * 开启了 ClickOnce 更新了 workflow 依赖版本 --- .github/workflows/build.yml | 4 +- SduNetCheckTool.Core/Tools/DNSSwitch.cs | 8 +- .../SduNetCheckTool.GUI.csproj | 2 +- .../Views/ToolboxTabs/DNSSwitchView.xaml | 49 ++++++++--- .../DNSSwitchViewModel.cs | 88 +++++++++++++++---- 5 files changed, 118 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 54627a9..10efdd0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,7 +41,7 @@ jobs: node-version: 18 - name: Setup MSBuild.exe - uses: microsoft/setup-msbuild@v1.1 + uses: microsoft/setup-msbuild@v2 - name: Restore the Wpf application run: msbuild ${{ env.solutionPath }} /t:Restore /p:Configuration=Release /p:Platform=x64 /p:RuntimeIdentifier=win-x64 @@ -63,7 +63,7 @@ jobs: Move-Item build\SduNetCheckTool.GUI_boxed.exe build\${{ env.appPackagesExecutable }} - name: 'Upload Artifact' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ env.artifactName }} path: | diff --git a/SduNetCheckTool.Core/Tools/DNSSwitch.cs b/SduNetCheckTool.Core/Tools/DNSSwitch.cs index 8b85824..67e5d37 100644 --- a/SduNetCheckTool.Core/Tools/DNSSwitch.cs +++ b/SduNetCheckTool.Core/Tools/DNSSwitch.cs @@ -1,11 +1,17 @@ using System.Net.NetworkInformation; using System.Text; +using System.Text.RegularExpressions; using SduNetCheckTool.Core.Utils; namespace SduNetCheckTool.Core.Tools { - public class DNSSwitch + public static class DNSSwitch { + private static readonly string pattern = @"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; + + private static readonly Regex regex = new(pattern); + public static bool IsValidIPv4(string ip) => regex.IsMatch(ip); + public static string Switch(NetworkInterface[] netInterfaces, string dnsServer) { var data = new StringBuilder(); diff --git a/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj b/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj index 37fc2ac..f9c6fdb 100644 --- a/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj +++ b/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj @@ -57,7 +57,7 @@ SduNetCheckTool.GUI_TemporaryKey.pfx - false + true false diff --git a/SduNetCheckTool.GUI/Views/ToolboxTabs/DNSSwitchView.xaml b/SduNetCheckTool.GUI/Views/ToolboxTabs/DNSSwitchView.xaml index 9940a14..7f95763 100644 --- a/SduNetCheckTool.GUI/Views/ToolboxTabs/DNSSwitchView.xaml +++ b/SduNetCheckTool.GUI/Views/ToolboxTabs/DNSSwitchView.xaml @@ -12,12 +12,14 @@ mc:Ignorable="d"> - - + + + - + + + + + + + + + HorizontalAlignment="Left" + Text="{Binding CurrentDNS, UpdateSourceTrigger=PropertyChanged}" + Width="{Binding ElementName=SelectDNSComboBox, Path=ActualWidth}"> + + + + - - diff --git a/SduNetCheckTool.Mvvm/ViewModels/ToolboxTabViewModels/DNSSwitchViewModel.cs b/SduNetCheckTool.Mvvm/ViewModels/ToolboxTabViewModels/DNSSwitchViewModel.cs index 3505d44..b832ad6 100644 --- a/SduNetCheckTool.Mvvm/ViewModels/ToolboxTabViewModels/DNSSwitchViewModel.cs +++ b/SduNetCheckTool.Mvvm/ViewModels/ToolboxTabViewModels/DNSSwitchViewModel.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Net.NetworkInformation; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; @@ -16,13 +17,13 @@ public struct DNSSwitchItem public string Name { get; set; } public string DNSIPAddress { get; set; } - public string NameAndValue => $"{Name} ({DNSIPAddress})"; + public readonly string NameAndValue => $"{Name} ({DNSIPAddress})"; } - public bool IsDnsSwitchEnabled {get { return _isDnsSwitchEnabled; }} + public bool IsDnsSwitchEnabled { get { return _isDnsSwitchEnabled; } } public readonly bool _isDnsSwitchEnabled = Identifier.IsAdministrator(); - + private readonly DNSSwitchItem[] DNSList = [ @@ -32,7 +33,6 @@ public struct DNSSwitchItem new DNSSwitchItem { Name = "谷歌 DNS", DNSIPAddress = "8.8.8.8" }, new DNSSwitchItem { Name = "自动分配DNS", DNSIPAddress = "DHCP" }, // 添加更多的项,如果需要 - new DNSSwitchItem { Name = "自定义", DNSIPAddress = string.Empty } ]; public DNSSwitchViewModel() @@ -51,20 +51,32 @@ public Task RunDnsSwitch() Tips = "脚本执行中"; - NetworkInterface[] interfaces = [SelectedNetworkInterface]; - if(Identifier.IsAdministrator()) - { - Tips = SelectedDNSSwitchItem.Name switch - { - "自定义" => DNSSwitch.Switch(interfaces, CustomDNS), - _ => DNSSwitch.Switch(interfaces, SelectedDNSSwitchItem.DNSIPAddress), - }; - SetStatus(TaskStatusEnum.Completed); - } else + if (!Identifier.IsAdministrator()) { Tips = "错误: 没有管理员权限!\n请尝试:点击按钮以管理员权限重启"; SetStatus(TaskStatusEnum.Error); + return; + } + + NetworkInterface[] interfaces = [SelectedNetworkInterface]; + + if (IsCustomDNS) + { + CurrentDNS = CurrentDNS.Trim(); + if (!DNSSwitch.IsValidIPv4(CurrentDNS)) + { + Tips = "无效的 IPv4 地址,请输入正确的 IPv4 地址。"; + SetStatus(TaskStatusEnum.Error); + return; + } + Tips = DNSSwitch.Switch(interfaces, CurrentDNS); + } + else + { + Tips = DNSSwitch.Switch(interfaces, SelectedDNSSwitchItem.DNSIPAddress); } + SetStatus(TaskStatusEnum.Completed); + }); } @@ -75,7 +87,8 @@ public void RebootAsAdmin() if (Identifier.IsAdministrator()) { Tips = "已经是管理员权限!\n可以修改DNS设置"; - } else + } + else { Identifier.RebootAsAdmin(); } @@ -92,7 +105,8 @@ private void InitializeProperties() if (IsDnsSwitchEnabled) { Tips = "已经是管理员权限!\n可以修改DNS设置"; - } else + } + else { Tips = "错误: 没有管理员权限!\n请尝试:点击按钮以管理员权限重启"; } @@ -103,9 +117,45 @@ private void InitializeProperties() public DNSSwitchItem[] DNSSwitchItems { get; set; } - public DNSSwitchItem SelectedDNSSwitchItem { get; set; } + public DNSSwitchItem _selectedDNSSwitchItem; + public DNSSwitchItem SelectedDNSSwitchItem + { + get => _selectedDNSSwitchItem; + set + { + if (!_selectedDNSSwitchItem.Equals(value)) + { + _selectedDNSSwitchItem = value; + + // Update IsCustomDNS based on the new SelectedDNSSwitchItem + CurrentDNS = SelectedDNSSwitchItem.DNSIPAddress; + OnPropertyChanged(nameof(SelectedDNSSwitchItem)); + + } + } + } + + public bool _isCustomDNS; + + public bool IsCustomDNS + { + get => _isCustomDNS; + set + { + if (_isCustomDNS != value) + { + _isCustomDNS = value; + OnPropertyChanged(nameof(IsCustomDNS)); + if (_isCustomDNS) + { + CurrentDNS = string.Empty; + } + } + } + } - public string CustomDNS { get; set; } + [ObservableProperty] + public string currentDNS; } From 708d8202593b35a5ece2ea899405771a94414578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ForDream=E4=B8=B6=E6=A2=A6=E7=A9=BA?= <56014859+Forgot-Dream@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:43:17 +0800 Subject: [PATCH 2/6] ci: change `retention-days` to 15 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 10efdd0..a916a40 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -69,4 +69,4 @@ jobs: path: | build/${{ env.appPackagesArchive }} build/${{ env.appPackagesExecutable }} - retention-days: 1 + retention-days: 15 From ef6fd9b1b27b8df239c865b08dc22bbadafe7606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ForDream=E4=B8=B6=E6=A2=A6=E7=A9=BA?= <56014859+Forgot-Dream@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:49:03 +0800 Subject: [PATCH 3/6] ci: add build_number to artifacts name --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a916a40..4e262ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,10 +20,10 @@ jobs: runs-on: windows-latest env: - # artifacts 命名 [名字]-[commit-hash] - artifactName: SduNetCheckTool-${{ github.sha }} - appPackagesArchive: SduNetCheckTool-${{ github.sha }}.zip - appPackagesExecutable: SduNetCheckTool-${{ github.sha }}.exe + # artifacts 命名 [名字]-[build-number]-[commit-hash] + artifactName: SduNetCheckTool-build.${{github.run_number}}-${{ github.sha }} + appPackagesArchive: SduNetCheckTool-build.${{github.run_number}}-${{ github.sha }}.zip + appPackagesExecutable: SduNetCheckTool-build.${{github.run_number}}-${{ github.sha }}.exe solutionPath: SduNetCheckTool.sln coreProjectDirectory: SduNetCheckTool.Core From ad3a1a3720c663dcabe35e9b9b076dc0b1fc8027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ForDream=E4=B8=B6=E6=A2=A6=E7=A9=BA?= <56014859+Forgot-Dream@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:51:13 +0800 Subject: [PATCH 4/6] ci: Update release.yml --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 409d409..cf8e32d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: env: # app 命名 [名字]-[commit-tag] - artifact_name: SduNetCheckTool-${{ github.sha }} + artifact_name: SduNetCheckTool-build.${{github.run_number}}-${{ github.sha }} steps: - name: Checkout @@ -44,4 +44,4 @@ jobs: tag_name: ${{ github.ref_name }} draft: false prerelease: false - token: ${{secrets.GITHUB_TOKEN}} \ No newline at end of file + token: ${{secrets.GITHUB_TOKEN}} From 886b8f8ffc9cfe90799c5ca87a424612fcc90153 Mon Sep 17 00:00:00 2001 From: Forgot-Dream <56014859+Forgot-Dream@users.noreply.github.com> Date: Mon, 26 Feb 2024 21:35:17 +0800 Subject: [PATCH 5/6] feat: add InfoDialog --- .../SduNetCheckTool.GUI.csproj | 9 +++++++ .../Views/Dialogs/InfoDialog.xaml | 26 +++++++++++++++++++ .../Views/Dialogs/InfoDialog.xaml.cs | 15 +++++++++++ SduNetCheckTool.GUI/Views/MainView.xaml.cs | 15 +++++++++++ .../Common/Messages/InfoDialogMessage.cs | 7 +++++ SduNetCheckTool.Mvvm/Utils/FileUtil.cs | 2 +- .../ViewModels/TestViewModel.cs | 10 +++++++ .../ToolboxTabViewModelBase.cs | 2 +- 8 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 SduNetCheckTool.GUI/Views/Dialogs/InfoDialog.xaml create mode 100644 SduNetCheckTool.GUI/Views/Dialogs/InfoDialog.xaml.cs create mode 100644 SduNetCheckTool.Mvvm/Common/Messages/InfoDialogMessage.cs diff --git a/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj b/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj index f9c6fdb..96d581a 100644 --- a/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj +++ b/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj @@ -92,6 +92,8 @@ + + @@ -115,6 +117,9 @@ AboutView.xaml + + InfoDialog.xaml + RootView.xaml @@ -131,6 +136,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + MSBuild:Compile Designer diff --git a/SduNetCheckTool.GUI/Views/Dialogs/InfoDialog.xaml b/SduNetCheckTool.GUI/Views/Dialogs/InfoDialog.xaml new file mode 100644 index 0000000..5e4c9df --- /dev/null +++ b/SduNetCheckTool.GUI/Views/Dialogs/InfoDialog.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + diff --git a/SduNetCheckTool.GUI/Views/Dialogs/InfoDialog.xaml.cs b/SduNetCheckTool.GUI/Views/Dialogs/InfoDialog.xaml.cs new file mode 100644 index 0000000..6ba40be --- /dev/null +++ b/SduNetCheckTool.GUI/Views/Dialogs/InfoDialog.xaml.cs @@ -0,0 +1,15 @@ +using ModernWpf.Controls; + +namespace SduNetCheckTool.GUI.Views.Dialogs +{ + /// + /// InfoDialog.xaml 的交互逻辑 + /// + public partial class InfoDialog : ContentDialog + { + public InfoDialog() + { + InitializeComponent(); + } + } +} diff --git a/SduNetCheckTool.GUI/Views/MainView.xaml.cs b/SduNetCheckTool.GUI/Views/MainView.xaml.cs index d996aaa..b64fbad 100644 --- a/SduNetCheckTool.GUI/Views/MainView.xaml.cs +++ b/SduNetCheckTool.GUI/Views/MainView.xaml.cs @@ -1,4 +1,7 @@ using System.Windows; +using CommunityToolkit.Mvvm.Messaging; +using SduNetCheckTool.GUI.Views.Dialogs; +using SduNetCheckTool.Mvvm.Common.Messages; namespace SduNetCheckTool.GUI.Views { @@ -10,6 +13,18 @@ public partial class MainView : Window public MainView() { InitializeComponent(); + + WeakReferenceMessenger.Default.Register(this, async (r, m) => + { + var dialog = new InfoDialog + { + Owner=this + }; + + dialog.Description.Text = m.Description; + + await dialog.ShowAsync(); + }); } } } \ No newline at end of file diff --git a/SduNetCheckTool.Mvvm/Common/Messages/InfoDialogMessage.cs b/SduNetCheckTool.Mvvm/Common/Messages/InfoDialogMessage.cs new file mode 100644 index 0000000..622070a --- /dev/null +++ b/SduNetCheckTool.Mvvm/Common/Messages/InfoDialogMessage.cs @@ -0,0 +1,7 @@ +namespace SduNetCheckTool.Mvvm.Common.Messages +{ + public class InfoDialogMessage(string description) + { + public string Description = description; + } +} diff --git a/SduNetCheckTool.Mvvm/Utils/FileUtil.cs b/SduNetCheckTool.Mvvm/Utils/FileUtil.cs index 5c105ff..a328c82 100644 --- a/SduNetCheckTool.Mvvm/Utils/FileUtil.cs +++ b/SduNetCheckTool.Mvvm/Utils/FileUtil.cs @@ -15,7 +15,7 @@ public static string ExportReport(ObservableCollection tasks) var exportFilePath = ExportPath + "\\" + System.DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".txt"; if (tasks.Any(i => i.TaskStatusEnum == TaskStatusEnum.Waiting)) - return "NoRecords"; + return null; if (!Directory.Exists(ExportPath)) Directory.CreateDirectory(ExportPath); diff --git a/SduNetCheckTool.Mvvm/ViewModels/TestViewModel.cs b/SduNetCheckTool.Mvvm/ViewModels/TestViewModel.cs index 109101c..0bd22f1 100644 --- a/SduNetCheckTool.Mvvm/ViewModels/TestViewModel.cs +++ b/SduNetCheckTool.Mvvm/ViewModels/TestViewModel.cs @@ -3,9 +3,12 @@ using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.Mvvm.Messaging; using SduNetCheckTool.Core.Repairs; using SduNetCheckTool.Core.Tests; using SduNetCheckTool.Mvvm.Common; +using SduNetCheckTool.Mvvm.Common.Messages; +using SduNetCheckTool.Mvvm.Utils; namespace SduNetCheckTool.Mvvm.ViewModels { @@ -103,6 +106,13 @@ private void ExportReport() .Show(); } }*/ + var output = FileUtil.ExportReport(Tasks); //temp + if (output == null) + { + WeakReferenceMessenger.Default.Send(new InfoDialogMessage("请先点击'开始检测'运行测试! >_<")); + return; + } + WeakReferenceMessenger.Default.Send(new InfoDialogMessage("日志文件已生成!(⑅•ᴗ•⑅) \n路径: " + output)); } [RelayCommand] diff --git a/SduNetCheckTool.Mvvm/ViewModels/ToolboxTabViewModels/ToolboxTabViewModelBase.cs b/SduNetCheckTool.Mvvm/ViewModels/ToolboxTabViewModels/ToolboxTabViewModelBase.cs index 79e7869..94cea56 100644 --- a/SduNetCheckTool.Mvvm/ViewModels/ToolboxTabViewModels/ToolboxTabViewModelBase.cs +++ b/SduNetCheckTool.Mvvm/ViewModels/ToolboxTabViewModels/ToolboxTabViewModelBase.cs @@ -5,7 +5,7 @@ namespace SduNetCheckTool.Mvvm.ViewModels.ToolboxTabViewModels; public partial class ToolboxTabViewModelBase:ObservableObject { - [ObservableProperty] private TaskStatusEnum status; + [ObservableProperty] private TaskStatusEnum _status; public void SetStatus(TaskStatusEnum s) { From 7abba74ee2ad9f5ff7259f97f7481c7bd71d9867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=8C=AF=E4=BC=9F?= Date: Mon, 26 Feb 2024 23:14:21 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 build 逻辑单独放到了 ps 脚本里 --- .github/utils/build.ps1 | 50 +++++++++++++++++++++++++++ .github/utils/pack.js | 69 +++++++++++++++++++++++++++---------- .github/utils/package.json | 1 + .github/workflows/build.yml | 13 +++---- 4 files changed, 106 insertions(+), 27 deletions(-) create mode 100644 .github/utils/build.ps1 diff --git a/.github/utils/build.ps1 b/.github/utils/build.ps1 new file mode 100644 index 0000000..07c0d97 --- /dev/null +++ b/.github/utils/build.ps1 @@ -0,0 +1,50 @@ +param( + [string]$SolutionPath = "SduNetCheckTool.sln", + [string]$Configuration = "Debug", + [string]$Platform = "x64", + [string]$RuntimeIdentifier = "win-x64" +) + +# 函数用于检测是否安装了需要的工具和依赖 +function CheckPrerequisites { + Write-Host "Checking prerequisites for build..." + + # 检测 MSBuild + if (-not (Get-Command -Name "msbuild" -ErrorAction SilentlyContinue)) { + Write-Host "MSBuild is not installed or not in PATH. Please install MSBuild." -ForegroundColor Red + exit 1 + } + + Write-Host "Prerequisites check passed for build." +} + +# 函数用于构建项目 +function BuildProject { + # 使用 MSBuild 进行 WPF 应用程序的恢复 + $restoreArgs = "/t:Restore /p:Configuration=$Configuration /p:Platform=$Platform /p:RuntimeIdentifier=$RuntimeIdentifier" + $restoreCommand = "msbuild $SolutionPath $restoreArgs" + + Write-Host "`n Restoring WPF project... `n" -ForegroundColor Cyan + Write-Host "$ $restoreCommand `n" + Invoke-Expression $restoreCommand + + + # 构建 wapproj 项目 + $buildArgs = "/p:Configuration=$Configuration /p:Platform=$Platform /p:RuntimIdentifier=$RuntimeIdentifier /p:UapAppxPackageBuildMode=StoreUpload /p:AppxBundle=Never /p:GenerateAppInstallerFile=False /p:AppxPackageSigningEnabled=False" + $buildCommand = "msbuild $SolutionPath $buildArgs" + Write-Host "`n Building WPF project... `n" -ForegroundColor Cyan + Write-Host "$ $buildCommand `n" + Invoke-Expression $buildCommand + +} + + +# 检查先决条件 +CheckPrerequisites + +# 构建项目 +BuildProject + +Write-Host "Build completed." + +Write-Host "Build result: SDUNetCheckTool.GUI\bin\$Platform\$Configuration\SDUNetCheckTool.GUI.exe" diff --git a/.github/utils/pack.js b/.github/utils/pack.js index 5512815..076aa1d 100644 --- a/.github/utils/pack.js +++ b/.github/utils/pack.js @@ -1,30 +1,63 @@ -var fs = require('fs'); -var child_process = require('child_process'); -var generateEvb = require('generate-evb'); +import { existsSync, statSync } from 'fs'; +import { execFile } from 'child_process'; +import generateEvb from 'generate-evb'; -// Change the following paths to the actual paths used in your project -var evbCliPath = 'enigmavbconsole.exe'; -var projectName = 'SDUNetCheckTool.evb'; -var inputExe = '../../SduNetCheckTool.GUI/bin/x64/Release/SduNetCheckTool.GUI.exe'; -var outputExe = '../../build/SduNetCheckTool.GUI_boxed.exe'; -var path2Pack = '../../SduNetCheckTool.GUI/bin/x64/Release'; +// Function to parse command line arguments +function parseArgs() { + const args = process.argv.slice(2); + const options = { + evbCliPath: 'enigmavbconsole.exe', + projectName: 'SDUNetCheckTool.evb', + inputExe: 'SduNetCheckTool.GUI/bin/x64/Release/SduNetCheckTool.GUI.exe', + outputExe: 'build/SduNetCheckTool.GUI_boxed.exe', + path2Pack: 'SduNetCheckTool.GUI/bin/x64/Release' + }; -generateEvb(projectName, inputExe, outputExe, path2Pack); + args.forEach((arg, index) => { + switch (arg) { + case '-evbCliPath': + options.evbCliPath = args[index + 1]; + break; + case '-projectName': + options.projectName = args[index + 1]; + break; + case '-inputExe': + options.inputExe = args[index + 1]; + break; + case '-outputExe': + options.outputExe = args[index + 1]; + break; + case '-path2Pack': + options.path2Pack = args[index + 1]; + break; + default: + break; + } + }); + + return options; +} + +// Parse command line arguments +const options = parseArgs(); + +// Generate EVB +generateEvb(options.projectName, options.inputExe, options.outputExe, options.path2Pack); -child_process.execFile(evbCliPath, [projectName], function (err, stdout, stderr) { - var success = false; +// Execute EVB CLI +execFile(options.evbCliPath, [options.projectName], function (err, stdout, stderr) { + let success = false; if (!err) { - // Sanity check (change this to what works for you): - // Check if the output file exists and if it's bigger than the input file - if (fs.existsSync(outputExe)) { - success = fs.statSync(outputExe).size > fs.statSync(inputExe).size; + // Sanity check: Check if the output file exists and if it's bigger than the input file + if (existsSync(options.outputExe)) { + success = statSync(options.outputExe).size > statSync(options.inputExe).size; } if (!success) { - err = new Error('Failed to pack EVB project!\nEVB stdout:\n' + stdout + '\nEVB stderr:\n' + stderr); + err = new Error(`Failed to pack EVB project!\nEVB stdout:\n${stdout}\nEVB stderr:\n${stderr}`); } } if (err) { - throw err; + throw err; } }); diff --git a/.github/utils/package.json b/.github/utils/package.json index c2c186c..e6623f0 100644 --- a/.github/utils/package.json +++ b/.github/utils/package.json @@ -1,4 +1,5 @@ { + "type": "module", "devDependencies": { "generate-evb": "git+ssh://git@github.com:Jenway/generate-evb" } diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4e262ce..f1be3d5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,11 +43,8 @@ jobs: - name: Setup MSBuild.exe uses: microsoft/setup-msbuild@v2 - - name: Restore the Wpf application - run: msbuild ${{ env.solutionPath }} /t:Restore /p:Configuration=Release /p:Platform=x64 /p:RuntimeIdentifier=win-x64 - - - name: Build wapproj - run: msbuild ${{ env.solutionPath }} /p:Configuration=${{env.Configuration}} /p:Platform=x64 /p:RuntimIdentifier=win /p:UapAppxPackageBuildMode=StoreUpload /p:AppxBundle=Never /p:GenerateAppInstallerFile=False /p:AppxPackageSigningEnabled=False + - name: Restore and build the Wpf application + run: ./.github/utils/build.ps1 - name: Create archive run: | @@ -56,10 +53,8 @@ jobs: - name: Pack into single file executable run: | - cd .\.github\utils\ - npm install - node pack.js - cd - + npm install .\.github\utils\ + node .\.github\utils\pack.js Move-Item build\SduNetCheckTool.GUI_boxed.exe build\${{ env.appPackagesExecutable }} - name: 'Upload Artifact'