Skip to content

Commit

Permalink
Added further error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaszanas committed May 23, 2021
1 parent 36b2467 commit bfa404e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/SC2MapLocaleExtractor/SC2MapLocaleExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdio>
#include <Windows.h>

// Third party:
Expand All @@ -12,7 +13,6 @@
#include "helpers.h"
#include "extractors.h"


int main(int argc, char** argv)
{
if(argc < 3) {
Expand Down Expand Up @@ -40,5 +40,8 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}

std::cout << "Press ENTER to continue...";
std::getchar();

return EXIT_SUCCESS;
}
22 changes: 20 additions & 2 deletions src/SC2MapLocaleExtractor/extractors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ std::optional<std::string> extract_map_name_string(std::string game_description)
std::vector<std::string> map_name_split_comment = split_string(map_name, " /// ");
map_name = map_name_split_comment[0];
}

if (map_name.empty())
{
std::cout << "Detected empty map name returning \n";
return std::nullopt;
}

return std::make_optional(map_name);
}
std::cout << "Error! Detected empty map name returning \n";
Expand Down Expand Up @@ -105,17 +112,28 @@ std::optional<nlohmann::json> locale_extractor(const std::filesystem::path& file
auto maybe_locale = extract_locale_from_mpq(MPQArchive, foundLocaleFileData);
// Checking if data was extracted:
if (!maybe_locale.has_value()) {
// TODO: log
std::cout << "Couldn't extract locale from MPQ, error: " << "\n";
continue;
}

// Extracting map name:
std::string map_name_string = *extract_map_name_string(*maybe_locale);
std::optional<std::string> maybe_map_name_string = extract_map_name_string(*maybe_locale);
if (!maybe_map_name_string.has_value())
{
std::cout << "Detected empty map_name_string, skipping." << "\n";
continue;
}
std::string map_name_string = *maybe_map_name_string;

// Obtaining region code:
std::string region_name = foundLocaleFileData.cFileName;
std::string locale_region = locale_region_extractor(region_name);

if (map_name_string == "")
{
std::cout << "Detected empty string as a foreign_map_name, skipping. This happened when reading: " << locale_region << "\n";
}

myMapping[locale_region] = map_name_string;

} while (SFileFindNextFile(searchHandle, &foundLocaleFileData));
Expand Down
7 changes: 6 additions & 1 deletion src/SC2MapLocaleExtractor/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ std::optional<nlohmann::json> generate_final_locale_mapping(const std::vector<nl
{
// Mapping foreign name to english name:
std::string foreign_map_name = foreign_map_mapping.value();

if (foreign_map_name != en_map_name)
{

if (foreign_map_name == "")
{
std::cout << "Detected empty string as a foreign_map_name, skipping. This happened when reading: " << en_map_name << "\n";
continue;
}
final_mapping.emplace(foreign_map_name, en_map_name);
}
}
Expand Down

0 comments on commit bfa404e

Please sign in to comment.