forked from lesteveinix/PsVDecrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.cs
64 lines (57 loc) · 1.9 KB
/
Util.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using PsVDecrypt.Domain;
namespace PsVDecrypt
{
class Util
{
public static void DecryptFile(string srcFile, string dstFile)
{
var stream = new VirtualFileStream(srcFile);
var output = new FileStream(dstFile, FileMode.OpenOrCreate, FileAccess.ReadWrite,
FileShare.None);
output.SetLength(0);
var buffer = stream.ReadAll();
output.Write(buffer, 0, buffer.Length);
output.Close();
}
public static string GetModuleHash(String Name, String AuthorHandle)
{
string s = Name + "|" + AuthorHandle;
using (MD5 md5 = MD5.Create())
return Convert.ToBase64String(md5.ComputeHash(Encoding.UTF8.GetBytes(s))).Replace('/', '_');
}
public static string TitleToFileName(String title)
{
StringBuilder sb = new StringBuilder();
foreach (char c in title)
{
if (c == ' ')
sb.Append('-');
else if (c == '-' || c == '_')
sb.Append('-');
else if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9')
sb.Append(c);
}
return sb.ToString();
}
public static void CreateDirectory(String path)
{
Directory.CreateDirectory(path);
while (!Directory.Exists(path))
System.Threading.Thread.Sleep(200);
}
public static void DeleteDirectory(String path)
{
Directory.Delete(path, true);
while (Directory.Exists(path))
System.Threading.Thread.Sleep(200);
}
}
}