1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Merge pull request #789 from duncanspumpkin/track_rename_delete

Track rename delete
This commit is contained in:
Ted John
2015-02-12 19:03:24 +00:00
2 changed files with 64 additions and 2 deletions

View File

@@ -93,6 +93,8 @@ void osinterface_set_cursor(char cursor);
HANDLE osinterface_file_open(const char* filename);
int osinterface_file_read(HANDLE handle, void* data, int size);
int osinterface_file_close(HANDLE handle);
int osinterface_file_move(const char* srcfilename, const char* dstfilename);
int osinterface_file_delete(const char* filename);
int osinterface_open_common_file_dialog(int type, char *title, char *filename, char *filterPattern, char *filterName);
void osinterface_show_messagebox(char* message);

View File

@@ -1055,7 +1055,47 @@ rct_track_design *track_get_info(int index, uint8** preview)
*/
int track_rename(const char *text)
{
return (RCT2_CALLPROC_X(0x006D3664, 0, 0, 0, 0, 0, (int)text, 0) & 0x100) == 0;
const char* txt_chr = text;
while (*txt_chr != '\0'){
switch (*txt_chr){
case '.':
case '/':
case '\\':
case '*':
case '?':
// Invalid characters
RCT2_GLOBAL(0x141E9AC, uint16) = 3353;
return 0;
}
txt_chr++;
}
char new_path[MAX_PATH];
subsitute_path(new_path, RCT2_ADDRESS(RCT2_ADDRESS_TRACKS_PATH, char), text);
strcat(new_path, ".TD6");
rct_window* w = window_find_by_class(WC_TRACK_DESIGN_LIST);
char old_path[MAX_PATH];
subsitute_path(old_path, RCT2_ADDRESS(RCT2_ADDRESS_TRACKS_PATH, char), &RCT2_ADDRESS(RCT2_ADDRESS_TRACK_LIST, char)[128 * w->track_list.var_482]);
if (osinterface_file_move(old_path, new_path)){
RCT2_GLOBAL(0x141E9AC, uint16) = 3354;
return 0;
}
ride_list_item item = { 0xFC, 0 };
track_load_list(item);
item.type = RCT2_GLOBAL(0xF44158, uint8);
item.entry_index = RCT2_GLOBAL(0xF44159, uint8);
track_load_list(item);
reset_track_list_cache();
window_invalidate(w);
return 1;
}
/**
@@ -1064,5 +1104,25 @@ int track_rename(const char *text)
*/
int track_delete()
{
return (RCT2_CALLPROC_X(0x006D3761, 0, 0, 0, 0, 0, 0, 0) & 0x100) == 0;
rct_window* w = window_find_by_class(WC_TRACK_DESIGN_LIST);
char path[MAX_PATH];
subsitute_path(path, RCT2_ADDRESS(RCT2_ADDRESS_TRACKS_PATH, char), &RCT2_ADDRESS(RCT2_ADDRESS_TRACK_LIST, char)[128 * w->track_list.var_482]);
if (osinterface_file_delete(path)){
RCT2_GLOBAL(0x141E9AC, uint16) = 3355;
return 0;
}
ride_list_item item = { 0xFC, 0 };
track_load_list(item);
item.type = RCT2_GLOBAL(0xF44158, uint8);
item.entry_index = RCT2_GLOBAL(0xF44159, uint8);
track_load_list(item);
reset_track_list_cache();
window_invalidate(w);
return 1;
}