internal static void InitializeStorageDir(bool useDropboxPath, bool fromAppStart) { //try from settings _storageDirectory = Settings.Default.DropboxDir; if (useDropboxPath) { if (string.IsNullOrEmpty(_storageDirectory) || !Directory.Exists(_storageDirectory)) { _storageDirectory = DropboxSettings.GetDropboxPath(); if (Directory.Exists(_storageDirectory)) { _storageDirectory = Path.Combine(_storageDirectory, "PersonalWiki"); if (!Directory.Exists(_storageDirectory)) { try { Directory.CreateDirectory(_storageDirectory); } catch (Exception) { } } } } } var shouldSave = false; while (string.IsNullOrEmpty(_storageDirectory) || !Directory.Exists(_storageDirectory)) { var slw = new StorageLocationWindow(); if (slw.ShowDialog().GetValueOrDefault()) { shouldSave = true; _storageDirectory = slw.SelectedPath; if (!Directory.Exists(_storageDirectory)) { try { Directory.CreateDirectory(_storageDirectory); } catch (Exception ex) { shouldSave = false; MessageBox.Show("The directory could not be created because of the following reason.\n\n" + ex.Message); } } } else { if (fromAppStart) { MessageBox.Show("Without a directory to store the files, the application can't run and will exit."); App.Current.Shutdown(); } return; } } if (shouldSave) { try { Settings.Default.DropboxDir = _storageDirectory; Settings.Default.Save(); } catch (Exception) { } } }