这是一次长久的提交:
1. 应用界面增加了返回主页的按钮 2. 修复了gif渲染内存泄漏的严重bug 3. 将PetDao当中的cJSON API替换为cpp_json,完美通过测试 4. 整合已经实现的各种上层建筑,实现了一个宠物对话基本业务应用,用于样品测试展示用 5. 重构了音频播放类,使其更modern,更加便于移植和拓展
This commit is contained in:
@@ -47,7 +47,7 @@ void SDFileManager::tryInitSDCard() {
|
||||
}
|
||||
|
||||
|
||||
bool SDFileManager::writeFileSync(const char* path, const char* data) {
|
||||
bool SDFileManager::writeFileSync(const char* path, const char* data, const size_t len, const char* type) {
|
||||
std::lock_guard<std::mutex> lock(file_operation_mutex);
|
||||
|
||||
if (!is_initialized) {
|
||||
@@ -55,8 +55,20 @@ bool SDFileManager::writeFileSync(const char* path, const char* data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_err_t result = s_example_write_file(path, const_cast<char*>(data));
|
||||
return result == ESP_OK;
|
||||
ESP_LOGI("SDFileManager", "Opening file %s", path);
|
||||
FILE *f = fopen(path, type);
|
||||
if (f == nullptr) {
|
||||
ESP_LOGE("SDFileManager", "Failed to open file for writing");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
const size_t written = fwrite(data, 1, len, f);
|
||||
fclose(f);
|
||||
if (written != len) {
|
||||
ESP_LOGE("SDFileManager", "Only %zu/%zu bytes written", written, len);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
ESP_LOGI("SDFileManager", "File written (%zu bytes)", written);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string SDFileManager::readFileSync(const char* path) {
|
||||
@@ -133,9 +145,9 @@ std::vector<std::string> SDFileManager::listFilesSync(const char* directory, con
|
||||
return {};
|
||||
}
|
||||
|
||||
const int max_files = 50;
|
||||
constexpr int max_files = 50;
|
||||
char file_names[max_files][100];
|
||||
uint16_t file_count = Folder_retrieval(directory, extension, file_names, max_files);
|
||||
const uint16_t file_count = Folder_retrieval(directory, extension, file_names, max_files);
|
||||
|
||||
std::vector<std::string> files;
|
||||
for (uint16_t i = 0; i < file_count; ++i) {
|
||||
@@ -163,12 +175,12 @@ bool SDFileManager::closeFileSync(FILE* file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SDFileManager::asyncWriteFile(const char* path, const char* data, WriteCallback callback) {
|
||||
void SDFileManager::asyncWriteFile(const char* path, const char* data, const size_t len, const char* type, WriteCallback callback) {
|
||||
ThreadConfig config = getThreadConfig("write_file");
|
||||
|
||||
ThreadManager::createThread(config, [this, path = std::string(path),
|
||||
data = std::string(data), callback]() {
|
||||
bool success = this->writeFileSync(path.c_str(), data.c_str());
|
||||
data = std::string(data), callback, type, len]() {
|
||||
const bool success = this->writeFileSync(path.c_str(), data.c_str(), len, type);
|
||||
if (callback) {
|
||||
callback(success, path.c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user