From b030e5923ac9aa0972ac038c9cbeab650b74ba53 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com>
Date: Wed, 21 Sep 2022 09:34:22 +0800
Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=AE=AF=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
BPASmart.ConfigurationSoftware/App.xaml | 3 +-
BPASmart.ConfigurationSoftware/App.xaml.cs | 27 +++++-
.../BPASmart.ConfigurationSoftware.csproj | 11 +++
BPASmart.ConfigurationSoftware/FileHelper.cs | 88 ++++++++++++++++++
.../MainWindowViewModel.cs | 40 +++++---
BPASmart.ConfigurationSoftware/fyf.ico | Bin 0 -> 4286 bytes
BPASmartClient.S7Net/SiemensHelper.cs | 11 ++-
7 files changed, 165 insertions(+), 15 deletions(-)
create mode 100644 BPASmart.ConfigurationSoftware/FileHelper.cs
create mode 100644 BPASmart.ConfigurationSoftware/fyf.ico
diff --git a/BPASmart.ConfigurationSoftware/App.xaml b/BPASmart.ConfigurationSoftware/App.xaml
index d9999060..5537954f 100644
--- a/BPASmart.ConfigurationSoftware/App.xaml
+++ b/BPASmart.ConfigurationSoftware/App.xaml
@@ -2,7 +2,6 @@
x:Class="BPASmart.ConfigurationSoftware.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="clr-namespace:BPASmart.ConfigurationSoftware"
- StartupUri="MainWindow.xaml">
+ xmlns:local="clr-namespace:BPASmart.ConfigurationSoftware">
diff --git a/BPASmart.ConfigurationSoftware/App.xaml.cs b/BPASmart.ConfigurationSoftware/App.xaml.cs
index 36d2ed7b..cc3e269a 100644
--- a/BPASmart.ConfigurationSoftware/App.xaml.cs
+++ b/BPASmart.ConfigurationSoftware/App.xaml.cs
@@ -1,4 +1,5 @@
-using System;
+using BPA.Helper;
+using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
@@ -13,5 +14,29 @@ namespace BPASmart.ConfigurationSoftware
///
public partial class App : Application
{
+ protected override void OnStartup(StartupEventArgs e)
+ {
+ base.OnStartup(e);
+ if (e.Args != null && e.Args.Length == 1)
+ {
+ var res = e.Args[0];
+ Json.Read(res);
+
+ var rrr = Json.Data.Pages.OrderBy(p => p.Key).ToDictionary(p => p.Key, s => s.Value);
+ rrr?.ToList()?.ForEach(item =>
+ {
+ MessageBox.Show(item.Key);
+ });
+
+
+ }
+ MainWindow window = new MainWindow();
+ window.Show();
+ }
+
+ protected override void OnExit(ExitEventArgs e)
+ {
+ base.OnExit(e);
+ }
}
}
diff --git a/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj b/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj
index 444235a8..7378c67c 100644
--- a/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj
+++ b/BPASmart.ConfigurationSoftware/BPASmart.ConfigurationSoftware.csproj
@@ -6,8 +6,19 @@
enable
true
true
+ fyf.ico
+
+
+
+
+
+
+ PreserveNewest
+
+
+
diff --git a/BPASmart.ConfigurationSoftware/FileHelper.cs b/BPASmart.ConfigurationSoftware/FileHelper.cs
new file mode 100644
index 00000000..bd851deb
--- /dev/null
+++ b/BPASmart.ConfigurationSoftware/FileHelper.cs
@@ -0,0 +1,88 @@
+using BPA.Helper;
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace BPASmart.ConfigurationSoftware
+{
+ public class FileHelper
+ {
+
+ private volatile static FileHelper _Instance;
+ public static FileHelper GetInstance => _Instance ?? (_Instance = new FileHelper());
+ private FileHelper() { }
+
+ public void RegisterOpenFileType()
+ {
+ string icoFile = System.Windows.Forms.Application.StartupPath + $"\\fyf.ico";
+ string DirectoryPath = $"{Json.Data.ProjectPath}\\Images";
+ Directory.CreateDirectory(DirectoryPath);
+ File.Copy(icoFile, $"{DirectoryPath}\\fyf.ico");
+ RegisterFileType(".project", "HBL", ".project", System.Windows.Forms.Application.ExecutablePath, $"{DirectoryPath}\\fyf.ico");
+ }
+
+ private void RegisterFileType(string typeName, string fileType, string fileContent, string app, string ico)
+ {
+ string toolPath = app;//工具启动路径
+ string extension = typeName;//fileType = "自定义文件类型";
+
+ //fileContent = "AAAA";
+ //获取信息
+ RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(extension);
+ if (registryKey != null)
+ {
+ try
+ {
+ RegistryKey _Regkey = Registry.ClassesRoot.OpenSubKey("", true);
+
+ RegistryKey _VRPkey = _Regkey.OpenSubKey(extension);
+ if (_VRPkey != null) _Regkey.DeleteSubKeyTree(extension, true);
+ if (_VRPkey != null) _Regkey.DeleteSubKeyTree("Exec");
+ }
+ catch (Exception e)
+ {
+
+ }
+ }
+
+ if (registryKey != null && registryKey.OpenSubKey("shell") != null && registryKey.OpenSubKey("shell").OpenSubKey("open") != null &&
+ registryKey.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command") != null)
+ {
+ var varSub = registryKey.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command");
+ var varValue = varSub.GetValue("");
+
+ if (Equals(varValue, toolPath + " \"%1\""))
+ {
+ return;
+ }
+ }
+
+ //文件注册
+ registryKey = Registry.ClassesRoot.CreateSubKey(extension);
+ registryKey.SetValue("", fileType);
+ registryKey.SetValue("Content Type", fileContent);
+ //设置默认图标
+ RegistryKey iconKey = registryKey.CreateSubKey("DefaultIcon");
+ //iconKey.SetValue("", Application.StartupPath + $"\\{ico}.ico");
+ iconKey.SetValue("", ico);
+ iconKey.Close();
+ //设置默认打开程序路径
+ registryKey = registryKey.CreateSubKey("shell\\open\\command");
+ registryKey.SetValue("", toolPath + " \"%1\"");
+ //关闭
+ registryKey.Close();
+ SHChangeNotify(0x8000000, 0, IntPtr.Zero, IntPtr.Zero);
+ }
+
+ [DllImport("shell32.dll")]
+ public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
+ }
+
+}
+
diff --git a/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs b/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs
index 4661f7b4..d4b24a38 100644
--- a/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs
+++ b/BPASmart.ConfigurationSoftware/MainWindowViewModel.cs
@@ -21,7 +21,7 @@ namespace BPASmart.ConfigurationSoftware
{
public MainWindowViewModel()
{
-
+ Init();
ActionManage.GetInstance.Register(new Action