Ejemplo n.º 1
0
        private void RestorePostListViewSettings()
        {
            IPostEditorPostSource postSource = listBoxPostSources.SelectedPostSource as IPostEditorPostSource;

            using (SettingsPersisterHelper postSourceSettings = _recentPostsSettings.GetSubSettings(postSource.UniqueId))
            {
                // number of posts
                RecentPostRequest recentPostRequest = new RecentPostRequest(postSourceSettings.GetInt32(NUMBER_OF_POSTS, postSource.RecentPostCapabilities.DefaultRequest.NumberOfPosts));
                if (comboBoxPosts.Items.Contains(recentPostRequest))
                {
                    comboBoxPosts.SelectedItem = recentPostRequest;
                }

                // pages
                if (postSource.SupportsPages)
                {
                    radioButtonPages.Checked = postSourceSettings.GetBoolean(SHOW_PAGES, false);
                }
                else
                {
                    radioButtonPages.Checked = false;
                }
                radioButtonPosts.Checked = !radioButtonPages.Checked;
            }
        }
        /// <summary>
        /// Saves preferences.
        /// </summary>
        protected override void SavePreferences()
        {
            string name = null;

            if (applicationStyleType == typeof(ApplicationStyleSkyBlue))
            {
                name = "SkyBlue";
            }
            else if (applicationStyleType == typeof(ApplicationStyleLavender))
            {
                name = "Lavender";
            }
            else if (applicationStyleType == typeof(ApplicationStyleSienna))
            {
                name = "Sienna";
            }
            else if (applicationStyleType == typeof(ApplicationStyleSterling))
            {
                name = "Sterling";
            }
            else if (applicationStyleType == typeof(ApplicationStyleWintergreen))
            {
                name = "Wintergreen";
            }
            else
            {
                Trace.Fail("Unexpected application style: " + applicationStyleType.Name);
                name = "SkyBlue";
            }

            SettingsPersisterHelper.SetString(APPLICATION_STYLE_TYPE_NAME, name);
        }
Ejemplo n.º 3
0
        public void SaveAsDefault(ImagePropertiesInfo imageInfo)
        {
            ImageDecoratorsList decorators = imageInfo.ImageDecorators;

            //delete the existing image settings
            DeleteImageSettings(_contextId);

            using (SettingsPersisterHelper contextImageSettings = GetImageSettingsPersister(_contextId, true))
            {
                //loop over the image decorators and save the settings of any decorators that are defaultable.
                StringBuilder sb = new StringBuilder();
                foreach (string decoratorId in decorators.GetImageDecoratorIds())
                {
                    ImageDecorator decorator = decorators.GetImageDecorator(decoratorId);
                    if (decorator.IsDefaultable)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(",");
                        }
                        sb.Append(decorator.Id);
                        using (SettingsPersisterHelper decoratorDefaultSettings = contextImageSettings.GetSubSettings(decoratorId))
                        {
                            PluginSettingsAdaptor settings = new PluginSettingsAdaptor(decoratorDefaultSettings);
                            IProperties           decoratorCurrentSettings = decorators.GetImageDecoratorSettings(decoratorId);
                            CopySettings(decoratorCurrentSettings, settings);
                            ImageDecoratorEditorContext editorContext =
                                new ImageDecoratorEditorContextImpl(decoratorCurrentSettings, null, imageInfo, new NoOpUndoUnitFactory(), _decoratorsManager.CommandManager);
                            decorator.ApplyCustomizeDefaultSettingsHook(editorContext, settings);
                        }
                    }
                }
                contextImageSettings.SetString(ImageDecoratorsListKey, sb.ToString());
            }
        }
        /// <summary>
        /// Remove the destination profile associated with the specified key.
        /// </summary>
        /// <param name="key"></param>
        public void deleteProfile(string key)
        {
            SettingsPersisterHelper settings = SettingsRoot;

            settings = settings.GetSubSettings(_destinationKey);
            settings.SettingsPersister.UnsetSubSettingsTree(key);
        }
Ejemplo n.º 5
0
        public string GetEditorTemplateHtml(BlogEditingTemplateType templateType, bool forceRTL)
        {
            SettingsPersisterHelper templates = _editorTemplateSettings.GetSubSettings(EDITOR_TEMPLATES_KEY);
            string templateHtmlFile           = templates.GetString(templateType.ToString(), null);

            // Sometimes templateHtmlFile is relative, sometimes it is already absolute (from older builds).
            templateHtmlFile = MakeAbsolute(templateHtmlFile);

            if (templateHtmlFile != null && File.Exists(templateHtmlFile))
            {
                string templateHtml;
                using (StreamReader reader = new StreamReader(templateHtmlFile, Encoding.UTF8))
                    templateHtml = reader.ReadToEnd();

                if (File.Exists(templateHtmlFile + ".path"))
                {
                    string origPath = File.ReadAllText(templateHtmlFile + ".path");
                    string newPath  = Path.Combine(Path.GetDirectoryName(templateHtmlFile), Path.GetFileName(origPath));
                    string newUri   = UrlHelper.SafeToAbsoluteUri(new Uri(newPath));
                    templateHtml = templateHtml.Replace(origPath, newUri);
                }

                return(templateHtml);
            }
            else
            {
                return(BlogEditingTemplate.GetDefaultTemplateHtml(forceRTL, templateType != BlogEditingTemplateType.Normal));
            }
        }
        /// <summary>
        /// Returns the registry subtree for a specified profile.
        /// </summary>
        /// <param name="profileKey"></param>
        /// <returns></returns>
        private SettingsPersisterHelper getProfileSettings(string profileKey)
        {
            SettingsPersisterHelper settings = SettingsRoot;

            settings = settings.GetSubSettings(_destinationKey + @"\" + profileKey);
            return(settings);
        }
        /// <summary>
        /// Returns the profile associated with the key, or null if no such profile exists.
        /// </summary>
        /// <param name="key">The name of the registry key to define the profile under.</param>
        /// <returns></returns>
        public DestinationProfile loadProfile(String key)
        {
            SettingsPersisterHelper settings = getProfileSettings(key);

            if (settings.GetNames().Length == 0)
            {
                return(null);
            }
            DestinationProfile profile = new DestinationProfile();

            profile.Id               = key;
            profile.Name             = settings.GetString(PROFILE_NAME_KEY, "");
            profile.WebsiteURL       = settings.GetString(PROFILE_WEBSITE_URL_KEY, "");
            profile.FtpServer        = settings.GetString(PROFILE_FTP_SERVER_KEY, "");
            profile.UserName         = settings.GetString(PROFILE_FTP_USER_KEY, "");
            profile.FtpPublishPath   = settings.GetString(PROFILE_FTP_PUBLISH_DIR_KEY, "");
            profile.LocalPublishPath = settings.GetString(PROFILE_PUBLISH_DIR_KEY, "");
            profile.Type             = (DestinationProfile.DestType)settings.GetInt32(PROFILE_DESTINATION_TYPE_KEY, 0);

            //load the decrypted password
            try
            {
                profile.Password = settings.GetEncryptedString(PROFILE_FTP_PASSWORD_KEY);
            }
            catch (Exception e)
            {
                Trace.Fail("Failed to decrypt password: " + e);
            }

            return(profile);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Load the default image decorators for the current image context.
 /// </summary>
 /// <returns></returns>
 public ImageDecoratorsList LoadDefaultImageDecoratorsList()
 {
     using (SettingsPersisterHelper contextImageSettings = GetImageSettingsPersister(_contextId, false))
     {
         ImageDecoratorsList decoratorsList;
         if (contextImageSettings == null)
         {
             decoratorsList = GetInitialLocalImageDecoratorsList();
         }
         else
         {
             decoratorsList = new ImageDecoratorsList(_decoratorsManager, new BlogPostSettingsBag(), false);
             string[] decoratorIds = contextImageSettings.GetString(ImageDecoratorsListKey, "").Split(',');
             foreach (string decoratorId in decoratorIds)
             {
                 ImageDecorator imageDecorator = _decoratorsManager.GetImageDecorator(decoratorId);
                 if (imageDecorator != null) //can be null if the decorator is no longer valid
                 {
                     decoratorsList.AddDecorator(imageDecorator);
                     using (SettingsPersisterHelper decoratorDefaultSettings = contextImageSettings.GetSubSettings(decoratorId))
                     {
                         PluginSettingsAdaptor settings = new PluginSettingsAdaptor(decoratorDefaultSettings);
                         CopySettings(settings, decoratorsList.GetImageDecoratorSettings(decoratorId));
                     }
                 }
             }
         }
         //now add the implicit decorators IFF they aren't already in the list
         decoratorsList.MergeDecorators(GetImplicitLocalImageDecorators());
         return(decoratorsList);
     }
 }
        private static ArrayList LoadAccountWizardsFromXml()
        {
            ArrayList accountWizardsFromXml = new ArrayList();

            try
            {
                using (SettingsPersisterHelper settingsKey = ApplicationEnvironment.UserSettingsRoot.GetSubSettings("AccountWizard\\Custom"))
                {
                    foreach (string customizationName in settingsKey.GetNames())
                    {
                        IBlogProviderAccountWizardDescription wizardDescription = LoadAccountWizardFromXml(settingsKey.GetString(customizationName, String.Empty));
                        if (wizardDescription != null)
                        {
                            accountWizardsFromXml.Add(wizardDescription);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception in LoadAccountWizardsFromXml: " + ex.ToString());
            }

            return(accountWizardsFromXml);
        }
Ejemplo n.º 10
0
 public PostHtmlEditingSettings(string blogId)
 {
     _blogId = blogId;
     using (SettingsPersisterHelper blogSettings = BlogSettings.GetWeblogSettingsKey(blogId))
     {
         _editorTemplateSettings = blogSettings.GetSubSettings("EditorTemplate");
     }
 }
        private void LoadPluginsFromRegistryPaths(PluginLoader pluginLoader, bool showErrors)
        {
            try
            {
                // build list of assemblies
                ArrayList assemblyPaths = new ArrayList();

                // HKCU
                using (SettingsPersisterHelper userSettingsKey = ApplicationEnvironment.UserSettingsRoot.GetSubSettings(PLUGIN_ASSEMBLIES))
                    AddPluginsFromKey(assemblyPaths, userSettingsKey);

                if (_pluginsKey != PLUGIN_LEGACY_KEY)
                {
                    using (RegistryKey legacyKey = Registry.CurrentUser.OpenSubKey(PLUGIN_LEGACY_KEY))
                        if (legacyKey != null) // Don't create the key if it doesn't already exist
                        {
                            using (SettingsPersisterHelper legacyUserSettingsKey = new SettingsPersisterHelper(new RegistrySettingsPersister(Registry.CurrentUser, PLUGIN_LEGACY_KEY)))
                                AddPluginsFromKey(assemblyPaths, legacyUserSettingsKey);
                        }
                }

                // HKLM (this may not work for limited users and/or on vista)

                try
                {
                    if (ApplicationEnvironment.MachineSettingsRoot.HasSubSettings(PLUGIN_ASSEMBLIES))
                    {
                        using (SettingsPersisterHelper machineSettingsKey = ApplicationEnvironment.MachineSettingsRoot.GetSubSettings(PLUGIN_ASSEMBLIES))
                            AddPluginsFromKey(assemblyPaths, machineSettingsKey);
                    }

                    if (_pluginsKey != PLUGIN_LEGACY_KEY)
                    {
                        using (RegistryKey legacyKey = Registry.LocalMachine.OpenSubKey(PLUGIN_LEGACY_KEY))
                            if (legacyKey != null) // Don't create the key if it doesn't already exist
                            {
                                using (SettingsPersisterHelper legacyUserSettingsKey = new SettingsPersisterHelper(new RegistrySettingsPersister(Registry.LocalMachine, PLUGIN_LEGACY_KEY)))
                                    AddPluginsFromKey(assemblyPaths, legacyUserSettingsKey);
                            }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error occurred while attempting to read HKLM for PluginAssemblies: " + ex.ToString());
                }

                // load them
                foreach (string assemblyPath in assemblyPaths)
                {
                    pluginLoader.LoadPluginsFromAssemblyPath(assemblyPath, showErrors);
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception loading plugins from registry paths: " + ex.ToString());
            }
        }
Ejemplo n.º 12
0
 private void SaveNumberOfPostsSettings()
 {
     // get post data/context to save
     using (SettingsPersisterHelper postSourceSettings = _recentPostsSettings.GetSubSettings(listBoxPostSources.SelectedPostSource.UniqueId))
     {
         // number of posts
         int numberOfPosts = (comboBoxPosts.SelectedItem as RecentPostRequest).NumberOfPosts;
         postSourceSettings.SetInt32(NUMBER_OF_POSTS, numberOfPosts);
     }
 }
        public bool HasProfile(string key)
        {
            if (key == string.Empty)
            {
                return(false);
            }

            SettingsPersisterHelper settings = SettingsRoot;

            return(settings.HasSubSettings(_destinationKey + @"\" + key));
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Deletes the default image settings for the specified context.
 /// </summary>
 /// <param name="contextId"></param>
 private static void DeleteImageSettings(string contextId)
 {
     //unset the existing image defaults
     using (SettingsPersisterHelper contextRootSettings = RootSettingsKey.GetSubSettings(contextId))
     {
         if (contextRootSettings.HasSubSettings(ImageDefaultsKey))
         {
             contextRootSettings.UnsetSubsettingTree(ImageDefaultsKey);
         }
     }
 }
 private void AddPluginsFromKey(ArrayList pluginPaths, SettingsPersisterHelper settingsKey)
 {
     foreach (string name in settingsKey.GetNames())
     {
         string assemblyPath = settingsKey.GetString(name, String.Empty);
         if (!pluginPaths.Contains(assemblyPath))
         {
             pluginPaths.Add(assemblyPath);
         }
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the Preferences class (optionally enable change monitoring)
        /// </summary>
        /// <param name="subKey">sub-key name</param>
        /// <param name="monitorChanges">specifies whether the creator intendes to monitor
        /// this prefs object for changes by calling the CheckForChanges method</param>
        public Preferences(string subKey, bool monitorChanges)
        {
            //	Instantiate the settings persister helper object.
            settingsPersisterHelper = ApplicationEnvironment.PreferencesSettingsRoot.GetSubSettings(subKey);

            //	Load preferences
            LoadPreferences();

            //	Monitor changes, if requested.
            if (monitorChanges)
            {
                ConfigureChangeMonitoring(subKey);
            }
        }
Ejemplo n.º 17
0
 private void SavePostsOrPagesSettings()
 {
     // get post data/context to save
     using (SettingsPersisterHelper postSourceSettings = _recentPostsSettings.GetSubSettings(listBoxPostSources.SelectedPostSource.UniqueId))
     {
         if (listBoxPostSources.SelectedPostSource.SupportsPages)
         {
             postSourceSettings.SetBoolean(SHOW_PAGES, radioButtonPages.Checked);
         }
         else
         {
             postSourceSettings.SetBoolean(SHOW_PAGES, false);
         }
     }
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Get the settings persister for the specified image context.
 /// </summary>
 /// <param name="contextId"></param>
 /// <param name="autoCreate"></param>
 /// <returns></returns>
 private static SettingsPersisterHelper GetImageSettingsPersister(string contextId, bool autoCreate)
 {
     //unset the existing image defaults
     using (SettingsPersisterHelper contextRootSettings = RootSettingsKey.GetSubSettings(contextId))
     {
         if (autoCreate || contextRootSettings.HasSubSettings(ImageDefaultsKey))
         {
             return(contextRootSettings.GetSubSettings(ImageDefaultsKey));
         }
         else
         {
             return(null);
         }
     }
 }
        /// <summary>
        /// Loads preferences.
        /// </summary>
        protected override void LoadPreferences()
        {
            //	Obtain the type name of the application style.  If it's null, use SkyBlue.
            string name = SettingsPersisterHelper.GetString(APPLICATION_STYLE_TYPE_NAME, "ApplicationStyleSkyBlue");

            // strip "AplicationStyle" preface (for legacy settings format support)
            const string APPLICATION_STYLE = "ApplicationStyle";

            if (name.StartsWith(APPLICATION_STYLE))
            {
                name = name.Substring(APPLICATION_STYLE.Length);
            }

            switch (name)
            {
            case "SkyBlue":
                applicationStyleType = typeof(ApplicationStyleSkyBlue);
                break;

            case "Lavender":
                applicationStyleType = typeof(ApplicationStyleLavender);
                break;

            case "Sienna":
                applicationStyleType = typeof(ApplicationStyleSienna);
                break;

            case "Sterling":
                applicationStyleType = typeof(ApplicationStyleSterling);
                break;

            case "Wintergreen":
                applicationStyleType = typeof(ApplicationStyleWintergreen);
                break;

            default:
                Trace.Fail("Unexpected application style type: " + name);
                applicationStyleType = typeof(ApplicationStyleSkyBlue);
                break;
            }

            //	Set the new application style.
            if (ApplicationManager.ApplicationStyle.GetType() != applicationStyleType)
            {
                ApplicationManager.ApplicationStyle = Activator.CreateInstance(applicationStyleType) as ApplicationStyle;
            }
        }
        public string GetEditorTemplateHtml(BlogEditingTemplateType templateType, bool forceRTL)
        {
            SettingsPersisterHelper templates = _editorTemplateSettings.GetSubSettings(EDITOR_TEMPLATES_KEY);
            string templateHtmlFile           = templates.GetString(templateType.ToString(), null);

            // Sometimes templateHtmlFile is relative, sometimes it is already absolute (from older builds).
            templateHtmlFile = MakeAbsolute(templateHtmlFile);

            if (templateHtmlFile != null && File.Exists(templateHtmlFile))
            {
                string templateHtml;
                using (StreamReader reader = new StreamReader(templateHtmlFile, Encoding.UTF8))
                    templateHtml = reader.ReadToEnd();

                if (File.Exists(templateHtmlFile + ".path"))
                {
                    string origPath = File.ReadAllText(templateHtmlFile + ".path");
                    string newPath  = Path.Combine(Path.GetDirectoryName(templateHtmlFile), Path.GetFileName(origPath));
                    string newUri   = UrlHelper.SafeToAbsoluteUri(new Uri(newPath));
                    templateHtml = templateHtml.Replace(origPath, newUri);
                }

                /*Parse meta tags in order to set CSS3 compatibility*/
                Regex metatag = new Regex(@"<(?i:meta)(\s)+(?i:http-equiv)(\s)*=""(?:X-UA-Compatible)""(\s)+(?i:content)(\s)*=""(?i:IE=edge)""(\s)*/>");
                Match match   = metatag.Match(templateHtml);

                if (!match.Success)
                {
                    // prepend the metatag to make css3 compatible at least on edge (Windows 8+)
                    int i = templateHtml.IndexOf("<HEAD>", StringComparison.OrdinalIgnoreCase);
                    if (i > 0)
                    {
                        templateHtml = (templateHtml.Substring(0, i + 6)
                                        + "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />"
                                        + templateHtml.Substring(i + 6));
                    }
                }


                return(templateHtml);
            }
            else
            {
                return(BlogEditingTemplate.GetDefaultTemplateHtml(forceRTL, templateType != BlogEditingTemplateType.Normal));
            }
        }
        static WebProxySettings()
        {
            _settingsKey = ApplicationEnvironment.PreferencesSettingsRoot.GetSubSettings("WebProxy");
            if (ApplicationDiagnostics.ProxySettingsOverride != null)
            {
                Match m = Regex.Match(ApplicationDiagnostics.ProxySettingsOverride,
                                      @"^ ( (?<username>[^@:]+) : (?<password>[^@:]+) @)? (?<host>[^@:]+) (:(?<port>\d*))? $",
                                      RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture);
                if (m.Success)
                {
                    string username = m.Groups["username"].Value;
                    string password = m.Groups["password"].Value;
                    string host     = m.Groups["host"].Value;
                    string port     = m.Groups["port"].Value;

                    _readSettingsKey = new SettingsPersisterHelper(new MemorySettingsPersister());

                    _readSettingsKey.SetBoolean("Enabled", true);

                    if (!string.IsNullOrEmpty(username))
                    {
                        _readSettingsKey.SetString("Username", username);
                    }
                    if (!string.IsNullOrEmpty(password))
                    {
                        _readSettingsKey.SetEncryptedString("Password", password);
                    }

                    _readSettingsKey.SetString("Hostname", host);

                    if (!string.IsNullOrEmpty(port))
                    {
                        _readSettingsKey.SetInt32("Port", int.Parse(port, CultureInfo.InvariantCulture));
                    }
                }
            }

            if (_readSettingsKey == null)
            {
                _readSettingsKey = _settingsKey;
            }
        }
        public BlogProviderButtonDescriptionFromSettings(SettingsPersisterHelper settingsKey)
        {
            // id
            string id = settingsKey.GetString(ID, String.Empty);

            // image (required)
            string imageUrl = settingsKey.GetString(IMAGE_URL, String.Empty);

            byte[] imageData = settingsKey.GetByteArray(IMAGE, null);
            Bitmap image     = null;

            if (imageData != null)
            {
                try
                {
                    image = new Bitmap(new MemoryStream(imageData));
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.ToString());
                }
            }

            // tool-tip text
            string description = settingsKey.GetString(DESCRIPTION, String.Empty);

            // click-url
            string clickUrl = settingsKey.GetString(CLICK_URL, String.Empty);

            // has content
            string contentUrl         = settingsKey.GetString(CONTENT_URL, String.Empty);
            Size   contentDisplaySize = settingsKey.GetSize(CONTENT_DISPLAY_SIZE, Size.Empty);

            // has notification image
            string notificationUrl = settingsKey.GetString(NOTIFICATION_URL, String.Empty);

            // initialize
            Init(id, imageUrl, image, description, clickUrl, contentUrl, contentDisplaySize, notificationUrl);
        }
Ejemplo n.º 23
0
        internal void CleanupUnusedTemplates()
        {
            try
            {
                using (SettingsPersisterHelper templates = _editorTemplateSettings.GetSubSettings(EDITOR_TEMPLATES_KEY))
                {
                    // get the list of templates which are legit
                    ArrayList templatesInUse = new ArrayList();
                    foreach (string key in templates.GetNames())
                    {
                        templatesInUse.Add(MakeAbsolute(templates.GetString(key, String.Empty)).Trim().ToLower(CultureInfo.CurrentCulture));
                    }

                    // delete each of the template files in the directory which
                    // are not contained in our list of valid templates
                    if (templatesInUse.Count > 0)
                    {
                        string templateDirectory = Path.GetDirectoryName((string)templatesInUse[0]);
                        if (Directory.Exists(templateDirectory))
                        {
                            string[] templateFiles = Directory.GetFiles(templateDirectory, "*.htm");
                            foreach (string templateFile in templateFiles)
                            {
                                string templateFileNormalized = templateFile.Trim().ToLower(CultureInfo.CurrentCulture);
                                if (!templatesInUse.Contains(templateFileNormalized))
                                {
                                    CleanupTemplateAndSupportingFiles(templateFile);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Error occurred cleaning up unused templates: " + ex.ToString());
            }
        }
Ejemplo n.º 24
0
        private static void MaybeMigrateSettings()
        {
            try
            {
                int applicationSettingsVer           = 1;
                SettingsPersisterHelper userSettings = ApplicationEnvironment.UserSettingsRoot;
                int currentSettingsVer = userSettings.GetInt32(SETTINGS_VERSION, 0);
                if (currentSettingsVer == 0)
                {
                    userSettings.SetInt32(SETTINGS_VERSION, applicationSettingsVer);
                    Trace.WriteLine("Migrating user settings...");

                    string legacyKeyName = @"Software\Open Live Writer";
                    SettingsPersisterHelper legacySettings = new SettingsPersisterHelper(new RegistrySettingsPersister(Registry.CurrentUser, legacyKeyName));
                    ApplicationEnvironment.UserSettingsRoot.CopyFrom(legacySettings, true, false); // Don't overwrite existing settings

                    Registry.CurrentUser.DeleteSubKeyTree(legacyKeyName);
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Error while attempting to migrate settings.", ex.ToString());
            }
        }
        /// <summary>
        /// Saves a destination profile into the registry.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="profile"></param>
        public void saveProfile(String key, DestinationProfile profile)
        {
            SettingsPersisterHelper settings = getProfileSettings(key);

            profile.Id = key;
            settings.SetString(PROFILE_NAME_KEY, profile.Name);
            settings.SetString(PROFILE_WEBSITE_URL_KEY, profile.WebsiteURL);
            settings.SetString(PROFILE_FTP_SERVER_KEY, profile.FtpServer);
            settings.SetString(PROFILE_FTP_PUBLISH_DIR_KEY, profile.FtpPublishPath);
            settings.SetString(PROFILE_FTP_USER_KEY, profile.UserName);
            settings.SetString(PROFILE_PUBLISH_DIR_KEY, profile.LocalPublishPath);
            settings.SetInt32(PROFILE_DESTINATION_TYPE_KEY, (short)profile.Type);

            //save an encrypted password
            try
            {
                settings.SetEncryptedString(PROFILE_FTP_PASSWORD_KEY, profile.Password);
            }
            catch (Exception e)
            {
                //if an exception occurs, just leave the password empty
                Trace.Fail("Failed to encrypt password: " + e.Message, e.StackTrace);
            }
        }
Ejemplo n.º 26
0
        public static void Initialize(Assembly rootAssembly, string installationDirectory, string settingsRootKeyName, string productName)
        {
            // initialize name and version based on assembly metadata
            string          rootAssemblyPath = rootAssembly.Location;
            FileVersionInfo fileVersionInfo  = FileVersionInfo.GetVersionInfo(rootAssemblyPath);

            _companyName    = fileVersionInfo.CompanyName;
            _productName    = productName;
            _productVersion = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}.{3}", fileVersionInfo.ProductMajorPart, fileVersionInfo.ProductMinorPart, fileVersionInfo.ProductBuildPart, fileVersionInfo.ProductPrivatePart);
            _appVersion     = new Version(_productVersion);

            Debug.Assert(_appVersion.Build < UInt16.MaxValue &&
                         _appVersion.Revision < UInt16.MaxValue &&
                         _appVersion.Major < UInt16.MaxValue &&
                         _appVersion.Minor < UInt16.MaxValue, "Invalid ApplicationVersion: " + _appVersion);

            // set installation directory and executable name
            _installationDirectory = installationDirectory;
            _mainExecutableName    = Path.GetFileName(rootAssemblyPath);

            // initialize icon/user-agent, etc.
            _userAgent        = FormatUserAgentString(ProductName, true);
            _productIcon      = ResourceHelper.LoadAssemblyResourceIcon("Images.ApplicationIcon.ico");
            _productIconSmall = ResourceHelper.LoadAssemblyResourceIcon("Images.ApplicationIcon.ico", 16, 16);

            // initialize IsHighContrastWhite and IsHighContrastBlack
            InitializeIsHighContrastBlackWhite();

            _settingsRootKeyName = settingsRootKeyName;
            string dataPath;

            // see if we're running in portable mode
#if PORTABLE
            dataPath = Path.Combine(_installationDirectory, "UserData");
            if (Directory.Exists(dataPath))
            {
                _portable = true;
                // initialize application data directories
                _applicationDataDirectory      = Path.Combine(dataPath, "AppData\\Roaming");
                _localApplicationDataDirectory = Path.Combine(dataPath, "AppData\\Local");

                // initialize settings
                _userSettingsRoot        = new SettingsPersisterHelper(XmlFileSettingsPersister.Open(Path.Combine(dataPath, "UserSettings.xml")));
                _machineSettingsRoot     = new SettingsPersisterHelper(XmlFileSettingsPersister.Open(Path.Combine(dataPath, "MachineSettings.xml")));
                _preferencesSettingsRoot = _userSettingsRoot.GetSubSettings(ApplicationConstants.PREFERENCES_SUB_KEY);
            }
            else
#endif
            {
                _portable = false;
                // initialize application data directories.
                _applicationDataDirectory      = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppDataFolderName);
                _localApplicationDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppDataFolderName);

                // initialize settings
                _userSettingsRoot        = new SettingsPersisterHelper(new RegistrySettingsPersister(Registry.CurrentUser, SettingsRootKeyName));
                _machineSettingsRoot     = new SettingsPersisterHelper(new RegistrySettingsPersister(Registry.LocalMachine, SettingsRootKeyName));
                _preferencesSettingsRoot = _userSettingsRoot.GetSubSettings(ApplicationConstants.PREFERENCES_SUB_KEY);

                dataPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            }

            _myWeblogPostsFolder = _userSettingsRoot.GetString("PostsDirectory", null);
            if (string.IsNullOrEmpty(_myWeblogPostsFolder))
            {
                if ((_productName == DefaultProductName) && (string.IsNullOrEmpty(dataPath)))
                {
                    throw new DirectoryException(MessageId.PersonalDirectoryFail);
                }
                else
                {
                    _myWeblogPostsFolder = Path.Combine(dataPath, "My Weblog Posts");
                }
            }

            // initialize diagnostics
            InitializeLogFilePath();
            _applicationDiagnostics = new ApplicationDiagnostics(LogFilePath, rootAssembly.GetName().Name);

            if (!Directory.Exists(_applicationDataDirectory))
            {
                Directory.CreateDirectory(_applicationDataDirectory);
            }
            if (!Directory.Exists(_localApplicationDataDirectory))
            {
                Directory.CreateDirectory(_localApplicationDataDirectory);
            }
        }
 public BlogPublishingPluginSettings(SettingsPersisterHelper settings)
 {
     _settings = settings;
 }
Ejemplo n.º 28
0
 public VideoServiceSettings(string serviceId, SettingsPersisterHelper parentPersister)
 {
     _settings = parentPersister.GetSubSettings(serviceId);
 }
 public static void SetContentSourceForFormat(LiveClipboardFormat format, string contentSourceId)
 {
     using (SettingsPersisterHelper formatSettings = _formatHandlerSettings.GetSubSettings(format.Id))
         formatSettings.SetString(CONTENT_SOURCE_ID, contentSourceId);
 }
 private static string GetContentSourceIdForFormat(LiveClipboardFormat format)
 {
     using (SettingsPersisterHelper formatSettings = _formatHandlerSettings.GetSubSettings(format.Id))
         return(formatSettings.GetString(CONTENT_SOURCE_ID, null));
 }