| | |
| | | using AutoUpdater.Util; |
| | | using ICSharpCode.SharpZipLib.Zip; |
| | | using log4net; |
| | | using Microsoft.Win32; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics; |
| | | using System.IO; |
| | | using System.Reflection; |
| | | using System.Runtime.InteropServices; |
| | | using System.Threading; |
| | | using System.Windows; |
| | | using VersionControl; |
| | |
| | | /// </summary> |
| | | public void StartListenerProcess() |
| | | { |
| | | string dir = Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); |
| | | string path1 = Path.Combine(dir, "Listener", "SolidWorksListener.exe"); |
| | | if (File.Exists(path1)) |
| | | try |
| | | { |
| | | ProcessStartInfo info = new ProcessStartInfo |
| | | string dir = Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); |
| | | string path1 = Path.Combine(dir, "Listener", "SolidWorksListener.exe"); |
| | | if (File.Exists(path1)) |
| | | { |
| | | FileName = path1, |
| | | WorkingDirectory = Path.GetDirectoryName(path1) |
| | | }; |
| | | ProcessStartInfo info = new ProcessStartInfo |
| | | { |
| | | FileName = path1, |
| | | WorkingDirectory = Path.GetDirectoryName(path1) |
| | | }; |
| | | |
| | | new Process |
| | | { |
| | | StartInfo = info |
| | | }.Start(); |
| | | new Process |
| | | { |
| | | StartInfo = info |
| | | }.Start(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Logger.Error("Start Listener Process Error!", ex); |
| | | } |
| | | } |
| | | |
| | |
| | | DoFinished(); |
| | | } |
| | | |
| | | private void DoFinished() |
| | | /// <summary> |
| | | /// 检查自启动注册表 |
| | | /// </summary> |
| | | private void CheckAutoRunRegKey() |
| | | { |
| | | RegistryKey root = null; |
| | | RegistryKey key = null; |
| | | try |
| | | { |
| | | root = Registry.CurrentUser; |
| | | key = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); |
| | | string name = "SolidWorksListener"; |
| | | if (key == null) |
| | | { |
| | | key = root.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); |
| | | } |
| | | // 没有路径或者路径指向exe不对,就更新自启动路径 |
| | | string listenerPath = key.GetValue(name)?.ToString(); |
| | | string rootDir = new DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.Parent.FullName; |
| | | string newPath = Path.Combine(rootDir, "Listener", "SolidWorksListener.exe"); |
| | | //listenerPath = listenerPath.Replace("\"", ""); |
| | | if (string.IsNullOrEmpty(listenerPath) || new Uri(listenerPath) != new Uri(newPath)) |
| | | { |
| | | key.SetValue(name, newPath, RegistryValueKind.String); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Logger.Error("CheckAutoRunRegKey Failed!", e); |
| | | } |
| | | finally |
| | | { |
| | | try |
| | | { |
| | | if (key != null) key.Close(); |
| | | if (root != null) root.Close(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Logger.Error("Reg Key Close Failed!", ex); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void BeforeRestart() |
| | | { |
| | | CheckAutoRunRegKey(); |
| | | // 启动监听进程 |
| | | StartListenerProcess(); |
| | | } |
| | | |
| | | private void DoFinished() |
| | | { |
| | | BeforeRestart(); |
| | | label.Content = "更新完成"; |
| | | bar.IsIndeterminate = false; |
| | | if (SwAppPath != null) |