diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2021-04-22 14:54:23 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-22 14:54:23 -0400 |
| commit | b0d98ff1bbda9fa25515a28bcf0c36314156c66c (patch) | |
| tree | fb72d1baab60c2e16dae5399be023debeba4a3a4 /ZAPD/ZResource.cpp | |
| parent | e06757c87e317e6bb102bd39fbe4cdcfed277fa9 (diff) | |
Add a few errors checks (#119)
* Check for repeated names, outnames and offsets
Signed-off-by: angie <angheloalf95@gmail.com>
* Check for File inside File
Signed-off-by: angie <angheloalf95@gmail.com>
* Error if a ZResource node has a child
Signed-off-by: angie <angheloalf95@gmail.com>
* Error if an invalid ZResource name is included in the XML
Signed-off-by: angie <angheloalf95@gmail.com>
* error when a ZResource is not in a ZFile
Signed-off-by: angie <angheloalf95@gmail.com>
* ups
Signed-off-by: angie <angheloalf95@gmail.com>
* Add error if unknown element is found and other fixes
* Run format
Diffstat (limited to 'ZAPD/ZResource.cpp')
| -rw-r--r-- | ZAPD/ZResource.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/ZAPD/ZResource.cpp b/ZAPD/ZResource.cpp index 9ffcc74..767fc0f 100644 --- a/ZAPD/ZResource.cpp +++ b/ZAPD/ZResource.cpp @@ -1,5 +1,8 @@ #include "ZResource.h" +#include <regex> +#include "StringHelper.h" + using namespace std; ZResource::ZResource(ZFile* nParent) @@ -42,7 +45,19 @@ void ZResource::ParseXML(tinyxml2::XMLElement* reader) if (reader != nullptr) { if (reader->Attribute("Name") != nullptr) + { name = reader->Attribute("Name"); + static std::regex r("[a-zA-Z_]+[a-zA-Z0-9_]*", + std::regex::icase | std::regex::optimize); + + if (!std::regex_match(name, r)) + { + throw std::domain_error( + StringHelper::Sprintf("ZResource::ParseXML: Fatal error in '%s'.\n\t Resource " + "with invalid 'Name' attribute.\n", + name.c_str())); + } + } else name = ""; @@ -55,6 +70,14 @@ void ZResource::ParseXML(tinyxml2::XMLElement* reader) isCustomAsset = true; else isCustomAsset = false; + + if (!canHaveInner && !reader->NoChildren()) + { + throw std::runtime_error( + StringHelper::Sprintf("ZResource::ParseXML: Fatal error in '%s'.\n\t Resource '%s' " + "with inner element/child detected.\n", + name.c_str(), reader->Name())); + } } } |
