public Task <int> GetAvailableCount(StableStorage stableStorage) { if (!stableStorage.Exists(database_name)) { return(Task.FromResult(0)); } return(Task.Run(() => { using (var stream = stableStorage.GetStream(database_name)) return readCollections(stream).Count; })); }
public Task ImportFromStableAsync(StableStorage stableStorage) { if (!stableStorage.Exists(database_name)) { // This handles situations like when the user does not have a collections.db file Logger.Log($"No {database_name} available in osu!stable installation", LoggingTarget.Information, LogLevel.Error); return(Task.CompletedTask); } return(Task.Run(async() => { using (var stream = stableStorage.GetStream(database_name)) await Import(stream).ConfigureAwait(false); })); }
private void load(LadderInfo ladder, GameHost host) { StableStorage stable; try { stable = new StableStorage(host as DesktopGameHost); } catch (Exception e) { Logger.Error(e, "Stable installation could not be found; disabling file based IPC"); return; } const string file_ipc_filename = "ipc.txt"; const string file_ipc_state_filename = "ipc-state.txt"; const string file_ipc_scores_filename = "ipc-scores.txt"; const string file_ipc_channel_filename = "ipc-channel.txt"; if (stable.Exists(file_ipc_filename)) { Scheduler.AddDelayed(delegate { try { using (var stream = stable.GetStream(file_ipc_filename)) using (var sr = new StreamReader(stream)) { var beatmapId = int.Parse(sr.ReadLine()); var mods = int.Parse(sr.ReadLine()); if (lastBeatmapId != beatmapId) { lastBeatmapId = beatmapId; var existing = ladder.CurrentMatch.Value?.Round.Value?.Beatmaps.FirstOrDefault(b => b.ID == beatmapId && b.BeatmapInfo != null); if (existing != null) { Beatmap.Value = existing.BeatmapInfo; } else { var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId }); req.Success += b => Beatmap.Value = b.ToBeatmap(Rulesets); API.Queue(req); } } Mods.Value = (LegacyMods)mods; } } catch { // file might be in use. } try { using (var stream = stable.GetStream(file_ipc_channel_filename)) using (var sr = new StreamReader(stream)) { ChatChannel.Value = sr.ReadLine(); } } catch (Exception) { // file might be in use. } try { using (var stream = stable.GetStream(file_ipc_state_filename)) using (var sr = new StreamReader(stream)) { State.Value = (TourneyState)Enum.Parse(typeof(TourneyState), sr.ReadLine()); } } catch (Exception) { // file might be in use. } try { using (var stream = stable.GetStream(file_ipc_scores_filename)) using (var sr = new StreamReader(stream)) { Score1.Value = int.Parse(sr.ReadLine()); Score2.Value = int.Parse(sr.ReadLine()); } } catch (Exception) { // file might be in use. } }, 250, true); } }