commit 7548688edaedbf0f7e7dfc9a61c3ebd6cc521a1e Author: King_DuckZ Date: Thu Mar 25 16:12:46 2021 +0100 First import List all books with associated info diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d91d243 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +compile_commands.json +tags diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ab8774b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "lib/lines-are-beautiful"] + path = lib/lines-are-beautiful + url = https://github.com/ax3l/lines-are-beautiful.git +[submodule "lib/simdjson"] + path = lib/simdjson + url = https://github.com/simdjson/simdjson.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f285432 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.10 FATAL_ERROR) +project(remarkable_tool LANGUAGES CXX VERSION 1.0.0) + +add_subdirectory("lib/lines-are-beautiful") +add_subdirectory("lib/simdjson") + +add_executable(${PROJECT_NAME} + main.cpp +) + +target_link_libraries(${PROJECT_NAME} + PRIVATE Rmlab::Rmlab + PRIVATE simdjson +) + +set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD_REQUIRED ON + CXX_STANDARD "20" +) diff --git a/lib/lines-are-beautiful b/lib/lines-are-beautiful new file mode 160000 index 0000000..55696bc --- /dev/null +++ b/lib/lines-are-beautiful @@ -0,0 +1 @@ +Subproject commit 55696bc76a6d162f96eb650df400aec3bd1b1b1e diff --git a/lib/simdjson b/lib/simdjson new file mode 160000 index 0000000..95b4870 --- /dev/null +++ b/lib/simdjson @@ -0,0 +1 @@ +Subproject commit 95b4870e20be5f97d9dcf63b23b1c6f520c366c1 diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..fc6d619 --- /dev/null +++ b/main.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +namespace fs = std::filesystem; + +namespace { +#define BASE_PATH "/run/media/duckz/Sabrent/deleme/remarkable_20210324/xochitl/" +//#define BASE_PATH "/home/duckz/dev/code/cpp/remarkable_tool/lib/lines-are-beautiful/share/rmlab/examples/" + +struct NotebookInfo { + std::string visible_name; + std::string parent; + std::string type; + std::vector files; + std::uint64_t version = 0; + std::uintmax_t total_size = 0; + bool deleted = false; +}; + +std::ostream& operator<< (std::ostream& str, const std::pair& v) { + auto& key = v.first; + auto& val = v.second; + str << key << " (\"" << val.visible_name << "\", " << val.type << + "): deleted=" << std::boolalpha << val.deleted << + ", parent=\"" << val.parent << + "\", version=" << val.version << + ", files="; + + std::string_view sep(""); + for (const auto& f : val.files) { + str << sep << f; + sep = ";"; + } + + str << ", size=" << std::setprecision(2) << + static_cast(val.total_size) / (1024.0 * 1024.0) << "MiB"; + return str; +} + +std::unordered_map build_notebook_infos ( + const fs::path& from_path +) { + simdjson::dom::parser parser; + std::unordered_map retval; + + for (const auto& entry : fs::directory_iterator(from_path)) { + NotebookInfo& curr_info = retval[entry.path().stem()]; + + if (entry.path().extension() == ".metadata") { + simdjson::dom::object json_doc = parser.load(entry.path()); + + curr_info.deleted = json_doc["deleted"]; + curr_info.parent = json_doc["parent"]; + curr_info.type = json_doc["type"]; + curr_info.version = json_doc["version"]; + curr_info.visible_name = json_doc["visibleName"]; + } + else if (fs::is_directory(entry)) { + for (const auto& subentry : fs::recursive_directory_iterator(entry)) { + curr_info.files.push_back(fs::relative(subentry, from_path)); + if (fs::is_regular_file(subentry)) + curr_info.total_size += fs::file_size(subentry); + } + } + + curr_info.files.push_back(fs::relative(entry, from_path)); + if (fs::is_regular_file(entry)) + curr_info.total_size += fs::file_size(entry); + } + + return retval; +} +} //unnamed namespace + +int main() { + using std::string_view; + + rmlab::Notebook doc(BASE_PATH "a4bcfe83-a91d-485b-b27c-2a06aa287641"); + //rmlab::Notebook doc(BASE_PATH "aa90b0e7-5c1a-42fe-930f-dad9cf3363cc"); + + std::cout << "Document version: " << doc.version << '\n'; + + auto notebooks = build_notebook_infos(BASE_PATH); + + int z = 0; + std::uintmax_t total = 0; + for (auto& nb : notebooks) { + std::cout << nb << '\n'; + std::cout << "------ " << z << "-----\n"; + ++z; + total += nb.second.total_size; + } + + std::cout << "Found " << notebooks.size() << " notebooks\n"; + std::cout << "Total size " << std::setprecision(2) << + static_cast(total) / (1024.0 * 1024.0 * 1024.0) << "GiB\n"; + return 0; +}