Skip to content

Commit

Permalink
try to use fallback save location if location cant be found from conf…
Browse files Browse the repository at this point in the history
…ig file
  • Loading branch information
Chris committed Jan 28, 2017
1 parent 8c8fe17 commit a43ccab
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/GwentTracker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public partial class MainWindow : IViewFor<MainWindowViewModel>
{
public MainWindow()
{
var defaultSavePath = Environment.ExpandEnvironmentVariables((ConfigurationManager.AppSettings["defaultSavePath"]));
var latestSave = GetLatestSave(defaultSavePath);
var savePath = Environment.ExpandEnvironmentVariables((ConfigurationManager.AppSettings["defaultSavePath"]));
var latestSave = GetLatestSave(savePath, out savePath);

if (latestSave == null)
Log.Warning("No save files (*.sav) found in default save path {path}", defaultSavePath);
Log.Warning("No save files (*.sav) found in default save path {path}", savePath);

ViewModel = new MainWindowViewModel(latestSave, ConfigurationManager.AppSettings["texturePath"]);
DataContext = ViewModel;
Expand All @@ -35,14 +35,14 @@ public MainWindow()
FileSystemWatcher watcher = null;
try
{
watcher = new FileSystemWatcher(defaultSavePath, "*.sav")
watcher = new FileSystemWatcher(savePath, "*.sav")
{
EnableRaisingEvents = Settings.Default.AutoLoad,
};
}
catch (Exception e)
{
Log.Error(e, "Unable to watch save game directory {directory} for changes", defaultSavePath);
Log.Error(e, "Unable to watch save game directory {directory} for changes", savePath);
Notify("Unable to watch save game directory for changes");
}
d(this.OneWayBind(ViewModel, vm => vm.Cards, v => v.Cards.ItemsSource));
Expand Down Expand Up @@ -75,12 +75,21 @@ public MainWindow()
InitializeComponent();
}

private string GetLatestSave(string path)
private string GetLatestSave(string path, out string finalPath)
{
finalPath = path;
if (!Directory.Exists(path))
{
Log.Warning("Directory {directory} doesn't exist", path);
return null;
var fallback = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "The Witcher 3", "gamesaves");

if (!Directory.Exists(fallback))
{
Log.Warning("Fallback directory {directory} doesn't exists", fallback);
return null;
}

path = finalPath = fallback;
}

return new DirectoryInfo(path).GetFiles("*.sav")
Expand Down

0 comments on commit a43ccab

Please sign in to comment.