Пример #1
0
        /// <summary>
        /// Load different Resource dictionaries based on whether the App is Game or Admin mode.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnStartup(StartupEventArgs e)
        {
            // splash screen is shown manually due to a race condition bug in WPF 3.5 (which was fixed in WPF 4.0)
            SplashScreen splashScreen = new SplashScreen("Resource/Images/FlashCardSplashScreen.png");

            splashScreen.Show(false);

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            InstallDefaultDecks();

            // get arguments from ClickOnce activation arguments or command line
            string[] arguments;

            if ((AppDomain.CurrentDomain.SetupInformation != null) &&
                (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null) &&
                (AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null))
            {
                arguments = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
            }
            else
            {
                arguments = e.Args;
            }

            // parse arguments
            if (arguments.Length > 0)
            {
                // check if open as Admin
                if (string.Compare(arguments[0], Taskbar.AdminArgument, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    MainViewModel.Instance.IsAdmin = true;
                }
                // check if open CreateNewCardDeck
                else if (string.Compare(arguments[0], Taskbar.CreateNewCardDeckArgument, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    MainViewModel.Instance.IsAdmin     = true;
                    MainViewModel.Instance.Decks.IsNew = true;
                }
                // check if first argument is a deck filename
                else if (arguments[0].EndsWith(MainViewModel.ZippedDeckExtension, StringComparison.InvariantCultureIgnoreCase))
                {
                    MainViewModel.Instance.SelectedZipPath = arguments[0];
                }
                // else, open as Game

                // check if second parameter is a deck filename
                if ((arguments.Length > 1) && (arguments[1].EndsWith(MainViewModel.ZippedDeckExtension, StringComparison.InvariantCultureIgnoreCase)))
                {
                    MainViewModel.Instance.SelectedZipPath = arguments[1];
                }
            }

            // work according to passed arguments
            if (MainViewModel.Instance.IsAdmin)
            {
                ResourceDictionary dic = new ResourceDictionary();
                dic.Source = new Uri("/FlashCards.Show;component/ViewModelMappingAdmin.xaml", UriKind.RelativeOrAbsolute);
                App.Current.Resources.MergedDictionaries.Add(dic);
            }
            else
            {
                ResourceDictionary dic = new ResourceDictionary();
                dic.Source = new Uri("/FlashCards.Show;component/ViewModelMappingGame.xaml", UriKind.RelativeOrAbsolute);
                App.Current.Resources.MergedDictionaries.Add(dic);
            }

            Taskbar.InitJumpList(MainViewModel.Instance.IsAdmin);

            if (!string.IsNullOrEmpty(MainViewModel.Instance.SelectedZipPath))
            {
                string outputPath = DeckPackagingHelper.ExtractFromZip(MainViewModel.Instance.SelectedZipPath);

                if (!string.IsNullOrEmpty(outputPath))
                {
                    string deckTitle = MainViewModel.Instance.LoadUnzippedDeck(MainViewModel.Instance.SelectedZipPath, outputPath);
                    Taskbar.AddEntryToJumpList(MainViewModel.Instance.SelectedZipPath, deckTitle);
                }
            }

            splashScreen.Close(TimeSpan.FromTicks(0));
            base.OnStartup(e);
        }