forked from dantmnf/MHC2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cs
More file actions
71 lines (66 loc) · 1.8 KB
/
Copy pathUtil.cs
File metadata and controls
71 lines (66 loc) · 1.8 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace MHC2Gen
{
internal ref struct Defer
{
private Action? _deferred;
public Defer(Action deferred)
{
_deferred = deferred;
}
public void Dispose()
{
if (_deferred != null)
{
_deferred();
_deferred = null;
}
}
}
internal class Util
{
[DllImport("kernel32.dll", ExactSpelling = true)]
private static extern IntPtr GetCommandLineW();
public static string GetArgv0()
{
var cmdline = Marshal.PtrToStringUni(GetCommandLineW())!.TrimStart();
string argv0;
if (cmdline.StartsWith("\""))
{
var end = cmdline.IndexOf('"', 1);
argv0 = cmdline.Substring(0, end + 1);
}
else
{
var end = cmdline.IndexOf(' ');
argv0 = end == -1 ? cmdline : cmdline.Substring(0, end);
}
return argv0;
}
}
internal static class ArrayHelper
{
public static bool AllEqual(int[] coll)
{
if (coll == null || coll.Length == 0) return false;
var first = coll[0];
foreach (var item in coll.Skip(1))
{
if (item != first) return false;
}
return true;
}
public static void Broadcast<T>(T[] array, T value)
{
for (var i = 0; i < array.Length; i++)
{
array[i] = value;
}
}
}
}