/// <summary> /// The initializer for this ShellComponent. /// </summary> /// <param name="lifetime"> /// The lifetime for this object. /// </param> public void Init(JB::JetBrains.DataFlow.Lifetime lifetime) { RegistryUtils registryUtils = new RegistryUtils(); DateTime initializationDate = Convert.ToDateTime(registryUtils.CUGetValue("LastInitializationDate")); string todayAsString = DateTime.Today.ToString("yyyy-MM-dd"); string value = registryUtils.LMGetValue("InstallDate") as string; DateTime lastInstalledDate; try { lastInstalledDate = Convert.ToDateTime(value); // If the installer stored a date that has now been read back in and seems to be in the future // then use the LocalUserInstallDate value. if (lastInstalledDate > DateTime.Today) { lastInstalledDate = GetInstallDateFromLocalUserRegistry(registryUtils, todayAsString); } } catch (FormatException ex) { // In some locales the installer saves the date in a format we can't parse back out. // Use today as the installed date and store it in the HKCU key. lastInstalledDate = GetInstallDateFromLocalUserRegistry(registryUtils, todayAsString); } if (registryUtils.CUGetValue("LastInitializationDate") == null || initializationDate < lastInstalledDate) { SettingsStore settingsStore = Shell.Instance.GetComponent <SettingsStore>(); IContextBoundSettingsStoreLive settings = settingsStore.BindToContextLive(lifetime, ContextRange.ApplicationWide); bool checkReSharperCodeStyleOptionsAtStartUp = settings.GetValue((StyleCopOptionsSettingsKey key) => key.CheckReSharperCodeStyleOptionsAtStartUp); if (checkReSharperCodeStyleOptionsAtStartUp) { if (!StyleCopOptionsPage.CodeStyleOptionsValid(settings)) { DialogResult result = MessageBox.Show( @"Your ReSharper code style settings are not completely compatible with StyleCop. Would you like to reset them now?", @"StyleCop", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { StyleCopOptionsPage.CodeStyleOptionsReset(settings); } } } } registryUtils.CUSetValue("LastInitializationDate", todayAsString); }
/// <summary> /// The initializer for this ShellComponent. /// </summary> /// <param name="lifetime"> /// The lifetime for this object. /// </param> public void Init(JetBrains.DataFlow.Lifetime lifetime) { RegistryUtils registryUtils = new RegistryUtils(); object oneTimeInitializationRequiredRegistryKey = registryUtils.CUGetValue("LastInitializationDate"); DateTime initializationDate = Convert.ToDateTime(oneTimeInitializationRequiredRegistryKey); string todayAsString = DateTime.Today.ToString("yyyy-MM-dd"); string value = registryUtils.LMGetValue("InstallDate") as string; DateTime lastInstalledDate; try { lastInstalledDate = Convert.ToDateTime(value); // If the installer stored a date that has now been read back in and seems to be in the future // then use the LocalUserInstallDate value. if (lastInstalledDate > DateTime.Today) { lastInstalledDate = GetInstallDateFromLocalUserRegistry(registryUtils, todayAsString); } } catch (FormatException ex) { // In some locales the installer saves the date in a format we can't parse back out. // Use today as the installed date and store it in the HKCU key. lastInstalledDate = GetInstallDateFromLocalUserRegistry(registryUtils, todayAsString); } if (oneTimeInitializationRequiredRegistryKey == null || initializationDate < lastInstalledDate) { SettingsStore settingsStore = Shell.Instance.GetComponent<SettingsStore>(); IContextBoundSettingsStoreLive settings = settingsStore.BindToContextLive(lifetime, ContextRange.ApplicationWide); bool checkReSharperCodeStyleOptionsAtStartUp = settings.GetValue((StyleCopOptionsSettingsKey key) => key.CheckReSharperCodeStyleOptionsAtStartUp); if (checkReSharperCodeStyleOptionsAtStartUp) { if (!StyleCopOptionsPage.CodeStyleOptionsValid(settings)) { DialogResult result = MessageBox.Show( @"Your ReSharper code style settings are not completely compatible with StyleCop. Would you like to reset them now?", @"StyleCop", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { StyleCopOptionsPage.CodeStyleOptionsReset(settings); } } } } registryUtils.CUSetValue("LastInitializationDate", todayAsString); }
/// <summary> /// Initializes our ShellComponent. /// </summary> public void Init() { StyleCopReferenceHelper.EnsureStyleCopIsLoaded(); RegistryUtils registryUtils = new RegistryUtils(); object oneTimeInitializationRequiredRegistryKey = registryUtils.CUGetValue("LastInitializationDate"); DateTime initializationDate = Convert.ToDateTime(oneTimeInitializationRequiredRegistryKey); string todayAsString = DateTime.Today.ToString("yyyy-MM-dd"); string value = registryUtils.LMGetValue("InstallDate") as string; DateTime lastInstalledDate; try { lastInstalledDate = Convert.ToDateTime(value); // If the installer stored a date that has now been read back in and seems to be in the future // then use the LocalUserInstallDate value. if (lastInstalledDate > DateTime.Today) { lastInstalledDate = GetInstallDateFromLocalUserRegistry(registryUtils, todayAsString); } } catch (FormatException ex) { // In some locales the installer saves the date in a format we can't parse back out. // Use today as the installed date and store it in the HKCU key. lastInstalledDate = GetInstallDateFromLocalUserRegistry(registryUtils, todayAsString); } if (oneTimeInitializationRequiredRegistryKey == null || initializationDate < lastInstalledDate) { if (!StyleCopOptionsPage.CodeStyleOptionsValid(null)) { DialogResult result = MessageBox.Show( @"Your ReSharper code style settings are not completely compatible with StyleCop. Would you like to reset them now?", @"StyleCop", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { StyleCopOptionsPage.ResetCodeStyleOptions(null); } } registryUtils.CUSetValue("LastInitializationDate", todayAsString); } }
/// <summary> /// Loads the InstallDate registry key value. /// </summary> /// <param name="registryUtils"> /// A <see cref="RegistryUtils"/> instance to access the registry. /// </param> /// <param name="defaultDateAsString"> /// The date to set the install date to if its value is not found in the registry. /// </param> /// <returns> /// The DateTime of the InstallDate LOCALUSER registry key. /// </returns> private static DateTime GetInstallDateFromLocalUserRegistry(RegistryUtils registryUtils, string defaultDateAsString) { string installDateRegistryKey = registryUtils.CUGetValue("InstallDate") as string; if (installDateRegistryKey != null) { return(Convert.ToDateTime(installDateRegistryKey)); } registryUtils.CUSetValue("InstallDate", defaultDateAsString); return(Convert.ToDateTime(defaultDateAsString)); }
/// <summary> /// Loads the InstallDate registry key value. /// </summary> /// <param name="registryUtils"> /// A <see cref="RegistryUtils"/> instance to access the registry. /// </param> /// <param name="defaultDateAsString"> /// The date to set the install date to if its value is not found in the registry. /// </param> /// <returns> /// The DateTime of the InstallDate LOCALUSER registry key. /// </returns> private static DateTime GetInstallDateFromLocalUserRegistry(RegistryUtils registryUtils, string defaultDateAsString) { string installDateRegistryKey = registryUtils.CUGetValue("InstallDate") as string; if (installDateRegistryKey != null) { return Convert.ToDateTime(installDateRegistryKey); } registryUtils.CUSetValue("InstallDate", defaultDateAsString); return Convert.ToDateTime(defaultDateAsString); }