diff --git a/xml_converter/integration_tests/test_cases/proto_and_xml_input_no_duplicates/testcase.yaml b/xml_converter/integration_tests/test_cases/proto_and_xml_input_no_duplicates/testcase.yaml index d36081b1..9f5d0f93 100644 --- a/xml_converter/integration_tests/test_cases/proto_and_xml_input_no_duplicates/testcase.yaml +++ b/xml_converter/integration_tests/test_cases/proto_and_xml_input_no_duplicates/testcase.yaml @@ -8,9 +8,9 @@ expected_stdout: | Please remove one of the packs or edit the name of the packs' top level category before running the program again. If you want to bypass this stop, use '--allow-duplicates'. The following top level categories were found in more than one pack: - mycategory in files - pack/xml_file.xml - pack3/xml_file.xml - pack2/markers.bin + "mycategory" in files: + pack/xml_file.xml + pack2/markers.bin + pack3/xml_file.xml expected_stderr: | expected_returncode: 0 \ No newline at end of file diff --git a/xml_converter/src/xml_converter.cpp b/xml_converter/src/xml_converter.cpp index 2392d950..18f88ddd 100644 --- a/xml_converter/src/xml_converter.cpp +++ b/xml_converter/src/xml_converter.cpp @@ -36,6 +36,7 @@ bool filename_comp(string a, string b) { return lowercase(a) < lowercase(b); } +// Searchs for files within a directory with a suffix and returns their relative paths. vector get_files_by_suffix(string directory, string suffix) { vector files; DIR* dir = opendir(directory.c_str()); @@ -49,11 +50,11 @@ vector get_files_by_suffix(string directory, string suffix) { // Default: markerpacks have all xml files in the first directory for (string subfile : subfiles) { cout << subfile << " found in subfolder" << endl; - files.push_back(subfile); + files.push_back(join_file_paths(filename, subfile)); } } else if (has_suffix(filename, suffix)) { - files.push_back(path); + files.push_back(filename); } } } @@ -66,7 +67,7 @@ map> read_taco_directory( string input_path, map* marker_categories, vector* parsed_pois) { - map> category_to_filepath; + map> top_level_category_file_locations; if (!filesystem::exists(input_path)) { cout << "Error: " << input_path << " is not an existing directory or file" << endl; } @@ -74,28 +75,28 @@ map> read_taco_directory( string directory_name = filesystem::path(input_path).filename(); vector xml_files = get_files_by_suffix(input_path, ".xml"); for (const string& path : xml_files) { - set category_names = (parse_xml_file(path, input_path, marker_categories, parsed_pois)); - string relative_path = directory_name + path.substr(input_path.size()); - for (set::iterator it = category_names.begin(); it != category_names.end(); it++) { - category_to_filepath[*it].push_back(relative_path); + set top_level_category_names = parse_xml_file(join_file_paths(input_path, path), input_path, marker_categories, parsed_pois); + string relative_path = join_file_paths(directory_name, path); + for (set::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) { + top_level_category_file_locations[*it].push_back(relative_path); } } } else if (filesystem::is_regular_file(input_path)) { - set category_names = parse_xml_file(input_path, get_base_dir(input_path), marker_categories, parsed_pois); + set top_level_category_names = parse_xml_file(input_path, get_base_dir(input_path), marker_categories, parsed_pois); string filename = filesystem::path(input_path).filename(); - for (set::iterator it = category_names.begin(); it != category_names.end(); it++) { - category_to_filepath[*it].push_back(filename); + for (set::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) { + top_level_category_file_locations[*it].push_back(filename); } } - return category_to_filepath; + return top_level_category_file_locations; } map> read_burrito_directory( string input_path, map* marker_categories, vector* parsed_pois) { - map> category_to_filepath; + map> top_level_category_file_locations; if (!filesystem::exists(input_path)) { cout << "Error: " << input_path << " is not an existing directory or file" << endl; } @@ -103,21 +104,21 @@ map> read_burrito_directory( string directory_name = filesystem::path(input_path).filename(); vector burrito_files = get_files_by_suffix(input_path, ".bin"); for (const string& path : burrito_files) { - set category_names = read_protobuf_file(path, input_path, marker_categories, parsed_pois); - string relative_path = directory_name + path.substr(input_path.size()); - for (set::iterator it = category_names.begin(); it != category_names.end(); it++) { - category_to_filepath[*it].push_back(relative_path); + set top_level_category_names = read_protobuf_file(join_file_paths(input_path, path), input_path, marker_categories, parsed_pois); + string relative_path = join_file_paths(directory_name, path); + for (set::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) { + top_level_category_file_locations[*it].push_back(relative_path); } } } else if (filesystem::is_regular_file(input_path)) { - set category_names = read_protobuf_file(input_path, get_base_dir(input_path), marker_categories, parsed_pois); + set top_level_category_names = read_protobuf_file(input_path, get_base_dir(input_path), marker_categories, parsed_pois); string filename = filesystem::path(input_path).filename(); - for (set::iterator it = category_names.begin(); it != category_names.end(); it++) { - category_to_filepath[*it].push_back(filename); + for (set::iterator it = top_level_category_names.begin(); it != top_level_category_names.end(); it++) { + top_level_category_file_locations[*it].push_back(filename); } } - return category_to_filepath; + return top_level_category_file_locations; } void write_taco_directory( @@ -172,21 +173,20 @@ void process_data( // All of the loaded pois and categories vector parsed_pois; map marker_categories; - map>> category_to_marker_pack_names; - map> duplicate_categories; + map>> top_level_category_file_locations_by_pack; + map> duplicate_categories; // Read in all the xml taco markerpacks 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; - // swap this to map >) - map> category_names = read_taco_directory( + map> top_level_category_file_locations = read_taco_directory( input_taco_paths[i], &marker_categories, &parsed_pois); - for (map>::iterator it = category_names.begin(); it != category_names.end(); it++) { - category_to_marker_pack_names[it->first].push_back(it->second); + for (map>::iterator it = top_level_category_file_locations.begin(); it != top_level_category_file_locations.end(); it++) { + top_level_category_file_locations_by_pack[it->first].push_back(it->second); } } auto end = chrono::high_resolution_clock::now(); @@ -198,20 +198,20 @@ void process_data( for (size_t i = 0; i < input_guildpoint_paths.size(); i++) { cout << "Loading guildpoint pack " << input_guildpoint_paths[i] << endl; - map> category_names = read_burrito_directory( + map> top_level_category_file_locations = read_burrito_directory( input_guildpoint_paths[i], &marker_categories, &parsed_pois); - for (map>::iterator it = category_names.begin(); it != category_names.end(); it++) { - category_to_marker_pack_names[it->first].push_back(it->second); + for (map>::iterator it = top_level_category_file_locations.begin(); it != top_level_category_file_locations.end(); it++) { + top_level_category_file_locations_by_pack[it->first].push_back(it->second); } } - for (map>>::iterator it = category_to_marker_pack_names.begin(); it != category_to_marker_pack_names.end(); it++) { + for (map>>::iterator it = top_level_category_file_locations_by_pack.begin(); it != top_level_category_file_locations_by_pack.end(); it++) { if (it->second.size() != 1) { for (size_t i = 0; i < it->second.size(); i++) { for (size_t j = 0; j < it->second[i].size(); j++) { - duplicate_categories[it->first].push_back(it->second[i][j]); + duplicate_categories[it->first].insert(it->second[i][j]); } } } @@ -224,10 +224,10 @@ void process_data( cout << "Please remove one of the packs or edit the name of the packs' top level category before running the program again." << endl; cout << "If you want to bypass this stop, use '--allow-duplicates'." << endl; cout << "The following top level categories were found in more than one pack:" << endl; - for (map>::iterator it = duplicate_categories.begin(); it != duplicate_categories.end(); it++) { - cout << it->first << " in files:" << endl; + for (map>::iterator it = duplicate_categories.begin(); it != duplicate_categories.end(); it++) { + cout << " \"" << it->first << "\" in files:" << endl; for (string str : it->second) { - cout << str << endl; + cout << " " << str << endl; } } return;