public Task <IMapset> Import(FileInfo file, TaskListener <IMapset> listener = null) { return(Task.Run <IMapset>(async() => { try { // Start importing the file Mapset mapset = await store.Import(file, listener: listener?.CreateSubListener <Mapset>()); if (mapset != null) { // Mapset must be fully loaded. Mapset loadedMapset = store.LoadData(mapset); if (loadedMapset != null) { // Dispatch mapset imported event on main thread. UnityThread.Dispatch(() => { // Add to all mapsets allMapsets.AddOrReplace(loadedMapset); // Reapply filter Search(lastSearch); OnImportMapset?.Invoke(loadedMapset); return null; }); } else { notificationBox?.Add(new Notification() { Message = $"Failed to load imported mapset ({mapset.Metadata.Artist} - {mapset.Metadata.Title})", Type = NotificationType.Error }); } } else { notificationBox?.Add(new Notification() { Message = $"Failed to import mapset at ({file.FullName})", Type = NotificationType.Error }); } listener?.SetFinished(mapset); return mapset; } catch (Exception e) { Logger.LogError($"Error while importing mapset: {e.Message}\n{e.StackTrace}"); listener?.SetFinished(); return null; } })); }
public PrefStorage(string id) { this.id = id; try { json = JsonConvert.DeserializeObject <JObject>(PlayerPrefs.GetString(id, "{}")); } catch (Exception e) { Logger.LogError($"PrefStorage - Failed to parse prefs of id ({id}): {e.Message}"); json = new JObject(); } }
/// <summary> /// Triggers actions on certain system events. /// </summary> private void HookEngine() { // Start listening to any exceptions that occurs during game. AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => { var exception = e.ExceptionObject as Exception; Logger.LogError($"Unhandled exception: {exception.ToString()}"); }; Application.logMessageReceived += (condition, stackTrace, type) => { if (type == LogType.Exception) { Logger.LogError($"Unhandled exception: {condition}\n{stackTrace}"); } }; }
/// <summary> /// Records the specified play record under the current player. /// </summary> public Task <IRecord> RecordScore(IScoreProcessor scoreProcessor, int playTime, TaskListener <IRecord> listener = null) { return(Task.Run <IRecord>(async() => { try { if (scoreProcessor == null || scoreProcessor.JudgeCount <= 0) { listener?.SetFinished(); return null; } // Retrieve user and user stats. var currentMap = currentParameter.Map; var user = UserManager.CurrentUser.Value; var userStats = user.GetStatistics(currentMap.PlayableMode); // Record the play result to records database and user statistics. Record newRecord = new Record(currentMap, user, scoreProcessor, playTime); lastRecord = newRecord; // Retrieve old records for the map and user. var records = await RecordStore.GetTopRecords(currentMap, user, limit: null, listener: listener?.CreateSubListener <List <IRecord> >()); // Save as cleared play. if (scoreProcessor.IsFinished) { RecordStore.SaveRecord(newRecord); var bestRecord = records == null || records.Count == 0 ? null : records[0]; userStats.RecordPlay(newRecord, bestRecord); } // Save as failed play. else { userStats.RecordIncompletePlay(newRecord); } listener?.SetFinished(newRecord); return newRecord; } catch (Exception e) { Logger.LogError($"Error while recording score: {e.Message}\n{e.StackTrace}"); listener?.SetFinished(); return null; } })); }
public override void Decode(StreamReader stream, T result) { SectionType section = SectionType.None; string line; while ((line = stream.ReadLine()) != null) { if (ShouldSkipLine(line)) { continue; } // If found a new section if (line.StartsWith("[", StringComparison.Ordinal) && line.EndsWith("]", StringComparison.Ordinal)) { // Parse the section type string sectionString = line.Substring(1, line.Length - 2); try { section = (SectionType)Enum.Parse(typeof(SectionType), sectionString); } catch (Exception e) { // If an error occurred, throw an exception. section = SectionType.None; throw e; } continue; } try { DecodeLine(result, section, line); } catch (Exception e) { Logger.LogError( $"OsuDecoder.Decode - Failed to decode line: {line}, Error: {e.Message}" ); } } }
public void TestLogger() { LogAssert.ignoreFailingMessages = true; Logger.Log("1"); Logger.LogWarning("2"); Logger.LogError("3"); Logger.OnWarning += (message) => { Logger.Log($"Dispatched warning: {message}"); }; Logger.OnError += (message) => { Logger.Log($"Dispatched error: {message}"); }; Logger.Log("a"); Logger.LogWarning("b"); Logger.LogError("c"); }
/// <summary> /// Event called from deep linker when the path indicates API response. /// </summary> private void OnDeepLinkApi(WebLink link) { if (link.Parameters.TryGetValue("response", out string response)) { try { var bytes = Convert.FromBase64String(response); string decodedResponse = Encoding.UTF8.GetString(bytes); var authResponse = new AuthResponse(new CustomWebResponse() { IsSuccess = true, TextData = decodedResponse }); authResponse.Evaluate(); HandleResponse(authResponse); } catch (Exception e) { // TODO: Log Logger.LogError($"Failed to parse deeplink response: {response}\n{e.ToString()}"); } } }
public void TestDummyLogger() { LogAssert.ignoreFailingMessages = true; var dummy = new DummyLogService(); Logger.Register(dummy); Assert.IsFalse(dummy.LoggedNormal); Assert.IsFalse(dummy.LoggedWarning); Assert.IsFalse(dummy.LoggedError); Logger.Log("AA"); Logger.LogWarning("BB"); try { Logger.LogError("CC"); } catch (Exception) {} Assert.IsTrue(dummy.LoggedNormal); Assert.IsTrue(dummy.LoggedWarning); Assert.IsTrue(dummy.LoggedError); }
public BaseHitObject Parse(string text) { try { string[] splits = text.Split(','); Vector2 pos = new Vector2(ParseUtils.ParseFloat(splits[0]), ParseUtils.ParseFloat(splits[1])); float startTime = ParseUtils.ParseFloat(splits[2]) + offset; HitObjectType type = (HitObjectType)ParseUtils.ParseInt(splits[3]); int comboOffset = (int)(type & HitObjectType.ComboOffset) >> 4; type &= ~HitObjectType.ComboOffset; bool isNewCombo = (int)(type & HitObjectType.NewCombo) != 0; type &= ~HitObjectType.NewCombo; var soundType = (SoundType)ParseUtils.ParseInt(splits[4]); var customSample = new CustomSampleInfo(); // Now parse the actual hit objects. BaseHitObject result = null; // If this object is a hit circle if ((type & HitObjectType.Circle) != 0) { result = CreateCircle(pos, isNewCombo, comboOffset); if (splits.Length > 5) { ParseCustomSample(splits[5], customSample); } } else if ((type & HitObjectType.Slider) != 0) { PathType pathType = PathType.Catmull; float length = 0; string[] pointSplits = splits[5].Split('|'); // Find the number of valid slider node points. int pointCount = 1; foreach (var p in pointSplits) { if (p.Length > 1) { pointCount++; } } // Parse node points var nodePoints = new Vector2[pointCount]; nodePoints[0] = Vector2.zero; int pointIndex = 1; foreach (var p in pointSplits) { // Determine which path type was found. if (p.Length == 1) { switch (p) { case "C": pathType = PathType.Catmull; break; case "B": pathType = PathType.Bezier; break; case "L": pathType = PathType.Linear; break; case "P": pathType = PathType.PerfectCurve; break; } continue; } // Parse point position string[] pointPos = p.Split(':'); nodePoints[pointIndex++] = new Vector2(ParseUtils.ParseFloat(pointPos[0]), ParseUtils.ParseFloat(pointPos[1])) - pos; } // Change perfect curve to linear if certain conditions meet. if (nodePoints.Length == 3 && pathType == PathType.PerfectCurve && IsLinearPerfectCurve(nodePoints)) { pathType = PathType.Linear; } // Parse slider repeat count int repeatCount = ParseUtils.ParseInt(splits[6]); if (repeatCount > 9000) { throw new Exception(); } // Osu file has +1 addition to the actual number of repeats. repeatCount = Math.Max(0, repeatCount - 1); if (splits.Length > 7) { length = Math.Max(0, ParseUtils.ParseFloat(splits[7])); } if (splits.Length > 10) { ParseCustomSample(splits[10], customSample); } // Number of repeats + start(1) + end(1) int nodeCount = repeatCount + 2; // Parse per-node sound samples var nodeCustomSamples = new List <CustomSampleInfo>(); for (int i = 0; i < nodeCount; i++) { nodeCustomSamples.Add(customSample.Clone()); } if (splits.Length > 9 && splits[9].Length > 0) { string[] sets = splits[9].Split('|'); for (int i = 0; i < nodeCount; i++) { if (i >= sets.Length) { break; } ParseCustomSample(sets[i], nodeCustomSamples[i]); } } // Set all nodes' sample types to default. var nodeSampleTypes = new List <SoundType>(); for (int i = 0; i < nodeCount; i++) { nodeSampleTypes.Add(soundType); } // Parse per-node sample types if (splits.Length > 8 && splits[8].Length > 0) { string[] nodeSampleSplits = splits[8].Split('|'); for (int i = 0; i < nodeCount; i++) { if (i > nodeSampleSplits.Length) { break; } nodeSampleTypes[i] = (SoundType)ParseUtils.ParseInt(nodeSampleSplits[i]); } } // Map sample types to custom sample infos. var nodeSamples = new List <List <SoundInfo> >(nodeCount); for (int i = 0; i < nodeCount; i++) { nodeSamples.Add(GetSamples(nodeSampleTypes[i], nodeCustomSamples[i])); } result = CreateSlider(pos, isNewCombo, comboOffset, nodePoints, length, pathType, repeatCount, nodeSamples); // Hit sound for the root slider should be played at the end. result.Samples = nodeSamples[nodeSamples.Count - 1]; } else if ((type & HitObjectType.Spinner) != 0) { float endTime = Math.Max(startTime, ParseUtils.ParseFloat(splits[5]) + offset); result = CreateSpinner(pos, isNewCombo, comboOffset, endTime); if (splits.Length > 6) { ParseCustomSample(splits[6], customSample); } } else if ((type & HitObjectType.Hold) != 0) { float endTime = Math.Max(startTime, ParseUtils.ParseFloat(splits[2] + offset)); // I can understand all others except this, because Hold type only exists for Mania mode. if (splits.Length > 5 && !string.IsNullOrEmpty(splits[5])) { string[] sampleSplits = splits[5].Split(':'); endTime = Math.Max(startTime, ParseUtils.ParseFloat(sampleSplits[0])); ParseCustomSample(string.Join(":", sampleSplits.Skip(1).ToArray()), customSample); } result = CreateHold(pos, isNewCombo, comboOffset, endTime + offset); } if (result == null) { Logger.LogVerbose("HitObjectParser.Parse - Unknown hit object for line: " + text); return(null); } result.StartTime = startTime; if (result.Samples.Count == 0) { result.Samples = GetSamples(soundType, customSample); } isFirstObject = false; return(result); } catch (Exception e) { Logger.LogError($"HitObjectParser.Parse - Failed to parse line: {text}, Error: {e.Message}"); } return(null); }