| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Configuration; |
| 4 | using System.Data; |
| 5 | using System.Linq; |
| 6 | using System.Threading.Tasks; |
| 7 | using System.Windows; |
| 8 | |
| 9 | namespace Updater |
| 10 | { |
| 11 | ///<summary> |
| 12 | /// |
| 13 | ///</summary> |
| 14 | public partial class App : Application |
| 15 | { |
| 16 | private System.Threading.Mutex mutex; |
| 17 | |
| 18 | protected override void OnStartup(StartupEventArgs e) |
| 19 | { |
| 20 | base.OnStartup(e); |
| 21 | |
| 22 | if (e.Args.Length == 0 || IsRuned()) |
| 23 | { |
| 24 | Shutdown(); |
| 25 | } |
| 26 | |
| 27 | Activated += (s, e2) => |
| 28 | { |
| 29 | var mainWindow = App.Current.MainWindow; |
| 30 | if (mainWindow.DataContext != null) |
| 31 | { |
| 32 | var mainModel = mainWindow.DataContext as MainModel; |
| 33 | if (string.IsNullOrEmpty(mainModel.Version)) |
| 34 | { |
| 35 | mainModel.Version = e.Args[0]; |
| 36 | } |
| 37 | } |
| 38 | }; |
| 39 | } |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | #region 获取当前程序是否已运行 |
| 46 | ///<summary> |
| 47 | /// |
| 48 | ///</summary> |
| 49 | private bool IsRuned() |
| 50 | { |
| 51 | bool ret; |
| 52 | mutex = new System.Threading.Mutex(true, System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name, out ret); |
| 53 | if (!ret) |
| 54 | { |
| 55 | return true; |
| 56 | } |
| 57 | return false; |
| 58 | } |
| 59 | #endregion |
| 60 | } |
| 61 | } |