forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserEnvironmentInformation.cs
83 lines (69 loc) · 2.6 KB
/
UserEnvironmentInformation.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
using System;
using System.Runtime.InteropServices;
using System.Text;
using GitCommands;
using GitExtUtils;
using GitExtUtils.GitUI;
namespace GitUI
{
public static class UserEnvironmentInformation
{
private static bool _alreadySet;
private static bool _dirty;
private static string? _sha;
public static void CopyInformation() => ClipboardUtil.TrySetText(GetInformation());
public static string GetInformation()
{
if (!_alreadySet)
{
throw new InvalidOperationException($"{nameof(Initialise)} must be called first");
}
string? gitVer;
try
{
gitVer = GitVersion.Current?.Full;
}
catch (Exception)
{
gitVer = null;
}
var gitVersionInfo = GetGitVersionInfo(gitVer, GitVersion.LastSupportedVersion, GitVersion.LastRecommendedVersion);
// Build and open FormAbout design to make sure info still looks good if you change this code.
StringBuilder sb = new();
sb.AppendLine($"- Git Extensions {AppSettings.ProductVersion}");
sb.AppendLine($"- Build {_sha}{(_dirty ? " (Dirty)" : "")}");
sb.AppendLine($"- Git {gitVersionInfo}");
sb.AppendLine($"- {Environment.OSVersion}");
sb.AppendLine($"- {RuntimeInformation.FrameworkDescription}");
sb.AppendLine($"- DPI {DpiUtil.DpiX}dpi ({(DpiUtil.ScaleX == 1 ? "no" : $"{Math.Round(DpiUtil.ScaleX * 100)}%")} scaling)");
return sb.ToString();
}
public static string GetGitVersionInfo(string? gitVersion, GitVersion lastSupportedVersion, GitVersion recommendedVersion)
{
if (string.IsNullOrWhiteSpace(gitVersion))
{
return $"- (minimum: {lastSupportedVersion}, recommended: {recommendedVersion})";
}
GitVersion actualVersion = new(gitVersion);
if (actualVersion < lastSupportedVersion)
{
return $"{gitVersion} (minimum: {lastSupportedVersion}, please update!)";
}
if (actualVersion < recommendedVersion)
{
return $"{gitVersion} (recommended: {recommendedVersion} or later)";
}
return gitVersion;
}
public static void Initialise(string sha, bool isDirty)
{
if (_alreadySet)
{
return;
}
_alreadySet = true;
_sha = sha;
_dirty = isDirty;
}
}
}