aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-02-12 15:42:16 +0100
committerdec05eba <dec05eba@protonmail.com>2022-02-12 16:23:09 +0100
commit2f9ae9e9462a5a366461f20b4d0c2f4b80ef1b68 (patch)
tree165a71177182aec90f8d8fe888ffdbb7d801abcf /src/QuickMedia.cpp
parenta8d597d59e347a80b109060ec8c7a88827487f57 (diff)
Local-manga: improve loading of page when using slow medium
Especially when using NFS. Only get the latest chapter when needed and cache link to the cover page.
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 8174680..edb1db1 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -51,6 +51,7 @@
#include <unistd.h>
#include <libgen.h>
#include <limits.h>
+#include <sys/stat.h>
#include <mglpp/graphics/Rectangle.hpp>
#include <mglpp/graphics/Sprite.hpp>
@@ -957,7 +958,7 @@ namespace QuickMedia {
show_notification("QuickMedia", "Upgrading mangadex ids", Urgency::LOW);
std::vector<int> legacy_manga_ids;
- for_files_in_dir_sort_last_modified(content_storage_dir, [&legacy_manga_ids](const Path &filepath) {
+ for_files_in_dir_sort_last_modified(content_storage_dir, [&legacy_manga_ids](const Path &filepath, FileType) {
if(strcmp(filepath.ext(), ".tmp") == 0)
return true;
@@ -1460,7 +1461,7 @@ namespace QuickMedia {
// TODO: Remove this once manga history file has been in use for a few months and is filled with history
time_t now = time(NULL);
- for_files_in_dir_sort_last_modified(content_storage_dir, [&history_items, plugin_name, &manga_id_to_thumbnail_url_map, now, local_thumbnail](const Path &filepath) {
+ for_files_in_dir_sort_last_modified(content_storage_dir, [&](const Path &filepath, FileType) {
// This can happen when QuickMedia crashes/is killed while writing to storage.
// In that case, the storage wont be corrupt but there will be .tmp files.
// TODO: Remove these .tmp files if they exist during startup
@@ -3387,6 +3388,12 @@ namespace QuickMedia {
return PageType::EXIT;
}
+ // TODO: Do the same for thumbnails?
+ static bool is_symlink_valid(const char *filepath) {
+ struct stat buf;
+ return lstat(filepath, &buf) != -1;
+ }
+
// TODO: Optimize this somehow. One image alone uses more than 20mb ram! Total ram usage for viewing one image
// becomes 40mb (private memory, almost 100mb in total!) Unacceptable!
Program::LoadImageResult Program::load_image_by_index(int image_index, mgl::Texture &image_texture, std::string &error_message) {
@@ -3401,7 +3408,7 @@ namespace QuickMedia {
upscaled_ok = false;
}
- if(get_file_type(image_path) == FileType::REGULAR && upscaled_ok) {
+ if(get_file_type(image_path) == FileType::REGULAR && is_symlink_valid(image_path.data.c_str()) && upscaled_ok) {
if(image_texture.load_from_file(image_path.data.c_str())) {
return LoadImageResult::OK;
} else {
@@ -3463,7 +3470,7 @@ namespace QuickMedia {
upscaled_ok = false;
}
- if(get_file_type(image_filepath) != FileType::FILE_NOT_FOUND && upscaled_ok)
+ if(get_file_type(image_filepath) != FileType::FILE_NOT_FOUND && is_symlink_valid(image_filepath.data.c_str()) && upscaled_ok)
return true;
std::vector<CommandArg> extra_args;