Skip to content

Commit 0fac23e

Browse files
author
a
committed
- new functionality to create expected cloud save dirs at startup
- new helper function to search for a substring with case insensitive support
1 parent 673c3a3 commit 0fac23e

File tree

11 files changed

+565
-10
lines changed

11 files changed

+565
-10
lines changed

dll/base.cpp

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,66 @@ bool check_timedout(std::chrono::high_resolution_clock::time_point old, double t
165165
return false;
166166
}
167167

168+
std::string get_full_exe_path()
169+
{
170+
// https://github.com/gpakosz/whereami/blob/master/src/whereami.c
171+
// https://stackoverflow.com/q/1023306
172+
173+
static std::string exe_path{};
174+
static std::recursive_mutex mtx{};
175+
176+
if (!exe_path.empty()) {
177+
return exe_path;
178+
}
179+
180+
std::lock_guard lock(mtx);
181+
// check again in case we didn't win this thread arbitration
182+
if (!exe_path.empty()) {
183+
return exe_path;
184+
}
185+
186+
#if defined(__WINDOWS__)
187+
static wchar_t path[8192]{};
188+
auto ret = ::GetModuleFileNameW(nullptr, path, _countof(path));
189+
if (ret >= _countof(path) || 0 == ret) {
190+
path[0] = '.';
191+
path[1] = 0;
192+
}
193+
exe_path = canonical_path(utf8_encode(path));
194+
#else
195+
// https://man7.org/linux/man-pages/man5/proc.5.html
196+
// https://linux.die.net/man/5/proc
197+
// https://man7.org/linux/man-pages/man2/readlink.2.html
198+
// https://linux.die.net/man/3/readlink
199+
static char path[8192]{};
200+
auto read = ::readlink("/proc/self/exe", path, sizeof(path) - 1);
201+
if (-1 == read) {
202+
path[0] = '.';
203+
read = 1;
204+
}
205+
path[read] = 0;
206+
exe_path = canonical_path(path);
207+
#endif // __WINDOWS__
208+
209+
return exe_path;
210+
}
211+
212+
std::string get_exe_dirname()
213+
{
214+
std::string env_exe_dir = get_env_variable("GseExeDir");
215+
if (!env_exe_dir.empty()) {
216+
if (env_exe_dir.back() != PATH_SEPARATOR[0]) {
217+
env_exe_dir = env_exe_dir.append(PATH_SEPARATOR);
218+
}
219+
220+
return env_exe_dir;
221+
}
222+
223+
std::string full_exe_path = get_full_exe_path();
224+
return full_exe_path.substr(0, full_exe_path.rfind(PATH_SEPARATOR)).append(PATH_SEPARATOR);
225+
226+
}
227+
168228
#ifdef __LINUX__
169229
std::string get_lib_path()
170230
{
@@ -692,4 +752,3 @@ void set_whitelist_ips(uint32_t *from, uint32_t *to, unsigned num_ips)
692752
}
693753

694754
#endif // EMU_EXPERIMENTAL_BUILD
695-

dll/dll/base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ CSteamID generate_steam_id_user();
4646
CSteamID generate_steam_id_server();
4747
CSteamID generate_steam_id_anonserver();
4848
CSteamID generate_steam_id_lobby();
49+
std::string get_full_exe_path();
50+
std::string get_exe_dirname();
4951
std::string get_full_lib_path();
5052
std::string get_full_program_path();
5153
std::string get_current_path();

dll/dll/common_includes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ static inline void reset_LastError()
136136
#include <netdb.h>
137137
#include <dlfcn.h>
138138
#include <utime.h>
139+
#include <pwd.h>
139140

140141
#include "crash_printer/linux.hpp"
141142

dll/dll/local_storage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Local_Storage {
5353
static constexpr char screenshots_folder[] = "screenshots";
5454
static constexpr char game_settings_folder[] = "steam_settings";
5555

56+
static std::string get_exe_dir();
5657
static std::string get_program_path();
5758
static std::string get_game_settings_path();
5859
static std::string get_user_appdata_path();

dll/dll/settings_parser_ufs.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Copyright (C) 2019 Mr Goldberg
2+
This file is part of the Goldberg Emulator
3+
4+
The Goldberg Emulator is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 3 of the License, or (at your option) any later version.
8+
9+
The Goldberg Emulator is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with the Goldberg Emulator; if not, see
16+
<http://www.gnu.org/licenses/>. */
17+
18+
#ifndef SETTINGS_PARSER_UFS_INCLUDE_H
19+
#define SETTINGS_PARSER_UFS_INCLUDE_H
20+
21+
#define SI_CONVERT_GENERIC
22+
#define SI_SUPPORT_IOSTREAMS
23+
#define SI_NO_MBCS
24+
#include "simpleini/SimpleIni.h"
25+
26+
#include "settings.h"
27+
28+
void parse_cloud_save(CSimpleIniA *ini, class Settings *settings_client, class Settings *settings_server, class Local_Storage *local_storage);
29+
30+
#endif // SETTINGS_PARSER_UFS_INCLUDE_H

dll/local_storage.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ std::string Local_Storage::saves_folder_name = "GSE Saves";
5050

5151
static const std::string empty_str{};
5252

53+
std::string Local_Storage::get_exe_dir()
54+
{
55+
return " ";
56+
}
57+
5358
std::string Local_Storage::get_program_path()
5459
{
5560
return " ";
@@ -455,6 +460,11 @@ static std::vector<struct File_Data> get_filenames_recursive(std::string base_pa
455460

456461
#endif
457462

463+
std::string Local_Storage::get_exe_dir()
464+
{
465+
return get_exe_dirname();
466+
}
467+
458468
std::string Local_Storage::get_program_path()
459469
{
460470
return get_full_program_path();
@@ -565,7 +575,7 @@ void Local_Storage::setAppId(uint32 appid)
565575

566576
int Local_Storage::store_file_data(std::string folder, std::string file, const char *data, unsigned int length)
567577
{
568-
if (folder.back() != *PATH_SEPARATOR) {
578+
if (!folder.empty() && folder.back() != *PATH_SEPARATOR) {
569579
folder.append(PATH_SEPARATOR);
570580
}
571581

dll/settings_parser.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
License along with the Goldberg Emulator; if not, see
1616
<http://www.gnu.org/licenses/>. */
1717

18-
#include "dll/settings_parser.h"
19-
#include "dll/base64.h"
20-
2118
#define SI_CONVERT_GENERIC
2219
#define SI_SUPPORT_IOSTREAMS
2320
#define SI_NO_MBCS
2421
#include "simpleini/SimpleIni.h"
2522

23+
#include "dll/settings_parser.h"
24+
#include "dll/settings_parser_ufs.h"
25+
#include "dll/base64.h"
26+
2627

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

18761878
*settings_client_out = settings_client;
18771879
*settings_server_out = settings_server;

0 commit comments

Comments
 (0)