-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathpaths.cpp
108 lines (98 loc) · 3.27 KB
/
paths.cpp
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
#include <iostream>
#include <string>
#include <stdexcept>
#include <boost/filesystem.hpp>
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include "paths.h"
#include "conversions.h"
namespace fs = boost::filesystem;
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE,PBOOL);
fs::path extractHDPath(std::string steamPath) {
std::string line;
std::string HDPath;
std::ifstream manifest((steamPath+"/steamapps/appmanifest_221380.acf").c_str());
while (std::getline(manifest,line)) {
u_int i;
if ((i = line.find("installdir")) != std::string::npos) {
i = line.find("\"", i+11);
int j = line.find("\"", i+1);
line = line.substr(i+1,j-i-1);
HDPath = steamPath+"/steamapps/common/"+line+"/";
break;
}
}
return fs::path(HDPath);
}
std::string getSteamPath() {
TCHAR temp[300];
unsigned long size = sizeof(temp);
HKEY hKey;
BOOL w64;
IsWow64Process(GetCurrentProcess(), &w64);
if(w64)
RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\WOW6432Node\\Valve\\Steam", 0, KEY_READ, &hKey);
else
RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Valve\\Steam", 0, KEY_READ, &hKey);
RegQueryValueEx(hKey, L"InstallPath", NULL, NULL, reinterpret_cast<LPBYTE>(temp), &size);
RegCloseKey(hKey);
std::string steamPath(wstrtostr(std::wstring(std::basic_string<TCHAR>(temp))));
return steamPath;
}
fs::path getHDPath(std::string steamPath) {
fs::path HDPath("../");
std::string line;
if(boost::filesystem::exists(steamPath+"/steamapps/appmanifest_221380.acf")) {
HDPath = extractHDPath(steamPath);
} else if (boost::filesystem::exists(steamPath+"/steamapps/libraryfolders.vdf")) {
std::ifstream libraryFolders((steamPath+"/steamapps/libraryfolders.vdf").c_str());
while (std::getline(libraryFolders,line)) {
u_int i;
if ((i = line.find("\"1\"")) != std::string::npos || (i = line.find("\"2\"")) != std::string::npos || (i = line.find("\"3\"")) != std::string::npos) {
i = line.find("\"", i+3);
int j = line.find("\"", i+1);
line = line.substr(i+1,j-i-1);
steamPath = line;
if(boost::filesystem::exists(steamPath+"/steamapps/appmanifest_221380.acf")) {
HDPath = extractHDPath(steamPath);
break;
}
}
}
}
if(!boost::filesystem::exists(HDPath/"/Launcher.exe")) {
if(boost::filesystem::exists("../../Launcher.exe")) {
HDPath = fs::path("../../");
} else {
return "";
}
}
return HDPath;
}
fs::path getOutPath(fs::path HDPath) {
TCHAR temp[300];
unsigned long size = sizeof(temp);
HKEY hKey;
BOOL w64;
IsWow64Process(GetCurrentProcess(), &w64);
if(w64)
RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\WOW6432Node\\Microsoft\\DirectPlay\\Applications\\Age of Empires II - The Conquerors Expansion", 0, KEY_READ, &hKey);
else
RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\DirectPlay\\Applications\\Age of Empires II - The Conquerors Expansion", 0, KEY_READ, &hKey);
RegQueryValueEx(hKey, L"CurrentDirectory", NULL, NULL, reinterpret_cast<LPBYTE>(temp), &size);
RegCloseKey(hKey);
fs::path outPath(wstrtostr(std::wstring(std::basic_string<TCHAR>(temp))));
bool aocFound = false;
if(boost::filesystem::exists(outPath))
aocFound = true;
if(!aocFound) {
if(boost::filesystem::exists(HDPath / "age2_x1")) {
outPath = HDPath;
aocFound = true;
} else {
outPath = HDPath/"WololoKingdoms/out/";
}
}
return outPath;
}