aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Storage.cpp7
-rw-r--r--src/plugins/LocalManga.cpp46
2 files changed, 53 insertions, 0 deletions
diff --git a/src/Storage.cpp b/src/Storage.cpp
index a0f20e4..f4732b8 100644
--- a/src/Storage.cpp
+++ b/src/Storage.cpp
@@ -163,6 +163,13 @@ namespace QuickMedia {
FILE *file = fopen_eintr(path.data.c_str(), "rb");
if(!file)
return -errno;
+
+ int fd = fileno(file);
+ struct stat s;
+ if(fstat(fd, &s) == -1 || !S_ISREG(s.st_mode)) {
+ fclose(file);
+ return -1;
+ }
fseek_eintr(file, 0, SEEK_END);
long file_size = ftell(file);
diff --git a/src/plugins/LocalManga.cpp b/src/plugins/LocalManga.cpp
index 4deb229..3ad4ffa 100644
--- a/src/plugins/LocalManga.cpp
+++ b/src/plugins/LocalManga.cpp
@@ -4,6 +4,7 @@
#include "../../include/Theme.hpp"
#include "../../include/StringUtils.hpp"
#include "../../include/Storage.hpp"
+#include <unordered_set>
namespace QuickMedia {
// Pages are sorted from 1.png to n.png
@@ -155,6 +156,47 @@ namespace QuickMedia {
return PluginResult::OK;
}
+ static std::unordered_set<std::string> get_lines_in_file(const Path &filepath) {
+ std::unordered_set<std::string> lines;
+
+ std::string file_content;
+ if(file_get_content(filepath, file_content) != 0)
+ return lines;
+
+ string_split(file_content, '\n', [&lines](const char *str_part, size_t size) {
+ lines.insert(std::string(str_part, size));
+ return true;
+ });
+
+ return lines;
+ }
+
+ static bool append_seen_manga_to_automedia_seen(const std::string &manga_chapter_name) {
+ Path automedia_config_dir = get_home_dir().join(".config").join("automedia");
+ if(create_directory_recursive(automedia_config_dir) != 0) {
+ fprintf(stderr, "Warning: failed to create directory: %s\n", automedia_config_dir.data.c_str());
+ return false;
+ }
+
+ Path automedia_seen_filepath = automedia_config_dir;
+ automedia_seen_filepath.join("seen");
+
+ std::unordered_set<std::string> lines = get_lines_in_file(automedia_seen_filepath);
+ if(lines.find(manga_chapter_name) != lines.end())
+ return true; // Already seen
+
+ FILE *file = fopen(automedia_seen_filepath.data.c_str(), "ab");
+ if(!file) {
+ fprintf(stderr, "Warning: failed to open automedia seen file %s\n", automedia_seen_filepath.data.c_str());
+ return false;
+ }
+
+ std::string new_line_data = manga_chapter_name + "\n";
+ fwrite(new_line_data.data(), 1, new_line_data.size(), file);
+ fclose(file);
+ return true;
+ }
+
PluginResult LocalMangaChaptersPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) {
if(get_config().local_manga_directory.empty()) {
show_notification("QuickMedia", "local_manga_directory config is not set", Urgency::CRITICAL);
@@ -169,6 +211,10 @@ namespace QuickMedia {
Path chapter_url = Path(get_config().local_manga_directory).join(content_url).join(args.url);
std::vector<LocalMangaPage> pages = get_images_in_manga(chapter_url);
result_tabs.push_back(Tab{nullptr, std::make_unique<LocalMangaImagesPage>(program, content_title, args.title, args.url, thumbnail_url, std::move(pages)), nullptr});
+
+ if(is_program_executable_by_name("automedia"))
+ append_seen_manga_to_automedia_seen(content_url + "/" + args.url);
+
return PluginResult::OK;
}