예제 #1
0
        public override string GetPasswordHash()
        {
            IvyLockSettings ivs = iss.OfType <IvyLockSettings>().FirstOrDefault();
            ProcessSettings ps  = iss.FindByPath(ProcessPath);

            return(ps?.Hash ?? ivs.Hash);
        }
예제 #2
0
        private void Deserialize(bool notify)
        {
            if (stream == null)
            {
                return;
            }

            try
            {
                if (stream.Length == 0)
                {
                    IvyLockSettings ils = new IvyLockSettings();

                    values = new List <SettingGroup>(new SettingGroup[] { ils });
                }
                else
                {
                    stream.Position = 0;

                    values = new List <SettingGroup>(xs.Deserialize(stream) as SettingGroup[]);
                }

                if (!values.Any(sg => sg is IvyLockSettings))
                {
                    values.Add(new IvyLockSettings());
                }

                values = values.Where(sg =>
                {
                    if (sg is IvyLockSettings)
                    {
                        return(true);
                    }

                    var psg = sg as ProcessSettings;

                    if (!File.Exists(psg.Path))
                    {
                        return(false);
                    }

                    return(true);
                }).Distinct(new SGCompare()).ToList();

                foreach (SettingGroup sg in values)
                {
                    sg.Initialize();
                    sg.PropertyChanged += SettingGroupChanged;
                }
            }
            catch
            {
                IvyLockSettings ils = new IvyLockSettings();

                values = new List <SettingGroup>(new SettingGroup[] { ils });

                foreach (SettingGroup sg in values)
                {
                    sg.Initialize();
                    sg.PropertyChanged += SettingGroupChanged;
                }
            }
        }
예제 #3
0
파일: App.xaml.cs 프로젝트: laptou/tsa-2017
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            if (e.Args.Length > 0)
            {
                XmlSettingsService.Init(true);

                IEnumerable <string> args = e.Args;

                if (e.Args[0].Equals("-encrypt", StringComparison.InvariantCultureIgnoreCase))
                {
                    args = args.Skip(1);

                    foreach (string arg in args)
                    {
                        FileAuthenticationView      fav  = new FileAuthenticationView();
                        FileAuthenticationViewModel favm = (FileAuthenticationViewModel)fav.DataContext;
                        favm.Path = arg;
                        fav.ShowDialog();
                    }

                    Shutdown();
                }
                else
                {
                    if (e.Args[0].Equals("-decrypt", StringComparison.InvariantCultureIgnoreCase))
                    {
                        args = args.Skip(1);
                    }

                    foreach (string arg in args)
                    {
                        if (!File.Exists(arg))
                        {
                            continue;
                        }

                        FileAuthenticationView      fav  = new FileAuthenticationView();
                        FileAuthenticationViewModel favm = (FileAuthenticationViewModel)fav.DataContext;
                        favm.Path = arg;
                        fav.ShowDialog();
                    }

                    Shutdown();
                }

                return;
            }

            if (!IsDesigner)
            {
                ips = ManagedProcessService.Default;
                XmlSettingsService.Init(false);
                iss = XmlSettingsService.Default;

                IvyLockSettings ils = iss.OfType <IvyLockSettings>().First();
                switch (ils.Theme)
                {
                case Theme.Light:
                    Resources.MergedDictionaries.Clear();
                    Resources.MergedDictionaries.Add(new ResourceDictionary()
                    {
                        Source = new Uri("pack://application:,,,/IvyLock;component/Content/Theme.Light.xaml")
                    });
                    break;
                }

                ips.ProcessChanged += ProcessChanged;

                MainWindow = new SettingsView();
                MainWindow.Show();
                MainWindow.Activate();

                ni        = new WF.NotifyIcon();
                ni.Click += (s, e1) =>
                {
                    MainWindow?.Show();
                    MainWindow?.Activate();
                };

                ni.Icon        = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location);
                ni.ContextMenu = new WF.ContextMenu();
                ni.ContextMenu.MenuItems.Add("Exit", (s, e2) =>
                {
                    SettingsViewModel svm = MainWindow.DataContext as SettingsViewModel;

                    svm.PropertyChanged += (s2, e3) =>
                    {
                        if (e3.PropertyName == "CurrentScreen" && svm.CurrentScreen == ViewModel.Screen.Main)
                        {
                            Shutdown();
                        }
                    };

                    svm.CurrentScreen = ViewModel.Screen.EnterPassword;

                    MainWindow.Show();
                    MainWindow.Activate();
                });
                ni.Visible = true;
            }
        }