diff --git a/.github/workflows/create_release.js b/.github/workflows/create_release.js
new file mode 100644
index 0000000..5a7a9c6
--- /dev/null
+++ b/.github/workflows/create_release.js
@@ -0,0 +1,144 @@
+const fs = require('fs');
+const {execSync} = require('child_process');
+const github = require('@actions/github');
+const {Octokit} = require('@octokit/rest');
+
+function notice(msg) {
+ console.log(`* ${msg}`);
+}
+
+function retry(fn, retryCount = 0) {
+ return fn().catch((e) => {
+ if (retryCount >= 3) {
+ throw e;
+ }
+ console.error(e);
+ console.warn(`第 ${retryCount + 1} 次执行失败,正在重试……`);
+ return retry(fn, retryCount + 1);
+ });
+}
+
+(async () => {
+ const owner = github.context.repo.owner;
+ const repo = github.context.repo.repo;
+
+ await Promise.all(['x64', 'x86', 'arm64'].map((arch) => {
+ execSync(`dotnet publish -p:Platform=${arch} -p:PublishProfile=Properties/PublishProfiles/win-${arch}.pubxml`);
+ notice(`${arch} 架构软件包生成完成。`);
+ execSync(`7z a -tzip Publish-${arch}.zip ./bin/publish/win-${arch}/*`);
+ execSync(`7z a -t7z Publish-${arch}.7z ./bin/publish/win-${arch}/*`);
+ notice(`${arch} 架构软件包压缩完成。`);
+ }));
+
+ const files = [
+ {
+ name: 'EdgePolicyManager-v${PUBLISH_VERSION}-x64.zip',
+ path: 'Publish-x64.zip',
+ contentType: 'application/zip'
+ },
+ {
+ name: 'EdgePolicyManager-v${PUBLISH_VERSION}-x64.7z',
+ path: 'Publish-x64.7z',
+ contentType: 'application/7z'
+ },
+ {
+ name: 'EdgePolicyManager-v${PUBLISH_VERSION}-x86.zip',
+ path: 'Publish-x86.zip',
+ contentType: 'application/zip'
+ },
+ {
+ name: 'EdgePolicyManager-v${PUBLISH_VERSION}-x86.7z',
+ path: 'Publish-x86.7z',
+ contentType: 'application/7z'
+ },
+ {
+ name: 'EdgePolicyManager-v${PUBLISH_VERSION}-arm64.zip',
+ path: 'Publish-arm64.zip',
+ contentType: 'application/zip'
+ },
+ {
+ name: 'EdgePolicyManager-v${PUBLISH_VERSION}-arm64.7z',
+ path: 'Publish-arm64.7z',
+ contentType: 'application/7z'
+ }
+ ];
+
+ function handleEnv(str) {
+ return str.replace(/\$\{(.+?)}/g, (_, name) => {
+ return process.env[name];
+ });
+ }
+
+ // GitHub Release
+ let releaseInfo;
+ {
+ const githubO = new Octokit({
+ auth: process.env.GITHUB_TOKEN
+ });
+
+ const release = await githubO.repos.createRelease({
+ owner, repo,
+ tag_name: `v${process.env.PUBLISH_VERSION}`,
+ name: `Release ${process.env.PUBLISH_VERSION}`,
+ body: `## 更新日志\n\n概述:**${process.env.COMMIT_TITLE}**\n\n\n\n${process.env.COMMIT_BODY}\n\n \n\n
\n\n> 发布时间:${process.env.PUBLISH_DATETIME}\n\n> 策略版本:${process.env.EDGE_POLICY_VERSION}`,
+ draft: false,
+ prerelease: false
+ });
+
+ const releaseId = release.data.id;
+
+ for (const file of files) {
+ // 上传到upload_url
+ await githubO.repos.uploadReleaseAsset({
+ release_id: releaseId,
+ owner, repo,
+ name: handleEnv(file.name),
+ data: fs.readFileSync(file.path)
+ });
+ }
+
+ releaseInfo = await githubO.repos.getRelease({
+ release_id: releaseId,
+ owner, repo
+ });
+ }
+ notice('GitHub Release 发布完成。');
+
+ // Gitee Release
+ {
+ const giteeO = new Octokit({
+ baseUrl: 'https://gitee.com/api/v5',
+ auth: process.env.GITEE_TOKEN
+ });
+
+ function fileSizeString(size) {
+ if (size < 1024) {
+ return `${size} B`;
+ } else if (size < 1024 * 1024) {
+ return `${(size / 1024).toFixed(2)} KB`;
+ } else if (size < 1024 * 1024 * 1024) {
+ return `${(size / 1024 / 1024).toFixed(2)} MB`;
+ } else if (size < 1024 * 1024 * 1024 * 1024) {
+ return `${(size / 1024 / 1024 / 1024).toFixed(2)} GB`;
+ } else {
+ return `${(size / 1024 / 1024 / 1024 / 1024).toFixed(2)} TB`;
+ }
+ }
+
+ let assetsTable = "|附件|大小|\n|---|---|\n",
+ assetIcon = "![asset icon](data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20height%3D%2216%22%20viewBox%3D%220%200%2016%2016%22%20width%3D%2216%22%3E%3Cpath%20d%3D%22m8.878.392%205.25%203.045c.54.314.872.89.872%201.514v6.098a1.75%201.75%200%200%201-.872%201.514l-5.25%203.045a1.75%201.75%200%200%201-1.756%200l-5.25-3.045A1.75%201.75%200%200%201%201%2011.049V4.951c0-.624.332-1.201.872-1.514L7.122.392a1.75%201.75%200%200%201%201.756%200ZM7.875%201.69l-4.63%202.685L8%207.133l4.755-2.758-4.63-2.685a.248.248%200%200%200-.25%200ZM2.5%205.677v5.372c0%20.09.047.171.125.216l4.625%202.683V8.432Zm6.25%208.271%204.625-2.683a.25.25%200%200%200%20.125-.216V5.677L8.75%208.432Z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E)";
+ for (const asset of releaseInfo.data.assets) {
+ assetsTable += `|${assetIcon} [${asset.name}](${asset.browser_download_url})|${fileSizeString(asset.size)}|\n`;
+ }
+
+ await retry(() => giteeO.repos.createRelease({
+ owner, repo,
+ tag_name: `v${process.env.PUBLISH_VERSION}`,
+ target_commitish: process.env.CONFIG === 'debug' ? 'test' : 'master',
+ name: `发行版 ${process.env.PUBLISH_VERSION}`,
+ body: `## 更新日志\n\n概述:**${process.env.COMMIT_TITLE}**\n\n\n\n${process.env.COMMIT_BODY}\n\n \n\n
\n\n> 发布时间:${process.env.PUBLISH_DATETIME}\n\n> 策略版本:${process.env.EDGE_POLICY_VERSION}\n\n${assetsTable}`,
+ prerelease: false
+ }));
+ }
+ notice('Gitee Release 发布完成。');
+})();
\ No newline at end of file
diff --git a/.github/workflows/edit_version.js b/.github/workflows/edit_version.js
new file mode 100644
index 0000000..740c10c
--- /dev/null
+++ b/.github/workflows/edit_version.js
@@ -0,0 +1,40 @@
+const fs = require('fs');
+const {XMLParser, XMLBuilder} = require('fast-xml-parser');
+
+(async () => {
+ const {PUBLISH_VERSION} = process.env;
+
+ const csprojPath = './PolicyManager.csproj';
+ const csprojData = fs.readFileSync(csprojPath);
+
+ // 解析XML
+ const options = {
+ ignoreAttributes: false,
+ attributeNamePrefix: '@',
+ suppressEmptyNode: true,
+ format: process.env.CONFIG === 'debug'
+ };
+
+ const parser = new XMLParser(options);
+ const csprojObj = parser.parse(csprojData);
+
+ // 修改版本号
+ if (csprojObj.Project?.PropertyGroup) {
+ const config = csprojObj.Project.PropertyGroup.find((item) => item["Version"]);
+ if (!config) {
+ console.log(JSON.stringify(csprojObj.Project.PropertyGroup));
+ throw new Error('Cannot find version property.');
+ }
+ config["Version"] = PUBLISH_VERSION;
+ } else {
+ console.log(JSON.stringify(csprojObj));
+ throw new Error('Cannot find PropertyGroup.');
+ }
+
+ // 转换为XML字符串
+ const builder = new XMLBuilder(options);
+ const xml = builder.build(csprojObj);
+
+ // 写回.csproj文件
+ fs.writeFileSync(csprojPath, xml);
+})();
\ No newline at end of file
diff --git a/.github/workflows/publisher.yml b/.github/workflows/publisher.yml
index f63097c..e79dabd 100644
--- a/.github/workflows/publisher.yml
+++ b/.github/workflows/publisher.yml
@@ -8,10 +8,15 @@ on:
jobs:
publish:
runs-on: windows-latest
+ strategy:
+ matrix:
+ node-version: [ 20.x ]
+ env:
+ CONFIG: Release
steps:
- name: 检出代码
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: 获取发布信息
run: |
@@ -30,109 +35,40 @@ jobs:
} >> "$GITHUB_ENV"
shell: bash
- - name: 创建 Release
- id: create_release
- uses: actions/create-release@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- tag_name: v${{ env.PUBLISH_VERSION }}
- release_name: Release ${{ env.PUBLISH_VERSION }}
- body: |
- ## 更新日志
-
- 概述:**${{ env.COMMIT_TITLE }}**
-
-
-
- ${{ env.COMMIT_BODY }}
-
-
-
-
-
- > 发布时间:${{ env.PUBLISH_DATETIME }}
-
- > 策略版本:${{ env.EDGE_POLICY_VERSION }}
- draft: false
- prerelease: false
-
- - name: 安装 .NET
- uses: actions/setup-dotnet@v1
- with:
- dotnet-version: '8.0.x'
-
- - name: 生成软件包
+ - name: 修改版本号
run: |
- dotnet publish -p:Platform=x64 -p:PublishProfile=Properties/PublishProfiles/win-x64.pubxml
- dotnet publish -p:Platform=x86 -p:PublishProfile=Properties/PublishProfiles/win-x86.pubxml
- dotnet publish -p:Platform=ARM64 -p:PublishProfile=Properties/PublishProfiles/win-arm64.pubxml
+ npm i fast-xml-parser
+ node .github/workflows/edit_version.js
- - name: 压缩软件包
+ - name: 克隆完整仓库
run: |
- 7z a -tzip -mx=9 Publish-x64.zip ./bin/publish/win-x64/*
- 7z a -t7z -mx=9 Publish-x64.7z ./bin/publish/win-x64/*
- 7z a -tzip -mx=9 Publish-x86.zip ./bin/publish/win-x86/*
- 7z a -t7z -mx=9 Publish-x86.7z ./bin/publish/win-x86/*
- 7z a -tzip -mx=9 Publish-arm64.zip ./bin/publish/win-arm64/*
- 7z a -t7z -mx=9 Publish-arm64.7z ./bin/publish/win-arm64/*
+ git fetch --unshallow
- - name: 上传软件包(x64-zip)
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-x64.zip
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x64.zip
- asset_content_type: application/zip
-
- - name: 上传软件包(x64-7z)
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-x64.7z
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x64.7z
- asset_content_type: application/7z
+ - name: 优化 Gitee 连接
+ run: |
+ echo 182.255.33.134 gitee.com >> C:\Windows\System32\drivers\etc\hosts
+ ipconfig /flushdns
- - name: 上传软件包(x86-zip)
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ - name: 同步分支到 Gitee
+ uses: nick-fields/retry@v3
with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-x86.zip
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x86.zip
- asset_content_type: application/zip
-
- - name: 上传软件包(x86-7z)
- uses: actions/upload-release-asset@v1
+ timeout_minutes: 5
+ max_attempts: 3
+ command: |
+ git fetch --unshallow
+ git push -f "https://NXY666:$env:GITEE_TOKEN@gitee.com/NXY666/EdgePolicyManager.git"
env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-x86.7z
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x86.7z
- asset_content_type: application/7z
+ GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }}
- - name: 上传软件包(arm64-zip)
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ - name: 安装 .NET
+ uses: actions/setup-dotnet@v4
with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-arm64.zip
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-arm64.zip
- asset_content_type: application/zip
+ dotnet-version: '8.0.x'
- - name: 上传软件包(arm64-7z)
- uses: actions/upload-release-asset@v1
+ - name: 发布软件包
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-arm64.7z
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-arm64.7z
- asset_content_type: application/7z
\ No newline at end of file
+ GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }}
+ run: |
+ npm i @actions/github @octokit/rest
+ node .github/workflows/create_release.js
diff --git a/.github/workflows/test_publisher.yml b/.github/workflows/test_publisher.yml
index df0ed59..31e0769 100644
--- a/.github/workflows/test_publisher.yml
+++ b/.github/workflows/test_publisher.yml
@@ -8,10 +8,15 @@ on:
jobs:
publish:
runs-on: windows-latest
+ strategy:
+ matrix:
+ node-version: [ 20.x ]
+ env:
+ CONFIG: Debug
steps:
- name: 检出代码
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: 获取发布信息
run: |
@@ -30,109 +35,40 @@ jobs:
} >> "$GITHUB_ENV"
shell: bash
- - name: 创建 Release
- id: create_release
- uses: actions/create-release@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- tag_name: v${{ env.PUBLISH_VERSION }}
- release_name: Release ${{ env.PUBLISH_VERSION }}
- body: |
- ## 更新日志
-
- 概述:**${{ env.COMMIT_TITLE }}**
-
-
-
- ${{ env.COMMIT_BODY }}
-
-
-
-
-
- > 发布时间:${{ env.PUBLISH_DATETIME }}
-
- > 策略版本:${{ env.EDGE_POLICY_VERSION }}
- draft: true
- prerelease: false
-
- - name: 安装 .NET
- uses: actions/setup-dotnet@v1
- with:
- dotnet-version: '8.0.x'
-
- - name: 生成软件包
+ - name: 修改版本号
run: |
- dotnet publish -p:Platform=x64 -p:PublishProfile=Properties/PublishProfiles/win-x64.pubxml
- dotnet publish -p:Platform=x86 -p:PublishProfile=Properties/PublishProfiles/win-x86.pubxml
- dotnet publish -p:Platform=ARM64 -p:PublishProfile=Properties/PublishProfiles/win-arm64.pubxml
+ npm i fast-xml-parser
+ node .github/workflows/edit_version.js
- - name: 压缩软件包
+ - name: 克隆完整仓库
run: |
- 7z a -tzip -mx=9 Publish-x64.zip ./bin/publish/win-x64/*
- 7z a -t7z -mx=9 Publish-x64.7z ./bin/publish/win-x64/*
- 7z a -tzip -mx=9 Publish-x86.zip ./bin/publish/win-x86/*
- 7z a -t7z -mx=9 Publish-x86.7z ./bin/publish/win-x86/*
- 7z a -tzip -mx=9 Publish-arm64.zip ./bin/publish/win-arm64/*
- 7z a -t7z -mx=9 Publish-arm64.7z ./bin/publish/win-arm64/*
+ git fetch --unshallow
- - name: 上传软件包(x64-zip)
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-x64.zip
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x64.zip
- asset_content_type: application/zip
-
- - name: 上传软件包(x64-7z)
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-x64.7z
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x64.7z
- asset_content_type: application/7z
-
- - name: 上传软件包(x86-zip)
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ - name: 优化 Gitee 连接
+ run: |
+ echo 182.255.33.134 gitee.com >> C:\Windows\System32\drivers\etc\hosts
+ ipconfig /flushdns
+
+ - name: 同步分支到 Gitee
+ uses: nick-fields/retry@v3
with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-x86.zip
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x86.zip
- asset_content_type: application/zip
-
- - name: 上传软件包(x86-7z)
- uses: actions/upload-release-asset@v1
+ timeout_minutes: 5
+ max_attempts: 3
+ command: |
+ git fetch --unshallow
+ git push -f "https://NXY666:$env:GITEE_TOKEN@gitee.com/NXY666/EdgePolicyManager.git"
env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-x86.7z
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-x86.7z
- asset_content_type: application/7z
+ GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }}
- - name: 上传软件包(arm64-zip)
- uses: actions/upload-release-asset@v1
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ - name: 安装 .NET
+ uses: actions/setup-dotnet@v4
with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-arm64.zip
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-arm64.zip
- asset_content_type: application/zip
-
- - name: 上传软件包(arm64-7z)
- uses: actions/upload-release-asset@v1
+ dotnet-version: '8.0.x'
+
+ - name: 发布软件包
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ steps.create_release.outputs.upload_url }}
- asset_path: ./Publish-arm64.7z
- asset_name: EdgePolicyManager-Release-${{ env.PUBLISH_VERSION }}-arm64.7z
- asset_content_type: application/7z
\ No newline at end of file
+ GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }}
+ run: |
+ npm i @actions/github @octokit/rest
+ node .github/workflows/create_release.js
diff --git a/App.xaml b/App.xaml
index 9091f22..2f2b78e 100644
--- a/App.xaml
+++ b/App.xaml
@@ -5,8 +5,8 @@
x:Class="PolicyManager.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:converters="using:PolicyManager.Utils.Converters"
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
+ xmlns:uiConverters="using:CommunityToolkit.WinUI.UI.Converters"
RequestedTheme="Light">
@@ -101,8 +101,9 @@
-
-
+
+
+
\ No newline at end of file
diff --git a/MainPage.xaml b/MainPage.xaml
index 924ac61..1d793b2 100644
--- a/MainPage.xaml
+++ b/MainPage.xaml
@@ -8,7 +8,6 @@
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
DataContext="{x:Bind _dataContext}">
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 79fd36d..e242d67 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -1,8 +1,10 @@
-
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:winUiEx="using:WinUIEx"
+ MinWidth="545" MinHeight="510">
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/Pages/Policy/Contents/BooleanContent.xaml b/Pages/Policy/Contents/BooleanContent.xaml
index eb22957..1cc9172 100644
--- a/Pages/Policy/Contents/BooleanContent.xaml
+++ b/Pages/Policy/Contents/BooleanContent.xaml
@@ -9,9 +9,9 @@
+ Visibility="{Binding Path=PolicyManager.PolicyValueExists, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=True}" />
\ No newline at end of file
diff --git a/Pages/Policy/Contents/DropdownContent.xaml b/Pages/Policy/Contents/DropdownContent.xaml
index 48fca34..64373f5 100644
--- a/Pages/Policy/Contents/DropdownContent.xaml
+++ b/Pages/Policy/Contents/DropdownContent.xaml
@@ -8,9 +8,9 @@
DataContext="{x:Bind This}">
+ SelectionChanged="ComboBox_OnSelectionChanged" MaxWidth="300"
+ Visibility="{Binding Path=PolicyManager.PolicyValueExists, Converter={StaticResource BoolToVisibilityConverter}}" />
+ Visibility="{Binding Path=PolicyManager.PolicyValueExists, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=True}" />
\ No newline at end of file
diff --git a/Pages/Policy/Contents/IntegerContent.xaml b/Pages/Policy/Contents/IntegerContent.xaml
index 77c7a94..cc0f83d 100644
--- a/Pages/Policy/Contents/IntegerContent.xaml
+++ b/Pages/Policy/Contents/IntegerContent.xaml
@@ -8,10 +8,16 @@
DataContext="{x:Bind This}">
+ Maximum="2147483647" Minimum="-2147483648" Width="120" MaxWidth="300"
+ GotFocus="NumberBox_OnGotFocus" LostFocus="NumberBox_OnLostFocus" />
+
+
+
+
+
+ Visibility="{Binding Path=PolicyManager.PolicyValueExists, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=True}" />
\ No newline at end of file
diff --git a/Pages/Policy/Contents/IntegerContent.xaml.cs b/Pages/Policy/Contents/IntegerContent.xaml.cs
index c1063e0..2957bcf 100644
--- a/Pages/Policy/Contents/IntegerContent.xaml.cs
+++ b/Pages/Policy/Contents/IntegerContent.xaml.cs
@@ -1,3 +1,4 @@
+using Microsoft.UI.Xaml;
using PolicyManager.Utils;
namespace PolicyManager.Pages.Policy.Contents;
@@ -8,4 +9,14 @@ public IntegerContent(NotifyPolicyManager policyManager) : base(policyManager)
{
InitializeComponent();
}
+
+ private void NumberBox_OnGotFocus(object sender, RoutedEventArgs e)
+ {
+ AcceptButton.Visibility = Visibility.Visible;
+ }
+
+ private void NumberBox_OnLostFocus(object sender, RoutedEventArgs e)
+ {
+ AcceptButton.Visibility = Visibility.Collapsed;
+ }
}
\ No newline at end of file
diff --git a/Pages/Policy/Contents/StringContent.xaml b/Pages/Policy/Contents/StringContent.xaml
index ea50af8..b8ac362 100644
--- a/Pages/Policy/Contents/StringContent.xaml
+++ b/Pages/Policy/Contents/StringContent.xaml
@@ -8,9 +8,15 @@
DataContext="{x:Bind This}">
+ Visibility="{Binding Path=PolicyManager.PolicyValueExists, Converter={StaticResource BoolToVisibilityConverter}}"
+ Text="{Binding Path=PolicyManager.PolicyValue, Mode=TwoWay}" MaxLength="100000" MaxWidth="300"
+ GotFocus="TextBox_OnGotFocus" LostFocus="TextBox_OnLostFocus" />
+
+
+
+
+
+ Visibility="{Binding Path=PolicyManager.PolicyValueExists, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=True}" />
\ No newline at end of file
diff --git a/Pages/Policy/Contents/StringContent.xaml.cs b/Pages/Policy/Contents/StringContent.xaml.cs
index 241be88..f95de7d 100644
--- a/Pages/Policy/Contents/StringContent.xaml.cs
+++ b/Pages/Policy/Contents/StringContent.xaml.cs
@@ -1,3 +1,4 @@
+using Microsoft.UI.Xaml;
using PolicyManager.Utils;
namespace PolicyManager.Pages.Policy.Contents;
@@ -8,4 +9,14 @@ public StringContent(NotifyPolicyManager policyManager) : base(policyManager)
{
InitializeComponent();
}
+
+ private void TextBox_OnGotFocus(object sender, RoutedEventArgs e)
+ {
+ AcceptButton.Visibility = Visibility.Visible;
+ }
+
+ private void TextBox_OnLostFocus(object sender, RoutedEventArgs e)
+ {
+ AcceptButton.Visibility = Visibility.Collapsed;
+ }
}
\ No newline at end of file
diff --git a/Pages/Policy/DetailPage.xaml b/Pages/Policy/DetailPage.xaml
index aad1ff9..b4054d5 100644
--- a/Pages/Policy/DetailPage.xaml
+++ b/Pages/Policy/DetailPage.xaml
@@ -5,7 +5,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
- xmlns:controls1="using:CommunityToolkit.WinUI.UI.Controls"
+ xmlns:uiControls="using:CommunityToolkit.WinUI.UI.Controls"
DataContext="{x:Bind _dataContext}">
@@ -27,12 +27,30 @@
-
+ Style="{ThemeResource BodyStrongTextBlockStyle}"
+ TextTrimming="CharacterEllipsis">
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
-
+
@@ -72,8 +90,8 @@
-
+ Visibility="{Binding Path=IsExpanderListItemsEmpty, Converter={StaticResource BoolToVisibilityConverter}}">
+
\ No newline at end of file
diff --git a/Pages/Policy/DetailPage.xaml.cs b/Pages/Policy/DetailPage.xaml.cs
index b7691e7..27592fa 100644
--- a/Pages/Policy/DetailPage.xaml.cs
+++ b/Pages/Policy/DetailPage.xaml.cs
@@ -5,6 +5,7 @@
using Windows.ApplicationModel.DataTransfer;
using Windows.System;
using CommunityToolkit.WinUI.UI.Controls;
+using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using PolicyManager.Models.Policy;
@@ -182,7 +183,29 @@ private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArg
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
-
+
_dataContext.Dispose();
}
+
+ private void CopyItemTitle_Click(object sender, RoutedEventArgs e)
+ {
+ var menuFlyoutItem = sender as MenuFlyoutItem;
+
+ var itemData = menuFlyoutItem?.DataContext as ExpanderListItem;
+
+ var dataPackage = new DataPackage();
+ dataPackage.SetText(itemData?.PolicyDetail.Name);
+ Clipboard.SetContent(dataPackage);
+ }
+
+ private void CopyItemShortDescription_Click(object sender, RoutedEventArgs e)
+ {
+ var menuFlyoutItem = sender as MenuFlyoutItem;
+
+ var itemData = menuFlyoutItem?.DataContext as ExpanderListItem;
+
+ var dataPackage = new DataPackage();
+ dataPackage.SetText(itemData?.PolicyDetail.ShortDescription);
+ Clipboard.SetContent(dataPackage);
+ }
}
\ No newline at end of file
diff --git a/Pages/Policy/SettingsPage.xaml b/Pages/Policy/SettingsPage.xaml
index 16e5a87..d27ccc1 100644
--- a/Pages/Policy/SettingsPage.xaml
+++ b/Pages/Policy/SettingsPage.xaml
@@ -5,6 +5,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
+ xmlns:winUi="using:CommunityToolkit.WinUI"
DataContext="{x:Bind _dataContext}">
@@ -28,6 +29,15 @@
+
+
+
+
\ No newline at end of file
diff --git a/Pages/Policy/SettingsPage.xaml.cs b/Pages/Policy/SettingsPage.xaml.cs
index e1c7f2b..df8e2fd 100644
--- a/Pages/Policy/SettingsPage.xaml.cs
+++ b/Pages/Policy/SettingsPage.xaml.cs
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
+using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using Windows.Win32.UI.Shell;
@@ -105,4 +106,67 @@ private async void ExportButton_OnClick(object sender, RoutedEventArgs e)
FileUtil.OpenFolder(saveFile);
}
+
+ private static bool CloseProcess(string processName, bool entireProcessTree = true)
+ {
+ var hasClosed = false;
+ foreach (var process in Process.GetProcessesByName(processName))
+ {
+ process.CloseMainWindow();
+ if (!process.HasExited)
+ {
+ process.Kill(entireProcessTree);
+ }
+
+ hasClosed = true;
+ }
+
+ return hasClosed;
+ }
+
+ private static void StartProcess(string fileName, string arguments = "")
+ {
+ var pWeb = new Process();
+ pWeb.StartInfo.UseShellExecute = true;
+ pWeb.StartInfo.FileName = fileName;
+ pWeb.StartInfo.Arguments = arguments;
+ pWeb.Start();
+ }
+
+ private async void RestartButton_OnClick(object sender, RoutedEventArgs e)
+ {
+ RestartButton.IsEnabled = false;
+
+ // 关闭edge
+ if (!CloseProcess("msedge"))
+ {
+ // 确认是否重启
+ var result = await new ContentDialog
+ {
+ // XamlRoot must be set in the case of a ContentDialog running in a Desktop app
+ XamlRoot = XamlRoot,
+ Title = ResourceUtil.GetString("SettingsPage/RestartButton_OnClick/ConfirmDialog/Title"),
+ Content = ResourceUtil.GetString("SettingsPage/RestartButton_OnClick/ConfirmDialog/Content"),
+ PrimaryButtonText = ResourceUtil.GetString("SettingsPage/RestartButton_OnClick/ConfirmDialog/PrimaryButtonText"),
+ CloseButtonText = ResourceUtil.GetString("SettingsPage/RestartButton_OnClick/ConfirmDialog/CloseButtonText"),
+ DefaultButton = ContentDialogButton.Primary
+ }.ShowAsync();
+
+ if (result == ContentDialogResult.None)
+ {
+ RestartButton.IsEnabled = true;
+ return;
+ }
+ }
+
+ // 启动edge
+ StartProcess("msedge");
+
+ RestartButton.IsEnabled = true;
+ }
+
+ private void OpenPolicyButton_OnClick(object sender, RoutedEventArgs e)
+ {
+ StartProcess("msedge", "edge://policy/");
+ }
}
\ No newline at end of file
diff --git a/Pages/WelcomePage.xaml b/Pages/WelcomePage.xaml
index 75f69aa..cf87d63 100644
--- a/Pages/WelcomePage.xaml
+++ b/Pages/WelcomePage.xaml
@@ -4,54 +4,49 @@
x:Class="PolicyManager.Pages.WelcomePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
-
+
-
-
-
-
+
-
-
-
-
+
+
-
-
-
+
+
+
-
-
+
+
+
+
+
-
-
+
+
+
-
+
@@ -77,14 +77,12 @@
-
-
-
-
-
-
-
-
+
+
+
\ No newline at end of file
diff --git a/Pages/WelcomePage.xaml.cs b/Pages/WelcomePage.xaml.cs
index ec87ae5..bb430af 100644
--- a/Pages/WelcomePage.xaml.cs
+++ b/Pages/WelcomePage.xaml.cs
@@ -1,8 +1,18 @@
using System;
using System.Collections.Generic;
+using System.Net.Http;
+using System.Reflection;
+using System.Text.Json;
+using System.Threading.Tasks;
using Windows.System;
+using Windows.UI;
+using Microsoft.UI;
+using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
+using Microsoft.UI.Xaml.Controls;
+using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
+using Microsoft.Win32;
using PolicyManager.Utils;
namespace PolicyManager.Pages;
@@ -58,9 +68,222 @@ private async void GithubButton_OnClick(object sender, RoutedEventArgs e)
await Launcher.LaunchUriAsync(new Uri("https://github.com/NXY666/EdgePolicyManager"));
}
+ private async void DownloadButton_OnClick(object sender, RoutedEventArgs e)
+ {
+ // 打开 Github Release
+ await Launcher.LaunchUriAsync(new Uri("https://github.com/NXY666/EdgePolicyManager/releases/latest"));
+ }
+
private async void FeedbackButton_OnClick(object sender, RoutedEventArgs e)
{
// 打开 Github Issues
await Launcher.LaunchUriAsync(new Uri("https://github.com/NXY666/EdgePolicyManager/issues/new/choose"));
}
+
+ private static int CompareVersion(string v1, string v2)
+ {
+ var v1S = v1.Split('.');
+ var v2S = v2.Split('.');
+ var len = Math.Max(v1S.Length, v2S.Length);
+ for (var i = 0; i < len; i++)
+ {
+ var v1I = i < v1S.Length ? int.Parse(v1S[i]) : 0;
+ var v2I = i < v2S.Length ? int.Parse(v2S[i]) : 0;
+ if (v1I > v2I)
+ {
+ return 1;
+ }
+
+ if (v1I < v2I)
+ {
+ return -1;
+ }
+ }
+
+ return 0;
+ }
+
+ private async void VersionButton_OnClick(object sender, RoutedEventArgs e)
+ {
+ var senderButton = (Button)sender;
+ senderButton.IsEnabled = false;
+
+ var grid = new Grid
+ {
+ HorizontalAlignment = HorizontalAlignment.Stretch,
+ VerticalAlignment = VerticalAlignment.Stretch
+ };
+
+ grid.RowDefinitions.Add(new RowDefinition());
+ grid.RowDefinitions.Add(new RowDefinition());
+ grid.RowDefinitions.Add(new RowDefinition());
+ grid.RowDefinitions.Add(new RowDefinition());
+ grid.RowDefinitions.Add(new RowDefinition());
+ grid.RowDefinitions.Add(new RowDefinition());
+ grid.RowDefinitions.Add(new RowDefinition());
+
+ grid.RowSpacing = 8;
+
+ grid.ColumnDefinitions.Add(new ColumnDefinition());
+ grid.ColumnDefinitions.Add(new ColumnDefinition());
+
+ var titleColor = new SolidColorBrush(Colors.Black);
+ var valueColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x64, 0x64, 0x64));
+
+ var title1 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/PolicyManagerTitle"), FontWeight = FontWeights.Bold };
+ title1.SetValue(Grid.RowProperty, 0);
+ title1.SetValue(Grid.ColumnProperty, 0);
+ title1.SetValue(Grid.ColumnSpanProperty, 2);
+ grid.Children.Add(title1);
+
+ var key1 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/CurrentVersionKey"), Foreground = titleColor };
+ key1.SetValue(Grid.RowProperty, 1);
+ key1.SetValue(Grid.ColumnProperty, 0);
+ grid.Children.Add(key1);
+
+ var key2 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/LatestVersionKey"), Foreground = titleColor };
+ key2.SetValue(Grid.RowProperty, 2);
+ key2.SetValue(Grid.ColumnProperty, 0);
+ grid.Children.Add(key2);
+
+ var title2 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/PolicyCompatibilityTitle"), FontWeight = FontWeights.Bold };
+ title2.SetValue(Grid.RowProperty, 3);
+ title2.SetValue(Grid.ColumnProperty, 0);
+ title2.SetValue(Grid.ColumnSpanProperty, 2);
+ grid.Children.Add(title2);
+
+ var key3 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/EdgeVersionKey"), Foreground = titleColor };
+ key3.SetValue(Grid.RowProperty, 4);
+ key3.SetValue(Grid.ColumnProperty, 0);
+ grid.Children.Add(key3);
+
+ var key4 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/CurrentCompatibleVersionKey"), Foreground = titleColor };
+ key4.SetValue(Grid.RowProperty, 5);
+ key4.SetValue(Grid.ColumnProperty, 0);
+ grid.Children.Add(key4);
+
+ var key5 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/LatestCompatibleVersionKey"), Foreground = titleColor };
+ key5.SetValue(Grid.RowProperty, 6);
+ key5.SetValue(Grid.ColumnProperty, 0);
+ grid.Children.Add(key5);
+
+ var value1 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/GettingValueText"), Foreground = valueColor };
+ value1.SetValue(Grid.RowProperty, 1);
+ value1.SetValue(Grid.ColumnProperty, 1);
+ grid.Children.Add(value1);
+
+ var value2 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/GettingValueText"), Foreground = valueColor };
+ value2.SetValue(Grid.RowProperty, 2);
+ value2.SetValue(Grid.ColumnProperty, 1);
+ grid.Children.Add(value2);
+
+ var value3 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/GettingValueText"), Foreground = valueColor };
+ value3.SetValue(Grid.RowProperty, 4);
+ value3.SetValue(Grid.ColumnProperty, 1);
+ grid.Children.Add(value3);
+
+ var value4 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/GettingValueText"), Foreground = valueColor };
+ value4.SetValue(Grid.RowProperty, 5);
+ value4.SetValue(Grid.ColumnProperty, 1);
+ grid.Children.Add(value4);
+
+ var value5 = new TextBlock { Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/GettingValueText"), Foreground = valueColor };
+ value5.SetValue(Grid.RowProperty, 6);
+ value5.SetValue(Grid.ColumnProperty, 1);
+ grid.Children.Add(value5);
+
+ var dialog = new ContentDialog
+ {
+ // XamlRoot must be set in the case of a ContentDialog running in a Desktop app
+ XamlRoot = XamlRoot,
+ Title = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/Title"),
+ CloseButtonText = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/CloseButtonText"),
+ Content = grid
+ };
+
+ var dialogTask = dialog.ShowAsync();
+
+ // 当前工具版本
+ try
+ {
+ value1.Text = Assembly.GetExecutingAssembly().GetName().Version?.ToString();
+ }
+ catch (Exception)
+ {
+ value1.Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/UnknownText");
+ }
+
+ // 最新工具版本
+ var task2 = Task.Run(() =>
+ {
+ using var client = new HttpClient();
+ try
+ {
+ client.DefaultRequestHeaders.UserAgent.ParseAdd("Hello/1.0");
+
+ var response = client.GetAsync("https://api.github.com/repos/NXY666/EdgePolicyManager/releases/latest").Result;
+ if (!response.IsSuccessStatusCode)
+ {
+ throw new Exception();
+ }
+
+ // 解析 JSON
+ var jsonContent = response.Content.ReadAsStringAsync().Result;
+ var jsonElement = JsonDocument.Parse(jsonContent).RootElement;
+ return jsonElement.GetProperty("tag_name").GetString()?[1..];
+ }
+ catch (Exception)
+ {
+ return ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/UnknownText");
+ }
+ });
+
+ // 获取 Edge 版本
+ try
+ {
+ value3.Text = (string)RegistryUtil.GetRegistryValue(Registry.CurrentUser, @"Software\Microsoft\Edge\BLBeacon", "version").Value;
+ }
+ catch (Exception)
+ {
+ value3.Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/UnknownText");
+ }
+
+ // 获取当前兼容版本
+ try
+ {
+ value4.Text = ResourceUtil.GetEmbeddedPlainText("StaticModels.Policy.SUPPORT_VERSION");
+ }
+ catch (Exception)
+ {
+ value4.Text = ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/UnknownText");
+ }
+
+ // 获取最新版本
+ var task5 = Task.Run(() =>
+ {
+ using var client = new HttpClient();
+ try
+ {
+ client.DefaultRequestHeaders.UserAgent.ParseAdd("Hello/1.0");
+
+ var response = client.GetAsync("https://raw.githubusercontents.com/NXY666/EdgePolicyManager/master/StaticModels/Policy/SUPPORT_VERSION").Result;
+ if (!response.IsSuccessStatusCode)
+ {
+ throw new Exception();
+ }
+
+ return response.Content.ReadAsStringAsync().Result;
+ }
+ catch (Exception)
+ {
+ return ResourceUtil.GetString($"WelcomePage/VersionButton_OnClick/VersionInfoDialog/UnknownText");
+ }
+ });
+
+ senderButton.IsEnabled = true;
+
+ value2.Text = await task2;
+ value5.Text = await task5;
+ await dialogTask;
+ }
}
\ No newline at end of file
diff --git a/PolicyManager.csproj b/PolicyManager.csproj
index 6a316a0..b429bee 100644
--- a/PolicyManager.csproj
+++ b/PolicyManager.csproj
@@ -1,5 +1,9 @@
+ EdgePolicyManager
+ NXY666
+ README.md
+ https://github.com/NXY666/EdgePolicyManager.git
WinExe
net8.0-windows10.0.22621.0
10.0.22621.0
@@ -18,12 +22,33 @@
true
partial
Assets\icon.ico
- EdgePolicyManager
true
+ 0.0.0.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -51,19 +76,20 @@
- all
+ all
-
-
+
+
+
- PreserveNewest
+ PreserveNewest
- PreserveNewest
+ PreserveNewest
PreserveNewest
@@ -75,6 +101,12 @@
PreserveNewest
+
+
+ True
+ \
+
+