mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-29 17:54:50 +01:00
Upgrade platform_sanitise_filename()
This commit is contained in:
@@ -139,7 +139,7 @@ static std::optional<std::string> screenshot_get_next_path()
|
||||
|
||||
// Generate a path with a `tries` number
|
||||
auto pathComposer = [&screenshotDirectory, &name](int tries) {
|
||||
auto composedFilename = platform_sanitise_filename(
|
||||
auto composedFilename = Platform::SanitiseFilename(
|
||||
name + ((tries > 0) ? " ("s + std::to_string(tries) + ")" : ""s) + ".png");
|
||||
return screenshotDirectory + PATH_SEPARATOR + composedFilename;
|
||||
};
|
||||
|
||||
@@ -50,6 +50,8 @@ namespace Platform
|
||||
|
||||
std::string GetUsername();
|
||||
|
||||
std::string SanitiseFilename(std::string_view originalName);
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__)
|
||||
std::string GetEnvironmentPath(const char* name);
|
||||
std::string GetHomePath();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "../config/Config.h"
|
||||
#include "../core/FileSystem.hpp"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../drawing/Drawing.h"
|
||||
#include "../drawing/LightFX.h"
|
||||
#include "../localisation/Currency.h"
|
||||
@@ -106,6 +107,24 @@ namespace Platform
|
||||
std::string combinedPath = Path::ResolveCasing(Path::Combine(path, "Data", "g1.dat"));
|
||||
return Platform::FileExists(combinedPath);
|
||||
}
|
||||
|
||||
std::string SanitiseFilename(std::string_view originalName)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
static constexpr std::array prohibited = { '<', '>', '*', '\\', ':', '|', '?', '"', '/' };
|
||||
#else
|
||||
static constexpr std::array prohibited = { '/' };
|
||||
#endif
|
||||
auto sanitised = std::string(originalName);
|
||||
std::replace_if(
|
||||
sanitised.begin(), sanitised.end(),
|
||||
[](const std::string::value_type& ch) -> bool {
|
||||
return std::find(prohibited.begin(), prohibited.end(), ch) != prohibited.end();
|
||||
},
|
||||
'_');
|
||||
sanitised = String::Trim(sanitised);
|
||||
return sanitised;
|
||||
}
|
||||
} // namespace Platform
|
||||
|
||||
GamePalette gPalette;
|
||||
@@ -241,21 +260,6 @@ CurrencyType platform_get_currency_value(const char* currCode)
|
||||
return CurrencyType::Pounds;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
std::string platform_sanitise_filename(const std::string& path)
|
||||
{
|
||||
static constexpr std::array prohibited = { '/' };
|
||||
auto sanitised = path;
|
||||
std::replace_if(
|
||||
sanitised.begin(), sanitised.end(),
|
||||
[](const std::string::value_type& ch) -> bool {
|
||||
return std::find(prohibited.begin(), prohibited.end(), ch) != prohibited.end();
|
||||
},
|
||||
'_');
|
||||
return sanitised;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __ANDROID__
|
||||
float platform_get_default_scale()
|
||||
{
|
||||
|
||||
@@ -185,20 +185,6 @@ std::string platform_get_rct2_steam_dir()
|
||||
return "Rollercoaster Tycoon 2";
|
||||
}
|
||||
|
||||
std::string platform_sanitise_filename(const std::string& path)
|
||||
{
|
||||
static constexpr std::array prohibited = { '<', '>', '*', '\\', ':', '|', '?', '"', '/' };
|
||||
auto sanitised = path;
|
||||
std::replace_if(
|
||||
sanitised.begin(), sanitised.end(),
|
||||
[](const std::string::value_type& ch) -> bool {
|
||||
return std::find(prohibited.begin(), prohibited.end(), ch) != prohibited.end();
|
||||
},
|
||||
'_');
|
||||
sanitised = String::Trim(sanitised);
|
||||
return sanitised;
|
||||
}
|
||||
|
||||
uint16_t platform_get_locale_language()
|
||||
{
|
||||
CHAR langCode[4];
|
||||
|
||||
@@ -115,7 +115,6 @@ bool platform_process_is_elevated();
|
||||
bool platform_get_steam_path(utf8* outPath, size_t outSize);
|
||||
std::string platform_get_rct1_steam_dir();
|
||||
std::string platform_get_rct2_steam_dir();
|
||||
std::string platform_sanitise_filename(const std::string&);
|
||||
|
||||
#ifndef NO_TTF
|
||||
bool platform_get_font_path(TTFFontDescriptor* font, utf8* buffer, size_t size);
|
||||
|
||||
Reference in New Issue
Block a user