use const ref in many places

This commit is contained in:
otavepto 2024-03-03 03:32:17 +02:00 committed by otavepto
parent 4bf76af19b
commit 5c312306d4
7 changed files with 32 additions and 32 deletions

View File

@ -59,15 +59,15 @@ public:
static std::string get_program_path(); static std::string get_program_path();
static std::string get_game_settings_path(); static std::string get_game_settings_path();
static std::string get_user_appdata_path(); static std::string get_user_appdata_path();
Local_Storage(std::string save_directory); Local_Storage(const std::string &save_directory);
static int get_file_data(std::string full_path, char *data, unsigned int max_length, unsigned int offset=0); static int get_file_data(std::string full_path, char *data, unsigned int max_length, unsigned int offset=0);
void setAppId(uint32 appid); void setAppId(uint32 appid);
static int store_file_data(std::string folder, std::string file, char *data, unsigned int length); static int store_file_data(std::string folder, std::string file, const char *data, unsigned int length);
static std::vector<std::string> get_filenames_path(std::string path); static std::vector<std::string> get_filenames_path(std::string path);
static std::vector<std::string> get_folders_path(std::string path); static std::vector<std::string> get_folders_path(std::string path);
int store_data(std::string folder, std::string file, char *data, unsigned int length); int store_data(std::string folder, std::string file, char *data, unsigned int length);
int store_data_settings(std::string file, char *data, unsigned int length); int store_data_settings(std::string file, const char *data, unsigned int length);
int get_data(std::string folder, std::string file, char *data, unsigned int max_length, unsigned int offset=0); int get_data(std::string folder, std::string file, char *data, unsigned int max_length, unsigned int offset=0);
int get_data_settings(std::string file, char *data, unsigned int max_length); int get_data_settings(std::string file, char *data, unsigned int max_length);
int count_files(std::string folder); int count_files(std::string folder);

View File

@ -188,14 +188,14 @@ public:
static const bool is_lobby_connect = false; static const bool is_lobby_connect = false;
#endif #endif
static std::string sanitize(std::string name); static std::string sanitize(const std::string &name);
Settings(CSteamID steam_id, CGameID game_id, std::string name, std::string language, bool offline); Settings(CSteamID steam_id, CGameID game_id, const std::string &name, const std::string &language, bool offline);
CSteamID get_local_steam_id(); CSteamID get_local_steam_id();
CGameID get_local_game_id(); CGameID get_local_game_id();
const char *get_local_name(); const char *get_local_name();
void set_local_name(char *name); void set_local_name(const char *name);
const char *get_language(); const char *get_language();
void set_language(char *language); void set_language(const char *language);
void set_game_id(CGameID game_id); void set_game_id(CGameID game_id);
void set_lobby(CSteamID lobby_id); void set_lobby(CSteamID lobby_id);
@ -216,12 +216,12 @@ public:
std::vector<DepotId_t> depots; std::vector<DepotId_t> depots;
//App Install paths //App Install paths
void setAppInstallPath(AppId_t appID, std::string path); void setAppInstallPath(AppId_t appID, const std::string &path);
std::string getAppInstallPath(AppId_t appID); std::string getAppInstallPath(AppId_t appID);
//mod stuff //mod stuff
void addMod(PublishedFileId_t id, std::string title, std::string path); void addMod(PublishedFileId_t id, const std::string &title, const std::string &path);
void addModDetails(PublishedFileId_t id, Mod_entry details); void addModDetails(PublishedFileId_t id, const Mod_entry &details);
Mod_entry getMod(PublishedFileId_t id); Mod_entry getMod(PublishedFileId_t id);
bool isModInstalled(PublishedFileId_t id); bool isModInstalled(PublishedFileId_t id);
std::set<PublishedFileId_t> modSet(); std::set<PublishedFileId_t> modSet();
@ -247,7 +247,7 @@ public:
//images //images
std::map<int, struct Image_Data> images; std::map<int, struct Image_Data> images;
int add_image(std::string data, uint32 width, uint32 height); int add_image(const std::string &data, uint32 width, uint32 height);
bool disable_account_avatar = false; bool disable_account_avatar = false;
//installed app ids, Steam_Apps::BIsAppInstalled() //installed app ids, Steam_Apps::BIsAppInstalled()

View File

@ -22,6 +22,6 @@
//returns appid //returns appid
uint32 create_localstorage_settings(Settings **settings_client_out, Settings **settings_server_out, Local_Storage **local_storage_out); uint32 create_localstorage_settings(Settings **settings_client_out, Settings **settings_server_out, Local_Storage **local_storage_out);
void save_global_settings(Local_Storage *local_storage, char *name, char *language); void save_global_settings(Local_Storage *local_storage, const char *name, const char *language);
#endif #endif

View File

@ -64,7 +64,7 @@ std::string Local_Storage::get_global_settings_path()
return ""; return "";
} }
Local_Storage::Local_Storage(std::string save_directory) Local_Storage::Local_Storage(const std::string &save_directory)
{ {
} }
@ -74,7 +74,7 @@ void Local_Storage::setAppId(uint32 appid)
} }
int Local_Storage::store_file_data(std::string folder, std::string file, char *data, unsigned int length) int Local_Storage::store_file_data(std::string folder, std::string file, const char *data, unsigned int length)
{ {
return -1; return -1;
} }
@ -84,7 +84,7 @@ int Local_Storage::store_data(std::string folder, std::string file, char *data,
return -1; return -1;
} }
int Local_Storage::store_data_settings(std::string file, char *data, unsigned int length) int Local_Storage::store_data_settings(std::string file, const char *data, unsigned int length)
{ {
return -1; return -1;
} }
@ -511,7 +511,7 @@ static std::string desanitize_file_name(std::string name)
return name; return name;
} }
Local_Storage::Local_Storage(std::string save_directory) Local_Storage::Local_Storage(const std::string &save_directory)
{ {
this->save_directory = save_directory; this->save_directory = save_directory;
@ -525,7 +525,7 @@ void Local_Storage::setAppId(uint32 appid)
this->appid = std::to_string(appid) + PATH_SEPARATOR; this->appid = std::to_string(appid) + PATH_SEPARATOR;
} }
int Local_Storage::store_file_data(std::string folder, std::string file, char *data, unsigned int length) 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.back() != *PATH_SEPARATOR) {
folder.append(PATH_SEPARATOR); folder.append(PATH_SEPARATOR);
@ -609,7 +609,7 @@ int Local_Storage::store_data(std::string folder, std::string file, char *data,
return store_file_data(save_directory + appid + folder, file, data, length); return store_file_data(save_directory + appid + folder, file, data, length);
} }
int Local_Storage::store_data_settings(std::string file, char *data, unsigned int length) int Local_Storage::store_data_settings(std::string file, const char *data, unsigned int length)
{ {
return store_file_data(get_global_settings_path(), file, data, length); return store_file_data(get_global_settings_path(), file, data, length);
} }

View File

@ -18,7 +18,7 @@
#include "dll/settings.h" #include "dll/settings.h"
std::string Settings::sanitize(std::string name) std::string Settings::sanitize(const std::string &name)
{ {
// https://github.com/microsoft/referencesource/blob/51cf7850defa8a17d815b4700b67116e3fa283c2/mscorlib/system/io/path.cs#L88C9-L89C1 // https://github.com/microsoft/referencesource/blob/51cf7850defa8a17d815b4700b67116e3fa283c2/mscorlib/system/io/path.cs#L88C9-L89C1
// https://github.com/microsoft/referencesource/blob/51cf7850defa8a17d815b4700b67116e3fa283c2/mscorlib/system/io/pathinternal.cs#L32 // https://github.com/microsoft/referencesource/blob/51cf7850defa8a17d815b4700b67116e3fa283c2/mscorlib/system/io/pathinternal.cs#L32
@ -53,12 +53,12 @@ std::string Settings::sanitize(std::string name)
} }
} }
std::string res; std::string res{};
utf8::utf32to8(unicode_name.begin(), unicode_name.end(), std::back_inserter(res)); utf8::utf32to8(unicode_name.begin(), unicode_name.end(), std::back_inserter(res));
return res; return res;
} }
Settings::Settings(CSteamID steam_id, CGameID game_id, std::string name, std::string language, bool offline) Settings::Settings(CSteamID steam_id, CGameID game_id, const std::string &name, const std::string &language, bool offline)
{ {
this->steam_id = steam_id; this->steam_id = steam_id;
this->game_id = game_id; this->game_id = game_id;
@ -102,12 +102,12 @@ const char *Settings::get_language()
return language.c_str(); return language.c_str();
} }
void Settings::set_local_name(char *name) void Settings::set_local_name(const char *name)
{ {
this->name = name; this->name = name;
} }
void Settings::set_language(char *language) void Settings::set_language(const char *language)
{ {
this->language = language; this->language = language;
} }
@ -148,7 +148,7 @@ void Settings::addDLC(AppId_t appID, std::string name, bool available)
DLCs.push_back(new_entry); DLCs.push_back(new_entry);
} }
void Settings::addMod(PublishedFileId_t id, std::string title, std::string path) void Settings::addMod(PublishedFileId_t id, const std::string &title, const std::string &path)
{ {
auto f = std::find_if(mods.begin(), mods.end(), [&id](Mod_entry const& item) { return item.id == id; }); auto f = std::find_if(mods.begin(), mods.end(), [&id](Mod_entry const& item) { return item.id == id; });
if (mods.end() != f) { if (mods.end() != f) {
@ -164,7 +164,7 @@ void Settings::addMod(PublishedFileId_t id, std::string title, std::string path)
mods.push_back(new_entry); mods.push_back(new_entry);
} }
void Settings::addModDetails(PublishedFileId_t id, Mod_entry details) void Settings::addModDetails(PublishedFileId_t id, const Mod_entry &details)
{ {
auto f = std::find_if(mods.begin(), mods.end(), [&id](Mod_entry const& item) { return item.id == id; }); auto f = std::find_if(mods.begin(), mods.end(), [&id](Mod_entry const& item) { return item.id == id; });
if (f != mods.end()) { if (f != mods.end()) {
@ -256,7 +256,7 @@ bool Settings::allDLCUnlocked() const
return this->unlockAllDLCs; return this->unlockAllDLCs;
} }
void Settings::setAppInstallPath(AppId_t appID, std::string path) void Settings::setAppInstallPath(AppId_t appID, const std::string &path)
{ {
app_paths[appID] = path; app_paths[appID] = path;
} }
@ -275,7 +275,7 @@ void Settings::setLeaderboard(std::string leaderboard, enum ELeaderboardSortMeth
leaderboards[leaderboard] = leader; leaderboards[leaderboard] = leader;
} }
int Settings::add_image(std::string data, uint32 width, uint32 height) int Settings::add_image(const std::string &data, uint32 width, uint32 height)
{ {
int last = images.size() + 1; int last = images.size() + 1;
struct Image_Data dt; struct Image_Data dt;

View File

@ -1385,7 +1385,7 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
return appid; return appid;
} }
void save_global_settings(Local_Storage *local_storage, char *name, char *language) void save_global_settings(Local_Storage *local_storage, const char *name, const char *language)
{ {
local_storage->store_data_settings("account_name.txt", name, strlen(name)); local_storage->store_data_settings("account_name.txt", name, strlen(name));
local_storage->store_data_settings("language.txt", language, strlen(language)); local_storage->store_data_settings("language.txt", language, strlen(language));

View File

@ -25,7 +25,7 @@ static constexpr int base_notif_window_id = 0 * max_window_id;
static constexpr int base_friend_window_id = 1 * max_window_id; static constexpr int base_friend_window_id = 1 * max_window_id;
static constexpr int base_friend_item_id = 2 * max_window_id; static constexpr int base_friend_item_id = 2 * max_window_id;
static constexpr char *valid_languages[] = { static const char* valid_languages[] = {
"english", "english",
"arabic", "arabic",
"bulgarian", "bulgarian",
@ -158,8 +158,8 @@ Steam_Overlay::Steam_Overlay(Settings* settings, SteamCallResults* callback_resu
const char *language = settings->get_language(); const char *language = settings->get_language();
int i = 0; int i = 0;
for (auto l : valid_languages) { for (auto &lang : valid_languages) {
if (strcmp(l, language) == 0) { if (strcmp(lang, language) == 0) {
current_language = i; current_language = i;
break; break;
} }
@ -1371,7 +1371,7 @@ void Steam_Overlay::RunCallbacks()
Steam_Matchmaking* steamMatchmaking = get_steam_client()->steam_matchmaking; Steam_Matchmaking* steamMatchmaking = get_steam_client()->steam_matchmaking;
if (save_settings) { if (save_settings) {
char *language_text = valid_languages[current_language]; const char *language_text = valid_languages[current_language];
save_global_settings(get_steam_client()->local_storage, username_text, language_text); save_global_settings(get_steam_client()->local_storage, username_text, language_text);
get_steam_client()->settings_client->set_local_name(username_text); get_steam_client()->settings_client->set_local_name(username_text);
get_steam_client()->settings_server->set_local_name(username_text); get_steam_client()->settings_server->set_local_name(username_text);