Skip to content

Commit

Permalink
Merge pull request #269 from Founntain/realm-import-crash
Browse files Browse the repository at this point in the history
Fixed Crash during import because of false encoded Folder-Paths
  • Loading branch information
Founntain committed Apr 9, 2024
2 parents b85d51f + 1d6165c commit f8c9419
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion OsuPlayer.IO/DbReader/RealmReader.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using OsuPlayer.Data.DataModels;
using Newtonsoft.Json;
using OsuPlayer.Data.DataModels;
using OsuPlayer.Data.DataModels.Interfaces;
using OsuPlayer.Data.LazerModels.Beatmaps;
using OsuPlayer.Data.LazerModels.Collections;
using OsuPlayer.Data.LazerModels.Files;
using OsuPlayer.Interfaces.Service;
using OsuPlayer.Services;
using Realms;
using Realms.Dynamic;
using Splat;
Expand Down
7 changes: 7 additions & 0 deletions OsuPlayer.IO/Importer/SongImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ await using (var config = new Config())

using var reader = dbReaderFactory.CreateDatabaseReader(path);

if (reader == null)
{
loggingService.Log($"Couldn't create database reader for given path {path}", LogType.Error);

return null;
}

loggingService.Log("Starting beatmap import...");

readMaps = await reader.ReadBeatmaps();
Expand Down
8 changes: 8 additions & 0 deletions OsuPlayer.Services/DbReaderFactory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using OsuPlayer.Data.DataModels;
using OsuPlayer.Data.DataModels.Interfaces;
using OsuPlayer.Data.Enums;
using OsuPlayer.Interfaces.Service;
using OsuPlayer.IO.DbReader;
using Splat;

namespace OsuPlayer.Services;

Expand All @@ -13,6 +15,8 @@ public class DbReaderFactory : OsuPlayerService, IDbReaderFactory

public IDatabaseReader? CreateDatabaseReader(string path)
{
var loggingService = Locator.Current.GetService<ILoggingService>();

switch (Type)
{
case DbCreationType.OsuDb:
Expand All @@ -22,8 +26,12 @@ public class DbReaderFactory : OsuPlayerService, IDbReaderFactory

var file = File.OpenRead(dbLoc);

LogToConsole($"Using osu!.db import for path {path}");

return new OsuDbReader(file, path, this);
case DbCreationType.Realm:
LogToConsole($"Using client.realm importer for path {path}");

return new RealmReader(path, this);
default:
throw new ArgumentOutOfRangeException();
Expand Down
4 changes: 4 additions & 0 deletions OsuPlayer/Views/SettingsView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Web;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
Expand Down Expand Up @@ -74,6 +75,9 @@ public async void ImportSongsClick(object? sender, RoutedEventArgs routedEventAr

var osuFolder = Path.GetDirectoryName(dbFilePath);

// Decode the path, so stuff like %20 are encoded properly
osuFolder = HttpUtility.UrlDecode(osuFolder);

await using (var config = new Config())
{
(await config.ReadAsync()).OsuPath = osuFolder!;
Expand Down

0 comments on commit f8c9419

Please sign in to comment.