1212using System . Windows ;
1313using System . Windows . Input ;
1414
15- namespace DS3Backup
15+ namespace DSBackup
1616{
1717 public class MainWindowViewModel : ViewModel
1818 {
@@ -26,7 +26,15 @@ public class MainWindowViewModel : ViewModel
2626 private static string SETTINGS_DIR = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "DS3Backup" ) ;
2727 private static string SETTINGS_PATH = Path . Combine ( SETTINGS_DIR , "ds3backup.settings" ) ;
2828 private static string SETTINGS_PATH_BAK = SETTINGS_PATH + ".bak" ;
29- private static readonly string SAVES_PATH = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "DarkSoulsIII" ) ;
29+ private static readonly List < string > DEFAULT_PATHS = new List < string > ( ) ;
30+
31+ static MainWindowViewModel ( )
32+ {
33+ DEFAULT_PATHS . Add ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) , "NBGI" , "DarkSouls" ) ) ;
34+ DEFAULT_PATHS . Add ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "DarkSoulsII" ) ) ;
35+ DEFAULT_PATHS . Add ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "DarkSoulsIII" ) ) ;
36+ DEFAULT_PATHS . Add ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) , "NBGI" , "DARK SOULS REMASTERED" ) ) ;
37+ }
3038
3139 #region Commands
3240
@@ -117,16 +125,17 @@ private void Backup()
117125 }
118126
119127 if ( Directory . Exists ( location . Directory ) )
120- foreach ( string saveDirectory in GetSaveDirectories ( SAVES_PATH ) )
128+ foreach ( string saveDirectory in GetSaveDirectories ( location . Directory ) )
121129 Backup ( location , saveDirectory ) ;
122-
123- SaveSettings ( ) ;
124130 }
125131 catch ( Exception ex )
126132 {
127133 location . Accessible = false ;
128134 MessageBox . Show ( "Error making backup. The location that caused the error will show as inaccessible. " + ex . Message , "DS3 Backup" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
129135 }
136+
137+ try { SaveSettings ( ) ; }
138+ catch { }
130139 }
131140
132141 private void Backup ( BackupLocation location , string saveDirectory )
@@ -158,6 +167,21 @@ private void Backup(BackupLocation location, string saveDirectory)
158167 location . LastBackup = modified . Value ;
159168 location . Accessible = true ;
160169 }
170+ else
171+ {
172+ location . LastBackup = modified . Value ;
173+ try
174+ {
175+ string testPath = Path . Combine ( location . Directory , "accessibilityTest.txt" ) ;
176+ File . WriteAllText ( testPath , "DSBackup Accessibility Test" ) ;
177+ location . Accessible = true ;
178+ File . Delete ( testPath ) ;
179+ }
180+ catch
181+ {
182+ location . Accessible = false ;
183+ }
184+ }
161185 }
162186 }
163187
@@ -166,7 +190,9 @@ private IEnumerable<string> GetSaveDirectories(string path)
166190 foreach ( string directory in Directory . GetDirectories ( path ) )
167191 {
168192 string dirName = Path . GetFileName ( directory ) ;
169- if ( dirName . Length == 16 )
193+ if ( dirName . Length == 8 // Dark Souls
194+ || dirName . Length == 16 // Dark Souls 2/3
195+ || dirName . Length == 7 ) // Dark Souls Remastered
170196 yield return directory ;
171197 }
172198 }
@@ -213,7 +239,10 @@ private void SaveSettings()
213239 private void LoadSettings ( )
214240 {
215241 if ( ! File . Exists ( SETTINGS_PATH ) )
216- BackupLocations . Add ( new BackupLocation ( SAVES_PATH ) ) ;
242+ {
243+ foreach ( var defaultPath in DEFAULT_PATHS )
244+ BackupLocations . Add ( new BackupLocation ( defaultPath ) ) ;
245+ }
217246 else
218247 BackupLocations = new ObservableCollection < BackupLocation > ( XmlHelper . FromXML < List < BackupLocation > > ( File . ReadAllText ( SETTINGS_PATH ) ) ) ;
219248 }
0 commit comments