Patch SD lib files for readability
This commit is contained in:
@@ -49,8 +49,9 @@ CardReader::CardReader() {
|
||||
sdprinting = cardOK = saving = logging = false;
|
||||
filesize = 0;
|
||||
sdpos = 0;
|
||||
workDirDepth = 0;
|
||||
file_subcall_ctr = 0;
|
||||
|
||||
workDirDepth = 0;
|
||||
ZERO(workDirParents);
|
||||
|
||||
autostart_stilltocheck = true; //the SD start is delayed, because otherwise the serial cannot answer fast enough to make contact with the host software.
|
||||
@@ -263,16 +264,7 @@ void CardReader::initsd() {
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOLNPGM(MSG_SD_CARD_OK);
|
||||
}
|
||||
workDir = root;
|
||||
curDir = &root;
|
||||
#if ENABLED(SDCARD_SORT_ALPHA)
|
||||
presort();
|
||||
#endif
|
||||
/**
|
||||
if (!workDir.openRoot(&volume)) {
|
||||
SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL);
|
||||
}
|
||||
*/
|
||||
setroot();
|
||||
}
|
||||
|
||||
void CardReader::setroot() {
|
||||
@@ -356,9 +348,8 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
|
||||
filespos[file_subcall_ctr] = sdpos;
|
||||
file_subcall_ctr++;
|
||||
}
|
||||
else {
|
||||
else
|
||||
doing = 1;
|
||||
}
|
||||
}
|
||||
else { // Opening fresh file
|
||||
doing = 2;
|
||||
@@ -368,7 +359,7 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
|
||||
if (doing) {
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOPGM("Now ");
|
||||
SERIAL_ECHO(doing == 1 ? "doing" : "fresh");
|
||||
serialprintPGM(doing == 1 ? PSTR("doing") : PSTR("fresh"));
|
||||
SERIAL_ECHOLNPAIR(" file: ", name);
|
||||
}
|
||||
|
||||
@@ -388,8 +379,7 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
|
||||
if (dirname_end != NULL && dirname_end > dirname_start) {
|
||||
char subdirname[FILENAME_LENGTH];
|
||||
strncpy(subdirname, dirname_start, dirname_end - dirname_start);
|
||||
subdirname[dirname_end - dirname_start] = 0;
|
||||
SERIAL_ECHOLN(subdirname);
|
||||
subdirname[dirname_end - dirname_start] = '\0';
|
||||
if (!myDir.open(curDir, subdirname, O_READ)) {
|
||||
SERIAL_PROTOCOLPGM(MSG_SD_OPEN_FILE_FAIL);
|
||||
SERIAL_PROTOCOL(subdirname);
|
||||
@@ -411,17 +401,15 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
|
||||
}
|
||||
}
|
||||
}
|
||||
else { //relative path
|
||||
curDir = &workDir;
|
||||
}
|
||||
else
|
||||
curDir = &workDir; // Relative paths start in current directory
|
||||
|
||||
if (read) {
|
||||
if (file.open(curDir, fname, O_READ)) {
|
||||
filesize = file.fileSize();
|
||||
sdpos = 0;
|
||||
SERIAL_PROTOCOLPAIR(MSG_SD_FILE_OPENED, fname);
|
||||
SERIAL_PROTOCOLLNPAIR(MSG_SD_SIZE, filesize);
|
||||
sdpos = 0;
|
||||
|
||||
SERIAL_PROTOCOLLNPGM(MSG_SD_FILE_SELECTED);
|
||||
getfilename(0, fname);
|
||||
lcd_setstatus(longFilename[0] ? longFilename : fname);
|
||||
@@ -446,14 +434,14 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
|
||||
}
|
||||
}
|
||||
|
||||
void CardReader::removeFile(char* name) {
|
||||
void CardReader::removeFile(const char * const name) {
|
||||
if (!cardOK) return;
|
||||
|
||||
stopSDPrint();
|
||||
|
||||
SdFile myDir;
|
||||
curDir = &root;
|
||||
char *fname = name;
|
||||
const char *fname = name;
|
||||
|
||||
char *dirname_start, *dirname_end;
|
||||
if (name[0] == '/') {
|
||||
@@ -468,29 +456,23 @@ void CardReader::removeFile(char* name) {
|
||||
subdirname[dirname_end - dirname_start] = 0;
|
||||
SERIAL_ECHOLN(subdirname);
|
||||
if (!myDir.open(curDir, subdirname, O_READ)) {
|
||||
SERIAL_PROTOCOLPAIR("open failed, File: ", subdirname);
|
||||
SERIAL_PROTOCOLPAIR(MSG_SD_OPEN_FILE_FAIL, subdirname);
|
||||
SERIAL_PROTOCOLCHAR('.');
|
||||
SERIAL_EOL();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
//SERIAL_ECHOLNPGM("dive ok");
|
||||
}
|
||||
|
||||
curDir = &myDir;
|
||||
dirname_start = dirname_end + 1;
|
||||
}
|
||||
else { // the remainder after all /fsa/fdsa/ is the filename
|
||||
else {
|
||||
fname = dirname_start;
|
||||
//SERIAL_ECHOLNPGM("remainder");
|
||||
//SERIAL_ECHOLN(fname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // relative path
|
||||
else // Relative paths are rooted in the current directory
|
||||
curDir = &workDir;
|
||||
}
|
||||
|
||||
if (file.remove(curDir, fname)) {
|
||||
SERIAL_PROTOCOLPGM("File deleted:");
|
||||
@@ -514,14 +496,13 @@ void CardReader::getStatus() {
|
||||
SERIAL_PROTOCOLCHAR('/');
|
||||
SERIAL_PROTOCOLLN(filesize);
|
||||
}
|
||||
else {
|
||||
else
|
||||
SERIAL_PROTOCOLLNPGM(MSG_SD_NOT_PRINTING);
|
||||
}
|
||||
}
|
||||
|
||||
void CardReader::write_command(char *buf) {
|
||||
char* begin = buf;
|
||||
char* npos = 0;
|
||||
char* npos = NULL;
|
||||
char* end = buf + strlen(buf) - 1;
|
||||
|
||||
file.writeError = false;
|
||||
|
Reference in New Issue
Block a user