forked from bloxstraplabs/bloxstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.cs
98 lines (83 loc) · 3.19 KB
/
Utilities.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
using System.ComponentModel;
namespace Bloxstrap
{
static class Utilities
{
public static void ShellExecute(string website)
{
try
{
Process.Start(new ProcessStartInfo
{
FileName = website,
UseShellExecute = true
});
}
catch (Win32Exception ex)
{
// lmfao
if (ex.NativeErrorCode != (int)ErrorCode.CO_E_APPNOTFOUND)
throw;
Process.Start(new ProcessStartInfo
{
FileName = "rundll32.exe",
Arguments = $"shell32,OpenAs_RunDLL {website}"
});
}
}
/// <summary>
///
/// </summary>
/// <param name="versionStr1"></param>
/// <param name="versionStr2"></param>
/// <returns>
/// Result of System.Version.CompareTo <br />
/// -1: version1 < version2 <br />
/// 0: version1 == version2 <br />
/// 1: version1 > version2
/// </returns>
public static VersionComparison CompareVersions(string versionStr1, string versionStr2)
{
try
{
var version1 = new Version(versionStr1.Replace("v", ""));
var version2 = new Version(versionStr2.Replace("v", ""));
return (VersionComparison)version1.CompareTo(version2);
}
catch (Exception)
{
// temporary diagnostic log for the issue described here:
// https://github.com/bloxstraplabs/bloxstrap/issues/3193
// the problem is that this happens only on upgrade, so my only hope of catching this is bug reports following the next release
App.Logger.WriteLine("Utilities::CompareVersions", "An exception occurred when comparing versions");
App.Logger.WriteLine("Utilities::CompareVersions", $"versionStr1={versionStr1} versionStr2={versionStr2}");
throw;
}
}
public static string GetRobloxVersion(bool studio)
{
string fileName = studio ? "Studio/RobloxStudioBeta.exe" : "Player/RobloxPlayerBeta.exe";
string playerLocation = Path.Combine(Paths.Roblox, fileName);
if (!File.Exists(playerLocation))
return "";
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(playerLocation);
if (versionInfo.ProductVersion is null)
return "";
return versionInfo.ProductVersion.Replace(", ", ".");
}
public static Process[] GetProcessesSafe()
{
const string LOG_IDENT = "Utilities::GetProcessesSafe";
try
{
return Process.GetProcesses();
}
catch (ArithmeticException ex) // thanks microsoft
{
App.Logger.WriteLine(LOG_IDENT, $"Unable to fetch processes!");
App.Logger.WriteException(LOG_IDENT, ex);
return Array.Empty<Process>(); // can we retry?
}
}
}
}