-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
141 lines (116 loc) · 4.55 KB
/
Copy pathProgram.cs
File metadata and controls
141 lines (116 loc) · 4.55 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using Microsoft.Win32;
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
namespace voiceCopy
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Downloading newest voice over");
DownLoadFileInBackground("http://storage.adamko.tech/voiceover.bnk");
Console.ReadKey();
return;
}
private static string GetDestinationPath()
{
try
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Classes\\.wotreplay\\shell\\open\\command"))
{
if (key != null)
{
Object result = key.GetValue("");
if (result != null)
{
string destPath = result.ToString().Remove(result.ToString().Length - 3).Replace("\"", "")
.Replace("\\win64\\WorldOfTanks.exe", "")
.Trim();
destPath = Path.Combine(destPath, "res_mods");
string temp = destPath;
int i = 0;
//find newest version folder
while (!char.IsDigit(destPath[destPath.Length - 1]))
{
destPath = Path.Combine(temp, new DirectoryInfo(temp).GetDirectories().OrderByDescending(d => d.LastWriteTimeUtc).ElementAt(i).Name).Trim();
i++;
}
destPath = Path.Combine(destPath, "audioww");
Console.WriteLine("Copied to \""+destPath+"\"");
return (string)destPath;
}
else
{
Console.WriteLine("Could not find path (Value of key is null)");
return null;
}
}
else
{
Console.WriteLine("Could not find path (Key not found)");
return null;
}
}
}
catch (Exception ex)
{
Console.WriteLine("Something went wrong with search for WoT game folder path...\n\n" + ex);
return null;
}
}
private static string GetSourcePath() {
string sourceFile = "voiceover.bnk";
return (string)sourceFile;
}
public static void DownLoadFileInBackground(string address)
{
WebClient client = new WebClient();
Uri uri = new Uri(address);
// Specify a DownloadFileCompleted handler here...
// Specify a progress notification handler.
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
client.DownloadFileAsync(uri, "voiceover.bnk");
}
private static void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)
{
Console.Write("\r{0}% downloaded. Progress: {1} KB / {2} KB",
e.ProgressPercentage,
e.BytesReceived / 1024,
e.TotalBytesToReceive / 1024);
if (e.ProgressPercentage == 100)
{
Thread.Sleep(250);
Console.Write("\n");
MoveFile();
}
}
private static void MoveFile()
{
string destPath = GetDestinationPath();
string sourcePath = GetSourcePath();
if (destPath == null)
{
Console.WriteLine("Could not find game folder, budzeš mušel ručne porobic :(");
return;
}
try
{
if (!Directory.Exists(destPath))
Directory.CreateDirectory(destPath);
//copy voiceover
File.Move(sourcePath, Path.Combine(destPath, "voiceover.bnk"), true);
Console.WriteLine("Done :)");
Console.WriteLine("Press any key to close app.");
}
catch (Exception e)
{
Console.WriteLine("Chyba pri kopírovaní: " + e);
}
}
}
}