Better File error message

Also improved the write command
This commit is contained in:
Stefan Kremser
2018-03-29 12:08:23 +02:00
parent 73b4640ce5
commit 94258712cf
5 changed files with 23 additions and 21 deletions

View File

@@ -38,7 +38,7 @@ void Names::save(bool force) {
String buf = String(OPEN_BRACKET); // [ String buf = String(OPEN_BRACKET); // [
if (!writeFile(FILE_PATH, buf)) { if (!writeFile(FILE_PATH, buf)) {
prnt(N_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
} }
@@ -61,7 +61,7 @@ void Names::save(bool force) {
if(buf.length() >= 1024){ if(buf.length() >= 1024){
if (!appendFile(FILE_PATH, buf)) { if (!appendFile(FILE_PATH, buf)) {
prnt(N_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
} }
@@ -73,7 +73,7 @@ void Names::save(bool force) {
buf += String(CLOSE_BRACKET); // ] buf += String(CLOSE_BRACKET); // ]
if (!appendFile(FILE_PATH, buf)) { if (!appendFile(FILE_PATH, buf)) {
prnt(N_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
} }

View File

@@ -42,7 +42,7 @@ void SSIDs::save(bool force) {
buf += String(DOUBLEQUOTES) + str(SS_JSON_SSIDS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + String(OPEN_BRACKET); // "ssids":[ buf += String(DOUBLEQUOTES) + str(SS_JSON_SSIDS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + String(OPEN_BRACKET); // "ssids":[
if (!writeFile(FILE_PATH, buf)) { if (!writeFile(FILE_PATH, buf)) {
prnt(SS_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
} }
@@ -61,7 +61,7 @@ void SSIDs::save(bool force) {
if(buf.length() >= 1024){ if(buf.length() >= 1024){
if (!appendFile(FILE_PATH, buf)) { if (!appendFile(FILE_PATH, buf)) {
prnt(SS_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
} }
@@ -73,7 +73,7 @@ void SSIDs::save(bool force) {
buf += String(CLOSE_BRACKET) + String(CLOSE_CURLY_BRACKET); // ]} buf += String(CLOSE_BRACKET) + String(CLOSE_CURLY_BRACKET); // ]}
if (!appendFile(FILE_PATH, buf)) { if (!appendFile(FILE_PATH, buf)) {
prnt(SS_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
} }

View File

@@ -253,7 +253,7 @@ void Scan::save(bool force) {
String buf = String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SC_JSON_APS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + String(OPEN_BRACKET); // {"aps":[ String buf = String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SC_JSON_APS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + String(OPEN_BRACKET); // {"aps":[
if(!writeFile(FILE_PATH, buf)) { // overwrite old file if(!writeFile(FILE_PATH, buf)) { // overwrite old file
prnt(SC_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
} }
@@ -274,7 +274,7 @@ void Scan::save(bool force) {
if(buf.length() >= 1024){ if(buf.length() >= 1024){
if(!appendFile(FILE_PATH, buf)) { if(!appendFile(FILE_PATH, buf)) {
prnt(SC_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
} }
@@ -300,7 +300,7 @@ void Scan::save(bool force) {
if(buf.length() >= 1024){ if(buf.length() >= 1024){
if(!appendFile(FILE_PATH, buf)) { if(!appendFile(FILE_PATH, buf)) {
prnt(SC_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
} }
@@ -312,7 +312,7 @@ void Scan::save(bool force) {
buf += String(CLOSE_BRACKET) + String(CLOSE_CURLY_BRACKET); // ]} buf += String(CLOSE_BRACKET) + String(CLOSE_CURLY_BRACKET); // ]}
if(!appendFile(FILE_PATH, buf)) { if(!appendFile(FILE_PATH, buf)) {
prnt(SC_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
} }

View File

@@ -789,17 +789,22 @@ void SerialInterface::runCommand(String input) {
// ===== WRITE ==== // // ===== WRITE ==== //
// write <file> <commands> // write <file> <commands>
else if (list->size() >= 3 && eqlsCMD(0, CLI_WRITE)) { else if (list->size() >= 3 && eqlsCMD(0, CLI_WRITE)) {
String tmp = String(); String path = list->get(1);
for (int i = 2; i < list->size(); i++) { String buf = String();
tmp += list->get(i);
if (i < list->size() - 1) tmp += SPACE; int listSize = list->size();
for (int i = 2; i < listSize; i++) {
buf += list->get(i);
if (i < listSize - 1) buf += SPACE;
} }
prnt(CLI_WRITTEN); prnt(CLI_WRITTEN);
prnt(tmp); prnt(buf);
prnt(CLI_TO); prnt(CLI_TO);
prntln(list->get(1)); prntln(list->get(1));
tmp += NEWLINE;
appendFile(list->get(1), tmp); buf += NEWLINE;
appendFile(path, buf);
} }
// ===== REPLACE ==== // // ===== REPLACE ==== //

View File

@@ -473,7 +473,6 @@ static const char S_DISPLAY_TIMEOUT[] PROGMEM = "displayTimeout";
static const char S_SETTINGS_LOADED[] PROGMEM = "Settings loaded from "; static const char S_SETTINGS_LOADED[] PROGMEM = "Settings loaded from ";
static const char S_SETTINGS_RESETED[] PROGMEM = "Settings reseted"; static const char S_SETTINGS_RESETED[] PROGMEM = "Settings reseted";
static const char S_SETTINGS_SAVED[] PROGMEM = "Settings saved in "; static const char S_SETTINGS_SAVED[] PROGMEM = "Settings saved in ";
static const char S_ERROR_SAVING[] PROGMEM = "ERROR: saving ";
static const char S_SETTINGS_HEADER[] PROGMEM = "[========== Settings ==========]"; static const char S_SETTINGS_HEADER[] PROGMEM = "[========== Settings ==========]";
static const char S_ERROR_VERSION[] PROGMEM = "Sorry, you can't change the version number"; static const char S_ERROR_VERSION[] PROGMEM = "Sorry, you can't change the version number";
static const char S_ERROR_NOT_FOUND[] PROGMEM = "ERROR: No setting found for "; static const char S_ERROR_NOT_FOUND[] PROGMEM = "ERROR: No setting found for ";
@@ -521,7 +520,6 @@ static const char L_OUTPUT_B[] PROGMEM = "(%u,%u,%u)\r\n";
// ===== NAMES ===== // // ===== NAMES ===== //
static const char N_SAVED[] PROGMEM = "Device names saved in "; static const char N_SAVED[] PROGMEM = "Device names saved in ";
static const char N_LOADED[] PROGMEM = "Device names loaded from "; static const char N_LOADED[] PROGMEM = "Device names loaded from ";
static const char N_ERROR_SAVING[] PROGMEM = "ERROR: saving ";
static const char N_REMOVED_ALL[] PROGMEM = "Removed all saved device names"; static const char N_REMOVED_ALL[] PROGMEM = "Removed all saved device names";
static const char N_HEADER[] PROGMEM = "[===== Saved Devices =====]"; static const char N_HEADER[] PROGMEM = "[===== Saved Devices =====]";
static const char N_TABLE_HEADER[] PROGMEM = "ID MAC Vendor Name AP-BSSID Ch Selected"; static const char N_TABLE_HEADER[] PROGMEM = "ID MAC Vendor Name AP-BSSID Ch Selected";
@@ -547,7 +545,6 @@ static const char SS_LOADED[] PROGMEM = "SSIDs loaded from ";
static const char SS_CLEARED[] PROGMEM = "Cleared SSID list"; static const char SS_CLEARED[] PROGMEM = "Cleared SSID list";
static const char SS_SAVED[] PROGMEM = "SSIDs saved"; static const char SS_SAVED[] PROGMEM = "SSIDs saved";
static const char SS_SAVED_IN[] PROGMEM = "SSIDs saved in "; static const char SS_SAVED_IN[] PROGMEM = "SSIDs saved in ";
static const char SS_ERROR_SAVING[] PROGMEM = "ERROR: saving ";
static const char SS_REMOVED[] PROGMEM = "Removed SSID "; static const char SS_REMOVED[] PROGMEM = "Removed SSID ";
static const char SS_ERROR_FULL[] PROGMEM = "ERROR: SSID list is full! Remove some SSIDs first or run command with -f (force) parameter."; static const char SS_ERROR_FULL[] PROGMEM = "ERROR: SSID list is full! Remove some SSIDs first or run command with -f (force) parameter.";
static const char SS_ADDED[] PROGMEM = "Added SSID "; static const char SS_ADDED[] PROGMEM = "Added SSID ";
@@ -583,7 +580,6 @@ static const char SC_JSON_STATIONS[] PROGMEM = "stations";
static const char SC_JSON_NAMES[] PROGMEM = "names"; static const char SC_JSON_NAMES[] PROGMEM = "names";
static const char SC_SAVED[] PROGMEM = "Saved scan results"; static const char SC_SAVED[] PROGMEM = "Saved scan results";
static const char SC_SAVED_IN[] PROGMEM = "Scan results saved in "; static const char SC_SAVED_IN[] PROGMEM = "Scan results saved in ";
static const char SC_ERROR_SAVING[] PROGMEM = "ERROR: Saving scan results in ";
// ===== FUNCTIONS ===== // // ===== FUNCTIONS ===== //
static const char F_ERROR_MAC[] PROGMEM = "ERROR: MAC address invalid"; static const char F_ERROR_MAC[] PROGMEM = "ERROR: MAC address invalid";
@@ -596,6 +592,7 @@ static const char F_ERROR_PARSING_JSON[] PROGMEM = "ERROR parsing JSON ";
static const char F_ERROR_TO_BIG[] PROGMEM = "ERROR file too big "; static const char F_ERROR_TO_BIG[] PROGMEM = "ERROR file too big ";
static const char F_TMP[] PROGMEM = "/tmp"; static const char F_TMP[] PROGMEM = "/tmp";
static const char F_COPY[] PROGMEM = "_copy"; static const char F_COPY[] PROGMEM = "_copy";
static const char F_ERROR_SAVING[] PROGMEM = "ERROR: saving file. Try 'format' and restart - ";
// ===== WIFI ===== // // ===== WIFI ===== //
static const char W_STOPPED_AP[] PROGMEM = "Stopped Access Point"; static const char W_STOPPED_AP[] PROGMEM = "Stopped Access Point";