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 ;
147using Rdmp . Core . Icons . IconProvision ;
158using Rdmp . Core . ReusableLibraryCode . Checks ;
169using Rdmp . Core . ReusableLibraryCode . Settings ;
2114using Rdmp . UI . Versioning ;
2215using SixLabors . ImageSharp ;
2316using 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 ;
2426using WideMessageBox = Rdmp . UI . SimpleDialogs . WideMessageBox ;
2527
2628namespace 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