fixed count forcing null byte at the end of query string

This commit is contained in:
Anonymous275
2022-01-19 01:31:43 +02:00
parent 955231c3f6
commit 48e6b21eda
3 changed files with 6 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ struct VersionParser {
explicit VersionParser(const std::string& from_string);
std::strong_ordering operator<=>(VersionParser const& rhs) const noexcept;
bool operator==(VersionParser const& rhs) const noexcept;
std::vector<std::string> split;
std::vector<size_t> data;
};

View File

@@ -50,7 +50,7 @@ std::string QueryValue(HKEY& hKey, const char* Name) {
DWORD keySize;
BYTE buffer[16384];
if(RegQueryValueExA(hKey, Name, nullptr, nullptr, buffer, &keySize) == ERROR_SUCCESS) {
return {(char*)buffer, keySize};
return {(char*)buffer, keySize-1};
}
return {};
}
@@ -62,7 +62,7 @@ std::string Launcher::GetLocalAppdata() {
if(!Path.empty()) {
Path += "\\BeamNG.drive\\";
VersionParser GameVer(BeamVersion);
Path += std::to_string(GameVer.data[0]) + '.' + std::to_string(GameVer.data[1]) + '\\';
Path += GameVer.split[0] + '.' + GameVer.split[1] + '\\';
return Path;
}
}
@@ -78,9 +78,9 @@ void Launcher::QueryRegistry() {
RegCloseKey(BeamNG);
if(BeamUserPath.empty() && !BeamVersion.empty()) {
BeamUserPath = GetLocalAppdata();
} else if(!BeamUserPath.empty()) {
} else if(!BeamUserPath.empty() && !BeamVersion.empty()) {
VersionParser GameVer(BeamVersion);
BeamUserPath += std::to_string(GameVer.data[0]) + '.' + std::to_string(GameVer.data[1]) + '\\';
BeamUserPath += GameVer.split[0] + '.' + GameVer.split[1] + '\\';
}
if(!BeamRoot.empty() && !BeamVersion.empty() && !BeamUserPath.empty())return;
}

View File

@@ -12,6 +12,7 @@ VersionParser::VersionParser(const std::string &from_string) {
std::istringstream tokenStream(from_string);
while (std::getline(tokenStream, token, '.')) {
data.emplace_back(std::stol(token));
split.emplace_back(token);
}
}