internal static bool TryParseStatusFile(string statusFilePath, out ParsedStatus result) { if (!TryReadFile(statusFilePath, out string?fileContents)) { // Between the time that we get an ID and the time that we try to read the associated stat // file(s), the process could be gone. result = default(ParsedStatus); return(false); } ParsedStatus results = default(ParsedStatus); foreach (ReadOnlySpan <char> line in fileContents.AsSpan().EnumerateLines()) { int startIndex = line.IndexOf(':'); if (startIndex == -1) { break; } ReadOnlySpan <char> name = line.Slice(0, startIndex); ReadOnlySpan <char> value = line.Slice(startIndex + 1); bool valueParsed = true; #if DEBUG if (name.SequenceEqual("Pid")) { valueParsed = int.TryParse(value, out results.Pid); } else #endif if (name.SequenceEqual("VmHWM")) { valueParsed = ulong.TryParse(value[..^ 3], out results.VmHWM);
private void OnParsedStatus(ParsedStatus parsedStatus) { if (parsedStatus != ParsedStatus.Done) { return; } var mP = _mediaService?.MediaPlayer; // Get chapters GetChapters(); // Get subtitle delay etc if (mP != null) { SetAudioDelay(mP.audioDelay()); SetSpuDelay(mP.spuDelay()); } if (_mediaService.MediaPlayer == null) { return; } SetPlaybackTypeFromTracks(); Playback_MediaParsed?.Invoke(parsedStatus); }
private async void Playback_MediaParsed(ParsedStatus parsedStatus) { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => { OnPropertyChanged(nameof(Chapters)); OnPropertyChanged(nameof(CurrentChapter)); }); }
internal static bool TryReadStatusFile(int pid, out ParsedStatus result, ReusableTextReader reusableReader) { var isParsed = TryParseStatusFile(GetStatusFilePathForProcess(pid), out result, reusableReader); Debug.Assert(!isParsed || result.Pid == pid, "Expected process ID from status file to match supplied pid"); return(isParsed); }
internal static bool TryParseStatusFile(string statusFilePath, out ParsedStatus result, ReusableTextReader reusableReader) { string statusFileContents; try { using (var source = new FileStream(statusFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, 1, false)) { statusFileContents = reusableReader.ReadAllText(source); } } catch (IOException) { // Between the time that we get an ID and the time that we try to read the associated stat // file(s), the process could be gone. result = default; return(false); } var results = default(ParsedStatus); var dict = statusFileContents.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .Select(_ => ToKeyValue(_, ':')) .ToDictionary(_ => _.Key, _ => _.Value.Trim(' ', '\t')); results.Name = dict.GetValueOrDefault("Name", string.Empty); results.State = dict.GetValueOrDefault("State", " ")[0]; results.Ppid = int.Parse(dict.GetValueOrDefault("PPid", DefaultId)); results.Pid = int.Parse(dict.GetValueOrDefault("Pid", DefaultId)); var uids = dict.GetValueOrDefault("Uid", string.Empty).Split('\t'); if (uids.Length >= 2) { results.Ruid = int.Parse(uids[0]); results.Euid = int.Parse(uids[1]); } else { results.Ruid = results.Euid = -1; } var gids = dict.GetValueOrDefault("Gid", string.Empty).Split('\t'); if (gids.Length >= 2) { results.Rgid = int.Parse(gids[0]); results.Egid = int.Parse(gids[1]); } else { results.Ruid = results.Euid = -1; } result = results; return(true); }
internal static bool TryReadStatusFile(int pid, out ParsedStatus result) { bool b = TryParseStatusFile(GetStatusFilePathForProcess(pid), out result); #if DEBUG Debug.Assert(!b || result.Pid == pid, "Expected process ID from status file to match supplied pid"); #endif return(b); }
private void OnParsedStatus(ParsedStatus parsedStatus) { if (parsedStatus != ParsedStatus.Done) { return; } // Get chapters GetChapters(); Playback_MediaParsed?.Invoke(parsedStatus); }
/// <summary> /// Increment respective count /// </summary> /// <param name="status">Parsing status</param> public void AddByStatus(ParsedStatus status) { switch (status) { case ParsedStatus.None: break; case ParsedStatus.Success: AddSucess(); break; case ParsedStatus.WithErrors: AddWithErrors(); break; case ParsedStatus.NotParsed: AddNotParsed(); break; } }
/// <summary> /// Increment respective count /// </summary> /// <param name="status">Parsing status</param> public void AddByStatus(ParsedStatus status) { switch (status) { case ParsedStatus.None: break; case ParsedStatus.Success: AddSuccess(); break; case ParsedStatus.WithErrors: AddWithErrors(); break; case ParsedStatus.NotParsed: AddNotParsed(); break; case ParsedStatus.NoStructure: AddNoStructure(); break; } }
internal static bool TryParseStatusFile(string statusFilePath, out ParsedStatus result) { if (!TryReadFile(statusFilePath, out string?fileContents)) { // Between the time that we get an ID and the time that we try to read the associated stat // file(s), the process could be gone. result = default(ParsedStatus); return(false); } ParsedStatus results = default(ParsedStatus); ReadOnlySpan <char> statusFileContents = fileContents.AsSpan(); int unitSliceLength = -1; #if DEBUG int nonUnitSliceLength = -1; #endif while (!statusFileContents.IsEmpty) { int startIndex = statusFileContents.IndexOf(':'); if (startIndex == -1) { // Reached end of file break; } ReadOnlySpan <char> title = statusFileContents.Slice(0, startIndex); statusFileContents = statusFileContents.Slice(startIndex + 1); int endIndex = statusFileContents.IndexOf('\n'); if (endIndex == -1) { endIndex = statusFileContents.Length - 1; unitSliceLength = statusFileContents.Length - 3; #if DEBUG nonUnitSliceLength = statusFileContents.Length; #endif } else { unitSliceLength = endIndex - 3; #if DEBUG nonUnitSliceLength = endIndex; #endif } ReadOnlySpan <char> value = default; bool valueParsed = true; #if DEBUG if (title.SequenceEqual("Pid".AsSpan())) { value = statusFileContents.Slice(0, nonUnitSliceLength); valueParsed = int.TryParse(value, out results.Pid); } #endif if (title.SequenceEqual("VmHWM".AsSpan())) { value = statusFileContents.Slice(0, unitSliceLength); valueParsed = ulong.TryParse(value, out results.VmHWM); } else if (title.SequenceEqual("VmRSS".AsSpan())) { value = statusFileContents.Slice(0, unitSliceLength); valueParsed = ulong.TryParse(value, out results.VmRSS); } else if (title.SequenceEqual("VmData".AsSpan())) { value = statusFileContents.Slice(0, unitSliceLength); valueParsed = ulong.TryParse(value, out ulong vmData); results.VmData += vmData; } else if (title.SequenceEqual("VmSwap".AsSpan())) { value = statusFileContents.Slice(0, unitSliceLength); valueParsed = ulong.TryParse(value, out results.VmSwap); } else if (title.SequenceEqual("VmSize".AsSpan())) { value = statusFileContents.Slice(0, unitSliceLength); valueParsed = ulong.TryParse(value, out results.VmSize); } else if (title.SequenceEqual("VmPeak".AsSpan())) { value = statusFileContents.Slice(0, unitSliceLength); valueParsed = ulong.TryParse(value, out results.VmPeak); } else if (title.SequenceEqual("VmStk".AsSpan())) { value = statusFileContents.Slice(0, unitSliceLength); valueParsed = ulong.TryParse(value, out ulong vmStack); results.VmData += vmStack; } Debug.Assert(valueParsed); statusFileContents = statusFileContents.Slice(endIndex + 1); } results.VmData *= 1024; results.VmPeak *= 1024; results.VmSize *= 1024; results.VmSwap *= 1024; results.VmRSS *= 1024; results.VmHWM *= 1024; result = results; return(true); }