forked from brianmiller/phvalheim-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tooling.cs
45 lines (40 loc) · 1.35 KB
/
Tooling.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
using System.Security.Cryptography;
namespace PhValheim.Tooling
{
public class PhValheim
{
//calculate md5 of a local file
public static string getMD5(string filename)
{
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}
}
//copy directory and files recursivley
public static void CloneDirectory(string root, string dest)
{
if (!Directory.Exists(dest))
{
Directory.CreateDirectory(dest);
}
foreach (var directory in Directory.GetDirectories(root))
{
string dirName = Path.GetFileName(directory);
if (!Directory.Exists(Path.Combine(dest, dirName)))
{
Directory.CreateDirectory(Path.Combine(dest, dirName));
}
CloneDirectory(directory, Path.Combine(dest, dirName));
}
foreach (var file in Directory.GetFiles(root))
{
File.Copy(file, Path.Combine(dest, Path.GetFileName(file)), true);
}
}
}
}