mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-29 15:42:20 +03:00
попытка использовать альтнрнативный метод поиска
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
#include "FileSystem.h"
|
||||
|
||||
#include "Utils/FileUtils.h"
|
||||
#include "Utils\SerialPrint.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
#include "FileSystem.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
#include "Utils\SerialPrint.h"
|
||||
|
||||
const String filepath(const String& filename) {
|
||||
return filename.startsWith("/") ? filename : "/" + filename;
|
||||
@@ -22,10 +21,10 @@ void removeFile(const String& filename) {
|
||||
String path = filepath(filename);
|
||||
if (FileFS.exists(path)) {
|
||||
if (!FileFS.remove(path)) {
|
||||
SerialPrint("I","Files","remove " + path);
|
||||
SerialPrint("I", "Files", "remove " + path);
|
||||
}
|
||||
} else {
|
||||
SerialPrint("E","Files","not exist" + path);
|
||||
SerialPrint("E", "Files", "not exist" + path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +32,7 @@ File seekFile(const String& filename, size_t position) {
|
||||
String path = filepath(filename);
|
||||
auto file = FileFS.open(path, "r");
|
||||
if (!file) {
|
||||
SerialPrint("[E]","Files","open " + path);
|
||||
SerialPrint("[E]", "Files", "open " + path);
|
||||
}
|
||||
// поставим курсор в начало файла
|
||||
file.seek(position, SeekSet);
|
||||
@@ -79,14 +78,14 @@ const String addFile(const String& filename, const String& str) {
|
||||
bool copyFile(const String& src, const String& dst, bool overwrite) {
|
||||
String srcPath = filepath(src);
|
||||
String dstPath = filepath(dst);
|
||||
SerialPrint("I","Files","copy " + srcPath + " to " + dstPath);
|
||||
SerialPrint("I", "Files", "copy " + srcPath + " to " + dstPath);
|
||||
if (!FileFS.exists(srcPath)) {
|
||||
SerialPrint("[E]","Files","not exist: " + srcPath);
|
||||
SerialPrint("[E]", "Files", "not exist: " + srcPath);
|
||||
return false;
|
||||
}
|
||||
if (FileFS.exists(dstPath)) {
|
||||
if (!overwrite) {
|
||||
SerialPrint("[E]","Files","already exist: " + dstPath);
|
||||
SerialPrint("[E]", "Files", "already exist: " + dstPath);
|
||||
return false;
|
||||
}
|
||||
FileFS.remove(dstPath);
|
||||
@@ -131,6 +130,22 @@ const String readFile(const String& filename, size_t max_size) {
|
||||
return temp;
|
||||
}
|
||||
|
||||
const String readFileSz(const String& filename, size_t max_size, size_t& size) {
|
||||
String path = filepath(filename);
|
||||
auto file = FileFS.open(path, "r");
|
||||
if (!file) {
|
||||
return "failed";
|
||||
}
|
||||
size = file.size();
|
||||
if (size > max_size) {
|
||||
file.close();
|
||||
return "large";
|
||||
}
|
||||
String temp = file.readString();
|
||||
file.close();
|
||||
return temp;
|
||||
}
|
||||
|
||||
const String getFileSize(const String filename) {
|
||||
String filepath(filename);
|
||||
auto file = FileFS.open(filepath, "r");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
#include "Consts.h"
|
||||
|
||||
String selectToMarkerLast(String str, String found) {
|
||||
@@ -75,7 +76,7 @@ uint16_t hexStringToUint16(String hex) {
|
||||
}
|
||||
}
|
||||
|
||||
size_t itemsCount(String str, const String& separator) {
|
||||
size_t itemsCount2(String& str, const String& separator) {
|
||||
// если строки поиск нет сразу выход
|
||||
if (str.indexOf(separator) == -1) {
|
||||
return 0;
|
||||
@@ -91,6 +92,19 @@ size_t itemsCount(String str, const String& separator) {
|
||||
return cnt;
|
||||
}
|
||||
|
||||
size_t itemsCount(String& str, const char* delim) {
|
||||
size_t cnt = 0;
|
||||
char* cstr = new char[str.length() + 1];
|
||||
strcpy(cstr, str.c_str());
|
||||
char* token;
|
||||
while ((token = strtok_r(cstr, delim, &cstr))) {
|
||||
cnt++;
|
||||
//printf("%s\n", token);
|
||||
}
|
||||
delete[] cstr;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
boolean isDigitStr(const String& str) {
|
||||
for (size_t i = 0; i < str.length(); i++) {
|
||||
if (!isDigit(str.charAt(i))) {
|
||||
@@ -110,6 +124,3 @@ String prettyBytes(size_t size) {
|
||||
else
|
||||
return String(size / 1024.0 / 1024.0 / 1024.0) + "GB";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user