From 5c3cc6858e2a0137ff66753e543d7d42944330f9 Mon Sep 17 00:00:00 2001 From: DisableGraphics Date: Fri, 22 Apr 2022 10:43:14 +0200 Subject: [PATCH] Now Korai can open folders with images --- src/comp.hpp | 10 ++++++---- src/main.cpp | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/comp.hpp b/src/comp.hpp index b6ff724..ac9e27e 100644 --- a/src/comp.hpp +++ b/src/comp.hpp @@ -4,10 +4,12 @@ namespace comp { + inline std::vector supportedImageExtensions{".png", ".jpeg", ".jpg", ".jfif", ".gif", ".webp", ".svg"}; + inline std::vector supportedCompressedExtensions{".cbz", ".cbr", ".rar", ".zip"}; inline bool isImage(std::filesystem::path path) { - std::vector supportedExtensions{".png", ".jpeg", ".jpg", ".jfif", ".gif", ".webp", ".svg"}; - for (auto extension : supportedExtensions) + + for (auto extension : supportedImageExtensions) { if(path.extension() == extension) { @@ -18,8 +20,8 @@ namespace comp } inline bool isCompressed(std::filesystem::path path) { - std::vector supportedExtensions{".cbz", ".cbr", ".rar", ".zip"}; - for (auto extension : supportedExtensions) + + for (auto extension : supportedCompressedExtensions) { if(path.extension() == extension) { diff --git a/src/main.cpp b/src/main.cpp index 715ddf2..0bb69f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -107,7 +107,19 @@ void decompress(std::string filename) std::string tmp_folder{(std::string)std::filesystem::current_path() + "/tmp/"}; std::filesystem::remove_all(tmp_folder); std::filesystem::create_directory(tmp_folder); - zipe::extract(filename, tmp_folder); + if(comp::isCompressed(file)) + { + zipe::extract(filename, tmp_folder); + } + else if(comp::isImage(file)) + { + std::vector filesInFolda{getFilesInFolder(folder)}; + for(auto foyal : filesInFolda) + { + std::filesystem::copy(foyal, tmp_folder); + } + } + } //Generates the page for a chapter @@ -245,6 +257,10 @@ void open(WebKitWebView * webview, Gtk::HeaderBar * titlebar) supported_file_types->add_pattern("*.cbr"); supported_file_types->add_pattern("*.zip"); supported_file_types->add_pattern("*.rar"); + for(std::string ext : comp::supportedImageExtensions) + { + supported_file_types->add_pattern("*" + ext); + } Gtk::FileChooserDialog o{"Select a manga/comic file"}; Glib::RefPtr cbz = Gtk::FileFilter::create(); cbz->set_name("CBZ archive");