Exemple #1
0
        public App(string userConfigPath = null)
        {
            MessageHandlers.RegisterMessageHandlers(this);

#if PORTABLE
            UserConfigPath = !string.IsNullOrWhiteSpace(userConfigPath) ? userConfigPath : DefaultUserConfigFileName;
#else
            UserConfigPath = !string.IsNullOrWhiteSpace(userConfigPath) ? userConfigPath : GetAppDataUserConfigPath();
#endif

            string userFile = UserConfigPath;

            AppViewModel.Init(Assembly.GetEntryAssembly(), () =>
            {
                return(GetResourceStream(new Uri("pack://application:,,,/Chordious.WPF.xml")).Stream);
            }, () =>
            {
                return(new FileStream(userFile, FileMode.Open));
            }, () =>
            {
                return(new FileStream(userFile, FileMode.Create));
            }, ImageUtils.SvgTextToBitmapImage
                              , ImageUtils.SvgTextToClipboard
                              , (action) =>
            {
                Dispatcher.Invoke(action);
            }
                              , GetFonts
                              , userFile);

            AppVM.LoadAppConfig();

            if (!File.Exists(userFile))
            {
                // Makes sure that LoadUserConfig will be successful
                AppVM.SaveUserConfig();
            }

            AppVM.LoadUserConfig(HandleUserConfigLoadException);

            // Makes sure textboxes accept localized inputs
            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            Exit += App_Exit;
        }
Exemple #2
0
        private string ResetAndBackupUserConfig(string userFile)
        {
            if (string.IsNullOrWhiteSpace(userFile))
            {
                throw new ArgumentNullException(nameof(userFile));
            }

            string userFolder   = Path.GetDirectoryName(userFile);
            string userFileName = Path.GetFileNameWithoutExtension(userFile);
            string userFileExt  = Path.GetExtension(userFile);

            string backupFile = Path.Combine(userFolder, string.Format("{0}.{1:yyyy.MM.dd.HH.mm.ss}{2}", userFileName, DateTime.UtcNow, userFileExt));

            File.Move(userFile, backupFile);

            AppVM.ResetUserConfig();
            AppVM.SaveUserConfig();

            return(backupFile);
        }
Exemple #3
0
        public App(string userConfigPath = null)
        {
            MessageHandlers.RegisterMessageHandlers(this);

            UserConfigPath = GetUserConfigPath(userConfigPath, true);

            AppViewModel.Init(Assembly.GetEntryAssembly(), this, UserConfigPath);

            AppVM.LoadAppConfig();

            if (!File.Exists(UserConfigPath))
            {
                // Makes sure that LoadUserConfig will be successful
                AppVM.SaveUserConfig();
            }

            AppVM.LoadUserConfig(HandleUserConfigLoadException);

            // Makes sure textboxes accept localized inputs
            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            Exit += App_Exit;
        }