diff --git a/xml_converter/integration_tests/test_cases/texture/input/pack/somedir/texture_three.png b/xml_converter/integration_tests/test_cases/texture/input/pack/somedir/texture_three.png new file mode 100644 index 00000000..3faad497 Binary files /dev/null and b/xml_converter/integration_tests/test_cases/texture/input/pack/somedir/texture_three.png differ diff --git a/xml_converter/integration_tests/test_cases/texture/input/pack/texture_one.png b/xml_converter/integration_tests/test_cases/texture/input/pack/texture_one.png new file mode 100644 index 00000000..392885bb Binary files /dev/null and b/xml_converter/integration_tests/test_cases/texture/input/pack/texture_one.png differ diff --git a/xml_converter/integration_tests/test_cases/texture/input/pack/texture_two.png b/xml_converter/integration_tests/test_cases/texture/input/pack/texture_two.png new file mode 100644 index 00000000..ce71402d Binary files /dev/null and b/xml_converter/integration_tests/test_cases/texture/input/pack/texture_two.png differ diff --git a/xml_converter/integration_tests/test_cases/texture/input/pack/xml_file.xml b/xml_converter/integration_tests/test_cases/texture/input/pack/xml_file.xml index 490a4897..d7135b25 100644 --- a/xml_converter/integration_tests/test_cases/texture/input/pack/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/texture/input/pack/xml_file.xml @@ -3,9 +3,9 @@ - - - - + + + + diff --git a/xml_converter/integration_tests/test_cases/texture/output_proto/markers.bin b/xml_converter/integration_tests/test_cases/texture/output_proto/markers.bin index 075d2117..93077c5e 100644 Binary files a/xml_converter/integration_tests/test_cases/texture/output_proto/markers.bin and b/xml_converter/integration_tests/test_cases/texture/output_proto/markers.bin differ diff --git a/xml_converter/integration_tests/test_cases/texture/output_proto/somedir/texture_three.png b/xml_converter/integration_tests/test_cases/texture/output_proto/somedir/texture_three.png new file mode 100644 index 00000000..3faad497 Binary files /dev/null and b/xml_converter/integration_tests/test_cases/texture/output_proto/somedir/texture_three.png differ diff --git a/xml_converter/integration_tests/test_cases/texture/output_proto/texture_one.png b/xml_converter/integration_tests/test_cases/texture/output_proto/texture_one.png new file mode 100644 index 00000000..392885bb Binary files /dev/null and b/xml_converter/integration_tests/test_cases/texture/output_proto/texture_one.png differ diff --git a/xml_converter/integration_tests/test_cases/texture/output_proto/texture_two.png b/xml_converter/integration_tests/test_cases/texture/output_proto/texture_two.png new file mode 100644 index 00000000..ce71402d Binary files /dev/null and b/xml_converter/integration_tests/test_cases/texture/output_proto/texture_two.png differ diff --git a/xml_converter/integration_tests/test_cases/texture/output_xml/somedir/texture_three.png b/xml_converter/integration_tests/test_cases/texture/output_xml/somedir/texture_three.png new file mode 100644 index 00000000..3faad497 Binary files /dev/null and b/xml_converter/integration_tests/test_cases/texture/output_xml/somedir/texture_three.png differ diff --git a/xml_converter/integration_tests/test_cases/texture/output_xml/texture_one.png b/xml_converter/integration_tests/test_cases/texture/output_xml/texture_one.png new file mode 100644 index 00000000..392885bb Binary files /dev/null and b/xml_converter/integration_tests/test_cases/texture/output_xml/texture_one.png differ diff --git a/xml_converter/integration_tests/test_cases/texture/output_xml/texture_two.png b/xml_converter/integration_tests/test_cases/texture/output_xml/texture_two.png new file mode 100644 index 00000000..ce71402d Binary files /dev/null and b/xml_converter/integration_tests/test_cases/texture/output_xml/texture_two.png differ diff --git a/xml_converter/integration_tests/test_cases/texture/output_xml/xml_file.xml b/xml_converter/integration_tests/test_cases/texture/output_xml/xml_file.xml index 5af46f44..5fa93e32 100644 --- a/xml_converter/integration_tests/test_cases/texture/output_xml/xml_file.xml +++ b/xml_converter/integration_tests/test_cases/texture/output_xml/xml_file.xml @@ -3,9 +3,9 @@ - - - - + + + + diff --git a/xml_converter/src/attribute/image.cpp b/xml_converter/src/attribute/image.cpp index dcbe677d..ad8cdf04 100644 --- a/xml_converter/src/attribute/image.cpp +++ b/xml_converter/src/attribute/image.cpp @@ -1,12 +1,12 @@ #include "image.hpp" -#include +#include #include #include #include "../rapid_helpers.hpp" #include "../rapidxml-1.13/rapidxml.hpp" -#include "waypoint.pb.h" +#include "../string_helper.hpp" using namespace std; @@ -21,8 +21,10 @@ void xml_attribute_to_image( XMLReaderState* state, Image* value, bool* is_set) { - value->filename = get_attribute_value(input); - value->original_filepath = state->xml_filedir + "/" + value->filename; + Image image; + image.filename = get_attribute_value(input); + image.original_filepath = join_file_paths(state->marker_pack_root_directory, image.filename); + *value = image; *is_set = true; } @@ -33,8 +35,16 @@ void xml_attribute_to_image( //////////////////////////////////////////////////////////////////////////////// string image_to_xml_attribute( const string& attribute_name, - XMLWriterState*, + XMLWriterState* state, const Image* value) { + if (filesystem::exists(filesystem::path(value->original_filepath))) { + filesystem::path output_path = filesystem::path(state->marker_pack_root_directory) / value->filename; + filesystem::create_directories(output_path.parent_path()); + filesystem::copy_file(filesystem::path(value->original_filepath), output_path, filesystem::copy_options::overwrite_existing); + } + else { + cout << "Warning: File path " << value->original_filepath << " not found." << endl; + } return " " + attribute_name + "=\"" + value->filename + "\""; } @@ -48,9 +58,9 @@ void proto_to_image( ProtoReaderState* state, Image* value, bool* is_set) { - // TODO: this is broken until we load the string index into the proto read state Image image; - // image.path = input.path(); + image.filename = state->textures[input].filepath(); + image.original_filepath = join_file_paths(state->marker_pack_root_directory, image.filename); *value = image; *is_set = true; } @@ -75,6 +85,14 @@ void image_to_proto( texture_index = state->textures.size(); state->texture_path_to_textures_index[value.original_filepath] = texture_index; state->textures.push_back(&value); + if (filesystem::exists(filesystem::path(value.original_filepath))) { + filesystem::path output_path = filesystem::path(state->marker_pack_root_directory) / value.filename; + filesystem::create_directories(output_path.parent_path()); + filesystem::copy_file(filesystem::path(value.original_filepath), output_path, filesystem::copy_options::overwrite_existing); + } + else { + cout << "Warning: File path " << value.original_filepath << " not found." << endl; + } } setter(texture_index); diff --git a/xml_converter/src/attribute/trail_data.cpp b/xml_converter/src/attribute/trail_data.cpp index c6fd8c26..341de3c3 100644 --- a/xml_converter/src/attribute/trail_data.cpp +++ b/xml_converter/src/attribute/trail_data.cpp @@ -32,7 +32,7 @@ void xml_attribute_to_trail_data( bool* is_map_id_set) { TrailData trail_data; string trail_data_relative_path = get_attribute_value(input); - if (state->xml_filedir == "") { + if (state->marker_pack_root_directory == "") { throw "Error: Marker pack base directory is an empty string"; } if (trail_data_relative_path == "") { @@ -41,7 +41,7 @@ void xml_attribute_to_trail_data( } ifstream trail_data_file; - string trail_path = state->xml_filedir + "/" + trail_data_relative_path; + string trail_path = join_file_paths(state->marker_pack_root_directory, trail_data_relative_path); trail_data_file.open(trail_path, ios::in | ios::binary); if (!trail_data_file.good()) { errors->push_back(new XMLAttributeValueError("No trail file found at " + trail_path, input)); @@ -132,7 +132,7 @@ string trail_data_to_xml_attribute( } string trail_file_name = long_to_hex_string(djb2_hash(byte_array, byte_array_size)) + ".trl"; - string trail_file_path = join_file_paths(state->filedir, trail_file_name); + string trail_file_path = join_file_paths(state->marker_pack_root_directory, trail_file_name); ofstream trail_data_file(trail_file_path, ios::binary); diff --git a/xml_converter/src/packaging_protobin.cpp b/xml_converter/src/packaging_protobin.cpp index 337c74ef..94cd27f8 100644 --- a/xml_converter/src/packaging_protobin.cpp +++ b/xml_converter/src/packaging_protobin.cpp @@ -1,5 +1,6 @@ #include "packaging_protobin.hpp" +#include #include #include #include @@ -8,6 +9,7 @@ #include "category_gen.hpp" #include "parseable.hpp" +#include "state_structs/proto_writer_state.hpp" #include "string_helper.hpp" #include "string_hierarchy.hpp" #include "waypoint.pb.h" @@ -25,17 +27,16 @@ void parse_waypoint_categories( string full_category_name, ::waypoint::Category proto_category, map* marker_categories, - vector* parsed_pois) { + vector* parsed_pois, + ProtoReaderState* state) { full_category_name += proto_category.name(); Category* this_category = &(*marker_categories)[full_category_name]; - ProtoReaderState state; - - this_category->parse_protobuf(proto_category, &state); + this_category->parse_protobuf(proto_category, state); for (int i = 0; i < proto_category.icon_size(); i++) { Icon* icon = new Icon(); - icon->parse_protobuf(proto_category.icon(i), &state); + icon->parse_protobuf(proto_category.icon(i), state); // TODO: The field category in Icon is being deprciated // This overwrites any icon.category with its position in the heirarchy icon->category.category = full_category_name; @@ -43,7 +44,7 @@ void parse_waypoint_categories( } for (int i = 0; i < proto_category.trail_size(); i++) { Trail* trail = new Trail(); - trail->parse_protobuf(proto_category.trail(i), &state); + trail->parse_protobuf(proto_category.trail(i), state); // TODO: The field category in Trail is being deprciated // This overwrites any trail.category with its position in the heirarchy trail->category.category = full_category_name; @@ -51,21 +52,26 @@ void parse_waypoint_categories( } for (int i = 0; i < proto_category.children_size(); i++) { - parse_waypoint_categories(full_category_name + ".", proto_category.children(i), &(this_category->children), parsed_pois); + parse_waypoint_categories(full_category_name + ".", proto_category.children(i), &(this_category->children), parsed_pois, state); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// -void read_protobuf_file(string proto_filepath, map* marker_categories, vector* parsed_pois) { +void read_protobuf_file(string proto_filepath, const string marker_pack_root_directory, map* marker_categories, vector* parsed_pois) { fstream infile; waypoint::Waypoint proto_message; + ProtoReaderState state; + state.marker_pack_root_directory = marker_pack_root_directory; infile.open(proto_filepath, ios::in | ios::binary); proto_message.ParseFromIstream(&infile); + + state.textures = proto_message.textures(); + for (int i = 0; i < proto_message.category_size(); i++) { - parse_waypoint_categories("", proto_message.category(i), marker_categories, parsed_pois); + parse_waypoint_categories("", proto_message.category(i), marker_categories, parsed_pois, &state); } } @@ -163,12 +169,11 @@ void _write_protobuf_file( const string& filepath, const StringHierarchy& category_filter, const map* marker_categories, - const std::map>& category_to_pois) { + const std::map>& category_to_pois, + ProtoWriterState* state) { ofstream outfile; outfile.open(filepath, ios::out | ios::binary); - ProtoWriterState state; - if (!outfile.is_open()) { cout << "Unable to open " << filepath << endl; } @@ -185,25 +190,27 @@ void _write_protobuf_file( category_filter, category_to_pois, &category_vector, - &state); + state); if (maybe_category.is_category) { output_message.add_category()->MergeFrom(maybe_category.category); } } - proto_post_processing(&state, &output_message); + proto_post_processing(state, &output_message); output_message.SerializeToOstream(&outfile); outfile.close(); } void write_protobuf_file( - const string& filepath, + const string& marker_pack_root_directory, const StringHierarchy& category_filter, const map* marker_categories, const vector* parsed_pois) { std::map> category_to_pois; + ProtoWriterState state; + state.marker_pack_root_directory = marker_pack_root_directory; for (size_t i = 0; i < parsed_pois->size(); i++) { Parseable* parsed_poi = (*parsed_pois)[i]; @@ -221,19 +228,22 @@ void write_protobuf_file( } _write_protobuf_file( - join_file_paths(filepath, "markers.bin"), + join_file_paths(state.marker_pack_root_directory, "markers.bin"), category_filter, marker_categories, - category_to_pois); + category_to_pois, + &state); } // Write protobuf per map id void write_protobuf_file_per_map_id( - const string& proto_directory, + const string& marker_pack_root_directory, const StringHierarchy& category_filter, const map* marker_categories, const vector* parsed_pois) { std::map>> mapid_to_category_to_pois; + ProtoWriterState state; + state.marker_pack_root_directory = marker_pack_root_directory; for (size_t i = 0; i < parsed_pois->size(); i++) { Parseable* parsed_poi = (*parsed_pois)[i]; @@ -251,12 +261,13 @@ void write_protobuf_file_per_map_id( } for (auto iterator = mapid_to_category_to_pois.begin(); iterator != mapid_to_category_to_pois.end(); iterator++) { - string output_filepath = join_file_paths(proto_directory, to_string(iterator->first) + ".data"); + string output_filepath = join_file_paths(state.marker_pack_root_directory, to_string(iterator->first) + ".bin"); _write_protobuf_file( output_filepath, category_filter, marker_categories, - iterator->second); + iterator->second, + &state); } } diff --git a/xml_converter/src/packaging_protobin.hpp b/xml_converter/src/packaging_protobin.hpp index a62c02b7..495ef54e 100644 --- a/xml_converter/src/packaging_protobin.hpp +++ b/xml_converter/src/packaging_protobin.hpp @@ -12,17 +12,18 @@ void read_protobuf_file( std::string proto_filepath, + const std::string marker_pack_root_directory, std::map* marker_categories, std::vector* parsed_pois); void write_protobuf_file( - const std::string& proto_directory, + const std::string& marker_pack_root_directory, const StringHierarchy& category_filter, const std::map* marker_categories, const std::vector* parsed_pois); void write_protobuf_file_per_map_id( - const std::string& proto_directory, + const std::string& marker_pack_root_directory, const StringHierarchy& category_filter, const std::map* marker_categories, const std::vector* parsed_pois); diff --git a/xml_converter/src/packaging_xml.cpp b/xml_converter/src/packaging_xml.cpp index 56b0e68e..f5700314 100644 --- a/xml_converter/src/packaging_xml.cpp +++ b/xml_converter/src/packaging_xml.cpp @@ -6,6 +6,7 @@ #include "rapid_helpers.hpp" #include "rapidxml-1.13/rapidxml.hpp" #include "rapidxml-1.13/rapidxml_utils.hpp" +#include "state_structs/xml_reader_state.hpp" #include "string_helper.hpp" using namespace std; @@ -20,16 +21,11 @@ void parse_marker_categories( map* marker_categories, Category* parent, vector* errors, - string base_dir, + XMLReaderState* state, int depth = 0) { if (get_node_name(node) == "MarkerCategory") { - XMLReaderState state = { - base_dir, - marker_categories, - }; - Category new_category; - new_category.init_from_xml(node, errors, &state); + new_category.init_from_xml(node, errors, state); string name; if (!new_category.name_is_set) { @@ -63,7 +59,6 @@ void parse_marker_categories( new_category.menu_id = new_id.unique_id(); new_category.menu_id_is_set = true; } - // Create and initialize a new category if this one does not exist Category* existing_category; auto existing_category_search = marker_categories->find(name); @@ -80,7 +75,7 @@ void parse_marker_categories( existing_category->apply_overlay(new_category); for (rapidxml::xml_node<>* child_node = node->first_node(); child_node; child_node = child_node->next_sibling()) { - parse_marker_categories(child_node, &(existing_category->children), existing_category, errors, base_dir, depth + 1); + parse_marker_categories(child_node, &(existing_category->children), existing_category, errors, state, depth + 1); } } else { @@ -131,14 +126,9 @@ Category* get_category(rapidxml::xml_node<>* node, map* marker // // Parse the xml block into an in-memory array of Markers. //////////////////////////////////////////////////////////////////////////////// -vector parse_pois(rapidxml::xml_node<>* root_node, map* marker_categories, vector* errors, string base_dir) { +vector parse_pois(rapidxml::xml_node<>* root_node, map* marker_categories, vector* errors, XMLReaderState* state) { vector markers; - XMLReaderState state = { - base_dir, - marker_categories, - }; - for (rapidxml::xml_node<>* node = root_node->first_node(); node; node = node->next_sibling()) { if (get_node_name(node) == "POI") { Category* default_category = get_category(node, marker_categories, errors); @@ -149,7 +139,7 @@ vector parse_pois(rapidxml::xml_node<>* root_node, mapdefault_icon; } - icon->init_from_xml(node, errors, &state); + icon->init_from_xml(node, errors, state); markers.push_back(icon); } else if (get_node_name(node) == "Trail") { @@ -161,7 +151,7 @@ vector parse_pois(rapidxml::xml_node<>* root_node, mapdefault_trail; } - trail->init_from_xml(node, errors, &state); + trail->init_from_xml(node, errors, state); markers.push_back(trail); } else { @@ -176,16 +166,17 @@ vector parse_pois(rapidxml::xml_node<>* root_node, map* marker_categories, vector* parsed_pois) { +void parse_xml_file(string xml_filepath, const string marker_pack_root_directory, map* marker_categories, vector* parsed_pois) { vector errors; rapidxml::xml_document<> doc; rapidxml::xml_node<>* root_node; + XMLReaderState state; + state.marker_pack_root_directory = marker_pack_root_directory; rapidxml::file<> xml_file(xml_filepath.c_str()); doc.parse(xml_file.data(), xml_filepath.c_str()); root_node = doc.first_node(); - string base_dir = get_base_dir(xml_filepath); // Validate the Root Node if (get_node_name(root_node) != "OverlayData") { errors.push_back(new XMLNodeNameError("Root node should be of type OverlayData", root_node)); @@ -196,10 +187,10 @@ void parse_xml_file(string xml_filepath, map* marker_categorie for (rapidxml::xml_node<>* node = root_node->first_node(); node; node = node->next_sibling()) { if (get_node_name(node) == "MarkerCategory") { - parse_marker_categories(node, marker_categories, nullptr, &errors, base_dir); + parse_marker_categories(node, marker_categories, nullptr, &errors, &state); } else if (get_node_name(node) == "POIs") { - vector temp_vector = parse_pois(node, marker_categories, &errors, base_dir); + vector temp_vector = parse_pois(node, marker_categories, &errors, &state); move(temp_vector.begin(), temp_vector.end(), back_inserter(*parsed_pois)); } else { @@ -215,14 +206,13 @@ void parse_xml_file(string xml_filepath, map* marker_categorie //////////////////////////////////////////////////////////////////////////////// ///////////////////////////////// DESERIALIZE ////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// - -void write_xml_file(string xml_filepath, map* marker_categories, vector* parsed_pois) { +void write_xml_file(const string marker_pack_root_directory, map* marker_categories, vector* parsed_pois) { ofstream outfile; string tab_string; - XMLWriterState state; - state.filedir = get_base_dir(xml_filepath); + state.marker_pack_root_directory = marker_pack_root_directory; + string xml_filepath = join_file_paths(marker_pack_root_directory, "xml_file.xml"); outfile.open(xml_filepath, ios::out); outfile << "\n"; diff --git a/xml_converter/src/packaging_xml.hpp b/xml_converter/src/packaging_xml.hpp index 791303c2..a099d625 100644 --- a/xml_converter/src/packaging_xml.hpp +++ b/xml_converter/src/packaging_xml.hpp @@ -12,10 +12,11 @@ void parse_xml_file( std::string xml_filepath, + const std::string marker_pack_root_directory, std::map* marker_categories, std::vector* parsed_pois); void write_xml_file( - std::string xml_filepath, + const std::string marker_pack_root_directory, std::map* marker_categories, std::vector* parsed_pois); diff --git a/xml_converter/src/state_structs/proto_reader_state.hpp b/xml_converter/src/state_structs/proto_reader_state.hpp index 7573a489..161fa1b2 100644 --- a/xml_converter/src/state_structs/proto_reader_state.hpp +++ b/xml_converter/src/state_structs/proto_reader_state.hpp @@ -1,4 +1,11 @@ #pragma once +#include + +#include "waypoint.pb.h" + struct ProtoReaderState { + // A list of all of the textures with their paths. + google::protobuf::RepeatedPtrField<::waypoint::TextureData> textures; + std::string marker_pack_root_directory; }; diff --git a/xml_converter/src/state_structs/proto_writer_state.hpp b/xml_converter/src/state_structs/proto_writer_state.hpp index d7817037..f3a36ca0 100644 --- a/xml_converter/src/state_structs/proto_writer_state.hpp +++ b/xml_converter/src/state_structs/proto_writer_state.hpp @@ -8,6 +8,7 @@ class Image; class ProtoWriterState { public: + std::string marker_pack_root_directory; // A map from texture path to the index within "textures" that the path is saved in. std::map texture_path_to_textures_index; diff --git a/xml_converter/src/state_structs/xml_reader_state.hpp b/xml_converter/src/state_structs/xml_reader_state.hpp index e60d12da..7c5c7be8 100644 --- a/xml_converter/src/state_structs/xml_reader_state.hpp +++ b/xml_converter/src/state_structs/xml_reader_state.hpp @@ -6,6 +6,6 @@ class Category; struct XMLReaderState { - std::string xml_filedir; + std::string marker_pack_root_directory; std::map* marker_categories; }; diff --git a/xml_converter/src/state_structs/xml_writer_state.hpp b/xml_converter/src/state_structs/xml_writer_state.hpp index b1d4c67b..ac7384cf 100644 --- a/xml_converter/src/state_structs/xml_writer_state.hpp +++ b/xml_converter/src/state_structs/xml_writer_state.hpp @@ -3,5 +3,5 @@ #include struct XMLWriterState { - std::string filedir; + std::string marker_pack_root_directory; }; diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index 96e02865..7f081d1f 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -62,57 +62,69 @@ vector get_files_by_suffix(string directory, string suffix) { return files; } -void move_supplementary_files(string input_directory, string output_directory) { - DIR* dir = opendir(input_directory.c_str()); - struct dirent* entry; - while ((entry = readdir(dir)) != NULL) { - string filename = entry->d_name; - if (filename != "." && filename != "..") { - string path = join_file_paths(input_directory, filename); - if (entry->d_type == DT_DIR) { - string new_directory = join_file_paths(output_directory, filename); - if (mkdir(new_directory.c_str(), 0700) == -1 && errno != EEXIST) { - cout << "Error making " << new_directory << endl; - continue; - } - move_supplementary_files(path, new_directory); - } - else if (has_suffix(filename, ".trl") || has_suffix(filename, ".xml")) { - continue; - } - else { - // TODO: Only include files that are referenced by the - // individual markers in order to avoid any unnessecary files - string new_path = join_file_paths(output_directory, filename); - copy_file(path, new_path); - } +void read_taco_directory( + string input_path, + map* marker_categories, + vector* parsed_pois) { + if (!filesystem::exists(input_path)) { + cout << "Error: " << input_path << " is not an existing directory or file" << endl; + } + else if (filesystem::is_directory(input_path)) { + vector xml_files = get_files_by_suffix(input_path, ".xml"); + for (const string& path : xml_files) { + parse_xml_file(path, input_path, marker_categories, parsed_pois); } } + else if (filesystem::is_regular_file(input_path)) { + parse_xml_file(input_path, get_base_dir(input_path), marker_categories, parsed_pois); + } } -void read_taco_directory(string input_path, map* marker_categories, vector* parsed_pois) { +void read_burrito_directory( + string input_path, + map* marker_categories, + vector* parsed_pois) { if (!filesystem::exists(input_path)) { cout << "Error: " << input_path << " is not an existing directory or file" << endl; } else if (filesystem::is_directory(input_path)) { - vector xml_files = get_files_by_suffix(input_path, ".xml"); - for (const string& path : xml_files) { - parse_xml_file(path, marker_categories, parsed_pois); + vector burrito_files = get_files_by_suffix(input_path, ".bin"); + for (const string& path : burrito_files) { + read_protobuf_file(path, input_path, marker_categories, parsed_pois); } } else if (filesystem::is_regular_file(input_path)) { - parse_xml_file(input_path, marker_categories, parsed_pois); + read_protobuf_file(input_path, get_base_dir(input_path), marker_categories, parsed_pois); } } -void write_taco_directory(string output_path, map* marker_categories, vector* parsed_pois) { +void write_taco_directory( + string output_path, + map* marker_categories, + vector* parsed_pois) { // TODO: Exportion of XML Marker Packs File Structure #111 if (!filesystem::is_directory(output_path)) { if (!filesystem::create_directory(output_path)) { cout << "Error: " << output_path << "is not a valid directory path" << endl; + return; + } + } + write_xml_file(output_path, marker_categories, parsed_pois); +} + +void write_burrito_directory( + string output_path, + map* marker_categories, + vector* parsed_pois) { + if (!filesystem::is_directory(output_path)) { + if (!filesystem::create_directory(output_path)) { + cout << "Error: " << output_path << "is not a valid directory path" << endl; + return; } } - write_xml_file(join_file_paths(output_path, "xml_file.xml"), marker_categories, parsed_pois); + StringHierarchy category_filter; + category_filter.add_path({}, true); + write_protobuf_file(output_path, category_filter, marker_categories, parsed_pois); } //////////////////////////////////////////////////////////////////////////////// @@ -141,16 +153,11 @@ void process_data( auto begin = chrono::high_resolution_clock::now(); for (size_t i = 0; i < input_taco_paths.size(); i++) { cout << "Loading taco pack " << input_taco_paths[i] << endl; + read_taco_directory( input_taco_paths[i], &marker_categories, &parsed_pois); - - // TODO: This is wildly incorrect now because we might have a - // different output directory then output_split_waypoint_dir - if (output_split_waypoint_dir != "") { - move_supplementary_files(input_taco_paths[i], output_split_waypoint_dir); - } } auto end = chrono::high_resolution_clock::now(); auto dur = end - begin; @@ -160,7 +167,8 @@ void process_data( // Read in all the protobin waypoint markerpacks for (size_t i = 0; i < input_waypoint_paths.size(); i++) { cout << "Loading waypoint pack " << input_waypoint_paths[i] << endl; - read_protobuf_file( + + read_burrito_directory( input_waypoint_paths[i], &marker_categories, &parsed_pois); @@ -178,9 +186,7 @@ void process_data( // Write all of the protobin waypoint paths for (size_t i = 0; i < output_waypoint_paths.size(); i++) { - StringHierarchy category_filter; - category_filter.add_path({}, true); - write_protobuf_file(output_waypoint_paths[i], category_filter, &marker_categories, &parsed_pois); + write_burrito_directory(output_waypoint_paths[i], &marker_categories, &parsed_pois); } // Write the special map-split protbin waypoint file