Skip to content

Commit f7ca39e

Browse files
authored
Copy existing User configuration when installing a new RDMP version (#2276)
* correct startup location * tidy up * codeql update * use correct order
1 parent 353ba16 commit f7ca39e

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [9.1.2] - Unreleased
8+
- Automatically fetch user settings from previous versions of RDMP when installing the latest version
89
- Allow new columns to be added to archive extractions
910
- Simplify use of Extraction Progress
1011

Rdmp.UI/TestsAndSetup/StartupUI.cs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
55
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
66

7-
using System;
8-
using System.ComponentModel;
9-
using System.Linq;
10-
using System.Reflection;
11-
using System.Text.RegularExpressions;
12-
using System.Threading.Tasks;
13-
using System.Windows.Forms;
147
using Rdmp.Core.Icons.IconProvision;
158
using Rdmp.Core.ReusableLibraryCode.Checks;
169
using Rdmp.Core.ReusableLibraryCode.Settings;
@@ -21,6 +14,15 @@
2114
using Rdmp.UI.Versioning;
2215
using SixLabors.ImageSharp;
2316
using SixLabors.ImageSharp.PixelFormats;
17+
using System;
18+
using System.ComponentModel;
19+
using System.IO;
20+
using System.IO.IsolatedStorage;
21+
using System.Linq;
22+
using System.Reflection;
23+
using System.Text.RegularExpressions;
24+
using System.Threading.Tasks;
25+
using System.Windows.Forms;
2426
using WideMessageBox = Rdmp.UI.SimpleDialogs.WideMessageBox;
2527

2628
namespace Rdmp.UI.TestsAndSetup;
@@ -167,6 +169,7 @@ private void StartOrRestart(bool forceClearRepositorySettings)
167169
pbLoadProgress.Maximum = 1000;
168170

169171
if (_startup.RepositoryLocator == null || forceClearRepositorySettings)
172+
{
170173
try
171174
{
172175
lblProgress.Text = "Constructing UserSettingsRepositoryFinder";
@@ -178,7 +181,13 @@ private void StartOrRestart(bool forceClearRepositorySettings)
178181
lblProgress.Text = "Constructing UserSettingsRepositoryFinder Failed";
179182
ragSmiley1.Fatal(ex);
180183
}
181-
184+
if (!forceClearRepositorySettings && (_startup.RepositoryLocator is null || _startup.RepositoryLocator.CatalogueRepository == null))
185+
{
186+
CopyExistingConfigurationToNewApplication();
187+
var finder = new UserSettingsRepositoryFinder();
188+
_startup.RepositoryLocator = finder;
189+
}
190+
}
182191
escapePressed = false;
183192
countDownToClose = 5;
184193
lastStatus = RDMPPlatformDatabaseStatus.Healthy;
@@ -213,6 +222,36 @@ private void StartOrRestart(bool forceClearRepositorySettings)
213222
private ChooseLocalFileSystemLocationUI _chooseLocalFileSystem;
214223
private bool _haveWarnedAboutOutOfDate;
215224

225+
226+
private static DirectoryInfo FindLatestConfig(string isolatedStoragePath)
227+
{
228+
var dirs = Directory.GetDirectories(isolatedStoragePath, "AppFiles", SearchOption.AllDirectories);
229+
var dir = dirs.Select(d => new DirectoryInfo(d))
230+
.OrderByDescending(d => d.LastWriteTime)
231+
.Where(d => d.GetFiles().Any(file => file.Name == "CatalogueConnectionString")).FirstOrDefault();
232+
return dir;
233+
}
234+
235+
private static void CopyExistingConfigurationToNewApplication()
236+
{
237+
var configPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\IsolatedStorage";
238+
var latestConfig = FindLatestConfig(configPath);
239+
if (latestConfig != null)
240+
{
241+
var isolated = IsolatedStorageFile.GetUserStoreForApplication();
242+
foreach (var file in latestConfig.GetFiles().Where(f => !isolated.FileExists(f.Name)))
243+
{
244+
try
245+
{
246+
isolated.CopyFile(file.FullName, file.Name);
247+
}
248+
finally { }
249+
}
250+
}
251+
252+
}
253+
254+
216255
private void HandleDatabaseFoundOnSimpleUI(PlatformDatabaseFoundEventArgs eventArgs)
217256
{
218257
//if status got worse
@@ -275,7 +314,7 @@ private void HandleDatabaseFoundOnSimpleUI(PlatformDatabaseFoundEventArgs eventA
275314
}
276315
else
277316
{
278-
MessageBox.Show("Patching was cancelled. Apply Patch to use the latest version of RDMP. Application will exit.");
317+
MessageBox.Show("Patching was cancelled. Apply Patch to use the latest version of RDMP. Application will exit.");
279318
Environment.Exit(0);
280319
}
281320

0 commit comments

Comments
 (0)