mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
feat: improve error messages when parsing an info string file fails
This commit is contained in:
parent
30394e6a4c
commit
5d913acfef
@ -1,6 +1,7 @@
|
|||||||
#include "InfoString.h"
|
#include "InfoString.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
@ -170,17 +171,26 @@ bool InfoString::FromStream(const std::string& prefix, std::istream& stream)
|
|||||||
|
|
||||||
std::string readPrefix;
|
std::string readPrefix;
|
||||||
if (!infoStream.NextField(readPrefix))
|
if (!infoStream.NextField(readPrefix))
|
||||||
|
{
|
||||||
|
std::cerr << "Invalid info string: Empty\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (prefix != readPrefix)
|
if (prefix != readPrefix)
|
||||||
|
{
|
||||||
|
std::cerr << "Invalid info string: Prefix \"" << readPrefix << "\" did not match expected prefix \"" << prefix << "\"\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::string key;
|
std::string key;
|
||||||
while (infoStream.NextField(key))
|
while (infoStream.NextField(key))
|
||||||
{
|
{
|
||||||
std::string value;
|
std::string value;
|
||||||
if (!infoStream.NextField(value))
|
if (!infoStream.NextField(value))
|
||||||
|
{
|
||||||
|
std::cerr << "Invalid info string: Unexpected eof, no value for key \"" << key << "\"\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const auto existingEntry = m_values.find(key);
|
const auto existingEntry = m_values.find(key);
|
||||||
if (existingEntry == m_values.end())
|
if (existingEntry == m_values.end())
|
||||||
|
@ -126,7 +126,7 @@ bool AssetLoaderPhysPreset::LoadFromRaw(
|
|||||||
InfoString infoString;
|
InfoString infoString;
|
||||||
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream))
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to read phys preset raw file: \"" << fileName << "\"\n";
|
std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +440,7 @@ bool AssetLoaderWeapon::LoadFromRaw(
|
|||||||
InfoString infoString;
|
InfoString infoString;
|
||||||
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON, *file.m_stream))
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON, *file.m_stream))
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to read weapon raw file: \"" << fileName << "\"\n";
|
std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -870,7 +870,7 @@ bool AssetLoaderWeapon::LoadFromRaw(
|
|||||||
InfoString infoString;
|
InfoString infoString;
|
||||||
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON, *file.m_stream))
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON, *file.m_stream))
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to read weapon raw file: \"" << fileName << "\"\n";
|
std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ bool AssetLoaderPhysConstraints::LoadFromRaw(
|
|||||||
InfoString infoString;
|
InfoString infoString;
|
||||||
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, *file.m_stream))
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, *file.m_stream))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to read phys constraints raw file: \"" << fileName << "\"\n";
|
std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ bool AssetLoaderPhysPreset::LoadFromRaw(
|
|||||||
InfoString infoString;
|
InfoString infoString;
|
||||||
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream))
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, *file.m_stream))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to read phys preset raw file: \"" << fileName << "\"\n";
|
std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ bool AssetLoaderTracer::LoadFromRaw(
|
|||||||
InfoString infoString;
|
InfoString infoString;
|
||||||
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_TRACER, *file.m_stream))
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_TRACER, *file.m_stream))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to read tracer raw file: \"" << fileName << "\"\n";
|
std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ bool AssetLoaderVehicle::LoadFromRaw(
|
|||||||
InfoString infoString;
|
InfoString infoString;
|
||||||
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_VEHICLE, *file.m_stream))
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_VEHICLE, *file.m_stream))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to read vehicle raw file: \"" << fileName << "\"\n";
|
std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,7 +621,7 @@ bool AssetLoaderWeapon::LoadFromRaw(
|
|||||||
InfoString infoString;
|
InfoString infoString;
|
||||||
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON, *file.m_stream))
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON, *file.m_stream))
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to read weapon raw file: \"" << fileName << "\"\n";
|
std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ bool AssetLoaderWeaponAttachment::LoadFromRaw(
|
|||||||
InfoString infoString;
|
InfoString infoString;
|
||||||
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT, *file.m_stream))
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT, *file.m_stream))
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to read attachment raw file: \"" << fileName << "\"\n";
|
std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ bool AssetLoaderWeaponAttachmentUnique::LoadFromRaw(
|
|||||||
InfoString infoString;
|
InfoString infoString;
|
||||||
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT_UNIQUE, *file.m_stream))
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT_UNIQUE, *file.m_stream))
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to read attachment unique raw file: \"" << fileName << "\"\n";
|
std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ bool AssetLoaderZBarrier::LoadFromRaw(
|
|||||||
InfoString infoString;
|
InfoString infoString;
|
||||||
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, *file.m_stream))
|
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, *file.m_stream))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to read zbarrier raw file: \"" << fileName << "\"\n";
|
std::cerr << "Could not parse as info string file: \"" << fileName << "\"\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user