-
Notifications
You must be signed in to change notification settings - Fork 1
/
TelemetryInstaller.cs
81 lines (70 loc) · 2.69 KB
/
TelemetryInstaller.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Win32;
using System.IO;
using System.Windows;
using Gameloop.Vdf;
using Gameloop.Vdf.Linq;
namespace AFKManager
{
class TelemetryInstaller
{
public string SteamPath { get; private set; }
public string GamePath { get; private set; }
public List<string> SteamLibraryPaths { get; private set; } = new List<string>();
public TelemetryInstaller()
{
try
{
SearchSteamInstallPath();
SearchSteamLibraryFolders();
CheckTelemetry();
}
catch (Exception e){
MessageBox.Show("Erorr while install/check sdk\n" + e.Message,"AFKManager Error", MessageBoxButton.OK ,MessageBoxImage.Error);
}
}
private void CheckTelemetry()
{
if (!File.Exists(Path.Combine(GamePath, @"bin\win_x64\plugins\scs-telemetry.dll")))
{
try
{
DirectoryInfo dI = new DirectoryInfo(Path.Combine(GamePath, @"bin\win_x64\plugins\"));
if (!dI.Exists) dI.Create();
File.Copy("./files/scs-telemetry.dll", Path.Combine(GamePath, @"bin\win_x64\plugins\scs-telemetry.dll"));
}
catch (DirectoryNotFoundException dirEx)
{
MessageBox.Show("Check Telemetry failed\n" + dirEx.Message);
}
}
}
private void SearchSteamInstallPath()
{
RegistryKey SteamPath1 = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Valve\\Steam\\");
SteamPath = SteamPath1.GetValue("SteamPath") as string;
SteamLibraryPaths.Add(SteamPath);
}
private void SearchSteamLibraryFolders()
{
VToken vdf = VdfConvert.Deserialize(File.ReadAllText(Path.Combine(SteamPath, @"steamapps\libraryfolders.vdf"))).Value;
string SteamLibraryWithGame = String.Empty;
int i = 0;
var tempObj = vdf[i.ToString()];
while (tempObj != null)
{
VToken tempToken = tempObj["apps"]["227300"];
if (tempToken !=null)
{
SteamLibraryWithGame = vdf[i.ToString()]["path"].ToString();
GamePath = Path.Combine(SteamLibraryWithGame, @"SteamApps\common\Euro Truck Simulator 2\");
return;
}
i++;
tempObj = vdf[i.ToString()];
}
}
}
}