* Open a file by DOS path for read * The 'subcall_type' flag indicates... * - 0 : Standard open from host or user interface. * - 1 : (file open) Opening a new sub-procedure. * - 1 : (no file open) Opening a macro (M98). * - 2 : Resuming from a sub-procedure */
| 789 | * - 2 : Resuming from a sub-procedure |
| 790 | */ |
| 791 | void CardReader::openFileRead(const char * const path, const uint8_t subcall_type/*=0*/) { |
| 792 | if (!isMounted()) return openFailed(path); |
| 793 | |
| 794 | switch (subcall_type) { |
| 795 | case 0: // Starting a new print. "Now fresh file: ..." |
| 796 | announceOpen(2, path); |
| 797 | TERN_(HAS_MEDIA_SUBCALLS, file_subcall_ctr = 0); |
| 798 | break; |
| 799 | |
| 800 | #if HAS_MEDIA_SUBCALLS |
| 801 | |
| 802 | case 1: // Starting a sub-procedure |
| 803 | |
| 804 | // With no file is open it's a simple macro. "Now doing file: ..." |
| 805 | if (!isFileOpen()) { announceOpen(1, path); break; } |
| 806 | |
| 807 | // Too deep? The firmware has to bail. |
| 808 | if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) { |
| 809 | SERIAL_ERROR_MSG("Exceeded max SUBROUTINE depth:", SD_PROCEDURE_DEPTH); |
| 810 | kill(GET_TEXT_F(MSG_KILL_SUBCALL_OVERFLOW)); |
| 811 | return; |
| 812 | } |
| 813 | |
| 814 | // Store current filename (based on workDirParents) and position |
| 815 | getAbsFilenameInCWD(proc_filenames[file_subcall_ctr]); |
| 816 | filespos[file_subcall_ctr] = sdpos; |
| 817 | |
| 818 | // For sub-procedures say 'SUBROUTINE CALL target: "..." parent: "..." pos12345' |
| 819 | SERIAL_ECHO_MSG("SUBROUTINE CALL target:\"", path, "\" parent:\"", proc_filenames[file_subcall_ctr], "\" pos", sdpos); |
| 820 | file_subcall_ctr++; |
| 821 | break; |
| 822 | |
| 823 | case 2: // Resuming previous file after sub-procedure |
| 824 | SERIAL_ECHO_MSG("END SUBROUTINE"); |
| 825 | break; |
| 826 | |
| 827 | #endif |
| 828 | } |
| 829 | |
| 830 | abortFilePrintNow(); |
| 831 | |
| 832 | MediaFile *diveDir; |
| 833 | const char * const fname = diveToFile(true, diveDir, path); |
| 834 | if (!fname) return openFailed(path); |
| 835 | |
| 836 | if (myfile.open(diveDir, fname, O_READ)) { |
| 837 | filesize = myfile.fileSize(); |
| 838 | sdpos = 0; |
| 839 | |
| 840 | { // Don't remove this block, as the PORT_REDIRECT is a RAII |
| 841 | PORT_REDIRECT(SerialMask::All); |
| 842 | SERIAL_ECHOLNPGM(STR_SD_FILE_OPENED, fname, STR_SD_SIZE, filesize); |
| 843 | SERIAL_ECHOLNPGM(STR_SD_FILE_SELECTED); |
| 844 | } |
| 845 | |
| 846 | selectFileByName(fname); |
| 847 | ui.set_status(longFilename[0] ? longFilename : fname); |
| 848 | } |
no test coverage detected