public void UpdateConfig(IPluginHost host) { if (!m_isDirty) { return; } host.SetConfig(GdsDefs.ConfigEnabledCmds, ((int)m_enabledCmds).ToString(NumberFormatInfo.InvariantInfo)); host.SetConfig(GdsDefs.ConfigAutoSync, m_autoSync.ToString()); host.SetConfig(GdsDefs.ConfigDefaultAppFolder, m_defaultFolder); host.SetConfig(GdsDefs.ConfigDefaultAppFolderColor, m_defaultFolderColor == null ? null : GoogleColor.SerializeToString(m_defaultFolderColor)); host.SetConfig(GdsDefs.ConfigDriveScope, m_defaultDriveScope); host.SetConfig(GdsDefs.ConfigDefaultClientId, m_defaultClientId); host.SetConfig(GdsDefs.ConfigDefaultClientSecret, m_defaultClientSecret == null ? string.Empty : m_defaultClientSecret.ReadString()); host.SetConfig(GdsDefs.EntryUseLegacyCreds, m_useLegacyCreds ? GdsDefs.ConfigTrue : GdsDefs.ConfigFalse); // Only set CurrentVer if all properties are proper at that level. host.SetConfig(GdsDefs.ConfigVersion, CurrentVer); m_isDirty = false; }
private void HandleColorsDrawItem(object sender, DrawItemEventArgs e) { Debug.Assert(ReferenceEquals(sender, m_cbColors)); ComboBox cb = ((ComboBox)sender); if (0 > e.Index || e.Index > cb.Items.Count) { return; } // Draw a combo box item using the color as a background. Graphics g = e.Graphics; Rectangle rect = e.Bounds; // Get the color proxy object. GoogleColor item = (GoogleColor)cb.Items[e.Index]; // Background fill color painting. Brush brush = new SolidBrush(item.Color); g.FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height); // Foreground is the color name in black. g.DrawString(item.ToString(), cb.Font, Brushes.Black, rect.X, rect.Top); }
private void HandleColorsSelectedIndexChanged(object sender, EventArgs e) { GoogleColor item = m_cbColors.Items .Cast <GoogleColor>() .ElementAt(m_cbColors.SelectedIndex); m_cbColors.BackColor = item.Color; m_data.DefaultAppFolderColor = item == m_nullColor ? null : item; }
PluginConfig() { m_autoSync = AutoSyncMode.DISABLED; m_enabledCmds = SyncCommands.All; m_defaultFolder = null; m_defaultFolderColor = null; m_defaultDriveScope = null; m_defaultClientId = string.Empty; m_defaultClientSecret = GdsDefs.PsEmptyEx; m_useLegacyCreds = false; m_isDirty = true; }
public static string SerializeToString(GoogleColor c) { if (c == null) { return(null); } IFormatter formatter = new BinaryFormatter() { Binder = new GoogleColor.Binder(), }; MemoryStream ms = new MemoryStream(); using (ms) { formatter.Serialize(ms, c); return(MemUtil.ByteArrayToHexString(ms.ToArray())); } }
public ConfigurationForm(ConfigurationFormData data) { InitializeComponent(); EnsureCheckEnabledGroupBox(m_chkDefaultUseLegacyCreds, m_grpDriveAuthDefaults); EnsureCheckEnabledGroupBox(m_chkUseLegacyCreds, m_grpDriveAuth); Text = GdsDefs.ProductName; DatabaseFilePath = string.Empty; m_lblAboutVer.Text = GdsDefs.Version; m_lblAboutProd.Text = GdsDefs.ProductAttributedTitle; m_lblCopyright.Text = Assembly .GetAssembly(typeof(ConfigurationForm)) .GetCustomAttribute <AssemblyCopyrightAttribute>() .Copyright; // Localize the form Control[] textCx = new Control[] { m_lnkGoogle, m_lnkHelp, m_lnkHome, m_lnkPrivacy, m_lnkGoogle2, m_lnkHelp2, m_tabGSignIn, m_tabOptions, m_tabAbout, m_grpEntry, m_grpDriveAuth, m_lblAccount, m_lblClientId, m_lblClientSecret, m_chkDriveScope, m_chkLegacyClientId, m_grpDriveOptions, m_lblHintFolder, m_lblFolder, m_btnCancel, m_btnOK, m_grpCmdEnabled, m_chkSyncEnabled, m_chkUploadEnabled, m_chkDownloadEnabled, m_grpAutoSync, m_chkSyncOnOpen, m_chkSyncOnSave, m_lblDefaultClientId, m_lblDefaultClientSecret, m_chkDefaultDriveScope, m_chkDefaultLegacyClientId, m_grpFolderDefaults, m_lblHintDefaultFolder, m_lblDefaultFolderLabel, m_lblDefFolderColor, m_btnGetColors, m_lblAttribution, m_chkDefaultUseLegacyCreds, m_chkUseLegacyCreds, }; foreach (Control c in textCx) { c.Text = Resources.GetString(c.Text); } m_data = data; // Wire events and such for the folder color picker. m_nullColor = new GoogleColor(m_cbColors.BackColor, GoogleColor.Default.Name); m_cbColors.DrawMode = DrawMode.OwnerDrawVariable; m_cbColors.DrawItem += HandleColorsDrawItem; m_btnGetColors.Click += HandleColorsComboLazyLoad; m_cbColors.SelectedIndexChanged += HandleColorsSelectedIndexChanged; if (m_data.DefaultAppFolderColor == null || m_data.DefaultAppFolderColor == GoogleColor.Default) { m_cbColors.Items.Add(m_nullColor); m_cbColors.SelectedIndex = 0; m_cbColors.Enabled = false; } else { GoogleColor[] userColors = new[] { m_nullColor, new GoogleColor(m_data.DefaultAppFolderColor.Color, m_data.DefaultAppFolderColor.Name) }; m_cbColors.Items.Clear(); m_cbColors.Items.AddRange(userColors); m_cbColors.SelectedItem = userColors[1]; m_cbColors.Enabled = string.IsNullOrWhiteSpace(m_txtFolderDefault.Text); } m_btnGetColors.Enabled = string.IsNullOrWhiteSpace(m_txtFolderDefault.Text); m_bColorsQueried = false; }
public static PluginConfig InitDefault(IPluginHost host) { PluginConfig update = new PluginConfig(); string cmds = host.GetConfig(GdsDefs.ConfigEnabledCmds, ((int)SyncCommands.All).ToString( NumberFormatInfo.InvariantInfo)); int cmdsAsInt; if (!int.TryParse(cmds, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out cmdsAsInt)) { cmdsAsInt = (int)SyncCommands.All; } update.EnabledCommands = (SyncCommands)cmdsAsInt; string syncOption = host.GetConfig(GdsDefs.ConfigAutoSync, AutoSyncMode.DISABLED.ToString()); AutoSyncMode mode; if (!Enum.TryParse(syncOption, out mode)) { // Support obsolete Sync on Save confg. if (host.GetConfig(GdsDefs.ConfigAutoSync, false)) { mode = AutoSyncMode.SAVE; } else { mode = AutoSyncMode.DISABLED; } } update.AutoSync = mode; update.Folder = host.GetConfig(GdsDefs.ConfigDefaultAppFolder, string.Empty); string encodedColor = host.GetConfig( GdsDefs.ConfigDefaultAppFolderColor); update.FolderColor = !string.IsNullOrEmpty(encodedColor) ? GoogleColor.DeserializeFromString(encodedColor) : null; update.LegacyDriveScope = host.GetConfig(GdsDefs.ConfigDriveScope, DriveService.Scope.Drive); // Default is no OAuth 2.0 credentials. update.PersonalClientId = host.GetConfig(GdsDefs.ConfigDefaultClientId, string.Empty); string secretVal = host.GetConfig(GdsDefs.ConfigDefaultClientSecret, string.Empty); update.PersonalClientSecret = new ProtectedString(true, secretVal); // Config version updates to occur up front. if (GetVersion(host) < new Version(Ver1)) { // Update the config with the new default "use new app creds". update.m_isDirty = true; } else { update.m_isDirty = false; } update.UpdateConfig(host); Default = update; return(Default); }