mirror of https://github.com/OpenRCT2/OpenRCT2.git
Fix rename park in sequence
This commit is contained in:
parent
ca27018231
commit
067d364002
|
@ -38,6 +38,11 @@ namespace File
|
||||||
return platform_file_delete(path);
|
return platform_file_delete(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Move(const utf8 * srcPath, const utf8 * dstPath)
|
||||||
|
{
|
||||||
|
return platform_file_move(srcPath, dstPath);
|
||||||
|
}
|
||||||
|
|
||||||
void * ReadAllBytes(const utf8 * path, size_t * length)
|
void * ReadAllBytes(const utf8 * path, size_t * length)
|
||||||
{
|
{
|
||||||
void * result = nullptr;
|
void * result = nullptr;
|
||||||
|
|
|
@ -22,5 +22,6 @@ namespace File
|
||||||
{
|
{
|
||||||
bool Copy(const utf8 * srcPath, const utf8 * dstPath, bool overwrite);
|
bool Copy(const utf8 * srcPath, const utf8 * dstPath, bool overwrite);
|
||||||
bool Delete(const utf8 * path);
|
bool Delete(const utf8 * path);
|
||||||
|
bool Move(const utf8 * srcPath, const utf8 * dstPath);
|
||||||
void * ReadAllBytes(const utf8 * path, size_t * length);
|
void * ReadAllBytes(const utf8 * path, size_t * length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,12 @@ public:
|
||||||
uint64 index = zip_name_locate(_zip, path, 0);
|
uint64 index = zip_name_locate(_zip, path, 0);
|
||||||
zip_delete(_zip, index);
|
zip_delete(_zip, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenameFile(const utf8 * path, const utf8 * newPath) override
|
||||||
|
{
|
||||||
|
uint64 index = zip_name_locate(_zip, path, 0);
|
||||||
|
zip_file_rename(_zip, index, newPath, ZIP_FL_ENC_GUESS);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Zip
|
namespace Zip
|
||||||
|
|
|
@ -40,6 +40,7 @@ interface IZipArchive
|
||||||
virtual void SetFileData(const utf8 * path, void * data, size_t dataSize) abstract;
|
virtual void SetFileData(const utf8 * path, void * data, size_t dataSize) abstract;
|
||||||
|
|
||||||
virtual void DeleteFile(const utf8 * path) abstract;
|
virtual void DeleteFile(const utf8 * path) abstract;
|
||||||
|
virtual void RenameFile(const utf8 * path, const utf8 * newPath) abstract;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ZIP_ACCESS
|
enum ZIP_ACCESS
|
||||||
|
|
|
@ -258,9 +258,45 @@ extern "C"
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TileSequenceRenamePark(TitleSequence * seq, size_t index, const utf8 * name)
|
||||||
|
{
|
||||||
|
Guard::Assert(index < seq->NumSaves, GUARD_LINE);
|
||||||
|
|
||||||
|
utf8 * oldRelativePath = seq->Saves[index];
|
||||||
|
if (seq->IsZip)
|
||||||
|
{
|
||||||
|
IZipArchive * zip = Zip::TryOpen(seq->Path, ZIP_ACCESS_WRITE);
|
||||||
|
if (zip == nullptr)
|
||||||
|
{
|
||||||
|
Console::Error::WriteLine("Unable to open '%s'", seq->Path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
zip->RenameFile(oldRelativePath, name);
|
||||||
|
delete zip;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
utf8 srcPath[MAX_PATH];
|
||||||
|
utf8 dstPath[MAX_PATH];
|
||||||
|
String::Set(srcPath, sizeof(srcPath), seq->Path);
|
||||||
|
Path::Append(srcPath, sizeof(srcPath), oldRelativePath);
|
||||||
|
String::Set(dstPath, sizeof(dstPath), seq->Path);
|
||||||
|
Path::Append(dstPath, sizeof(dstPath), name);
|
||||||
|
if (!File::Move(srcPath, dstPath))
|
||||||
|
{
|
||||||
|
Console::Error::WriteLine("Unable to move '%s' to '%s'", srcPath, dstPath);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Memory::Free(seq->Saves[index]);
|
||||||
|
seq->Saves[index] = String::Duplicate(name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool TitleSequenceRemovePark(TitleSequence * seq, size_t index)
|
bool TitleSequenceRemovePark(TitleSequence * seq, size_t index)
|
||||||
{
|
{
|
||||||
Guard::Assert(seq->NumSaves > index, GUARD_LINE);
|
Guard::Assert(index < seq->NumSaves, GUARD_LINE);
|
||||||
|
|
||||||
// Delete park file
|
// Delete park file
|
||||||
utf8 * relativePath = seq->Saves[index];
|
utf8 * relativePath = seq->Saves[index];
|
||||||
|
|
|
@ -95,6 +95,7 @@ extern "C"
|
||||||
void TitleSequenceCloseParkHandle(TitleSequenceParkHandle * handle);
|
void TitleSequenceCloseParkHandle(TitleSequenceParkHandle * handle);
|
||||||
bool TileSequenceSave(TitleSequence * seq);
|
bool TileSequenceSave(TitleSequence * seq);
|
||||||
bool TileSequenceAddPark(TitleSequence * seq, const utf8 * path, const utf8 * name);
|
bool TileSequenceAddPark(TitleSequence * seq, const utf8 * path, const utf8 * name);
|
||||||
|
bool TileSequenceRenamePark(TitleSequence * seq, size_t index, const utf8 * name);
|
||||||
bool TitleSequenceRemovePark(TitleSequence * seq, size_t index);
|
bool TitleSequenceRemovePark(TitleSequence * seq, size_t index);
|
||||||
|
|
||||||
bool TitleSequenceIsLoadCommand(const TitleCommand * command);
|
bool TitleSequenceIsLoadCommand(const TitleCommand * command);
|
||||||
|
|
|
@ -65,7 +65,7 @@ static void window_title_editor_load_sequence(size_t index);
|
||||||
static ITitleSequencePlayer * window_title_editor_get_player();
|
static ITitleSequencePlayer * window_title_editor_get_player();
|
||||||
static bool window_title_editor_check_can_edit();
|
static bool window_title_editor_check_can_edit();
|
||||||
static void window_title_editor_add_park_callback(int result, const utf8 * path);
|
static void window_title_editor_add_park_callback(int result, const utf8 * path);
|
||||||
static void window_title_editor_save_sequence();
|
static void window_title_editor_rename_park(size_t index, const utf8 * name);
|
||||||
|
|
||||||
static rct_window_event_list window_title_editor_events = {
|
static rct_window_event_list window_title_editor_events = {
|
||||||
window_title_editor_close,
|
window_title_editor_close,
|
||||||
|
@ -399,7 +399,7 @@ static void window_title_editor_mouseup(rct_window *w, int widgetIndex)
|
||||||
if (w->selected_list_item >= (sint16)_editingTitleSequence->NumCommands) {
|
if (w->selected_list_item >= (sint16)_editingTitleSequence->NumCommands) {
|
||||||
w->selected_list_item--;
|
w->selected_list_item--;
|
||||||
}
|
}
|
||||||
window_title_editor_save_sequence();
|
TileSequenceSave(_editingTitleSequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -422,7 +422,7 @@ static void window_title_editor_mouseup(rct_window *w, int widgetIndex)
|
||||||
*a = *b;
|
*a = *b;
|
||||||
*b = tmp;
|
*b = tmp;
|
||||||
w->selected_list_item++;
|
w->selected_list_item++;
|
||||||
window_title_editor_save_sequence();
|
TileSequenceSave(_editingTitleSequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -435,7 +435,7 @@ static void window_title_editor_mouseup(rct_window *w, int widgetIndex)
|
||||||
*b = *a;
|
*b = *a;
|
||||||
*a = tmp;
|
*a = tmp;
|
||||||
w->selected_list_item--;
|
w->selected_list_item--;
|
||||||
window_title_editor_save_sequence();
|
TileSequenceSave(_editingTitleSequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -641,17 +641,7 @@ static void window_title_editor_textinput(rct_window *w, int widgetIndex, char *
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WIDX_TITLE_EDITOR_RENAME_SAVE:
|
case WIDX_TITLE_EDITOR_RENAME_SAVE:
|
||||||
// if (filename_valid_characters(text)) {
|
window_title_editor_rename_park(w->selected_list_item, text);
|
||||||
// if (!title_sequence_save_exists(_selectedTitleSequence, text)) {
|
|
||||||
// title_sequence_rename_save(_selectedTitleSequence, w->selected_list_item, text);
|
|
||||||
// TileSequenceSave(_editingTitleSequence);
|
|
||||||
// window_invalidate(w);
|
|
||||||
// } else {
|
|
||||||
// window_error_open(STR_ERROR_EXISTING_NAME, STR_NONE);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// window_error_open(STR_ERROR_INVALID_CHARACTERS, STR_NONE);
|
|
||||||
// }
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1024,9 +1014,24 @@ static void window_title_editor_add_park_callback(int result, const utf8 * path)
|
||||||
TileSequenceAddPark(_editingTitleSequence, path, filename);
|
TileSequenceAddPark(_editingTitleSequence, path, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_title_editor_save_sequence()
|
static void window_title_editor_rename_park(size_t index, const utf8 * name)
|
||||||
{
|
{
|
||||||
if (_editingTitleSequence != NULL) {
|
if (!filename_valid_characters(name)) {
|
||||||
|
window_error_open(STR_ERROR_INVALID_CHARACTERS, STR_NONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < _editingTitleSequence->NumSaves; i++) {
|
||||||
|
if (i != index) {
|
||||||
|
const utf8 * savePath = _editingTitleSequence->Saves[i];
|
||||||
|
if (_strcmpi(savePath, name) == 0) {
|
||||||
|
window_error_open(STR_ERROR_EXISTING_NAME, STR_NONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TileSequenceRenamePark(_editingTitleSequence, index, name)) {
|
||||||
TileSequenceSave(_editingTitleSequence);
|
TileSequenceSave(_editingTitleSequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue