Unfortunately, at the moment I came to the conclusion that it is impossible to implement automatic reading.
The idea was based on the fact that the catalog
Local Settings\Application Data\"Company"\"Application"\
compare all versions with the current one, open the config file of the previous version and overwrite it as new. This algorithm should be executed once when the application is first launched. The code looks like this:
if (Properties.Settings.Default.CallUpgrade) { Assembly assem = Assembly.GetExecutingAssembly(); AssemblyName assemName = assem.GetName(); Version curver = assemName.Version; DirectoryInfo dir = Directory.GetParent(Application.LocalUserAppDataPath); DirectoryInfo[] dirs = dir.GetDirectories(); if (dirs.Length < 1) return; Version[] vrs = new Version[dirs.Length]; for (int i = 0; i < dirs.Length; i++) vrs[i] = new Version(dirs[i].Name); Array.Sort(vrs); if (vrs[vrs.Length - 1] < curver) { ExeConfigurationFileMap file = new ExeConfigurationFileMap(); file.LocalUserConfigFilename = dir.FullName + "\\" + vrs[vrs.Length - 1].ToString() + "\\user.config"; file.ExeConfigFilename = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath; file.RoamingUserConfigFilename = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming).FilePath; ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.PerUserRoamingAndLocal).SaveAs( dir.ToString() + "\\" + curver.ToString() + "\\user.config"); Properties.Settings.Default.CallUpgrade = false; Properties.Settings.Default.Save(); } }
The algorithm could not be debugged due to the fact that configs ( user.config ) actually do not lie directly in the Application.LocalUserAppDataPath directory, as Microsoft claims, but along certain surrogate paths, for example:
Local Settings\Application Data\"Company"\"Application"_Url_npzl40sahdaapou10uiyprujpbidwoao\version\
and for each copy of the exe-shnik there is a creation of a new similar directory. And this is not saying that when debugging the config is saved in the directory
Local Settings\Application Data\"Company"\"Application"vhost.exe\version\
In general, I feel that users will have to worry about the security of their config themselves. The benefit of maintaining the settings in a separate file is provided by the development.