Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Cleanup] onplay.c fileop.c

clean-up a bit more
add/correct some comments

fix some error passing
guard delete path on PATH_TOO_LONG

add some cpu_boost

Change-Id: Icf179dd727271bdc61ab78400e10847222b9f858

authored by

William Wilgus and committed by
William Wilgus
b0dfcde2 3e9ca6ec

+300 -310
+168 -176
apps/fileop.c
··· 1 1 /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 8 * $Id$ 9 9 * 10 10 * Copyright (C) 2002 Björn Stenberg ··· 50 50 size_t append; /* Append position in 'path' for stack push */ 51 51 }; 52 52 53 + static int prompt_name(char* buf, size_t bufsz) 54 + { 55 + if (kbd_input(buf, bufsz, NULL) < 0) 56 + return FORC_CANCELLED; 57 + /* at least prevent escapes out of the base directory from keyboard- 58 + entered filenames; the file code should reject other invalidities */ 59 + if (*buf != '\0' && !strchr(buf, PATH_SEPCH) && !is_dotdir_name(buf)) 60 + return FORC_SUCCESS; 61 + return FORC_UNKNOWN_FAILURE; 62 + } 63 + 53 64 static bool poll_cancel_action(const char *path, int operation, int current, int total) 54 65 { 55 66 const char *op_str = ""; ··· 75 86 return ACTION_STD_CANCEL == get_action(CONTEXT_STD, TIMEOUT_NOBLOCK); 76 87 } 77 88 78 - static struct file_op_params* init_file_op(struct file_op_params *param, 89 + static void init_file_op(struct file_op_params *param, 79 90 const char *basename, 80 91 const char *selected_file) 81 92 { ··· 90 101 param->is_dir = dir_exists(param->path); 91 102 param->objects = 0; /* how many files and subdirectories*/ 92 103 param->processed = 0; 93 - 94 - return param; 95 104 } 96 105 97 106 /* counts file objects, deletes file objects */ ··· 144 153 145 154 if (info.attribute & ATTR_DIRECTORY) { 146 155 /* remove a subdirectory */ 147 - rc = directory_fileop(param, fileop); 156 + rc = directory_fileop(param, fileop); /* recursion */ 148 157 } else { 149 158 /* remove a file */ 150 159 if (poll_cancel_action(param->path, FOC_DELETE, param->processed, param->objects)) ··· 165 174 } 166 175 167 176 if (info.attribute & ATTR_DIRECTORY) { 168 - /* remove a subdirectory */ 169 - rc = directory_fileop(param, FOC_COUNT); 177 + /* enter subdirectory */ 178 + rc = directory_fileop(param, FOC_COUNT); /* recursion */ 170 179 } else { 171 180 if (poll_cancel_action(param->path, FOC_COUNT, param->objects, 0)) 172 181 { ··· 195 204 return rc; 196 205 } 197 206 207 + /* Walk a directory tree and count the number of objects (dirs & files) 208 + * also check that enough resources exist to do an operation */ 198 209 static int check_count_fileobjects(struct file_op_params *param) 199 210 { 211 + cpu_boost(true); 200 212 int rc = directory_fileop(param, FOC_COUNT); 213 + cpu_boost(false); 201 214 DEBUGF("%s res:(%d) objects %d \n", __func__, rc, param->objects); 202 215 return rc; 203 216 } 204 217 205 - static bool check_new_name(const char *basename) 206 - { 207 - /* at least prevent escapes out of the base directory from keyboard- 208 - entered filenames; the file code should reject other invalidities */ 209 - return *basename != '\0' && !strchr(basename, PATH_SEPCH) && 210 - !is_dotdir_name(basename); 211 - } 212 - 213 - int create_dir(void) 214 - { 215 - int rc = FORC_UNKNOWN_FAILURE; 216 - char dirname[MAX_PATH]; 217 - size_t pathlen = path_append(dirname, getcwd(NULL, 0), PA_SEP_HARD, 218 - sizeof (dirname)); 219 - char *basename = dirname + pathlen; 220 - 221 - if (pathlen >= sizeof (dirname)) { 222 - /* Too long */ 223 - } else if (kbd_input(basename, sizeof (dirname) - pathlen, NULL) < 0) { 224 - rc = FORC_CANCELLED; 225 - } else if (check_new_name(basename)) { 226 - rc = mkdir(dirname); 227 - } 228 - 229 - return rc; 230 - } 231 - 232 - /************************************************************************************/ 233 - /* share code for file and directory deletion, saves space */ 234 - static int delete_file_dir(struct file_op_params *param) 235 - { 236 - /* Note: delete_file_dir() will happily delete whatever 237 - * path is passed (after confirmation) */ 238 - if (confirm_delete_yesno(param->path) != YESNO_YES) { 239 - return FORC_CANCELLED; 240 - } 241 - 242 - clear_screen_buffer(true); 243 - poll_cancel_action(param->path, FOC_DELETE, param->processed, param->objects); 244 - 245 - int rc = FORC_UNKNOWN_FAILURE; 246 - 247 - if (param->is_dir) { /* if directory */ 248 - cpu_boost(true); 249 - rc = directory_fileop(param, FOC_DELETE); 250 - cpu_boost(false); 251 - } else { 252 - rc = remove(param->path); 253 - } 254 - 255 - return rc; 256 - } 257 - 258 - int delete_fileobject(const char *selected_file) 259 - { 260 - struct file_op_params param; 261 - if (init_file_op(&param, selected_file, NULL)->is_dir == true) 262 - { 263 - int rc = check_count_fileobjects(&param); 264 - DEBUGF("%s res: %d, ct: %d, %s", __func__, rc, param.objects, param.path); 265 - if (rc != FORC_SUCCESS) 266 - return rc; 267 - } 268 - 269 - return delete_file_dir(&param); 270 - } 271 - 272 - int rename_file(const char *selected_file) 273 - { 274 - int rc = FORC_UNKNOWN_FAILURE; 275 - char newname[MAX_PATH]; 276 - const char *oldbase, *selection = selected_file; 277 - 278 - path_basename(selection, &oldbase); 279 - size_t pathlen = oldbase - selection; 280 - char *newbase = newname + pathlen; 281 - 282 - if (strmemccpy(newname, selection, sizeof (newname)) == NULL) { 283 - /* Too long */ 284 - } else if (kbd_input(newbase, sizeof (newname) - pathlen, NULL) < 0) { 285 - rc = FORC_CANCELLED; 286 - } else if (!strcmp(oldbase, newbase)) { 287 - rc = FORC_NOOP; /* No change at all */ 288 - } else if (check_new_name(newbase)) { 289 - switch (relate(selection, newname)) 290 - { 291 - case RELATE_DIFFERENT: 292 - if (file_exists(newname)) { 293 - break; /* don't overwrite */ 294 - } 295 - /* Fall-through */ 296 - case RELATE_SAME: 297 - rc = rename(selection, newname); 298 - break; 299 - case RELATE_PREFIX: 300 - default: 301 - break; 302 - } 303 - } 304 - 305 - return rc; 306 - } 307 - 218 + /* Attempt to just rename a file or directory */ 308 219 static int move_by_rename(const char *src_path, 309 220 const char *dst_path, 310 221 unsigned int *pflags) 311 222 { 312 223 unsigned int flags = *pflags; 313 224 int rc = FORC_UNKNOWN_FAILURE; 314 - while (!(flags & (PASTE_COPY | PASTE_EXDEV))) { 225 + if (!(flags & (PASTE_COPY | PASTE_EXDEV))) { 315 226 if ((flags & PASTE_OVERWRITE) || !file_exists(dst_path)) { 316 227 /* Just try to move the directory / file */ 317 228 if (poll_cancel_action(src_path, FOC_MOVE, 0 , 0)) { 318 229 rc = FORC_CANCELLED; 319 230 } else { 320 231 rc = rename(src_path, dst_path); 321 - } 322 - 323 - if (rc < 0) { 324 - int errnum = errno; 325 - if (errnum == ENOTEMPTY && (flags & PASTE_OVERWRITE)) { 326 - /* Directory is not empty thus rename() will not do a quick 327 - overwrite */ 328 - break; 232 + #ifdef HAVE_MULTIVOLUME 233 + if (rc < FORC_SUCCESS && errno == EXDEV) { 234 + /* Failed because cross volume rename doesn't work */ 235 + *pflags |= PASTE_EXDEV; /* force a move instead */ 329 236 } 330 - #ifdef HAVE_MULTIVOLUME 331 - else if (errnum == EXDEV) { 332 - /* Failed because cross volume rename doesn't work; force 333 - a move instead */ 334 - *pflags |= PASTE_EXDEV; 335 - break; 336 - } 337 - #endif /* HAVE_MULTIVOLUME */ 237 + #endif /* HAVE_MULTIVOLUME */ 238 + /* if (errno == ENOTEMPTY && (flags & PASTE_OVERWRITE)) { 239 + * Directory is not empty thus rename() will not do a quick overwrite */ 338 240 } 339 241 } 340 242 341 - break; 342 243 } 343 244 return rc; 344 245 } ··· 365 266 return FORC_NO_BUFFER_AVAIL; 366 267 } 367 268 368 - buffersize &= ~0x1ff; /* Round buffer size to multiple of sector 369 - size */ 269 + buffersize &= ~0x1ff; /* Round buffer size to multiple of sector size */ 370 270 371 271 int src_fd = open(src_path, O_RDONLY); 372 272 if (src_fd >= 0) { ··· 423 323 } 424 324 425 325 if (rc == FORC_SUCCESS) { 426 - /* If overwriting, set the correct length if original was 427 - longer */ 428 - rc = ftruncate(dst_fd, total_size) * 10; 326 + if (total_size != src_sz) 327 + rc = FORC_UNKNOWN_FAILURE; 328 + else { 329 + /* If overwriting, set the correct length if original was longer */ 330 + rc = ftruncate(dst_fd, total_size) * 10; 331 + } 429 332 } 430 333 431 334 close(dst_fd); ··· 449 352 450 353 /* Paste a directory */ 451 354 static int copy_move_directory(struct file_op_params *src, 452 - struct file_op_params *dst, 453 - unsigned int flags) 355 + struct file_op_params *dst, 356 + unsigned int flags) 454 357 { 455 - int rc = FORC_UNKNOWN_FAILURE; 358 + DIR *srcdir = opendir(src->path); 456 359 457 - DIR *srcdir = opendir(src->path); 360 + if (!srcdir) 361 + return FORC_PATH_NOT_EXIST; 458 362 459 - if (srcdir) { 460 - /* Make a directory to copy things to */ 461 - rc = mkdir(dst->path) * 10; 462 - if (rc < 0 && errno == EEXIST && (flags & PASTE_OVERWRITE)) { 463 - /* Exists and overwrite was approved */ 464 - rc = FORC_SUCCESS; 465 - } 363 + /* Make a directory to copy things to */ 364 + int rc = mkdir(dst->path) * 10; 365 + if (rc < 0 && errno == EEXIST && (flags & PASTE_OVERWRITE)) { 366 + /* Exists and overwrite was approved */ 367 + rc = FORC_SUCCESS; 466 368 } 467 369 468 370 size_t srcap = src->append, dstap = dst->append; ··· 488 390 /* Append names to current directories */ 489 391 src->append = srcap + 490 392 path_append(&src->path[srcap], PA_SEP_HARD, entry->d_name, 491 - sizeof(src->path) - srcap); 393 + sizeof (src->path) - srcap); 492 394 493 395 dst->append = dstap + 494 396 path_append(&dst->path[dstap], PA_SEP_HARD, entry->d_name, ··· 538 440 return rc; 539 441 } 540 442 443 + /************************************************************************************/ 444 + /* PUBLIC FUNCTIONS */ 445 + /************************************************************************************/ 446 + 447 + /* Copy or move a file or directory see: file_op_flags */ 541 448 int copy_move_fileobject(const char *src_path, const char *dst_path, unsigned int flags) 542 449 { 543 450 if (!src_path[0]) 544 451 return FORC_NOOP; 545 - 546 - int rc = FORC_UNKNOWN_FAILURE; 547 452 548 453 struct file_op_params src, dst; 549 454 ··· 553 458 554 459 /* Final target is current directory plus name of selection */ 555 460 init_file_op(&dst, dst_path, nameptr); 461 + if (dst.append >= sizeof (dst.path)) 462 + return FORC_PATH_TOO_LONG; 556 463 557 - switch (dst.append < sizeof (dst.path) ? 558 - relate(src_path, dst.path) : FORC_PATH_TOO_LONG) 559 - { 560 - case RELATE_SAME: 561 - rc = FORC_NOOP; 562 - break; 464 + int rel = relate(src_path, dst.path); 465 + if (rel == RELATE_SAME) 466 + return FORC_NOOP; 563 467 564 - case RELATE_DIFFERENT: 468 + if (rel == RELATE_DIFFERENT) { 469 + int rc; 565 470 if (file_exists(dst.path)) { 566 471 /* If user chooses not to overwrite, cancel */ 567 472 if (confirm_overwrite_yesno() == YESNO_NO) { 568 - rc = FORC_NOOVERWRT; 569 - break; 473 + return FORC_NOOVERWRT; 570 474 } 571 475 572 476 flags |= PASTE_OVERWRITE; 573 477 } 574 478 479 + init_file_op(&src, src_path, NULL); 480 + if (src.append >= sizeof (src.path)) 481 + return FORC_PATH_TOO_LONG; 575 482 /* Now figure out what we're doing */ 576 483 cpu_boost(true); 577 - 578 - init_file_op(&src, src_path, NULL); 579 - 580 484 if (src.is_dir) { 581 485 /* Copy or move a subdirectory */ 582 - 583 - if (src.append < sizeof (src.path)) { 584 - /* Try renaming first */ 585 - rc = move_by_rename(src.path, dst.path, &flags); 586 - if (rc != FORC_SUCCESS && rc != FORC_CANCELLED) { 587 - if (check_count_fileobjects(&src) == FORC_SUCCESS) { 588 - rc = copy_move_directory(&src, &dst, flags); 589 - } 486 + /* Try renaming first */ 487 + rc = move_by_rename(src.path, dst.path, &flags); 488 + if (rc < FORC_SUCCESS) { 489 + rc = check_count_fileobjects(&src); 490 + if (rc == FORC_SUCCESS) { 491 + rc = copy_move_directory(&src, &dst, flags); 590 492 } 591 493 } 592 494 } else { ··· 595 497 } 596 498 597 499 cpu_boost(false); 598 - break; 500 + DEBUGF("%s res: %d, ct: %d/%d %s\n", 501 + __func__, rc, src.objects, src.processed, src.path); 502 + return rc; 503 + } 599 504 600 - case RELATE_PREFIX: 601 - default: /* Some other relation / failure */ 602 - break; 505 + /* Else Some other relation / failure */ 506 + DEBUGF("%s res: %d, rel: %d\n", __func__, rc, rel); 507 + return FORC_UNKNOWN_FAILURE; 508 + } 509 + 510 + int create_dir(void) 511 + { 512 + int rc; 513 + char dirname[MAX_PATH]; 514 + size_t pathlen = path_append(dirname, getcwd(NULL, 0), PA_SEP_HARD, 515 + sizeof (dirname)); 516 + char *basename = dirname + pathlen; 517 + 518 + if (pathlen >= sizeof (dirname)) 519 + return FORC_PATH_TOO_LONG; 520 + 521 + rc = prompt_name(basename, sizeof (dirname) - pathlen); 522 + if (rc == FORC_SUCCESS) 523 + rc = mkdir(dirname) * 10; 524 + return rc; 525 + } 526 + 527 + /* share code for file and directory deletion, saves space */ 528 + int delete_fileobject(const char *selected_file) 529 + { 530 + int rc; 531 + struct file_op_params param; 532 + init_file_op(&param, selected_file, NULL); 533 + if (param.append >= sizeof (param.path)) 534 + return FORC_PATH_TOO_LONG; 535 + 536 + if (param.is_dir) { 537 + int rc = check_count_fileobjects(&param); 538 + DEBUGF("%s res: %d, ct: %d, %s", __func__, rc, param.objects, param.path); 539 + if (rc != FORC_SUCCESS) 540 + return rc; 541 + } 542 + 543 + /* Note: delete_fileobject() will happily delete whatever 544 + * path is passed (after confirmation) */ 545 + if (confirm_delete_yesno(param.path) != YESNO_YES) { 546 + return FORC_CANCELLED; 547 + } 548 + 549 + clear_screen_buffer(true); 550 + if (poll_cancel_action(param.path, FOC_DELETE, param.processed, param.objects)) 551 + return FORC_CANCELLED; 552 + 553 + if (param.is_dir) { /* if directory */ 554 + cpu_boost(true); 555 + rc = directory_fileop(&param, FOC_DELETE); 556 + cpu_boost(false); 557 + } else { 558 + rc = remove(param.path) * 10; 603 559 } 604 560 605 561 return rc; 606 562 } 563 + 564 + int rename_file(const char *selected_file) 565 + { 566 + int rc; 567 + char newname[MAX_PATH]; 568 + const char *oldbase, *selection = selected_file; 569 + 570 + path_basename(selection, &oldbase); 571 + size_t pathlen = oldbase - selection; 572 + char *newbase = newname + pathlen; 573 + 574 + if (strmemccpy(newname, selection, sizeof (newname)) == NULL) 575 + return FORC_PATH_TOO_LONG; 576 + 577 + rc = prompt_name(newbase, sizeof (newname) - pathlen); 578 + 579 + if (rc != FORC_SUCCESS) 580 + return rc; 581 + 582 + if (!strcmp(oldbase, newbase)) 583 + return FORC_NOOP; /* No change at all */ 584 + 585 + int rel = relate(selection, newname); 586 + if (rel == RELATE_DIFFERENT) 587 + { 588 + if (file_exists(newname)) { /* don't overwrite */ 589 + return FORC_PATH_EXISTS; 590 + } 591 + return rename(selection, newname) * 10; 592 + } 593 + if (rel == RELATE_SAME) 594 + return rename(selection, newname) * 10; 595 + 596 + /* Else Some other relation / failure */ 597 + return FORC_UNKNOWN_FAILURE; 598 + }
+10 -9
apps/fileop.h
··· 1 1 /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 8 * $Id$ 9 9 * 10 10 * Copyright (C) 2002 Björn Stenberg ··· 26 26 /* result codes of various file operations */ 27 27 enum fileop_result_code 28 28 { 29 + FORC_PATH_EXISTS = -8, 29 30 FORC_READ_FAILURE = -7, 30 31 FORC_WRITE_FAILURE = -6, 31 32 FORC_NO_BUFFER_AVAIL = -5, ··· 55 56 FOC_MOVE, 56 57 FOC_COPY, 57 58 FOC_DELETE, 58 - FOC_CREATE, 59 59 }; 60 60 61 61 int create_dir(void); ··· 64 64 65 65 int delete_fileobject(const char *selected_file); 66 66 67 - int copy_move_fileobject(const char *src_path, const char *dst_path, 68 - unsigned int flags); 67 + int copy_move_fileobject(const char *src_path, 68 + const char *dst_path, 69 + unsigned int flags); 69 70 70 71 #endif /* FILEOP_H */
+121 -124
apps/onplay.c
··· 65 65 #include "shortcuts.h" 66 66 #include "misc.h" 67 67 68 - static int context; 69 - static const char *selected_file = NULL; 70 - static char selected_file_path[MAX_PATH]; 71 - static int selected_file_attr = 0; 72 68 static int onplay_result = ONPLAY_OK; 73 69 static bool in_queue_submenu = false; 70 + 74 71 static bool (*ctx_current_playlist_insert)(int position, bool queue, bool create_new); 75 72 static int (*ctx_add_to_playlist)(const char* playlist, bool new_playlist); 76 73 extern struct menu_item_ex file_menu; /* settings_menu.c */ ··· 84 81 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ 85 82 { (void*)name##_},{.callback_and_desc = & name##__}}; 86 83 84 + static struct selected_file 85 + { 86 + char buf[MAX_PATH]; 87 + const char *path; 88 + int attr; 89 + int context; 90 + } selected_file; 91 + 87 92 static struct clipboard 88 93 { 89 94 char path[MAX_PATH]; /* Clipped file's path */ 90 95 unsigned int attr; /* Clipped file's attributes */ 91 96 unsigned int flags; /* Operation type flags */ 92 97 } clipboard; 98 + 99 + /* set selected file (doesn't touch buffer) */ 100 + static void selected_file_set(int context, const char *path, int attr) 101 + { 102 + selected_file.path = path; 103 + selected_file.attr = attr; 104 + selected_file.context = context; 105 + } 93 106 94 107 /* Empty the clipboard */ 95 108 static void clipboard_clear_selection(struct clipboard *clip) ··· 149 162 struct gui_synclist *this_list) 150 163 { 151 164 (void) this_list; 152 - switch (action) 165 + if (action == ACTION_REQUEST_MENUITEM) 153 166 { 154 - case ACTION_REQUEST_MENUITEM: 155 - /* hide loading bookmarks menu if no bookmarks exist */ 156 - if (this_item == &bookmark_load_menu_item) 157 - { 158 - if (!bookmark_exists()) 159 - return ACTION_EXIT_MENUITEM; 160 - } 161 - break; 162 - case ACTION_EXIT_MENUITEM: 163 - settings_save(); 164 - break; 167 + /* hide loading bookmarks menu if no bookmarks exist */ 168 + if (this_item == &bookmark_load_menu_item) 169 + { 170 + if (!bookmark_exists()) 171 + return ACTION_EXIT_MENUITEM; 172 + } 165 173 } 174 + else if (action == ACTION_EXIT_MENUITEM) 175 + settings_save(); 176 + 166 177 return action; 167 178 } 168 179 ··· 244 255 static void op_playlist_insert_selected(int position, bool queue) 245 256 { 246 257 #ifdef HAVE_TAGCACHE 247 - if (context == CONTEXT_STD && ctx_current_playlist_insert != NULL) 258 + if (selected_file.context == CONTEXT_STD && ctx_current_playlist_insert != NULL) 248 259 { 249 260 ctx_current_playlist_insert(position, queue, false); 250 261 return; 251 262 } 252 263 #endif 253 - if ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO) 254 - playlist_insert_track(NULL, selected_file, position, queue, true); 255 - else if ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U) 256 - playlist_insert_playlist(NULL, selected_file, position, queue); 257 - else if (selected_file_attr & ATTR_DIRECTORY) 264 + if ((selected_file.attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO) 265 + playlist_insert_track(NULL, selected_file.path, position, queue, true); 266 + else if ((selected_file.attr & FILE_ATTR_MASK) == FILE_ATTR_M3U) 267 + playlist_insert_playlist(NULL, selected_file.path, position, queue); 268 + else if (selected_file.attr & ATTR_DIRECTORY) 258 269 { 259 270 #ifdef HAVE_TAGCACHE 260 - if (context == CONTEXT_ID3DB) 271 + if (selected_file.context == CONTEXT_ID3DB) 261 272 { 262 273 tagtree_current_playlist_insert(position, queue); 263 274 return; ··· 269 280 270 281 const char *lines[] = { 271 282 ID2P(LANG_RECURSE_DIRECTORY_QUESTION), 272 - selected_file 283 + selected_file.path 273 284 }; 274 285 const struct text_message message={lines, 2}; 275 286 /* Ask if user wants to recurse directory */ 276 287 recurse = (gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES); 277 288 } 278 289 279 - playlist_insert_directory(NULL, selected_file, position, queue, 290 + playlist_insert_directory(NULL, selected_file.path, position, queue, 280 291 recurse == RECURSE_ON); 281 292 } 282 293 } ··· 336 347 { 337 348 bool result; 338 349 339 - result = playlist_viewer_ex(selected_file, NULL); 350 + result = playlist_viewer_ex(selected_file.path, NULL); 340 351 341 352 if (result == PLAYLIST_VIEWER_OK && 342 353 onplay_result == ONPLAY_OK) ··· 431 442 struct gui_synclist *this_list) 432 443 { 433 444 (void)this_list; 434 - int sel_file_attr = (selected_file_attr & FILE_ATTR_MASK); 445 + int sel_file_attr = (selected_file.attr & FILE_ATTR_MASK); 435 446 436 447 switch (action) 437 448 { ··· 440 451 { 441 452 if (sel_file_attr != FILE_ATTR_AUDIO && 442 453 sel_file_attr != FILE_ATTR_M3U && 443 - (selected_file_attr & ATTR_DIRECTORY) == 0) 454 + (selected_file.attr & ATTR_DIRECTORY) == 0) 444 455 return ACTION_EXIT_MENUITEM; 445 456 } 446 457 else if (this_item == &queue_menu) ··· 471 482 return ACTION_EXIT_MENUITEM; 472 483 473 484 if (sel_file_attr != FILE_ATTR_M3U && 474 - (selected_file_attr & ATTR_DIRECTORY) == 0) 485 + (selected_file.attr & ATTR_DIRECTORY) == 0) 475 486 return ACTION_EXIT_MENUITEM; 476 487 } 477 488 ··· 494 505 495 506 void onplay_show_playlist_menu(const char* path, int attr, void (*playlist_insert_cb)) 496 507 { 497 - context = CONTEXT_STD; 498 508 ctx_current_playlist_insert = playlist_insert_cb; 499 - selected_file = path; 500 - selected_file_attr = attr; 509 + selected_file_set(CONTEXT_STD, path, attr); 501 510 in_queue_submenu = false; 502 511 do_menu(&tree_playlist_menu, NULL, NULL, false); 503 512 } ··· 505 514 /* playlist catalog options */ 506 515 static bool cat_add_to_a_playlist(void) 507 516 { 508 - return catalog_add_to_a_playlist(selected_file, selected_file_attr, 517 + return catalog_add_to_a_playlist(selected_file.path, selected_file.attr, 509 518 false, NULL, ctx_add_to_playlist); 510 519 } 511 520 512 521 static bool cat_add_to_a_new_playlist(void) 513 522 { 514 - return catalog_add_to_a_playlist(selected_file, selected_file_attr, 523 + return catalog_add_to_a_playlist(selected_file.path, selected_file.attr, 515 524 true, NULL, ctx_add_to_playlist); 516 525 } 517 526 ··· 529 538 530 539 void onplay_show_playlist_cat_menu(const char* track_name, int attr, void (*add_to_pl_cb)) 531 540 { 532 - context = CONTEXT_STD; 533 541 ctx_add_to_playlist = add_to_pl_cb; 534 - selected_file = track_name; 535 - selected_file_attr = attr; 542 + selected_file_set(CONTEXT_STD, track_name, attr); 536 543 do_menu(&cat_playlist_menu, NULL, NULL, false); 537 544 } 538 545 ··· 542 549 { 543 550 (void)this_item; 544 551 (void)this_list; 545 - if (!selected_file || 546 - (((selected_file_attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) && 547 - ((selected_file_attr & FILE_ATTR_MASK) != FILE_ATTR_M3U) && 548 - ((selected_file_attr & ATTR_DIRECTORY) == 0))) 552 + if (!selected_file.path || 553 + (((selected_file.attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) && 554 + ((selected_file.attr & FILE_ATTR_MASK) != FILE_ATTR_M3U) && 555 + ((selected_file.attr & ATTR_DIRECTORY) == 0))) 549 556 { 550 557 return ACTION_EXIT_MENUITEM; 551 558 } 552 559 553 - switch (action) 560 + if (action == ACTION_REQUEST_MENUITEM) 554 561 { 555 - case ACTION_REQUEST_MENUITEM: 556 - if ((audio_status() & AUDIO_STATUS_PLAY) || context != CONTEXT_WPS) 557 - { 558 - return action; 559 - } 560 - else 561 - return ACTION_EXIT_MENUITEM; 562 - break; 562 + if ((audio_status() & AUDIO_STATUS_PLAY) 563 + || selected_file.context != CONTEXT_WPS) 564 + { 565 + return action; 566 + } 567 + return ACTION_EXIT_MENUITEM; 563 568 } 564 569 return action; 565 570 } ··· 579 584 580 585 static bool clipboard_cut(void) 581 586 { 582 - return clipboard_clip(&clipboard, selected_file, selected_file_attr, 587 + return clipboard_clip(&clipboard, selected_file.path, selected_file.attr, 583 588 PASTE_CUT); 584 589 } 585 590 586 591 static bool clipboard_copy(void) 587 592 { 588 - return clipboard_clip(&clipboard, selected_file, selected_file_attr, 593 + return clipboard_clip(&clipboard, selected_file.path, selected_file.attr, 589 594 PASTE_COPY); 590 595 } 591 596 ··· 596 601 return 1; 597 602 598 603 int rc = copy_move_fileobject(clipboard.path, getcwd(NULL, 0), clipboard.flags); 599 - 600 - 601 - clear_screen_buffer(true); 602 604 603 605 switch (rc) 604 606 { ··· 643 645 { 644 646 (void)this_item; 645 647 (void)this_list; 646 - switch (action) 648 + if (action == ACTION_REQUEST_MENUITEM) 647 649 { 648 - case ACTION_REQUEST_MENUITEM: 649 - if (!selected_file || !global_settings.runtimedb || 650 - !tagcache_is_usable()) 651 - return ACTION_EXIT_MENUITEM; 652 - break; 650 + if (!selected_file.path || !global_settings.runtimedb || !tagcache_is_usable()) 651 + return ACTION_EXIT_MENUITEM; 653 652 } 654 653 return action; 655 654 } ··· 676 675 (void)this_item; 677 676 (void)this_list; 678 677 struct mp3entry* id3 = audio_current_track(); 679 - switch (action) 678 + if (action == ACTION_REQUEST_MENUITEM) 680 679 { 681 - case ACTION_REQUEST_MENUITEM: 682 - if (!selected_file 683 - || !id3 || !id3->cuesheet) 684 - return ACTION_EXIT_MENUITEM; 685 - break; 680 + if (!selected_file.path || !id3 || !id3->cuesheet) 681 + return ACTION_EXIT_MENUITEM; 686 682 } 687 683 return action; 688 684 } ··· 712 708 713 709 static int clipboard_delete_selected_fileobject(void) 714 710 { 715 - int rc = delete_fileobject(selected_file); 711 + int rc = delete_fileobject(selected_file.path); 716 712 if (rc < FORC_SUCCESS) { 717 713 splash_failed(LANG_DELETE, rc); 718 714 } else if (rc == FORC_CANCELLED) { ··· 747 743 748 744 static int clipboard_rename_selected_file(void) 749 745 { 750 - int rc = rename_file(selected_file); 746 + int rc = rename_file(selected_file.path); 751 747 752 748 show_result(rc, LANG_RENAME); 753 749 ··· 777 773 /* other items */ 778 774 static bool list_viewers(void) 779 775 { 780 - int ret = filetype_list_viewers(selected_file); 776 + int ret = filetype_list_viewers(selected_file.path); 781 777 if (ret == PLUGIN_USB_CONNECTED) 782 778 onplay_result = ONPLAY_RELOAD_DIR; 783 779 return false; ··· 786 782 #ifdef HAVE_TAGCACHE 787 783 static bool prepare_database_sel(void *param) 788 784 { 789 - if (context == CONTEXT_ID3DB && 790 - (selected_file_attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) 785 + if (selected_file.context == CONTEXT_ID3DB && 786 + (selected_file.attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) 791 787 { 792 788 if (!strcmp(param, "properties")) 793 - strmemccpy(selected_file_path, MAKE_ACT_STR(ACTIVITY_DATABASEBROWSER), 794 - sizeof(selected_file_path)); 795 - else if (!tagtree_get_subentry_filename(selected_file_path, MAX_PATH)) 789 + strmemccpy(selected_file.buf, MAKE_ACT_STR(ACTIVITY_DATABASEBROWSER), 790 + sizeof(selected_file.buf)); 791 + else if (!tagtree_get_subentry_filename(selected_file.buf, MAX_PATH)) 796 792 { 797 793 onplay_result = ONPLAY_RELOAD_DIR; 798 794 return false; 799 795 } 800 796 801 - selected_file = selected_file_path; 797 + selected_file.path = selected_file.buf; 802 798 } 803 799 return true; 804 800 } ··· 810 806 if (!prepare_database_sel(param)) 811 807 return false; 812 808 #endif 813 - int ret = filetype_load_plugin((const char*)param, selected_file); 809 + int ret = filetype_load_plugin((const char*)param, selected_file.path); 814 810 if (ret == PLUGIN_USB_CONNECTED) 815 811 onplay_result = ONPLAY_RELOAD_DIR; 816 812 else if (ret == PLUGIN_GOTO_PLUGIN) ··· 835 831 #endif 836 832 static bool onplay_add_to_shortcuts(void) 837 833 { 838 - shortcuts_add(SHORTCUT_BROWSER, selected_file); 834 + shortcuts_add(SHORTCUT_BROWSER, selected_file.path); 839 835 return false; 840 836 } 841 837 MENUITEM_FUNCTION(add_to_faves_item, 0, ID2P(LANG_ADD_TO_FAVES), ··· 844 840 845 841 static void set_dir_helper(char* dirnamebuf, size_t bufsz) 846 842 { 847 - path_append(dirnamebuf, selected_file, PA_SEP_HARD, bufsz); 843 + path_append(dirnamebuf, selected_file.path, PA_SEP_HARD, bufsz); 848 844 settings_save(); 849 845 } 850 846 ··· 882 878 883 879 static bool set_catalogdir(void) 884 880 { 885 - catalog_set_directory(selected_file); 881 + catalog_set_directory(selected_file.path); 886 882 settings_save(); 887 883 return false; 888 884 } ··· 893 889 static bool set_databasedir(void) 894 890 { 895 891 struct tagcache_stat *tc_stat = tagcache_get_stat(); 896 - if (strcasecmp(selected_file, tc_stat->db_path)) 892 + if (strcasecmp(selected_file.path, tc_stat->db_path)) 897 893 { 898 894 splash(HZ, ID2P(LANG_PLEASE_REBOOT)); 899 895 } ··· 927 923 case ACTION_REQUEST_MENUITEM: 928 924 #ifdef HAVE_MULTIVOLUME 929 925 /* no rename+delete for volumes */ 930 - if ((selected_file_attr & ATTR_VOLUME) && 926 + if ((selected_file.attr & ATTR_VOLUME) && 931 927 (this_item == &rename_file_item || 932 928 this_item == &delete_dir_item || 933 929 this_item == &clipboard_cut_item || ··· 935 931 return ACTION_EXIT_MENUITEM; 936 932 #endif 937 933 #ifdef HAVE_TAGCACHE 938 - if (context == CONTEXT_ID3DB) 934 + if (selected_file.context == CONTEXT_ID3DB) 939 935 { 940 936 if (this_item == &track_info_item || 941 937 this_item == &pictureflow_item) ··· 953 949 { 954 950 return action; 955 951 } 956 - else if (selected_file) 952 + else if (selected_file.path) 957 953 { 958 954 /* requires an actual file */ 959 955 if (this_item == &rename_file_item || 960 956 this_item == &clipboard_cut_item || 961 957 this_item == &clipboard_copy_item || 962 958 (this_item == &track_info_item && 963 - (selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO) || 959 + (selected_file.attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO) || 964 960 (this_item == &properties_item && 965 - (selected_file_attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) || 961 + (selected_file.attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) || 966 962 this_item == &add_to_faves_item) 967 963 { 968 964 return action; 969 965 } 970 - else if ((selected_file_attr & ATTR_DIRECTORY)) 966 + else if ((selected_file.attr & ATTR_DIRECTORY)) 971 967 { 972 968 /* only for directories */ 973 969 if (this_item == &delete_dir_item || ··· 992 988 #if LCD_DEPTH > 1 993 989 else if (this_item == &set_backdrop_item) 994 990 { 995 - char *suffix = strrchr(selected_file, '.'); 991 + char *suffix = strrchr(selected_file.path, '.'); 996 992 if (suffix) 997 993 { 998 994 if (strcasecmp(suffix, ".bmp") == 0) ··· 1066 1062 case ACTION_REQUEST_MENUITEM: 1067 1063 if (this_item == &view_playlist_item) 1068 1064 { 1069 - if ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U && 1070 - context == CONTEXT_TREE) 1065 + if ((selected_file.attr & FILE_ATTR_MASK) == FILE_ATTR_M3U && 1066 + selected_file.context == CONTEXT_TREE) 1071 1067 return action; 1072 1068 } 1073 1069 return ACTION_EXIT_MENUITEM; 1074 1070 break; 1075 1071 case ACTION_EXIT_MENUITEM: 1076 1072 return ACTION_EXIT_AFTER_THIS_MENUITEM; 1073 + break; 1074 + default: 1077 1075 break; 1078 1076 } 1079 1077 return action; ··· 1085 1083 { 1086 1084 #ifdef HAVE_MULTIVOLUME 1087 1085 /* no delete for volumes */ 1088 - if (selected_file_attr & ATTR_VOLUME) 1086 + if (selected_file.attr & ATTR_VOLUME) 1089 1087 return false; 1090 1088 #endif 1091 1089 1092 1090 #ifdef HAVE_TAGCACHE 1093 - if (context == CONTEXT_ID3DB && 1094 - (selected_file_attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) 1091 + if (selected_file.context == CONTEXT_ID3DB && 1092 + (selected_file.attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) 1095 1093 return false; 1096 1094 #endif 1097 1095 ··· 1101 1099 static bool hotkey_open_with(void) 1102 1100 { 1103 1101 /* only open files */ 1104 - if (selected_file_attr & ATTR_DIRECTORY) 1102 + if (selected_file.attr & ATTR_DIRECTORY) 1105 1103 return false; 1106 1104 #ifdef HAVE_MULTIVOLUME 1107 - if (selected_file_attr & ATTR_VOLUME) 1105 + if (selected_file.attr & ATTR_VOLUME) 1108 1106 return false; 1109 1107 #endif 1110 1108 return list_viewers(); ··· 1113 1111 static int hotkey_tree_pl_insert_shuffled(void) 1114 1112 { 1115 1113 if ((audio_status() & AUDIO_STATUS_PLAY) || 1116 - (selected_file_attr & ATTR_DIRECTORY) || 1117 - ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U)) 1114 + (selected_file.attr & ATTR_DIRECTORY) || 1115 + ((selected_file.attr & FILE_ATTR_MASK) == FILE_ATTR_M3U)) 1118 1116 { 1119 1117 add_to_playlist(&addtopl_insert_shuf); 1120 1118 } ··· 1127 1125 if (!prepare_database_sel(param)) 1128 1126 return ONPLAY_RELOAD_DIR; 1129 1127 #endif 1130 - if (filetype_load_plugin((const char*)param, selected_file) == PLUGIN_GOTO_WPS) 1128 + if (filetype_load_plugin((const char*)param, selected_file.path) == PLUGIN_GOTO_WPS) 1131 1129 return ONPLAY_START_PLAY; 1132 1130 1133 1131 return ONPLAY_RELOAD_DIR; ··· 1253 1251 } 1254 1252 #endif /* HOTKEY */ 1255 1253 1256 - int onplay(char* file, int attr, int from, bool hotkey) 1254 + int onplay(char* file, int attr, int from_context, bool hotkey) 1257 1255 { 1258 1256 const struct menu_item_ex *menu; 1259 1257 onplay_result = ONPLAY_OK; 1260 - context = from; 1261 1258 ctx_current_playlist_insert = NULL; 1262 - selected_file = NULL; 1259 + selected_file_set(from_context, NULL, attr); 1260 + 1263 1261 #ifdef HAVE_TAGCACHE 1264 - if (context == CONTEXT_ID3DB && 1262 + if (from_context == CONTEXT_ID3DB && 1265 1263 (attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO) 1266 1264 { 1267 1265 ctx_add_to_playlist = tagtree_add_to_playlist; ··· 1269 1267 { 1270 1268 /* add a leading slash so that catalog_add_to_a_playlist 1271 1269 later prefills the name when creating a new playlist */ 1272 - snprintf(selected_file_path, MAX_PATH, "/%s", file); 1273 - selected_file = selected_file_path; 1270 + snprintf(selected_file.buf, MAX_PATH, "/%s", file); 1271 + selected_file.path = selected_file.buf; 1274 1272 } 1275 1273 } 1276 1274 else ··· 1279 1277 ctx_add_to_playlist = NULL; 1280 1278 if (file != NULL) 1281 1279 { 1282 - strmemccpy(selected_file_path, file, MAX_PATH); 1283 - selected_file = selected_file_path; 1280 + strmemccpy(selected_file.buf, file, MAX_PATH); 1281 + selected_file.path = selected_file.buf; 1284 1282 } 1285 1283 1286 1284 } 1287 - selected_file_attr = attr; 1288 1285 int menu_selection; 1286 + 1289 1287 #ifdef HAVE_HOTKEY 1290 1288 if (hotkey) 1291 - return execute_hotkey(context == CONTEXT_WPS); 1289 + return execute_hotkey(from_context == CONTEXT_WPS); 1292 1290 #else 1293 1291 (void)hotkey; 1294 1292 #endif 1295 1293 1296 1294 push_current_activity(ACTIVITY_CONTEXTMENU); 1297 - if (context == CONTEXT_WPS) 1295 + if (from_context == CONTEXT_WPS) 1298 1296 menu = &wps_onplay_menu; 1299 1297 else 1300 1298 menu = &tree_onplay_menu; ··· 1303 1301 if (get_current_activity() == ACTIVITY_CONTEXTMENU) /* Activity may have been */ 1304 1302 pop_current_activity(); /* popped already by menu item */ 1305 1303 1306 - switch (menu_selection) 1307 - { 1308 - case GO_TO_WPS: 1309 - return ONPLAY_START_PLAY; 1310 - case GO_TO_ROOT: 1311 - case GO_TO_MAINMENU: 1312 - return ONPLAY_MAINMENU; 1313 - case GO_TO_PLAYLIST_VIEWER: 1314 - return ONPLAY_PLAYLIST; 1315 - case GO_TO_PLUGIN: 1316 - return ONPLAY_PLUGIN; 1317 - default: 1318 - return onplay_result; 1319 - } 1304 + 1305 + if (menu_selection == GO_TO_WPS) 1306 + return ONPLAY_START_PLAY; 1307 + if (menu_selection == GO_TO_ROOT) 1308 + return ONPLAY_MAINMENU; 1309 + if (menu_selection == GO_TO_MAINMENU) 1310 + return ONPLAY_MAINMENU; 1311 + if (menu_selection == GO_TO_PLAYLIST_VIEWER) 1312 + return ONPLAY_PLAYLIST; 1313 + if (menu_selection == GO_TO_PLUGIN) 1314 + return ONPLAY_PLUGIN; 1315 + 1316 + return onplay_result; 1320 1317 } 1321 1318 1322 1319 int get_onplay_context(void) 1323 1320 { 1324 - return context; 1321 + return selected_file.context; 1325 1322 }
+1 -1
apps/onplay.h
··· 25 25 #include "menu.h" 26 26 #endif 27 27 28 - int onplay(char* file, int attr, int from_screen, bool hotkey); 28 + int onplay(char* file, int attr, int from_context, bool hotkey); 29 29 int get_onplay_context(void); 30 30 31 31 enum {