每次我重新编译我的 Windows 应用程序时,我都会更新 AssemblyInfo.cs 中的 AssemblyVersion 和 AssemblyFileVersion。
当我的应用程序加载时,我打电话
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
每次我新编译的应用程序运行时,所有保存的首选项都消失了,应用程序恢复为默认首选项。
知道是什么触发了应用程序失去它的偏好吗?是不是因为我更新了版本号?如果是这样,我该如何解决?
是因为我重新插入了注册表项吗?
会是什么呢?
编辑
首选项在运行的应用程序实例之间加载和保存良好,直到我进行新构建......但无论如何这里是代码:
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;
}
谢谢