Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameApplication"/> class.</summary>
        /// <remarks><para>
        /// This constructor performs the following actions:
        /// </para><list type="bullet"><item>
        /// Call <see cref="ApplicationUtility.CheckSingleInstance"/> to make sure that the current
        /// user is not already running another instance of the <see cref="GameApplication"/>.
        /// </item><item>
        /// Call <see cref="FilePaths.CheckUserFolders"/> to make sure that the current user has
        /// write permission in the directories that hold user-specific data.
        /// </item><item>
        /// Attach a handler to the <see cref="Application.DispatcherUnhandledException"/> event
        /// that calls <see cref="ApplicationUtility.OnUnhandledException"/>.
        /// </item><item>
        /// Create a global instance of the <see cref="ApplicationOptions"/> class and load the
        /// current user settings.</item></list></remarks>

        public GameApplication()
        {
            // make sure this is the only instance
            if (!ApplicationUtility.CheckSingleInstance())
            {
                Application.Current.Shutdown(-1);
                return;
            }

            // make sure we can create user files
            if (!FilePaths.CheckUserFolders())
            {
                Application.Current.Shutdown(-2);
                return;
            }

            // hook up custom exception handler
            Application.Current.DispatcherUnhandledException += OnUnhandledException;

            // read user settings from Hexkit Game options file
            ApplicationOptions options = ApplicationOptions.CreateInstance();

            // select user-defined display theme, if any
            if (options.View.Theme != DefaultTheme.System)
            {
                DefaultThemeSetter.Select(options.View.Theme);
            }
        }