Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from Jenway/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Jenway authored Feb 26, 2024
2 parents 46340a6 + 7abba74 commit bc2e6a3
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 39 deletions.
50 changes: 50 additions & 0 deletions .github/utils/build.ps1
Original file line number Diff line number Diff line change
@@ -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"
69 changes: 51 additions & 18 deletions .github/utils/pack.js
Original file line number Diff line number Diff line change
@@ -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;
}
});
1 change: 1 addition & 0 deletions .github/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"devDependencies": {
"generate-evb": "git+ssh://[email protected]:Jenway/generate-evb"
}
Expand Down
27 changes: 11 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,13 +41,10 @@ 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

- 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: |
Expand All @@ -56,17 +53,15 @@ 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'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifactName }}
path: |
build/${{ env.appPackagesArchive }}
build/${{ env.appPackagesExecutable }}
retention-days: 1
retention-days: 15
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,4 +44,4 @@ jobs:
tag_name: ${{ github.ref_name }}
draft: false
prerelease: false
token: ${{secrets.GITHUB_TOKEN}}
token: ${{secrets.GITHUB_TOKEN}}
11 changes: 10 additions & 1 deletion SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<ManifestKeyFile>SduNetCheckTool.GUI_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>false</SignManifests>
Expand Down Expand Up @@ -92,6 +92,8 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand All @@ -115,6 +117,9 @@
<DependentUpon>AboutView.xaml</DependentUpon>
</Compile>
<Compile Include="Utils\Commands.cs" />
<Compile Include="Views\Dialogs\InfoDialog.xaml.cs">
<DependentUpon>InfoDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Views\RootView.xaml.cs">
<DependentUpon>RootView.xaml</DependentUpon>
</Compile>
Expand All @@ -131,6 +136,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Dialogs\InfoDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\MainView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
26 changes: 26 additions & 0 deletions SduNetCheckTool.GUI/Views/Dialogs/InfoDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<ui:ContentDialog
x:Class="SduNetCheckTool.GUI.Views.Dialogs.InfoDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SduNetCheckTool.GUI.Views.Dialogs"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019"
d:DesignHeight="450"
d:DesignWidth="800"
DefaultButton="Close"
CloseButtonText="我知道了"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
FontSize="20"
Text="提示"
FontWeight="Bold"
TextAlignment="Left" />
<TextBlock Grid.Row="1" Margin="4,8" x:Name="Description" />
</Grid>
</ui:ContentDialog>
15 changes: 15 additions & 0 deletions SduNetCheckTool.GUI/Views/Dialogs/InfoDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using ModernWpf.Controls;

namespace SduNetCheckTool.GUI.Views.Dialogs
{
/// <summary>
/// InfoDialog.xaml 的交互逻辑
/// </summary>
public partial class InfoDialog : ContentDialog
{
public InfoDialog()
{
InitializeComponent();
}
}
}
15 changes: 15 additions & 0 deletions SduNetCheckTool.GUI/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -10,6 +13,18 @@ public partial class MainView : Window
public MainView()
{
InitializeComponent();

WeakReferenceMessenger.Default.Register<InfoDialogMessage>(this, async (r, m) =>
{
var dialog = new InfoDialog
{
Owner=this
};

dialog.Description.Text = m.Description;

await dialog.ShowAsync();
});
}
}
}
7 changes: 7 additions & 0 deletions SduNetCheckTool.Mvvm/Common/Messages/InfoDialogMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SduNetCheckTool.Mvvm.Common.Messages
{
public class InfoDialogMessage(string description)
{
public string Description = description;
}
}
2 changes: 1 addition & 1 deletion SduNetCheckTool.Mvvm/Utils/FileUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static string ExportReport(ObservableCollection<DetectionTask> 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);
Expand Down
10 changes: 10 additions & 0 deletions SduNetCheckTool.Mvvm/ViewModels/TestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit bc2e6a3

Please sign in to comment.