Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion dll/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,66 @@ bool check_timedout(std::chrono::high_resolution_clock::time_point old, double t
return false;
}

std::string get_full_exe_path()
{
// https://github.com/gpakosz/whereami/blob/master/src/whereami.c
// https://stackoverflow.com/q/1023306

static std::string exe_path{};
static std::recursive_mutex mtx{};

if (!exe_path.empty()) {
return exe_path;
}

std::lock_guard lock(mtx);
// check again in case we didn't win this thread arbitration
if (!exe_path.empty()) {
return exe_path;
}

#if defined(__WINDOWS__)
static wchar_t path[8192]{};
auto ret = ::GetModuleFileNameW(nullptr, path, _countof(path));
if (ret >= _countof(path) || 0 == ret) {
path[0] = '.';
path[1] = 0;
}
exe_path = canonical_path(utf8_encode(path));
#else
// https://man7.org/linux/man-pages/man5/proc.5.html
// https://linux.die.net/man/5/proc
// https://man7.org/linux/man-pages/man2/readlink.2.html
// https://linux.die.net/man/3/readlink
static char path[8192]{};
auto read = ::readlink("/proc/self/exe", path, sizeof(path) - 1);
if (-1 == read) {
path[0] = '.';
read = 1;
}
path[read] = 0;
exe_path = canonical_path(path);
#endif // __WINDOWS__

return exe_path;
}

std::string get_exe_dirname()
{
std::string env_exe_dir = get_env_variable("GseExeDir");
if (!env_exe_dir.empty()) {
if (env_exe_dir.back() != PATH_SEPARATOR[0]) {
env_exe_dir = env_exe_dir.append(PATH_SEPARATOR);
}

return env_exe_dir;
}

std::string full_exe_path = get_full_exe_path();
return full_exe_path.substr(0, full_exe_path.rfind(PATH_SEPARATOR)).append(PATH_SEPARATOR);

}

#ifdef __LINUX__
std::string get_lib_path()
{
Expand Down Expand Up @@ -692,4 +752,3 @@ void set_whitelist_ips(uint32_t *from, uint32_t *to, unsigned num_ips)
}

#endif // EMU_EXPERIMENTAL_BUILD

2 changes: 2 additions & 0 deletions dll/dll/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ CSteamID generate_steam_id_user();
CSteamID generate_steam_id_server();
CSteamID generate_steam_id_anonserver();
CSteamID generate_steam_id_lobby();
std::string get_full_exe_path();
std::string get_exe_dirname();
std::string get_full_lib_path();
std::string get_full_program_path();
std::string get_current_path();
Expand Down
1 change: 1 addition & 0 deletions dll/dll/common_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ static inline void reset_LastError()
#include <netdb.h>
#include <dlfcn.h>
#include <utime.h>
#include <pwd.h>

#include "crash_printer/linux.hpp"

Expand Down
1 change: 1 addition & 0 deletions dll/dll/local_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Local_Storage {
static constexpr char screenshots_folder[] = "screenshots";
static constexpr char game_settings_folder[] = "steam_settings";

static std::string get_exe_dir();
static std::string get_program_path();
static std::string get_game_settings_path();
static std::string get_user_appdata_path();
Expand Down
30 changes: 30 additions & 0 deletions dll/dll/settings_parser_ufs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (C) 2019 Mr Goldberg
This file is part of the Goldberg Emulator

The Goldberg Emulator is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.

The Goldberg Emulator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with the Goldberg Emulator; if not, see
<http://www.gnu.org/licenses/>. */

#ifndef SETTINGS_PARSER_UFS_INCLUDE_H
#define SETTINGS_PARSER_UFS_INCLUDE_H

#define SI_CONVERT_GENERIC
#define SI_SUPPORT_IOSTREAMS
#define SI_NO_MBCS
#include "simpleini/SimpleIni.h"

#include "settings.h"

void parse_cloud_save(CSimpleIniA *ini, class Settings *settings_client, class Settings *settings_server, class Local_Storage *local_storage);

#endif // SETTINGS_PARSER_UFS_INCLUDE_H
12 changes: 11 additions & 1 deletion dll/local_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ std::string Local_Storage::saves_folder_name = "GSE Saves";

static const std::string empty_str{};

std::string Local_Storage::get_exe_dir()
{
return " ";
}

std::string Local_Storage::get_program_path()
{
return " ";
Expand Down Expand Up @@ -455,6 +460,11 @@ static std::vector<struct File_Data> get_filenames_recursive(std::string base_pa

#endif

std::string Local_Storage::get_exe_dir()
{
return get_exe_dirname();
}

std::string Local_Storage::get_program_path()
{
return get_full_program_path();
Expand Down Expand Up @@ -565,7 +575,7 @@ void Local_Storage::setAppId(uint32 appid)

int Local_Storage::store_file_data(std::string folder, std::string file, const char *data, unsigned int length)
{
if (folder.back() != *PATH_SEPARATOR) {
if (!folder.empty() && folder.back() != *PATH_SEPARATOR) {
folder.append(PATH_SEPARATOR);
}

Expand Down
8 changes: 5 additions & 3 deletions dll/settings_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
License along with the Goldberg Emulator; if not, see
<http://www.gnu.org/licenses/>. */

#include "dll/settings_parser.h"
#include "dll/base64.h"

#define SI_CONVERT_GENERIC
#define SI_SUPPORT_IOSTREAMS
#define SI_NO_MBCS
#include "simpleini/SimpleIni.h"

#include "dll/settings_parser.h"
#include "dll/settings_parser_ufs.h"
#include "dll/base64.h"


constexpr const static char config_ini_app[] = "configs.app.ini";
constexpr const static char config_ini_main[] = "configs.main.ini";
Expand Down Expand Up @@ -1872,6 +1873,7 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
parse_overlay_general_config(settings_client, settings_server);
load_overlay_appearance(settings_client, settings_server, local_storage);
parse_steam_game_stats_reports_dir(settings_client, settings_server);
parse_cloud_save(&ini, settings_client, settings_server, local_storage);

*settings_client_out = settings_client;
*settings_server_out = settings_server;
Expand Down
Loading