diff --git a/UserManagerTool/Images/install.png b/UserManagerTool/Images/install.png
new file mode 100644
index 0000000..a6a94fa
Binary files /dev/null and b/UserManagerTool/Images/install.png differ
diff --git a/UserManagerTool/InstallWindow.xaml b/UserManagerTool/InstallWindow.xaml
index 18fd731..f825512 100644
--- a/UserManagerTool/InstallWindow.xaml
+++ b/UserManagerTool/InstallWindow.xaml
@@ -6,8 +6,76 @@
xmlns:local="clr-namespace:UserManagerTool"
mc:Ignorable="d" WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
- Icon="./instal.ico"
- Title="Spark 1.0 Install Tools" Height="550" Width="500">
+ Icon="./instal.ico" Loaded="InstallWindow_OnLoaded"
+ Title="Spark 1.0 Install Tools" Height="450" Width="500">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -17,14 +85,29 @@
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -32,9 +115,15 @@
-
-
-
+
+
+
+
+
+
+
@@ -43,8 +132,12 @@
-
-
+
+
+
+
@@ -53,8 +146,13 @@
-
-
+
+
+
+
+
@@ -63,28 +161,52 @@
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
diff --git a/UserManagerTool/InstallWindow.xaml.cs b/UserManagerTool/InstallWindow.xaml.cs
index 66da9c1..40155b1 100644
--- a/UserManagerTool/InstallWindow.xaml.cs
+++ b/UserManagerTool/InstallWindow.xaml.cs
@@ -1,5 +1,9 @@
-using System.Windows;
+using System.Security.Principal;
+using System.Text.RegularExpressions;
+using System.Windows;
using System.Windows.Controls;
+using Microsoft.Win32;
+using UserManagerTool.Model.Helper;
namespace UserManagerTool;
@@ -21,6 +25,13 @@ public partial class InstallWindow : Window
* 6.写入注册表安装位置,首次安装时间(留后续升级用)
* 7.复制完成 ->安装完成
*/
+ if (InstallSprakCheck())
+ {
+ //检查资源完整性
+ string strBaseUrl = AppDomain.CurrentDomain.BaseDirectory;
+
+ MessageBox.Show("部署完成");
+ }
}
private bool InstallSprakCheck()
@@ -34,12 +45,90 @@ public partial class InstallWindow : Window
* | config -- 存放配置文件 db文件,文件校验文件
* Install.exe
*/
+ string strInstallPath = InstallPath.Text;
+ if (string.IsNullOrWhiteSpace(strInstallPath))
+ {
+ MessageBox.Show("请选择部署路径!");
+ return false;
+ }
+ else
+ {
+ if (!Common.IsValidPath(strInstallPath))
+ {
+ MessageBox.Show("无效的部署路径!");
+ return false;
+ }
+
+ string pattern = @"[\u4e00-\u9fff\s!@#$%^&*(),.?\{}|<>]";
+ if (Regex.IsMatch(strInstallPath, pattern))
+ {
+ MessageBoxResult result = MessageBox.Show("所选路径不建议包括中文、空格等特殊符号,可能引发异常,是否忽略?", "提醒", MessageBoxButton.YesNo, MessageBoxImage.Question);
+ if (!(result == MessageBoxResult.Yes || result == MessageBoxResult.OK))
+ {
+ return false;
+ }
+ }
+ }
+
+ string strUserName = DefaultUserName.Text;
+ string strPassword = DefaultPassword.Text;
+
+ if (string.IsNullOrWhiteSpace(strUserName) || string.IsNullOrWhiteSpace(strPassword))
+ {
+ MessageBox.Show("请为系统添加一个用户和密码!");
+ return false;
+ }
+
+ if (strPassword.Length < 6)
+ {
+ MessageBox.Show("密码长度至少6位!");
+ return false;
+ }
+
+ string strDeviceCode = DeviceCode.Text;
+ if (strDeviceCode.Length < 4)
+ {
+ MessageBox.Show("设备号长度至少4位!");
+ return false;
+ }
+
+ string strCutUrl = CutUrl.Text;
+ if (string.IsNullOrWhiteSpace(strCutUrl))
+ {
+ MessageBox.Show("请设置切工仪URL!");
+ return false;
+ }
+
return true;
}
+ void TestCutUrlPing()
+ {
+ if (Common.IsHostReachable(CutUrl.Text))
+ {
+ MessageBox.Show("Ping测试成功!", "成功");
+ }
+ else
+ {
+ MessageBox.Show("Ping测试失败!", "失败");
+ }
+ }
+
private void SetInstallPath()
{
-
+ var dialog = new OpenFolderDialog
+ {
+ Title = "请选择部署位置"
+ };
+
+ // 显示对话框并检查结果
+ bool? result = dialog.ShowDialog();
+
+ if (result == true)
+ {
+ // 返回用户选择的目录路径
+ InstallPath.Text = dialog.FolderName.EndsWith(@"\")?dialog.FolderName+"SparkClient":dialog.FolderName+@"\SparkClient";
+ }
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
@@ -51,13 +140,27 @@ public partial class InstallWindow : Window
case "Install":
InstallSprak();
break;
- case "InstallCheck":
- InstallSprakCheck();
+ case "TestCutUrl":
+ TestCutUrlPing();
break;
- case "InstallPath":
+ case "BrowseInstallPath":
SetInstallPath();
break;
}
}
}
+
+ private void InstallWindow_OnLoaded(object sender, RoutedEventArgs e)
+ {
+ WindowsIdentity identity = WindowsIdentity.GetCurrent();
+ WindowsPrincipal principal = new WindowsPrincipal(identity);
+
+ bool isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
+
+ if (!isAdmin)
+ {
+ MessageBox.Show("建议以管理员权限运行此程序!", "权限不足", MessageBoxButton.OK, MessageBoxImage.Warning);
+ }
+
+ }
}
\ No newline at end of file
diff --git a/UserManagerTool/Model/Helper/Common.cs b/UserManagerTool/Model/Helper/Common.cs
index c9abd6a..3addf23 100644
--- a/UserManagerTool/Model/Helper/Common.cs
+++ b/UserManagerTool/Model/Helper/Common.cs
@@ -1,7 +1,10 @@
using System.Data;
+using System.IO;
+using System.Net.NetworkInformation;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
+using System.Text.RegularExpressions;
using Newtonsoft.Json;
namespace UserManagerTool.Model.Helper;
@@ -100,4 +103,60 @@ public class Common
return string.Concat(hashBytes.Select(b => b.ToString("X2")));
}
}
+
+ public static bool IsValidPath(string path)
+ {
+ // 使用正则表达式检查路径格式
+ string pattern = @"^[a-zA-Z]:\\[^\\/:*?""<>|]+(?:\\(?:[^\\/:*?""<>|]+\\)*[^\\/:*?""<>|]+)?$";
+ if (!Regex.IsMatch(path, pattern))
+ {
+ return false;
+ }
+
+ // 使用 Path.GetFullPath 进一步验证路径
+ try
+ {
+ string fullPath = Path.GetFullPath(path);
+ return true;
+ }
+ catch
+ {
+ return false;
+ }
+ }
+ public static bool IsHostReachable(string url)
+ {
+ string host = ExtractHostFromUrl(url);
+
+ if (string.IsNullOrEmpty(host))
+ {
+ return false;
+ }
+
+ try
+ {
+ Ping ping = new Ping();
+ PingReply reply = ping.Send(host, 1000); // 超时时间为 1000 毫秒
+
+ return reply.Status == IPStatus.Success;
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
+ }
+
+ public static string ExtractHostFromUrl(string url)
+ {
+ // 使用正则表达式提取主机部分
+ string pattern = @"^(https?:\/\/)?([^\/\?:]+)";
+ Match match = Regex.Match(url, pattern);
+
+ if (match.Success)
+ {
+ return match.Groups[2].Value;
+ }
+
+ return null;
+ }
}
\ No newline at end of file
diff --git a/UserManagerTool/UserManagerTool.csproj b/UserManagerTool/UserManagerTool.csproj
index a0f4f86..8cd82cf 100644
--- a/UserManagerTool/UserManagerTool.csproj
+++ b/UserManagerTool/UserManagerTool.csproj
@@ -19,6 +19,8 @@
+
+