mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-22 18:31:59 -05:00
Replace calls to path_get_filename()
This commit is contained in:
parent
fea9254368
commit
49b414a40e
11 changed files with 25 additions and 27 deletions
|
@ -20,6 +20,7 @@
|
|||
#include <openrct2/actions/LoadOrQuitAction.h>
|
||||
#include <openrct2/audio/audio.h>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/core/Path.hpp>
|
||||
#include <openrct2/core/String.hpp>
|
||||
#include <openrct2/drawing/Drawing.h>
|
||||
#include <openrct2/localisation/Formatter.h>
|
||||
|
@ -1236,12 +1237,12 @@ private:
|
|||
DrawTextBasic(dpi, screenPos, stringId, {}, { COLOUR_WHITE, TextAlignment::RIGHT });
|
||||
screenPos.y += LIST_ROW_HEIGHT;
|
||||
|
||||
// Draw object dat name
|
||||
// Draw object filename
|
||||
{
|
||||
const char* path = path_get_filename(listItem->repositoryItem->Path.c_str());
|
||||
auto path = Path::GetFileName(listItem->repositoryItem->Path);
|
||||
auto ft = Formatter();
|
||||
ft.Add<rct_string_id>(STR_STRING);
|
||||
ft.Add<const char*>(path);
|
||||
ft.Add<const utf8*>(path.c_str());
|
||||
DrawTextBasic(
|
||||
dpi, { windowPos.x + this->width - 5, screenPos.y }, STR_WINDOW_COLOUR_2_STRINGID, ft,
|
||||
{ COLOUR_BLACK, TextAlignment::RIGHT });
|
||||
|
|
|
@ -966,15 +966,12 @@ static void SetAndSaveConfigPath(u8string& config_str, u8string_view path)
|
|||
|
||||
static bool IsValidPath(const char* path)
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
safe_strcpy(filename, path_get_filename(path), sizeof(filename));
|
||||
|
||||
// HACK This is needed because tracks get passed through with td?
|
||||
// I am sure this will change eventually to use the new FileScanner
|
||||
// which handles multiple patterns
|
||||
path_remove_extension(filename);
|
||||
auto filename = Path::GetFileNameWithoutExtension(path);
|
||||
|
||||
return filename_valid_characters(filename);
|
||||
return filename_valid_characters(filename.c_str());
|
||||
}
|
||||
|
||||
static void WindowLoadsaveSelect(rct_window* w, const char* path)
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <openrct2/Input.h>
|
||||
#include <openrct2/OpenRCT2.h>
|
||||
#include <openrct2/core/Memory.hpp>
|
||||
#include <openrct2/core/Path.hpp>
|
||||
#include <openrct2/drawing/Drawing.h>
|
||||
#include <openrct2/entity/Balloon.h>
|
||||
#include <openrct2/entity/Duck.h>
|
||||
|
@ -143,7 +144,7 @@ static void ScenarioSelectCallback(const utf8* path)
|
|||
{
|
||||
if (_command.Type == TitleScript::LoadSc)
|
||||
{
|
||||
const utf8* fileName = path_get_filename(path);
|
||||
const auto fileName = Path::GetFileName(path);
|
||||
auto scenario = GetScenarioRepository()->GetByFilename(fileName);
|
||||
safe_strcpy(_command.Scenario, scenario->internal_name, sizeof(_command.Scenario));
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <openrct2/OpenRCT2.h>
|
||||
#include <openrct2/ParkImporter.h>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/core/Path.hpp>
|
||||
#include <openrct2/localisation/Formatter.h>
|
||||
#include <openrct2/localisation/Formatting.h>
|
||||
#include <openrct2/localisation/Localisation.h>
|
||||
|
@ -182,7 +183,7 @@ static bool _isSequenceReadOnly;
|
|||
static std::unique_ptr<TitleSequence> _editingTitleSequence;
|
||||
static const utf8* _sequenceName;
|
||||
|
||||
static utf8* _renameSavePath = nullptr;
|
||||
static u8string _renameSavePath = u8string();
|
||||
|
||||
static int16_t _window_title_editor_highlighted_index;
|
||||
|
||||
|
@ -247,7 +248,7 @@ static void WindowTitleEditorClose(rct_window* w)
|
|||
_editingTitleSequence = nullptr;
|
||||
_sequenceName = nullptr;
|
||||
|
||||
SafeFree(_renameSavePath);
|
||||
_renameSavePath.clear();
|
||||
}
|
||||
|
||||
static void WindowTitleEditorMouseup(rct_window* w, rct_widgetindex widgetIndex)
|
||||
|
@ -1120,19 +1121,18 @@ static void WindowTitleEditorAddParkCallback(int32_t result, const utf8* path)
|
|||
if (extension != FileExtension::SV4 && extension != FileExtension::SV6 && extension != FileExtension::PARK)
|
||||
return;
|
||||
|
||||
const utf8* filename = path_get_filename(path);
|
||||
if (SaveFilenameExists(filename))
|
||||
const auto filename = Path::GetFileName(path);
|
||||
if (SaveFilenameExists(filename.c_str()))
|
||||
{
|
||||
free(_renameSavePath);
|
||||
_renameSavePath = _strdup(filename);
|
||||
_renameSavePath = filename;
|
||||
rct_window* w = window_find_by_class(WC_TITLE_EDITOR);
|
||||
WindowTextInputOpen(
|
||||
w, WIDX_TITLE_EDITOR_RENAME_SAVE, STR_FILEBROWSER_RENAME_SAVE_TITLE, STR_ERROR_EXISTING_NAME, {}, STR_STRING,
|
||||
reinterpret_cast<uintptr_t>(_renameSavePath), 52 - 1);
|
||||
reinterpret_cast<uintptr_t>(_renameSavePath.c_str()), 52 - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
TitleSequenceAddPark(*_editingTitleSequence, path, filename);
|
||||
TitleSequenceAddPark(*_editingTitleSequence, path, filename.c_str());
|
||||
}
|
||||
|
||||
static void WindowTitleEditorRenamePark(size_t index, const utf8* name)
|
||||
|
|
|
@ -578,13 +578,11 @@ void save_game_with_name(u8string_view name)
|
|||
|
||||
void* create_save_game_as_intent()
|
||||
{
|
||||
char name[MAX_PATH];
|
||||
safe_strcpy(name, path_get_filename(gScenarioSavePath.c_str()), MAX_PATH);
|
||||
path_remove_extension(name);
|
||||
auto name = Path::GetFileNameWithoutExtension(gScenarioSavePath);
|
||||
|
||||
Intent* intent = new Intent(WC_LOADSAVE);
|
||||
intent->putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME);
|
||||
intent->putExtra(INTENT_EXTRA_PATH, std::string{ name });
|
||||
intent->putExtra(INTENT_EXTRA_PATH, name);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "../core/Console.hpp"
|
||||
#include "../core/File.h"
|
||||
#include "../core/Imaging.h"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../drawing/Drawing.h"
|
||||
#include "../drawing/X8DrawingEngine.h"
|
||||
#include "../localisation/Formatter.h"
|
||||
|
@ -415,9 +416,10 @@ void screenshot_giant()
|
|||
WriteDpiToFile(path.value(), &dpi, gPalette);
|
||||
|
||||
// Show user that screenshot saved successfully
|
||||
const auto filename = Path::GetFileName(path.value());
|
||||
Formatter ft;
|
||||
ft.Add<rct_string_id>(STR_STRING);
|
||||
ft.Add<char*>(path_get_filename(path->c_str()));
|
||||
ft.Add<const utf8*>(filename.c_str());
|
||||
context_show_error(STR_SCREENSHOT_SAVED_AS, STR_NONE, ft);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
|
|
|
@ -340,7 +340,7 @@ namespace RCT1
|
|||
return "";
|
||||
}
|
||||
|
||||
return path_get_filename(scenarioEntry->path);
|
||||
return Path::GetFileName(scenarioEntry->path);
|
||||
}
|
||||
|
||||
void InitialiseEntryMaps()
|
||||
|
|
|
@ -383,7 +383,7 @@ public:
|
|||
return result;
|
||||
}
|
||||
|
||||
const scenario_index_entry* GetByFilename(const utf8* filename) const override
|
||||
const scenario_index_entry* GetByFilename(u8string_view filename) const override
|
||||
{
|
||||
for (const auto& scenario : _scenarios)
|
||||
{
|
||||
|
|
|
@ -75,7 +75,7 @@ struct IScenarioRepository
|
|||
|
||||
virtual size_t GetCount() const abstract;
|
||||
virtual const scenario_index_entry* GetByIndex(size_t index) const abstract;
|
||||
virtual const scenario_index_entry* GetByFilename(const utf8* filename) const abstract;
|
||||
virtual const scenario_index_entry* GetByFilename(u8string_view filename) const abstract;
|
||||
/**
|
||||
* Does not return custom scenarios due to the fact that they may have the same name.
|
||||
*/
|
||||
|
|
|
@ -81,7 +81,7 @@ utf8* path_get_directory(const utf8* path)
|
|||
return directory;
|
||||
}
|
||||
|
||||
const char* path_get_filename(const utf8* path)
|
||||
static const char* path_get_filename(const utf8* path)
|
||||
{
|
||||
// Find last slash or backslash in the path
|
||||
char* filename = const_cast<char*>(strrchr(path, *PATH_SEPARATOR));
|
||||
|
|
|
@ -26,7 +26,6 @@ int32_t mph_to_dmps(int32_t mph);
|
|||
bool filename_valid_characters(const utf8* filename);
|
||||
|
||||
char* path_get_directory(const utf8* path);
|
||||
const char* path_get_filename(const utf8* path);
|
||||
void path_set_extension(utf8* path, const utf8* newExtension, size_t size);
|
||||
void path_append_extension(utf8* path, const utf8* newExtension, size_t size);
|
||||
void path_remove_extension(utf8* path);
|
||||
|
|
Loading…
Reference in a new issue