Loading src/theme.cpp +2 −71 Changes for src/theme.cpp: 2 added lines, 71 removed lines. Original line number Diff line number Diff line Loading @@ -31,15 +31,7 @@ #include <fstream> #include <compare> #include <string> #ifdef Windows #include <Windows.h> #include <filesystem> #else #include <dirent.h> #include <dlfcn.h> #include <unistd.h> #endif #include <httppp/exception.h> Loading @@ -53,23 +45,19 @@ blogi::Theme::Theme(blogi::ThemeConfig& config,bool formated){ _Config=config; _Formated=formated; #ifdef Windows // Construct the path using std::filesystem::path, which handles separators portably std::string ppath(_Config.Theme); ppath+="\\public"; std::filesystem::path public_path = std::filesystem::path(ppath); // Check if the directory exists before attempting to iterate if (std::filesystem::exists(public_path) && std::filesystem::is_directory(public_path)) { // Use directory_iterator to loop through files in the directory for (const auto& entry : std::filesystem::directory_iterator(public_path)) { // Check if the current entry is a regular file if (std::filesystem::is_regular_file(entry.path())) { std::string buf; // It's good practice to use a dynamic buffer for reads // const int BLOCKSIZE = 4096; // Assuming this is defined char* tmp = new char[BLOCKSIZE]; std::ifstream fs_stream; Loading Loading @@ -102,8 +90,7 @@ blogi::Theme::Theme(blogi::ThemeConfig& config,bool formated){ size_t dot_pos = fname.rfind('.'); if (dot_pos != std::string::npos) { tfile.Ending = fname.substr(dot_pos + 1); } else { } else { tfile.Ending = ""; } Loading @@ -126,62 +113,6 @@ blogi::Theme::Theme(blogi::ThemeConfig& config,bool formated){ } } } #else DIR *directory = opendir(std::string(_Config.Theme).append("/public").c_str()); if (directory != nullptr) { struct dirent *direntStruct; while((direntStruct = readdir(directory))) { std::string buf; char tmp[BLOCKSIZE]; std::ifstream fs; std::string fpath=std::string(_Config.Theme).append("/public"); fpath.append("/"); fpath.append(direntStruct->d_name); struct stat curstat; stat(fpath.c_str(),&curstat); if(S_ISREG(curstat.st_mode)!=0){ try{ fs.open(fpath); }catch(std::exception &e){ continue; } while (fs.good()) { fs.read(tmp,BLOCKSIZE); buf.append(tmp,fs.gcount()); } ThemeFiles tfile; tfile.Path=std::string("/theme/public/").append(direntStruct->d_name); tfile.Content=buf; std::string fname=direntStruct->d_name; tfile.Ending=fname.substr(fname.rfind(".")+1,fname.length()-(fname.rfind(".")+1)); if(tfile.Ending=="png" || tfile.Ending=="jpg" || tfile.Ending=="webp" || tfile.Ending=="ico" || tfile.Ending=="svg"){ tfile.Type=ThemeFilesTypes::IMAGE; }else if(tfile.Ending=="css" || tfile.Ending=="html"){ compress<std::string>(tfile.Content,tfile.Compressed); tfile.Type=ThemeFilesTypes::TEXT; }else if(tfile.Ending=="js"){ compress<std::string>(tfile.Content,tfile.Compressed); tfile.Type=ThemeFilesTypes::JAVASCRIPT; }else{ tfile.Type=ThemeFilesTypes::GENERIC; } _PublicFiles.push_back(tfile); fs.close(); } } closedir(directory); } #endif } blogi::Theme::~Theme(){ Loading Loading
src/theme.cpp +2 −71 Changes for src/theme.cpp: 2 added lines, 71 removed lines. Original line number Diff line number Diff line Loading @@ -31,15 +31,7 @@ #include <fstream> #include <compare> #include <string> #ifdef Windows #include <Windows.h> #include <filesystem> #else #include <dirent.h> #include <dlfcn.h> #include <unistd.h> #endif #include <httppp/exception.h> Loading @@ -53,23 +45,19 @@ blogi::Theme::Theme(blogi::ThemeConfig& config,bool formated){ _Config=config; _Formated=formated; #ifdef Windows // Construct the path using std::filesystem::path, which handles separators portably std::string ppath(_Config.Theme); ppath+="\\public"; std::filesystem::path public_path = std::filesystem::path(ppath); // Check if the directory exists before attempting to iterate if (std::filesystem::exists(public_path) && std::filesystem::is_directory(public_path)) { // Use directory_iterator to loop through files in the directory for (const auto& entry : std::filesystem::directory_iterator(public_path)) { // Check if the current entry is a regular file if (std::filesystem::is_regular_file(entry.path())) { std::string buf; // It's good practice to use a dynamic buffer for reads // const int BLOCKSIZE = 4096; // Assuming this is defined char* tmp = new char[BLOCKSIZE]; std::ifstream fs_stream; Loading Loading @@ -102,8 +90,7 @@ blogi::Theme::Theme(blogi::ThemeConfig& config,bool formated){ size_t dot_pos = fname.rfind('.'); if (dot_pos != std::string::npos) { tfile.Ending = fname.substr(dot_pos + 1); } else { } else { tfile.Ending = ""; } Loading @@ -126,62 +113,6 @@ blogi::Theme::Theme(blogi::ThemeConfig& config,bool formated){ } } } #else DIR *directory = opendir(std::string(_Config.Theme).append("/public").c_str()); if (directory != nullptr) { struct dirent *direntStruct; while((direntStruct = readdir(directory))) { std::string buf; char tmp[BLOCKSIZE]; std::ifstream fs; std::string fpath=std::string(_Config.Theme).append("/public"); fpath.append("/"); fpath.append(direntStruct->d_name); struct stat curstat; stat(fpath.c_str(),&curstat); if(S_ISREG(curstat.st_mode)!=0){ try{ fs.open(fpath); }catch(std::exception &e){ continue; } while (fs.good()) { fs.read(tmp,BLOCKSIZE); buf.append(tmp,fs.gcount()); } ThemeFiles tfile; tfile.Path=std::string("/theme/public/").append(direntStruct->d_name); tfile.Content=buf; std::string fname=direntStruct->d_name; tfile.Ending=fname.substr(fname.rfind(".")+1,fname.length()-(fname.rfind(".")+1)); if(tfile.Ending=="png" || tfile.Ending=="jpg" || tfile.Ending=="webp" || tfile.Ending=="ico" || tfile.Ending=="svg"){ tfile.Type=ThemeFilesTypes::IMAGE; }else if(tfile.Ending=="css" || tfile.Ending=="html"){ compress<std::string>(tfile.Content,tfile.Compressed); tfile.Type=ThemeFilesTypes::TEXT; }else if(tfile.Ending=="js"){ compress<std::string>(tfile.Content,tfile.Compressed); tfile.Type=ThemeFilesTypes::JAVASCRIPT; }else{ tfile.Type=ThemeFilesTypes::GENERIC; } _PublicFiles.push_back(tfile); fs.close(); } } closedir(directory); } #endif } blogi::Theme::~Theme(){ Loading