コード例 #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            //Launage switch
            ResourceDictionary dict = new ResourceDictionary();

            dict.Source = new Uri(@"Resources\Language\" + LanguageHelper.PreferenceLanguage + ".xaml", UriKind.Relative);
            ConfigHelper.Instance.SetLang(LanguageHelper.PreferenceLanguage == "zh-CN" ? "zh-cn" : "en");
            Current.Resources.MergedDictionaries.Add(dict);

            //theme switch
            ResourceDictionary themeDictionary = new ResourceDictionary();
            ResourceDictionary chartDictionary = new ResourceDictionary();

            switch (appData.ThemeSetting)
            {
            case 0:
                themeDictionary.Source = new Uri(@"pack://*****:*****@"Resources\Theme\DefaultTheme.xaml", UriKind.Relative);
                break;

            case 1:
                themeDictionary.Source = new Uri(@"pack://*****:*****@"Resources\Theme\DarkTheme.xaml", UriKind.Relative);
                break;

            default:     //bright default
                themeDictionary.Source = new Uri(@"pack://*****:*****@"Resources\Theme\DefaultTheme.xaml", UriKind.Relative);
                break;
            }
            Current.Resources.MergedDictionaries.Add(themeDictionary);
            Current.Resources.MergedDictionaries.Add(chartDictionary);

            //tray icon
            mutex = new Mutex(true, "FrogyMainProgram");
            string startupArg = e.Args.Count() > 0 ? e.Args[0] : null;

            //if frogy not running
            if (mutex.WaitOne(0, false) || startupArg == "restart")
            {
                //Promote permission if not Administrator
                var principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
                if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
                {
                    MyDeviceHelper.PromotePermission();
                }

                taskbarIcon = (TaskbarIcon)FindResource("icon");

                ShowNotification(
                    LanguageHelper.InquireLocalizedWord("TaskBar_AppName"),
                    LanguageHelper.InquireLocalizedWord("TaskBar_StartUp"),
                    BalloonIcon.Info);

                appData.InitializeMyAppData();
                appData.StartLogic();

                base.OnStartup(e);
            }
            else
            {
                MessageBox.Show(
                    LanguageHelper.InquireLocalizedWord("TaskBar_Overlap"),
                    LanguageHelper.InquireLocalizedWord("TaskBar_AppName"),
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);

                Environment.Exit(1);
            }
        }