forked from File-New-Project/EarTrumpet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SnapshotData.cs
102 lines (96 loc) · 3.92 KB
/
SnapshotData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using EarTrumpet.DataModel;
using EarTrumpet.Extensibility.Hosting;
using EarTrumpet.Interop;
using EarTrumpet.Interop.Helpers;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
namespace EarTrumpet.Diagnosis
{
class SnapshotData
{
public static string InvokeNoThrow(Func<object> func)
{
try
{
return $"{func()}";
}
catch (Exception ex)
{
return $"{ex}";
}
}
public static Dictionary<string, Func<object>> App
{
get
{
return new Dictionary<string, Func<object>>
{
{ "version", () => EarTrumpet.App.PackageVersion.ToString() },
{ "runtimeMinutes", () => (int)EarTrumpet.App.Duration.TotalMinutes },
{ "gdiObjects", () => User32.GetGuiResources(Kernel32.GetCurrentProcess(), User32.GR_FLAGS.GR_GDIOBJECTS) },
{ "userObjects", () => User32.GetGuiResources(Kernel32.GetCurrentProcess(), User32.GR_FLAGS.GR_USEROBJECTS) },
{ "globalGdiObjects", () => User32.GetGuiResources(User32.GR_GLOBAL, User32.GR_FLAGS.GR_USEROBJECTS) },
{ "globalUserObjects", () => User32.GetGuiResources(User32.GR_GLOBAL, User32.GR_FLAGS.GR_USEROBJECTS) },
{ "handleCount", () => GetProcessHandleCount() },
#if DEBUG
{ "releaseStage", () => "development" },
#else
{ "releaseStage", () => "production" },
#endif
};
}
}
public static Dictionary<string, Func<object>> Device
{
get
{
return new Dictionary<string, Func<object>>
{
{ "osVersionBuild", () => SystemSettings.BuildLabel },
{ "osArchitecture", () => Environment.Is64BitOperatingSystem ? "64 bit" : "32 bit" },
{ "processorCount", () => Environment.ProcessorCount + " core(s)" },
};
}
}
public static Dictionary<string, Func<object>> AppSettings
{
get
{
return new Dictionary<string, Func<object>>
{
{ "IsLightTheme", () => SystemSettings.IsLightTheme },
{ "IsSystemLightTheme", () => SystemSettings.IsSystemLightTheme },
{ "IsRTL", () => SystemSettings.IsRTL },
{ "IsTransparencyEnabled", () => SystemSettings.IsTransparencyEnabled },
{ "UseAccentColor", () => SystemSettings.UseAccentColor },
{ "AnimationsEnabled", () => SystemParameters.MenuAnimation },
{ "IsHighContrast", () => SystemParameters.HighContrast },
{ "HasIdentity", () => EarTrumpet.App.HasIdentity },
{ "IsShuttingDown", () => EarTrumpet.App.IsShuttingDown },
{ "Culture", () => CultureInfo.CurrentCulture.Name },
{ "CurrentUICulture", () => CultureInfo.CurrentUICulture.Name },
};
}
}
public static Dictionary<string, Func<object>> LocalOnly
{
get
{
return new Dictionary<string, Func<object>>
{
{ "systemDpi", () => User32.GetDpiForSystem() },
{ "taskbarDpi", () => WindowsTaskbar.Dpi },
{ "addons", () => AddonManager.GetDiagnosticInfo() },
{ "region", () => new RegionInfo(CultureInfo.CurrentCulture.LCID).TwoLetterISORegionName }
};
}
}
private static uint GetProcessHandleCount()
{
Kernel32.GetProcessHandleCount(Kernel32.GetCurrentProcess(), out uint handleCount);
return handleCount;
}
}
}