diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index 5a772b1a..82bf4605 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -174,6 +174,16 @@ bool Local_Storage::save_screenshot(std::string const& image_path, uint8_t* img_ return false; } +std::string Local_Storage::sanitize_string(std::string name) +{ + return ""; +} + +std::string Local_Storage::desanitize_string(std::string name) +{ + return ""; +} + #else #if defined(__WINDOWS__) @@ -457,6 +467,8 @@ static std::string replace_with(std::string s, std::string const &old, const cha static std::string sanitize_file_name(std::string name) { + if (name.empty()) return name; + //I'm not sure all of these are necessary but just to be sure if (name[0] == '.' && name.size() > 2 && (name[1] == '\\' || name[1] == '/')) name.erase(0, 2); @@ -478,6 +490,8 @@ static std::string sanitize_file_name(std::string name) static std::string desanitize_file_name(std::string name) { + if (name.empty()) return name; + //I'm not sure all of these are necessary but just to be sure name = replace_with(name, ".SLASH.", "/"); name = replace_with(name, ".B_SLASH.", "\\"); @@ -794,21 +808,20 @@ std::vector Local_Storage::load_image(std::string const& image_pa std::string Local_Storage::load_image_resized(std::string const& image_path, std::string const& image_data, int resolution) { std::string resized_image(resolution * resolution * 4, 0); - char* resized_img = (char*)malloc(sizeof(char) * resolution * resolution * 4); + char *resized_img = (char*)malloc(sizeof(char) * resolution * resolution * 4); PRINT_DEBUG("Local_Storage::load_image_resized: %s for resized image (%i)\n", (resized_img == nullptr ? "could not allocate memory" : "memory allocated"), (resolution * resolution * 4)); if (resized_img != nullptr) { if (image_path.length() > 0) { int width, height; - unsigned char* img = stbi_load(image_path.c_str(), &width, &height, nullptr, 4); + unsigned char *img = stbi_load(image_path.c_str(), &width, &height, nullptr, 4); PRINT_DEBUG("Local_Storage::load_image_resized: \"%s\" %s\n", image_path.c_str(), (img == nullptr ? stbi_failure_reason() : "loaded")); if (img != nullptr) { stbir_resize_uint8(img, width, height, NULL, (unsigned char*)resized_img, resolution, resolution, NULL, 4); resized_image = std::string(resized_img, resolution * resolution * 4); stbi_image_free(img); } - } - else if (image_data.length() > 0) { + } else if (image_data.length() > 0) { stbir_resize_uint8((unsigned char*)image_data.c_str(), 184, 184, NULL, (unsigned char*)resized_img, resolution, resolution, NULL, 4); resized_image = std::string(resized_img, resolution * resolution * 4); } @@ -827,4 +840,14 @@ bool Local_Storage::save_screenshot(std::string const& image_path, uint8_t* img_ return stbi_write_png(screenshot_path.c_str(), width, height, channels, img_ptr, 0) == 1; } +std::string Local_Storage::sanitize_string(std::string name) +{ + return sanitize_file_name(name); +} + +std::string Local_Storage::desanitize_string(std::string name) +{ + return desanitize_file_name(name); +} + #endif diff --git a/dll/local_storage.h b/dll/local_storage.h index dd6d454b..7578ec9c 100644 --- a/dll/local_storage.h +++ b/dll/local_storage.h @@ -87,6 +87,9 @@ public: std::vector load_image(std::string const& image_path); static std::string load_image_resized(std::string const& image_path, std::string const& image_data, int resolution); bool save_screenshot(std::string const& image_path, uint8_t* img_ptr, int32_t width, int32_t height, int32_t channels); + + static std::string sanitize_string(std::string name); + static std::string desanitize_string(std::string name); }; #endif diff --git a/dll/settings.h b/dll/settings.h index 04871ca3..c3df1e3c 100644 --- a/dll/settings.h +++ b/dll/settings.h @@ -213,6 +213,7 @@ public: //warn people who use local save bool warn_local_save = false; + std::string local_save; //steamhttp external download support bool http_online = false; diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index 6cf1a0b0..6c0906ae 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -469,6 +469,11 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s settings_client->http_online = steamhttp_online_mode; settings_server->http_online = steamhttp_online_mode; + if (local_save) { + settings_client->local_save = save_path; + settings_server->local_save = save_path; + } + { std::string dlc_config_path = Local_Storage::get_game_settings_path() + "DLC.txt"; std::ifstream input( utf8_decode(dlc_config_path) ); diff --git a/dll/steam_friends.h b/dll/steam_friends.h index c4d69a15..1f7ed2ee 100644 --- a/dll/steam_friends.h +++ b/dll/steam_friends.h @@ -127,7 +127,13 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id) if (i == 0) file_name = "account_avatar.png"; if (i == 1) file_name = "account_avatar.jpg"; if (i == 2) file_name = "account_avatar.jpeg"; - file_path = Local_Storage::get_user_appdata_path() + "/settings/" + file_name; + + if (settings->local_save.length() > 0) { + file_path = settings->local_save + "/settings/" + file_name; + } else { + file_path = Local_Storage::get_user_appdata_path() + "/settings/" + file_name; + } + file_size = file_size_(file_path); if (file_size) break; } @@ -165,7 +171,13 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id) if (i == 0) file_name = "account_avatar_default.png"; if (i == 1) file_name = "account_avatar_default.jpg"; if (i == 2) file_name = "account_avatar_default.jpeg"; - file_path = Local_Storage::get_user_appdata_path() + "/settings/" + file_name; + + if (settings->local_save.length() > 0) { + file_path = settings->local_save + "/settings/" + file_name; + } else { + file_path = Local_Storage::get_user_appdata_path() + "/settings/" + file_name; + } + file_size = file_size_(file_path); if (file_size) break; } diff --git a/dll/steam_http.cpp b/dll/steam_http.cpp index 8205ed15..aaea15d9 100644 --- a/dll/steam_http.cpp +++ b/dll/steam_http.cpp @@ -51,7 +51,7 @@ HTTPRequestHandle Steam_HTTP::CreateHTTPRequest( EHTTPMethod eHTTPRequestMethod, struct Steam_Http_Request request; if (url_index) { if (url[url.size() - 1] == '/') url += "index.html"; - std::string file_path = Local_Storage::get_game_settings_path() + "http/" + url.substr(url_index); + std::string file_path = Local_Storage::get_game_settings_path() + "http/" + Local_Storage::sanitize_string(url.substr(url_index)); unsigned long long file_size = file_size_(file_path); if (file_size) { request.response.resize(file_size);