Skip to content

Commit

Permalink
Now Korai can open folders with images
Browse files Browse the repository at this point in the history
  • Loading branch information
DisableGraphics committed Apr 22, 2022
1 parent dcbe823 commit 5c3cc68
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/comp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace comp
{
inline std::vector<std::string> supportedImageExtensions{".png", ".jpeg", ".jpg", ".jfif", ".gif", ".webp", ".svg"};
inline std::vector<std::string> supportedCompressedExtensions{".cbz", ".cbr", ".rar", ".zip"};
inline bool isImage(std::filesystem::path path)
{
std::vector<std::string> supportedExtensions{".png", ".jpeg", ".jpg", ".jfif", ".gif", ".webp", ".svg"};
for (auto extension : supportedExtensions)

for (auto extension : supportedImageExtensions)
{
if(path.extension() == extension)
{
Expand All @@ -18,8 +20,8 @@ namespace comp
}
inline bool isCompressed(std::filesystem::path path)
{
std::vector<std::string> supportedExtensions{".cbz", ".cbr", ".rar", ".zip"};
for (auto extension : supportedExtensions)

for (auto extension : supportedCompressedExtensions)
{
if(path.extension() == extension)
{
Expand Down
18 changes: 17 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> filesInFolda{getFilesInFolder(folder)};
for(auto foyal : filesInFolda)
{
std::filesystem::copy(foyal, tmp_folder);
}
}

}

//Generates the page for a chapter
Expand Down Expand Up @@ -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<Gtk::FileFilter> cbz = Gtk::FileFilter::create();
cbz->set_name("CBZ archive");
Expand Down

0 comments on commit 5c3cc68

Please sign in to comment.