vxorg/vxorg.cpp

101 lines
2.8 KiB
C++
Raw Normal View History

#include <filesystem>
#include <fstream>
2024-10-21 21:21:37 -04:00
#include <indicators/progress_bar.hpp>
#include <indicators/terminal_size.hpp>
#include <string>
2024-10-21 21:21:37 -04:00
#include "indicators/terminal_size.hpp"
#include "tree.hpp"
#include "vxheaven_parse.hpp"
2024-10-21 21:21:37 -04:00
namespace ind = indicators;
int main() {
2024-10-21 12:27:40 -04:00
std::ifstream ifs("./testdata/samples.sort");
vxorg::VxHeavenTree tree;
vxorg::parse_into_tree(tree, ifs);
2024-10-21 21:21:37 -04:00
std::filesystem::path root = std::filesystem::current_path() / "testdata";
std::filesystem::path unorg = root / "unorg";
std::filesystem::path org = root / "org";
if(!std::filesystem::exists(org))
std::filesystem::create_directories(org);
2024-10-21 21:21:37 -04:00
std::size_t sampleCount = 0;
2024-10-21 21:21:37 -04:00
// Walk the tree to get the amount of sample nodes
tree.walk([&](auto* node) {
if(node->data().is_sample)
sampleCount++;
});
ind::ProgressBar bar { ind::option::BarWidth { indicators::terminal_width() - 64 },
ind::option::Start { "[" },
ind::option::Fill { "" },
ind::option::Lead { "" },
ind::option::Remainder { "-" },
ind::option::End { " ]" },
ind::option::ForegroundColor { ind::Color::cyan },
ind::option::FontStyles { std::vector<ind::FontStyle> { ind::FontStyle::bold } },
ind::option::MaxProgress { sampleCount } };
// Walk the tree to perform the operation
tree.walk([&](auto* node) {
auto tabulation_level = node->parent_count();
auto& data = node->data();
#if 0
if(tabulation_level != 0) {
for(auto i = 0; i < tabulation_level; ++i) {
std::printf("\t");
}
}
2024-10-21 19:56:43 -04:00
if(node->is_root()) {
std::printf("(root)\n");
} else {
if(data.is_sample) {
2024-10-21 12:27:40 -04:00
std::string sample_name = vxorg::get_sample_name(node);
std::printf("%s (sample %s)\n", data.name.c_str(), sample_name.c_str());
} else {
std::printf("%s\n", data.name.c_str());
}
}
#endif
#if 1
2024-10-21 21:21:37 -04:00
if(!node->is_root()) {
if(data.is_sample) {
std::string sample_name = vxorg::get_sample_name(node);
2024-10-21 21:21:37 -04:00
// paths
auto path = org / vxorg::get_sample_path(node);
auto source_path = unorg / vxorg::get_sample_name(node);
2024-10-21 21:21:37 -04:00
if(!std::filesystem::exists(source_path)) {
std::printf("WARNING: sample %s/%s in tree (source disk file %s) does not exist\n", path.string().c_str(), sample_name.c_str(),
source_path.string().c_str());
} else {
if(!std::filesystem::exists(path)) {
std::filesystem::create_directories(path);
}
2024-10-21 21:21:37 -04:00
bar.set_option(ind::option::PostfixText { std::format("Moving {}", sample_name) });
2024-10-21 21:21:37 -04:00
// FIXME Make this a move
std::filesystem::copy_file(source_path, path / vxorg::get_sample_name(node));
bar.tick();
}
// std::printf("sample %s/%s in tree (source disk file %s)\n", path.string().c_str(), sample_name.c_str(),
// source_path.string().c_str());
}
}
#endif
});
return 0;
}