Каждый раз, когда я перекомпилирую свое приложение для Windows, я обновляю AssemblyVersion и AssemblyFileVersion в AssemblyInfo.cs.Новая Windows C# Build вызывает приложение, чтобы потерять сохраненные настройки
Когда мое приложение загружает, я называю
Microsoft.Win32.RegistryKey key1 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Classes\\MyFileType\\shell\\open\\command", true);
if (key1 == null)
{
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Classes\MyFileType\shell\open\command", null, "\"" + Application.ExecutablePath + "\"" + " \"%1\"");
flag = true;
}
Microsoft.Win32.RegistryKey key2 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Classes\\.abc", true);
if (key2 == null)
{
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Classes\.abc", null, "MyFileType");
flag = true;
}
Microsoft.Win32.RegistryKey key3 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Classes\\MyFileType\\DefaultIcon", true);
if (key3 == null)
{
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Classes\MyFileType\DefaultIcon", "", Application.ExecutablePath + ",2");
flag = true;
}
if (flag) SHChangeNotify(0x08000000, 0x0000, (IntPtr)null, (IntPtr)null);//SHCNE_ASSOCCHANGED SHCNF_IDLIST
Каждый раз, когда работает моя вновь компилируется приложение, все сохраненные настройки исчезли, и приложение возвращается в настройки по умолчанию.
Любая идея, что заставляет приложение потерять свои предпочтения? Это потому, что я обновляю номер версии? Если да, то как мне обойти это?
Это потому, что я вставляю ключи реестра?
Что это может быть?
EDIT
Настройках загрузка и сохранение тонкой между экземплярами приложение работает, пока я не сделать новую сборку ... но вот код все равно:
private void SaveSettings()
{
Properties.Settings.Default.useLastB = this.lastB.Checked;
Properties.Settings.Default.useLast2B = this.last2B.Checked;
Properties.Settings.Default.useLast3B = this.last3B.Checked;
Properties.Settings.Default.useLastSV = this.lastSV.Checked;
Properties.Settings.Default.useLast2SV = this.last2SV.Checked;
Properties.Settings.Default.useLast3SV = this.last3SV.Checked;
Properties.Settings.Default.showAverage = this.averageBox.Checked;
Properties.Settings.Default.showSum = this.sumBox.Checked;
Properties.Settings.Default.showNormalized = this.normalBox.Checked;
Properties.Settings.Default.pessimistic = this.pessimistic.Checked;
Properties.Settings.Default.realistic = this.realistic.Checked;
Properties.Settings.Default.optimistic = this.optimistic.Checked;
Properties.Settings.Default.useAinsley = this.ainsleyBox.Checked;
Properties.Settings.Default.useHandicapper = this.handicapperBox.Checked;
Properties.Settings.Default.useCustom = this.customBox.Checked;
Properties.Settings.Default.UseMorningLine = this.useMLBox.Checked;
Properties.Settings.Default.SolveAllRacesToSingleFile = this.singleFileCheckBox.Checked;
Properties.Settings.Default.Save();
}
private void LoadSettings()
{
Properties.Settings.Default.Reload();
this.lastB.Checked = Properties.Settings.Default.useLastB;
this.last2B.Checked = Properties.Settings.Default.useLast2B;
this.last3B.Checked = Properties.Settings.Default.useLast3B;
this.lastSV.Checked = Properties.Settings.Default.useLastSV;
this.last2SV.Checked = Properties.Settings.Default.useLast2SV;
this.last3SV.Checked = Properties.Settings.Default.useLast3SV;
this.averageBox.Checked = Properties.Settings.Default.showAverage;
this.sumBox.Checked = Properties.Settings.Default.showSum;
this.normalBox.Checked = Properties.Settings.Default.showNormalized;
this.pessimistic.Checked = Properties.Settings.Default.pessimistic;
this.realistic.Checked = Properties.Settings.Default.realistic;
this.optimistic.Checked = Properties.Settings.Default.optimistic;
this.handicapperBox.Checked = Properties.Settings.Default.useHandicapper;
this.ainsleyBox.Checked = Properties.Settings.Default.useAinsley;
this.customBox.Checked = Properties.Settings.Default.useCustom;
this.useMLBox.Checked = Properties.Settings.Default.UseMorningLine;
this.singleFileCheckBox.Checked = Properties.Settings.Default.SolveAllRacesToSingleFile;
}
Благодаря
мммм ... что вы используете, чтобы сохранить настройки? – Hogan
Я добавил сохранение сохранности и загрузку кода в свой первоначальный комментарий. Он отлично работает, пока я не перестрою новую версию. – TonyMLake