First import

List all books with associated info
This commit is contained in:
King_DuckZ 2021-03-25 16:12:46 +01:00
commit 7548688eda
6 changed files with 133 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
compile_commands.json
tags

6
.gitmodules vendored Normal file
View file

@ -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

19
CMakeLists.txt Normal file
View file

@ -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"
)

@ -0,0 +1 @@
Subproject commit 55696bc76a6d162f96eb650df400aec3bd1b1b1e

1
lib/simdjson Submodule

@ -0,0 +1 @@
Subproject commit 95b4870e20be5f97d9dcf63b23b1c6f520c366c1

104
main.cpp Normal file
View file

@ -0,0 +1,104 @@
#include <iostream>
#include <rmlab/rmlab.hpp>
#include <simdjson.h>
#include <string_view>
#include <filesystem>
#include <vector>
#include <unordered_map>
#include <cstdint>
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<std::string> files;
std::uint64_t version = 0;
std::uintmax_t total_size = 0;
bool deleted = false;
};
std::ostream& operator<< (std::ostream& str, const std::pair<std::string, NotebookInfo>& 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<double>(val.total_size) / (1024.0 * 1024.0) << "MiB";
return str;
}
std::unordered_map<std::string, NotebookInfo> build_notebook_infos (
const fs::path& from_path
) {
simdjson::dom::parser parser;
std::unordered_map<std::string, NotebookInfo> 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<double>(total) / (1024.0 * 1024.0 * 1024.0) << "GiB\n";
return 0;
}