This commit is contained in:
TinyHerm committed 2026-11-24 23:40:08 +03:00
commit 1c7a8cf25f
579 files changed
+83196

No files matched your search

+132
View File
@@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using VibranceHud.Capabilities;
using VibranceHud.Licensing;
namespace VibranceHud.Support;
public static class BugReportClient
{
private static readonly TimeSpan Timeout = TimeSpan.FromSeconds(10.0);
public const int MinText = 10;
public const int MaxText = 2000;
public const int MaxContact = 200;
private static string Url => ActivationEndpoint.Origin + "/api/app/bug-report";
public static IReadOnlyDictionary<string, string> Facts(MachineCapabilities caps, OverlayMode overlay, ReassertMeter? meter, string version)
{
return new Dictionary<string, string>
{
["gammaRamp"] = caps.GammaRamp.ToString(),
["elevated"] = (caps.Elevated ? "yes" : "no"),
["hdr"] = (caps.HdrActive ? "on" : "off"),
["gpu"] = caps.Gpu.ToString(),
["driverVibrance"] = (caps.DriverVibrance ? "yes" : "no"),
["monitors"] = caps.MonitorCount.ToString(),
["overlay"] = overlay.ToString(),
["windows"] = Environment.OSVersion.Version.ToString(),
["overlayMode"] = RuntimeFacts.Overlay,
["magInitialized"] = (RuntimeFacts.MagInitialized ? "yes" : "no"),
["screenEffectHeld"] = (RuntimeFacts.ScreenEffectHeld ? "yes" : "no"),
["saturation"] = RuntimeFacts.Saturation.ToString(CultureInfo.InvariantCulture),
["gammaRefusedWhy"] = caps.RefusedWhy.ToString(),
["gammaByDevice"] = DescribeDevices(caps.Devices),
["rampOutcome"] = RuntimeFacts.RampDelivery.ReportValue,
["rampSoftenedStep"] = RuntimeFacts.RampDelivery.Step,
["gdiIcmGammaRange"] = WindowsRampRule.ReadGammaRange()?.ToString() ?? "default",
["exclusiveFullscreenSeen"] = (RuntimeFacts.ExclusiveFullscreenSeen ? "yes" : "no"),
["reassertCount"] = (meter?.Reasserts ?? 0).ToString(CultureInfo.InvariantCulture),
["reassertMaxMs"] = (meter?.MaxMs ?? 0.0).ToString("0.00", CultureInfo.InvariantCulture),
["flavour"] = "store",
["version"] = version ?? string.Empty
};
}
internal static string DescribeDevices(IReadOnlyList<DeviceGamma> devices)
{
if (devices == null || devices.Count == 0)
{
return "none";
}
StringBuilder stringBuilder = new StringBuilder();
foreach (DeviceGamma device in devices)
{
string text = device.Device ?? "";
int num = text.LastIndexOf('\\');
if (num >= 0)
{
text = text.Substring(num + 1);
}
string text2 = text + ":" + device.Result;
if (stringBuilder.Length + ((stringBuilder.Length != 0) ? 1 : 0) + text2.Length > 60)
{
break;
}
if (stringBuilder.Length > 0)
{
stringBuilder.Append(' ');
}
stringBuilder.Append(text2);
}
if (stringBuilder.Length != 0)
{
return stringBuilder.ToString();
}
return "none";
}
public static bool IsEnough(string? text)
{
return (text ?? "").Trim().Length >= 10;
}
public static string BuildBody(string version, string? text, string? contact, IReadOnlyDictionary<string, string> facts)
{
string text2 = (text ?? string.Empty).Trim();
if (text2.Length > 2000)
{
text2 = text2.Substring(0, 2000);
}
string text3 = (contact ?? string.Empty).Trim();
if (text3.Length > 200)
{
text3 = text3.Substring(0, 200);
}
return JsonSerializer.Serialize(new
{
version = (version ?? string.Empty),
text = text2,
contact = ((text3.Length == 0) ? null : text3),
facts = facts
});
}
public static async Task<bool> SendAsync(string body, CancellationToken cancel = default(CancellationToken))
{
try
{
using HttpClient client = new HttpClient
{
Timeout = Timeout
};
client.DefaultRequestHeaders.UserAgent.ParseAdd("PlexusX");
using StringContent content = new StringContent(body, Encoding.UTF8, "application/json");
using HttpResponseMessage httpResponseMessage = await client.PostAsync(Url, content, cancel).ConfigureAwait(continueOnCapturedContext: false);
return httpResponseMessage.IsSuccessStatusCode;
}
catch
{
return false;
}
}
}
+59
View File
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace VibranceHud.Support;
public static class CrashReportOffer
{
public const string Question = "Send this crash report to PlexusX so it can be fixed?\n\nIt holds the error and where it happened. It has no licence key, no account name and no contact details. Nothing is sent unless you press Yes.";
internal const string Heading = "Crash report, sent by the user after a crash.\n";
public static string BuildBody(string logText, string version)
{
string text = CrashLog.Redact(logText ?? string.Empty).Trim();
string text2 = "Crash report, sent by the user after a crash.\n" + text;
Dictionary<string, string> facts = new Dictionary<string, string>
{
["flavour"] = "store",
["version"] = version ?? string.Empty,
["windows"] = SafeWindows()
};
return BugReportClient.BuildBody(version ?? string.Empty, text2, null, facts);
}
public static async Task<bool> OfferAsync(string logPath, string version, Func<bool> userConsents, Func<string, Task<bool>> send)
{
try
{
if (string.IsNullOrEmpty(logPath) || !File.Exists(logPath))
{
return false;
}
if (!userConsents())
{
return false;
}
string arg = BuildBody(File.ReadAllText(logPath), version);
return await send(arg).ConfigureAwait(continueOnCapturedContext: false);
}
catch
{
return false;
}
}
private static string SafeWindows()
{
try
{
return Environment.OSVersion.Version.ToString();
}
catch
{
return "unknown";
}
}
}
+126
View File
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
namespace VibranceHud.Support;
public sealed class ReassertMeter
{
public sealed record LayerStat(int Count, double LastMs, double MaxMs)
{
public static readonly LayerStat Never = new LayerStat(0, 0.0, 0.0);
}
public const string Driver = "driver";
public const string Gamma = "gamma";
public const string Overlay = "overlay";
private readonly Func<long> _ticks;
private readonly double _msPerTick;
private readonly object _gate = new object();
private readonly Dictionary<string, LayerStat> _layers = new Dictionary<string, LayerStat>(StringComparer.Ordinal);
private readonly List<string> _order = new List<string>();
public int Reasserts { get; private set; }
public double LastMs { get; private set; }
public double MaxMs { get; private set; }
public ReassertMeter(Func<long>? ticks = null, long? frequency = null)
{
_ticks = ticks ?? new Func<long>(Stopwatch.GetTimestamp);
long num = frequency ?? Stopwatch.Frequency;
_msPerTick = 1000.0 / (double)((num <= 0) ? 1 : num);
}
public long Now()
{
return _ticks();
}
public double MsSince(long start)
{
double num = (double)(_ticks() - start) * _msPerTick;
if (!(num > 0.0))
{
return 0.0;
}
return num;
}
public void Record(string layer, double ms)
{
if (string.IsNullOrEmpty(layer))
{
return;
}
if (double.IsNaN(ms) || ms < 0.0)
{
ms = 0.0;
}
lock (_gate)
{
if (!_layers.TryGetValue(layer, out LayerStat value))
{
value = LayerStat.Never;
_order.Add(layer);
}
_layers[layer] = new LayerStat(value.Count + 1, ms, Math.Max(value.MaxMs, ms));
}
}
public void Completed(double totalMs)
{
if (double.IsNaN(totalMs) || totalMs < 0.0)
{
totalMs = 0.0;
}
lock (_gate)
{
Reasserts++;
LastMs = totalMs;
if (totalMs > MaxMs)
{
MaxMs = totalMs;
}
}
}
public LayerStat For(string layer)
{
lock (_gate)
{
LayerStat value;
return _layers.TryGetValue(layer, out value) ? value : LayerStat.Never;
}
}
private static string Ms(double ms)
{
return ms.ToString("0.00", CultureInfo.InvariantCulture) + "ms";
}
public string Describe()
{
lock (_gate)
{
List<string> list = new List<string>();
list.Add("reasserts " + Reasserts.ToString(CultureInfo.InvariantCulture) + " last " + Ms(LastMs) + " max " + Ms(MaxMs));
List<string> list2 = list;
foreach (string item in _order)
{
LayerStat layerStat = _layers[item];
list2.Add(" " + item + ": n=" + layerStat.Count.ToString(CultureInfo.InvariantCulture) + " last=" + Ms(layerStat.LastMs) + " max=" + Ms(layerStat.MaxMs));
}
return string.Join(Environment.NewLine, list2);
}
}
}
+90
View File
@@ -0,0 +1,90 @@
using System;
using System.Globalization;
using System.IO;
namespace VibranceHud.Support;
public static class ReassertTrace
{
public sealed record Reading(ReassertMeter? Meter, string OverlayMode, bool MagInitialized, bool ExclusiveFullscreenSeen, DateTime Now, string Version, string Flavour, string Directory, TimeSpan? SessionLength = null);
public const int IntervalMs = 60000;
public const string FileName = "colour-trace.txt";
public static string Text(Reading r)
{
if (r == null)
{
return "(no reading)" + Environment.NewLine;
}
string newLine = Environment.NewLine;
return string.Format(CultureInfo.InvariantCulture, "PlexusX {0} ({1}) {2:yyyy-MM-dd HH:mm:ss}", r.Version ?? "", r.Flavour ?? "", r.Now) + newLine + "overlayMode: " + r.OverlayMode + newLine + "magInitialized: " + YesNo(r.MagInitialized) + newLine + "exclusiveFullscreenSeen: " + YesNo(r.ExclusiveFullscreenSeen) + newLine + Rates(r) + ((r.Meter == null) ? "(no meter)" : r.Meter.Describe()) + newLine;
}
private static string Rates(Reading r)
{
TimeSpan? sessionLength = r.SessionLength;
if (sessionLength.HasValue)
{
TimeSpan valueOrDefault = sessionLength.GetValueOrDefault();
if (!(valueOrDefault.TotalMinutes < 1.0))
{
string newLine = Environment.NewLine;
double totalMinutes = valueOrDefault.TotalMinutes;
string text = "sessionMinutes: " + totalMinutes.ToString("0.0", CultureInfo.InvariantCulture) + newLine;
if (r.Meter == null)
{
return text;
}
text = text + "reassertsPerMinute: " + ((double)r.Meter.Reasserts / totalMinutes).ToString("0.0", CultureInfo.InvariantCulture) + newLine;
string[] array = new string[3] { "driver", "gamma", "overlay" };
foreach (string text2 in array)
{
int count = r.Meter.For(text2).Count;
if (count != 0)
{
text = text + text2 + "WritesPerMinute: " + ((double)count / totalMinutes).ToString("0.0", CultureInfo.InvariantCulture) + newLine;
}
}
return text;
}
}
return "";
}
private static string YesNo(bool value)
{
if (!value)
{
return "no";
}
return "yes";
}
public static void Write(Reading r)
{
try
{
Directory.CreateDirectory(r.Directory);
File.WriteAllText(Path.Combine(r.Directory, "colour-trace.txt"), Text(r));
}
catch
{
}
}
public static void WriteNow(Func<Reading> read)
{
try
{
if (read != null)
{
Write(read());
}
}
catch
{
}
}
}
+91
View File
@@ -0,0 +1,91 @@
namespace VibranceHud.Support;
public static class RuntimeFacts
{
private static OverlayMode _mode = OverlayMode.Mag;
private static bool _effectIsLive;
public static string Overlay => DescribeOverlay(_mode, _effectIsLive);
public static bool MagInitialized
{
get
{
if (_mode == OverlayMode.Mag)
{
return _effectIsLive;
}
return false;
}
}
public static bool ExclusiveFullscreenSeen { get; private set; }
public static bool ScreenEffectHeld { get; internal set; }
public static int Saturation { get; internal set; } = 100;
public static bool DisplayIsCarryingTheLook { get; private set; }
public static string? WhatTheDisplayCannotHold { get; private set; }
public static GammaDelivery RampDelivery { get; private set; } = GammaDelivery.Full;
public static string DescribeOverlay(OverlayMode mode, bool effectIsLive)
{
if (!effectIsLive)
{
return "None";
}
if (mode != OverlayMode.Dx)
{
return "Mag";
}
return "Dx";
}
public static void NoteOverlay(OverlayMode mode, bool effectIsLive)
{
_mode = mode;
_effectIsLive = effectIsLive;
}
public static void NoteRampDelivery(GammaDelivery delivery)
{
RampDelivery = delivery;
}
public static void NoteDisplayOnlyLook(bool carrying, string? cannotHold)
{
DisplayIsCarryingTheLook = carrying;
WhatTheDisplayCannotHold = (carrying ? cannotHold : null);
}
public static void NoteFullscreen(bool seenNow)
{
if (seenNow)
{
ExclusiveFullscreenSeen = true;
}
}
internal static void ForgetTheDisplayCarryForTest()
{
RampDelivery = GammaDelivery.Full;
DisplayIsCarryingTheLook = false;
WhatTheDisplayCannotHold = null;
}
internal static void ResetForTest()
{
_mode = OverlayMode.Mag;
_effectIsLive = false;
ExclusiveFullscreenSeen = false;
ScreenEffectHeld = false;
Saturation = 100;
RampDelivery = GammaDelivery.Full;
DisplayIsCarryingTheLook = false;
WhatTheDisplayCannotHold = null;
}
}
+113
View File
@@ -0,0 +1,113 @@
using System;
using System.Globalization;
using System.IO;
using System.Text;
namespace VibranceHud.Support;
public sealed class ScreenEffectLog
{
internal const int CapBytes = 262144;
internal const int KeepBytes = 131072;
internal const string FileName = "screen-effect.log";
private static readonly Encoding NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
private static readonly ScreenEffectLog Shared = new ScreenEffectLog(null, null);
private readonly object _gate = new object();
private readonly string? _folder;
private readonly Func<DateTime> _utcNow;
private bool? _lastHeld;
internal string Path => System.IO.Path.Combine(_folder ?? System.IO.Path.Combine(AppFolders.Local, "logs"), "screen-effect.log");
internal ScreenEffectLog(string? folder, Func<DateTime>? utcNow)
{
_folder = folder;
_utcNow = utcNow ?? ((Func<DateTime>)(() => DateTime.UtcNow));
}
public static string Line(DateTime utc, bool held, int sat)
{
return utc.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture) + (held ? " held" : " released") + " sat=" + sat.ToString(CultureInfo.InvariantCulture);
}
public static void Note(bool held, int sat)
{
Shared.Record(held, sat);
}
internal void Record(bool held, int sat)
{
try
{
lock (_gate)
{
if (_lastHeld != held)
{
_lastHeld = held;
Append(Line(_utcNow(), held, sat));
}
}
}
catch
{
}
}
private void Append(string line)
{
try
{
string path = Path;
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
FileInfo fileInfo = new FileInfo(path);
if (fileInfo.Exists && fileInfo.Length > 262144)
{
CutToTheTail(path);
}
File.AppendAllText(path, line + "\n", NoBom);
}
catch (Exception)
{
}
}
private static void CutToTheTail(string path)
{
byte[] array;
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
int num = (int)Math.Min(fileStream.Length, 131072L);
array = new byte[num];
fileStream.Seek(-num, SeekOrigin.End);
int i;
int num2;
for (i = 0; i < num; i += num2)
{
num2 = fileStream.Read(array, i, num - i);
if (num2 <= 0)
{
break;
}
}
if (i < num)
{
Array.Resize(ref array, i);
}
}
int num3 = Array.IndexOf(array, (byte)10) + 1;
if (num3 <= 0 || num3 >= array.Length)
{
num3 = 0;
}
using FileStream fileStream2 = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
fileStream2.Write(array, num3, array.Length - num3);
}
}
+74
View File
@@ -0,0 +1,74 @@
using System;
using System.Globalization;
using System.IO;
using System.Text;
namespace VibranceHud.Support;
public sealed class ZoomLog
{
internal const string FileName = "zoom.log";
internal const int CapBytes = 131072;
internal const int KeepBytes = 65536;
private static readonly Encoding NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
private static readonly ZoomLog Shared = new ZoomLog(null, null);
private readonly object _gate = new object();
private readonly string? _folder;
private readonly Func<DateTime> _utcNow;
internal string Path => System.IO.Path.Combine(_folder ?? System.IO.Path.Combine(AppFolders.Local, "logs"), "zoom.log");
internal ZoomLog(string? folder, Func<DateTime>? utcNow)
{
_folder = folder;
_utcNow = utcNow ?? ((Func<DateTime>)(() => DateTime.UtcNow));
}
public static void Note(string what)
{
Shared.Write(what);
}
internal void Write(string what)
{
try
{
lock (_gate)
{
string text = _utcNow().ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture);
string path = Path;
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
FileInfo fileInfo = new FileInfo(path);
if (fileInfo.Exists && fileInfo.Length > 131072)
{
CutToTheTail(path);
}
File.AppendAllText(path, text + " " + what + "\n", NoBom);
}
}
catch
{
}
}
private static void CutToTheTail(string path)
{
byte[] array = File.ReadAllBytes(path);
int num = Math.Min(array.Length, 65536);
int num2 = array.Length - num;
int num3 = Array.IndexOf(array, (byte)10, num2);
if (num3 >= 0 && num3 + 1 < array.Length)
{
num2 = num3 + 1;
}
using FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
fileStream.Write(array, num2, array.Length - num2);
}
}