Skip to content

Commit

Permalink
Fix crashing when osu!.db cannot be found.
Browse files Browse the repository at this point in the history
StreamCompanion will still use its cache as beatmap data source.
  • Loading branch information
Piotrekol committed Oct 22, 2016
1 parent c4eba6e commit a233e90
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,22 @@ public void Start(ILogger logger)
new System.Threading.Thread(() =>
{
string osudb = Path.Combine(_settingsHandle.Get<string>(_names.MainOsuDirectory), "osu!.db");
string newOsuFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
@"Files", "osu!.db");
if (File.Exists(osudb))
{
string newOsuFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
@"Files", "osu!.db");

if (File.Exists(newOsuFile))
File.Delete(newOsuFile);
if (File.Exists(newOsuFile))
File.Delete(newOsuFile);

File.Copy(osudb, newOsuFile);
_osuDatabaseLoader.LoadDatabase(newOsuFile);
File.Delete(newOsuFile);
File.Copy(osudb, newOsuFile);
_osuDatabaseLoader.LoadDatabase(newOsuFile);
File.Delete(newOsuFile);
}
else
{
_mainWindowHandle.BeatmapsLoaded = "Could not locate osu!.db";
}
}).Start();
}

Expand Down
36 changes: 24 additions & 12 deletions osu!StreamCompanion/Code/Modules/osuPathReslover/osuPathResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ public void Start(ILogger logger)
if (LoadOsuDir() == "" || !Directory.Exists(LoadOsuDir()))
{
string osuRunningDir = GetRunningOsuDir();
SaveOsuDir(osuRunningDir);
if (Directory.Exists(osuRunningDir))
SaveOsuDir(osuRunningDir);
else
{
SaveOsuDir(GetManualOsuDir());
}
}
}
public void SetSettingsHandle(Settings settings)
Expand Down Expand Up @@ -129,22 +134,29 @@ public string GetRunningOsuDir()
}
return string.Empty;
}
string GetManualOsuDir()
private string GetManualOsuDir()
{
var directory = SelectDirectory("Where is your osu! folder located at?");

if (directory == string.Empty || File.Exists(directory + @"\osu!.db"))
{
return directory;
}
MessageBox.Show(@"This isn't osu! folder", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return string.Empty;
}

private string SelectDirectory(string text)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
//set description and base folder for browsing
var description = "Where is your osu! folder located at?";
dialog.ShowNewFolderButton = false;
dialog.Description = description;
dialog.RootFolder = Environment.SpecialFolder.MyComputer;

if (dialog.ShowDialog() == DialogResult.OK)
dialog.ShowNewFolderButton = true;
dialog.Description = text;
dialog.RootFolder = Environment.SpecialFolder.MyComputer;
if (dialog.ShowDialog() == DialogResult.OK && Directory.Exists((dialog.SelectedPath)))
{
if (File.Exists(dialog.SelectedPath + @"\osu!.db"))
{
return dialog.SelectedPath;
}
MessageBox.Show(@"This isn't osu! folder", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return dialog.SelectedPath;
}
return string.Empty;
}
Expand Down

0 comments on commit a233e90

Please sign in to comment.