Add support for setting app/DLC paths.

This commit is contained in:
Mr_Goldberg 2019-05-09 08:10:03 -04:00
parent fae4df7012
commit a36f6e8e68
No known key found for this signature in database
GPG key ID: 8597D87419DEF278
8 changed files with 117 additions and 5 deletions

View file

@ -19,6 +19,7 @@
#ifdef STEAM_WIN32
#include <windows.h>
#include <direct.h>
#define SystemFunction036 NTAPI SystemFunction036
#include <ntsecapi.h>
@ -39,7 +40,7 @@ std::string get_env_variable(std::string name)
return std::string();
}
env_variable[ret - 1] = 0;
env_variable[ret] = 0;
return std::string(env_variable);
}
@ -204,6 +205,40 @@ std::string get_full_program_path()
return program_path;
}
std::string get_current_path()
{
std::string path;
#if defined(STEAM_WIN32)
char *buffer = _getcwd( NULL, 0 );
#else
char *buffer = get_current_dir_name();
#endif
if (buffer) {
path = buffer;
path.append(PATH_SEPARATOR);
free(buffer);
}
return path;
}
std::string canonical_path(std::string path)
{
std::string output;
#if defined(STEAM_WIN32)
char *buffer = _fullpath(NULL, path.c_str(), 0);
#else
char *buffer = canonicalize_file_name(path.c_str());
#endif
if (buffer) {
output = buffer;
free(buffer);
}
return output;
}
static void steam_auth_ticket_callback(void *object, Common_Message *msg)
{
PRINT_DEBUG("steam_auth_ticket_callback\n");

View file

@ -135,6 +135,8 @@ CSteamID generate_steam_id_server();
CSteamID generate_steam_id_anonserver();
CSteamID generate_steam_id_lobby();
std::string get_full_program_path();
std::string get_current_path();
std::string canonical_path(std::string path);
class SteamCallResults {
std::vector<struct Steam_Call_Result> callresults;

View file

@ -184,3 +184,13 @@ bool Settings::getDLC(unsigned int index, AppId_t &appID, bool &available, std::
name = DLCs[index].name;
return true;
}
void Settings::setAppInstallPath(AppId_t appID, std::string path)
{
app_paths[appID] = path;
}
std::string Settings::getAppInstallPath(AppId_t appID)
{
return app_paths[appID];
}

View file

@ -43,6 +43,8 @@ class Settings {
bool offline;
std::vector<struct DLC_entry> DLCs;
std::vector<struct Mod_entry> mods;
std::map<AppId_t, std::string> app_paths;
public:
#ifdef LOBBY_CONNECT
static const bool is_lobby_connect = true;
@ -67,6 +69,10 @@ public:
bool hasDLC(AppId_t appID);
bool getDLC(unsigned int index, AppId_t &appID, bool &available, std::string &name);
//App Install paths
void setAppInstallPath(AppId_t appID, std::string path);
std::string getAppInstallPath(AppId_t appID);
//mod stuff
void addMod(PublishedFileId_t id, std::string title, std::string path);
Mod_entry getMod(PublishedFileId_t id);

View file

@ -188,11 +188,26 @@ uint32 Steam_Apps::GetInstalledDepots( AppId_t appID, DepotId_t *pvecDepots, uin
// returns current app install folder for AppID, returns folder name length
uint32 Steam_Apps::GetAppInstallDir( AppId_t appID, char *pchFolder, uint32 cchFolderBufferSize )
{
PRINT_DEBUG("GetAppInstallDir %u\n", cchFolderBufferSize);
PRINT_DEBUG("GetAppInstallDir %u %u\n", appID, cchFolderBufferSize);
//TODO return real path instead of dll path
if (!pchFolder || !cchFolderBufferSize) return 0;
std::string path = get_full_program_path();
snprintf(pchFolder, cchFolderBufferSize, "%s", path.c_str());
std::string installed_path = settings->getAppInstallPath(appID);
if (installed_path.size() == 0) {
std::string dll_path = get_full_program_path();
std::string current_path = get_current_path();
PRINT_DEBUG("paths %s %s\n", dll_path.c_str(), current_path.c_str());
//Just pick the smallest path, it has the most chances of being the good one
if (dll_path.size() > current_path.size() && current_path.size()) {
installed_path = current_path;
} else {
installed_path = dll_path;
}
}
PRINT_DEBUG("path %s\n", installed_path.c_str());
snprintf(pchFolder, cchFolderBufferSize, "%s", installed_path.c_str());
return strlen(pchFolder);
}

View file

@ -211,6 +211,7 @@ Steam_Client::Steam_Client()
std::ifstream input( dlc_config_path );
if (input.is_open()) {
settings_client->unlockAllDLC(false);
settings_server->unlockAllDLC(false);
PRINT_DEBUG("Locking all DLC\n");
for( std::string line; getline( input, line ); ) {
@ -243,6 +244,39 @@ Steam_Client::Steam_Client()
}
}
{
std::string dlc_config_path = Local_Storage::get_game_settings_path() + "app_paths.txt";
std::ifstream input( dlc_config_path );
if (input.is_open()) {
for( std::string line; getline( input, line ); ) {
if (!line.empty() && line[line.length()-1] == '\n') {
line.erase(line.length()-1);
}
if (!line.empty() && line[line.length()-1] == '\r') {
line.erase(line.length()-1);
}
std::size_t deliminator = line.find("=");
if (deliminator != 0 && deliminator != std::string::npos && deliminator != line.size()) {
AppId_t appid = stol(line.substr(0, deliminator));
std::string rel_path = line.substr(deliminator + 1);
std::string path = canonical_path(program_path + rel_path);
if (appid) {
if (path.size()) {
PRINT_DEBUG("Adding app path: %u|%s|\n", appid, path.c_str());
settings_client->setAppInstallPath(appid, path);
settings_server->setAppInstallPath(appid, path);
} else {
PRINT_DEBUG("Error adding app path for: %u does this path exist? |%s|\n", appid, rel_path.c_str());
}
}
}
}
}
}
{
std::string mod_path = Local_Storage::get_game_settings_path() + "mods";
std::vector<std::string> paths = Local_Storage::get_filenames_path(mod_path);