diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index 1c333b8..c8d1a33 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -156,7 +156,7 @@ std::vector Local_Storage::get_filenames_path(std::string path) return std::vector(); } -std::vector Local_Storage::load_image(std::string const& image_path) +std::vector Local_Storage::load_image(std::string const& image_path, uint32_t * out_width, uint32_t * out_height) { return std::vector(); } @@ -612,6 +612,14 @@ bool Local_Storage::file_exists(std::string folder, std::string file) return file_exists_(full_path); } +bool Local_Storage::data_settings_exists(std::string file) +{ + file = sanitize_file_name(file); + + std::string full_path = get_global_settings_path() + file; + return file_exists_(full_path); +} + unsigned int Local_Storage::file_size(std::string folder, std::string file) { file = sanitize_file_name(file); @@ -623,6 +631,23 @@ unsigned int Local_Storage::file_size(std::string folder, std::string file) return file_size_(full_path); } +unsigned int Local_Storage::data_settings_size(std::string file) +{ + file = sanitize_file_name(file); + + std::string full_path = get_global_settings_path() + file; + return file_size_(full_path); +} + +bool _internal_file_delete(std::string & full_path) +{ +#if defined(STEAM_WIN32) + return _wremove(utf8_decode(full_path).c_str()) == 0; +#else + return remove(full_path.c_str()) == 0; +#endif +} + bool Local_Storage::file_delete(std::string folder, std::string file) { file = sanitize_file_name(file); @@ -631,11 +656,15 @@ bool Local_Storage::file_delete(std::string folder, std::string file) } std::string full_path = save_directory + appid + folder + file; -#if defined(STEAM_WIN32) - return _wremove(utf8_decode(full_path).c_str()) == 0; -#else - return remove(full_path.c_str()) == 0; -#endif + return _internal_file_delete(full_path); +} + +bool Local_Storage::delete_data_settings(std::string file) +{ + file = sanitize_file_name(file); + + std::string full_path = get_global_settings_path() + file; + return _internal_file_delete(full_path); } uint64_t Local_Storage::file_timestamp(std::string folder, std::string file) @@ -766,10 +795,11 @@ bool Local_Storage::write_json_file(std::string folder, std::string const&file, return false; } -std::vector Local_Storage::load_image(std::string const& image_path) +std::vector Local_Storage::load_image(std::string const& image_path, uint32_t * out_width, uint32_t * out_height) { std::vector res; - int width, height; + int32_t width = 0; + int32_t height = 0; image_pixel_t* img = (image_pixel_t*)stbi_load(image_path.c_str(), &width, &height, nullptr, 4); if (img != nullptr) { @@ -778,6 +808,20 @@ std::vector Local_Storage::load_image(std::string const& image_pa stbi_image_free(img); } + if (out_width != nullptr) { + if (width > 0) { + *out_width = static_cast(width); + } else { + *out_width = 0; + } + } + if (out_height != nullptr) { + if (height > 0) { + *out_height = static_cast(height); + } else { + *out_height = 0; + } + } reset_LastError(); return res; diff --git a/dll/local_storage.h b/dll/local_storage.h index ddb1c33..ae7b6aa 100644 --- a/dll/local_storage.h +++ b/dll/local_storage.h @@ -72,8 +72,11 @@ public: int count_files(std::string folder); bool iterate_file(std::string folder, int index, char *output_filename, int32 *output_size); bool file_exists(std::string folder, std::string file); + bool data_settings_exists(std::string file); unsigned int file_size(std::string folder, std::string file); + unsigned int data_settings_size(std::string file); bool file_delete(std::string folder, std::string file); + bool delete_data_settings(std::string file); uint64_t file_timestamp(std::string folder, std::string file); std::string get_global_settings_path(); std::string get_path(std::string folder); @@ -84,7 +87,7 @@ public: bool load_json_file(std::string folder, std::string const& file, nlohmann::json& json); bool write_json_file(std::string folder, std::string const& file, nlohmann::json const& json); - std::vector load_image(std::string const& image_path); + std::vector load_image(std::string const& image_path, uint32_t * out_width, uint32_t * out_height); bool save_screenshot(std::string const& image_path, uint8_t* img_ptr, int32_t width, int32_t height, int32_t channels); };