mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-02-20 15:14:26 +01:00
Reworked pagedArticle too to use the new Directory helpers.
This commit is contained in:
parent
5292da82ba
commit
52f85862bd
@ -1,11 +1,8 @@
|
|||||||
#include "paged_article.h"
|
#include "paged_article.h"
|
||||||
|
|
||||||
#include "core/database/query_builder.h"
|
#include "core/os/directory.h"
|
||||||
#include "core/database/query_result.h"
|
|
||||||
#include "core/database/table_builder.h"
|
|
||||||
#include "core/utils.h"
|
#include "core/utils.h"
|
||||||
|
|
||||||
#include <tinydir/tinydir.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void PagedArticle::handle_request_main(Request *request) {
|
void PagedArticle::handle_request_main(Request *request) {
|
||||||
@ -47,28 +44,22 @@ void PagedArticle::handle_request_main(Request *request) {
|
|||||||
void PagedArticle::load() {
|
void PagedArticle::load() {
|
||||||
ERR_FAIL_COND_MSG(articles_folder == "", "Error: PagedArticle::load called, but a articles_folder is not set!");
|
ERR_FAIL_COND_MSG(articles_folder == "", "Error: PagedArticle::load called, but a articles_folder is not set!");
|
||||||
|
|
||||||
tinydir_dir dir;
|
Ref<Directory> dir;
|
||||||
ERR_FAIL_COND_MSG(tinydir_open(&dir, articles_folder.c_str()) == -1, "Error opening PagedArticle::folder! folder: " + articles_folder);
|
dir.instance();
|
||||||
|
|
||||||
|
ERR_FAIL_COND_MSG(!dir->open(articles_folder.c_str(), false), "Error opening PagedArticle::folder! folder: " + articles_folder);
|
||||||
|
|
||||||
Vector<String> files;
|
Vector<String> files;
|
||||||
|
|
||||||
while (dir.has_next) {
|
while (dir->has_next()) {
|
||||||
tinydir_file file;
|
dir->next();
|
||||||
if (tinydir_readfile(&dir, &file) == -1) {
|
|
||||||
tinydir_next(&dir);
|
if (dir->current_is_file()) {
|
||||||
continue;
|
files.push_back(dir->current_get_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file.is_dir) {
|
|
||||||
String np = file.name;
|
|
||||||
|
|
||||||
files.push_back(np);
|
|
||||||
}
|
|
||||||
|
|
||||||
tinydir_next(&dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tinydir_close(&dir);
|
dir->close();
|
||||||
|
|
||||||
if (files.size() == 0) {
|
if (files.size() == 0) {
|
||||||
return;
|
return;
|
||||||
@ -85,19 +76,9 @@ void PagedArticle::load() {
|
|||||||
|
|
||||||
file_path += files[i];
|
file_path += files[i];
|
||||||
|
|
||||||
FILE *f = fopen(file_path.c_str(), "r");
|
|
||||||
|
|
||||||
ERR_CONTINUE_MSG(!f, "PagedArticle::load_folder: Error opening file! " + file_path);
|
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
|
||||||
long fsize = ftell(f);
|
|
||||||
fseek(f, 0, SEEK_SET); /* same as rewind(f); */
|
|
||||||
|
|
||||||
String fd;
|
String fd;
|
||||||
fd.resize(fsize);
|
|
||||||
|
|
||||||
fread(&fd[0], 1, fsize, f);
|
ERR_CONTINUE_MSG(!dir->read_file_into(file_path, &fd), "PagedArticle::load_folder: Error opening file! " + file_path);
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
Utils::markdown_to_html(&fd);
|
Utils::markdown_to_html(&fd);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user