-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTools.cs
55 lines (45 loc) · 1.21 KB
/
Tools.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
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System;
namespace CTRMovieInjector
{
public static class Tools
{
public static int RunCommand(string executableName, string arguments, string workingDirectory)
{
using (Process p = new Process())
{
p.StartInfo.FileName = executableName;
p.StartInfo.Arguments = arguments;
p.StartInfo.WorkingDirectory = workingDirectory;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();
return p.ExitCode;
}
}
}
public static class Extensions
{
public static string Hex(this IEnumerable<byte> b) =>
b.Aggregate("", (current, t) => current + t.ToString("X2"));
private static T[] Reverse<T>(this T[] input)
{
T[] output = (T[])input.Clone();
Array.Reverse(output);
return output;
}
public static byte[] ToBytes(this string hex, bool bigEndian = false)
{
int numberChars = hex.Length;
byte[] bytes = new byte[numberChars / 2];
for (int i = 0; i < numberChars; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bigEndian && BitConverter.IsLittleEndian ? bytes.Reverse() : bytes;
}
}
}