mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-03 03:13:25 +02:00
Casts (#556)
* Killed casts and .c_str() in WebServer.cpp Most of them were unnecessary, as the methods with which they were used accept String arguments. * More casts gone in WebSettings.cpp * Another one bites the dust
This commit is contained in:
@@ -280,11 +280,11 @@ namespace WebUI {
|
|||||||
if ((path.substring(0, 4) == "/SD/")) {
|
if ((path.substring(0, 4) == "/SD/")) {
|
||||||
//remove /SD
|
//remove /SD
|
||||||
path = path.substring(3);
|
path = path.substring(3);
|
||||||
if (SD.exists((char*)pathWithGz.c_str()) || SD.exists((char*)path.c_str())) {
|
if (SD.exists(pathWithGz) || SD.exists(path)) {
|
||||||
if (SD.exists((char*)pathWithGz.c_str())) {
|
if (SD.exists(pathWithGz)) {
|
||||||
path = pathWithGz;
|
path = pathWithGz;
|
||||||
}
|
}
|
||||||
File datafile = SD.open((char*)path.c_str());
|
File datafile = SD.open(path);
|
||||||
if (datafile) {
|
if (datafile) {
|
||||||
vTaskDelay(1 / portTICK_RATE_MS);
|
vTaskDelay(1 / portTICK_RATE_MS);
|
||||||
size_t totalFileSize = datafile.size();
|
size_t totalFileSize = datafile.size();
|
||||||
@@ -315,7 +315,7 @@ namespace WebUI {
|
|||||||
}
|
}
|
||||||
String content = "cannot find ";
|
String content = "cannot find ";
|
||||||
content += path;
|
content += path;
|
||||||
_webserver->send(404, "text/plain", content.c_str());
|
_webserver->send(404, "text/plain", content);
|
||||||
return;
|
return;
|
||||||
} else
|
} else
|
||||||
# endif
|
# endif
|
||||||
@@ -498,7 +498,7 @@ namespace WebUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (silent || !espresponse->anyOutput()) {
|
if (silent || !espresponse->anyOutput()) {
|
||||||
_webserver->send(err ? 401 : 200, "text/plain", answer.c_str());
|
_webserver->send(err ? 401 : 200, "text/plain", answer);
|
||||||
} else {
|
} else {
|
||||||
espresponse->flush();
|
espresponse->flush();
|
||||||
}
|
}
|
||||||
@@ -592,8 +592,8 @@ namespace WebUI {
|
|||||||
String sadminPassword = admin_password->get();
|
String sadminPassword = admin_password->get();
|
||||||
String suserPassword = user_password->get();
|
String suserPassword = user_password->get();
|
||||||
|
|
||||||
if (!(((sUser == DEFAULT_ADMIN_LOGIN) && (strcmp(sPassword.c_str(), sadminPassword.c_str()) == 0)) ||
|
if (!((sUser == DEFAULT_ADMIN_LOGIN && sPassword == sadminPassword) ||
|
||||||
((sUser == DEFAULT_USER_LOGIN) && (strcmp(sPassword.c_str(), suserPassword.c_str()) == 0)))) {
|
(sUser == DEFAULT_USER_LOGIN && sPassword == suserPassword)) {
|
||||||
msg_alert_error = true;
|
msg_alert_error = true;
|
||||||
smsg = "Error: Incorrect password";
|
smsg = "Error: Incorrect password";
|
||||||
code = 401;
|
code = 401;
|
||||||
@@ -611,9 +611,9 @@ namespace WebUI {
|
|||||||
if (COMMANDS::isLocalPasswordValid((char*)newpassword.c_str())) {
|
if (COMMANDS::isLocalPasswordValid((char*)newpassword.c_str())) {
|
||||||
err_t err;
|
err_t err;
|
||||||
if (sUser == DEFAULT_ADMIN_LOGIN) {
|
if (sUser == DEFAULT_ADMIN_LOGIN) {
|
||||||
err = admin_password->setStringValue((char*)newpassword.c_str());
|
err = admin_password->setStringValue(newpassword);
|
||||||
} else {
|
} else {
|
||||||
err = user_password->setStringValue((char*)newpassword.c_str());
|
err = user_password->setStringValue(newpassword);
|
||||||
}
|
}
|
||||||
if (err) {
|
if (err) {
|
||||||
msg_alert_error = true;
|
msg_alert_error = true;
|
||||||
@@ -965,8 +965,8 @@ namespace WebUI {
|
|||||||
fsUploadFile.close();
|
fsUploadFile.close();
|
||||||
}
|
}
|
||||||
String sizeargname = upload.filename + "S";
|
String sizeargname = upload.filename + "S";
|
||||||
if (_webserver->hasArg(sizeargname.c_str())) {
|
if (_webserver->hasArg(sizeargname)) {
|
||||||
uint32_t filesize = _webserver->arg(sizeargname.c_str()).toInt();
|
uint32_t filesize = _webserver->arg(sizeargname).toInt();
|
||||||
uint32_t freespace = SPIFFS.totalBytes() - SPIFFS.usedBytes();
|
uint32_t freespace = SPIFFS.totalBytes() - SPIFFS.usedBytes();
|
||||||
if (filesize > freespace) {
|
if (filesize > freespace) {
|
||||||
_upload_status = UploadStatusType::FAILED;
|
_upload_status = UploadStatusType::FAILED;
|
||||||
@@ -1020,7 +1020,7 @@ namespace WebUI {
|
|||||||
uint32_t filesize = fsUploadFile.size();
|
uint32_t filesize = fsUploadFile.size();
|
||||||
fsUploadFile.close();
|
fsUploadFile.close();
|
||||||
|
|
||||||
if (_webserver->hasArg(sizeargname.c_str()) && _webserver->arg(sizeargname.c_str()) != String(filesize)) {
|
if (_webserver->hasArg(sizeargname) && _webserver->arg(sizeargname) != String(filesize)) {
|
||||||
_upload_status = UploadStatusType::FAILED;
|
_upload_status = UploadStatusType::FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1101,7 +1101,7 @@ namespace WebUI {
|
|||||||
grbl_send(CLIENT_ALL, "[MSG:Update Firmware]\r\n");
|
grbl_send(CLIENT_ALL, "[MSG:Update Firmware]\r\n");
|
||||||
_upload_status = UploadStatusType::ONGOING;
|
_upload_status = UploadStatusType::ONGOING;
|
||||||
String sizeargname = upload.filename + "S";
|
String sizeargname = upload.filename + "S";
|
||||||
if (_webserver->hasArg(sizeargname.c_str())) {
|
if (_webserver->hasArg(sizeargname)) {
|
||||||
maxSketchSpace = _webserver->arg(sizeargname).toInt();
|
maxSketchSpace = _webserver->arg(sizeargname).toInt();
|
||||||
}
|
}
|
||||||
//check space
|
//check space
|
||||||
@@ -1184,7 +1184,7 @@ namespace WebUI {
|
|||||||
//Function to delete not empty directory on SD card
|
//Function to delete not empty directory on SD card
|
||||||
bool Web_Server::deleteRecursive(String path) {
|
bool Web_Server::deleteRecursive(String path) {
|
||||||
bool result = true;
|
bool result = true;
|
||||||
File file = SD.open((char*)path.c_str());
|
File file = SD.open(path);
|
||||||
//failed
|
//failed
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1192,7 +1192,7 @@ namespace WebUI {
|
|||||||
if (!file.isDirectory()) {
|
if (!file.isDirectory()) {
|
||||||
file.close();
|
file.close();
|
||||||
//return if success or not
|
//return if success or not
|
||||||
return SD.remove((char*)path.c_str());
|
return SD.remove(path);
|
||||||
}
|
}
|
||||||
file.rewindDirectory();
|
file.rewindDirectory();
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -1208,7 +1208,7 @@ namespace WebUI {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
entry.close();
|
entry.close();
|
||||||
if (!SD.remove((char*)entryPath.c_str())) {
|
if (!SD.remove(entryPath)) {
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1217,7 +1217,7 @@ namespace WebUI {
|
|||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
if (result) {
|
if (result) {
|
||||||
return SD.rmdir((char*)path.c_str());
|
return SD.rmdir(path);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1268,10 +1268,10 @@ namespace WebUI {
|
|||||||
filename = path + shortname;
|
filename = path + shortname;
|
||||||
shortname.replace("/", "");
|
shortname.replace("/", "");
|
||||||
filename.replace("//", "/");
|
filename.replace("//", "/");
|
||||||
if (!SD.exists((char*)filename.c_str())) {
|
if (!SD.exists(filename)) {
|
||||||
sstatus = shortname + " does not exist!";
|
sstatus = shortname + " does not exist!";
|
||||||
} else {
|
} else {
|
||||||
if (SD.remove((char*)filename.c_str())) {
|
if (SD.remove(filename)) {
|
||||||
sstatus = shortname + " deleted";
|
sstatus = shortname + " deleted";
|
||||||
} else {
|
} else {
|
||||||
sstatus = "Cannot deleted ";
|
sstatus = "Cannot deleted ";
|
||||||
@@ -1287,7 +1287,7 @@ namespace WebUI {
|
|||||||
filename = path + "/" + shortname;
|
filename = path + "/" + shortname;
|
||||||
filename.replace("//", "/");
|
filename.replace("//", "/");
|
||||||
if (filename != "/") {
|
if (filename != "/") {
|
||||||
if (!SD.exists((char*)filename.c_str())) {
|
if (!SD.exists(filename)) {
|
||||||
sstatus = shortname + " does not exist!";
|
sstatus = shortname + " does not exist!";
|
||||||
} else {
|
} else {
|
||||||
if (!deleteRecursive(filename)) {
|
if (!deleteRecursive(filename)) {
|
||||||
@@ -1309,10 +1309,10 @@ namespace WebUI {
|
|||||||
filename = path + shortname;
|
filename = path + shortname;
|
||||||
shortname.replace("/", "");
|
shortname.replace("/", "");
|
||||||
filename.replace("//", "/");
|
filename.replace("//", "/");
|
||||||
if (SD.exists((char*)filename.c_str())) {
|
if (SD.exists(filename)) {
|
||||||
sstatus = shortname + " already exists!";
|
sstatus = shortname + " already exists!";
|
||||||
} else {
|
} else {
|
||||||
if (!SD.mkdir((char*)filename.c_str())) {
|
if (!SD.mkdir(filename)) {
|
||||||
sstatus = "Cannot create ";
|
sstatus = "Cannot create ";
|
||||||
sstatus += shortname;
|
sstatus += shortname;
|
||||||
} else {
|
} else {
|
||||||
@@ -1333,15 +1333,15 @@ namespace WebUI {
|
|||||||
if (path != "/") {
|
if (path != "/") {
|
||||||
path = path.substring(0, path.length() - 1);
|
path = path.substring(0, path.length() - 1);
|
||||||
}
|
}
|
||||||
if (path != "/" && !SD.exists((char*)path.c_str())) {
|
if (path != "/" && !SD.exists(path)) {
|
||||||
String s = "{\"status\":\" ";
|
String s = "{\"status\":\" ";
|
||||||
s += path;
|
s += path;
|
||||||
s += " does not exist on SD Card\"}";
|
s += " does not exist on SD Card\"}";
|
||||||
_webserver->send(200, "application/json", s.c_str());
|
_webserver->send(200, "application/json", s);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (list_files) {
|
if (list_files) {
|
||||||
File dir = SD.open((char*)path.c_str());
|
File dir = SD.open(path);
|
||||||
if (!dir.isDirectory()) {
|
if (!dir.isDirectory()) {
|
||||||
dir.close();
|
dir.close();
|
||||||
}
|
}
|
||||||
@@ -1413,7 +1413,7 @@ namespace WebUI {
|
|||||||
jsonfile += sstatus + "\"";
|
jsonfile += sstatus + "\"";
|
||||||
jsonfile += "}";
|
jsonfile += "}";
|
||||||
_webserver->sendHeader("Cache-Control", "no-cache");
|
_webserver->sendHeader("Cache-Control", "no-cache");
|
||||||
_webserver->send(200, "application/json", jsonfile.c_str());
|
_webserver->send(200, "application/json", jsonfile);
|
||||||
_upload_status = UploadStatusType::NONE;
|
_upload_status = UploadStatusType::NONE;
|
||||||
set_sd_state(SDCARD_IDLE);
|
set_sd_state(SDCARD_IDLE);
|
||||||
}
|
}
|
||||||
@@ -1449,12 +1449,12 @@ namespace WebUI {
|
|||||||
} else {
|
} else {
|
||||||
set_sd_state(SDCARD_BUSY_UPLOADING);
|
set_sd_state(SDCARD_BUSY_UPLOADING);
|
||||||
//delete file on SD Card if already present
|
//delete file on SD Card if already present
|
||||||
if (SD.exists((char*)filename.c_str())) {
|
if (SD.exists(filename)) {
|
||||||
SD.remove((char*)filename.c_str());
|
SD.remove(filename);
|
||||||
}
|
}
|
||||||
String sizeargname = upload.filename + "S";
|
String sizeargname = upload.filename + "S";
|
||||||
if (_webserver->hasArg(sizeargname.c_str())) {
|
if (_webserver->hasArg(sizeargname)) {
|
||||||
uint32_t filesize = _webserver->arg(sizeargname.c_str()).toInt();
|
uint32_t filesize = _webserver->arg(sizeargname).toInt();
|
||||||
uint64_t freespace = SD.totalBytes() - SD.usedBytes();
|
uint64_t freespace = SD.totalBytes() - SD.usedBytes();
|
||||||
if (filesize > freespace) {
|
if (filesize > freespace) {
|
||||||
_upload_status = UploadStatusType::FAILED;
|
_upload_status = UploadStatusType::FAILED;
|
||||||
@@ -1464,7 +1464,7 @@ namespace WebUI {
|
|||||||
}
|
}
|
||||||
if (_upload_status != UploadStatusType::FAILED) {
|
if (_upload_status != UploadStatusType::FAILED) {
|
||||||
//Create file for writing
|
//Create file for writing
|
||||||
sdUploadFile = SD.open((char*)filename.c_str(), FILE_WRITE);
|
sdUploadFile = SD.open(filename, FILE_WRITE);
|
||||||
//check if creation succeed
|
//check if creation succeed
|
||||||
if (!sdUploadFile) {
|
if (!sdUploadFile) {
|
||||||
//if creation failed
|
//if creation failed
|
||||||
@@ -1502,12 +1502,12 @@ namespace WebUI {
|
|||||||
sdUploadFile.close();
|
sdUploadFile.close();
|
||||||
//TODO Check size
|
//TODO Check size
|
||||||
String sizeargname = upload.filename + "S";
|
String sizeargname = upload.filename + "S";
|
||||||
if (_webserver->hasArg(sizeargname.c_str())) {
|
if (_webserver->hasArg(sizeargname)) {
|
||||||
uint32_t filesize = 0;
|
uint32_t filesize = 0;
|
||||||
sdUploadFile = SD.open(filename.c_str(), FILE_READ);
|
sdUploadFile = SD.open(filename, FILE_READ);
|
||||||
filesize = sdUploadFile.size();
|
filesize = sdUploadFile.size();
|
||||||
sdUploadFile.close();
|
sdUploadFile.close();
|
||||||
if (_webserver->arg(sizeargname.c_str()) != String(filesize)) {
|
if (_webserver->arg(sizeargname) != String(filesize)) {
|
||||||
_upload_status = UploadStatusType::FAILED;
|
_upload_status = UploadStatusType::FAILED;
|
||||||
pushError(ESP_ERROR_UPLOAD, "File upload mismatch");
|
pushError(ESP_ERROR_UPLOAD, "File upload mismatch");
|
||||||
grbl_send(CLIENT_ALL, "[MSG:Upload failed]\r\n");
|
grbl_send(CLIENT_ALL, "[MSG:Upload failed]\r\n");
|
||||||
@@ -1542,8 +1542,8 @@ namespace WebUI {
|
|||||||
if (sdUploadFile) {
|
if (sdUploadFile) {
|
||||||
sdUploadFile.close();
|
sdUploadFile.close();
|
||||||
}
|
}
|
||||||
if (SD.exists((char*)filename.c_str())) {
|
if (SD.exists(filename)) {
|
||||||
SD.remove((char*)filename.c_str());
|
SD.remove(filename);
|
||||||
}
|
}
|
||||||
set_sd_state(SDCARD_IDLE);
|
set_sd_state(SDCARD_IDLE);
|
||||||
}
|
}
|
||||||
|
@@ -666,19 +666,19 @@ namespace WebUI {
|
|||||||
if (parameter[0] != '/') {
|
if (parameter[0] != '/') {
|
||||||
path = "/" + path;
|
path = "/" + path;
|
||||||
}
|
}
|
||||||
File file2del = SD.open(path.c_str());
|
File file2del = SD.open(path);
|
||||||
if (!file2del) {
|
if (!file2del) {
|
||||||
webPrintln("Cannot stat file!");
|
webPrintln("Cannot stat file!");
|
||||||
return STATUS_SD_FILE_NOT_FOUND;
|
return STATUS_SD_FILE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
if (file2del.isDirectory()) {
|
if (file2del.isDirectory()) {
|
||||||
if (!SD.rmdir((char*)path.c_str())) {
|
if (!SD.rmdir(path)) {
|
||||||
webPrintln("Cannot delete directory! Is directory empty?");
|
webPrintln("Cannot delete directory! Is directory empty?");
|
||||||
return STATUS_SD_FAILED_DEL_DIR;
|
return STATUS_SD_FAILED_DEL_DIR;
|
||||||
}
|
}
|
||||||
webPrintln("Directory deleted.");
|
webPrintln("Directory deleted.");
|
||||||
} else {
|
} else {
|
||||||
if (!SD.remove((char*)path.c_str())) {
|
if (!SD.remove(path)) {
|
||||||
webPrintln("Cannot delete file!");
|
webPrintln("Cannot delete file!");
|
||||||
return STATUS_SD_FAILED_DEL_FILE;
|
return STATUS_SD_FAILED_DEL_FILE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user