mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
NinjaXmlReader.GetNsUidの出力引数をstringに変更
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@839 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
f52c9aa892
commit
ec2707e62b
@ -33,7 +33,7 @@ NinjaXmlReader::~NinjaXmlReader()
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
void NinjaXmlReader::GetNsUid(char* pNsUid, size_t size, std::string xml)
|
||||
void NinjaXmlReader::GetNsUid(std::string& nsUid, std::string xml)
|
||||
{
|
||||
if(!SimpleXmlPreprocessor::Canonicalize(xml))
|
||||
{
|
||||
@ -42,7 +42,7 @@ void NinjaXmlReader::GetNsUid(char* pNsUid, size_t size, std::string xml)
|
||||
nn::xml::simple::SimpleXmlParser parser(common::GetAllocator());
|
||||
parser.parse(reinterpret_cast<u8*>(const_cast<char*>(xml.c_str())), xml.size());
|
||||
|
||||
GetContentOfElement(parser, "ns_uid", pNsUid, size);
|
||||
GetContentOfElement(parser, "ns_uid", nsUid);
|
||||
}
|
||||
|
||||
bool NinjaXmlReader::HasContentLock(std::string xml)
|
||||
@ -62,29 +62,20 @@ nn::fnd::DateTime NinjaXmlReader::GetPlayableDate(std::string xml)
|
||||
return nn::fnd::DateTime::MIN_DATETIME;
|
||||
}
|
||||
|
||||
const size_t BUF_SIZE = 1024 * 1024;
|
||||
common::HeapManager manager(BUF_SIZE);
|
||||
void* buf = manager.GetAddr();
|
||||
char* playableDateStr = reinterpret_cast<char*>(buf);
|
||||
if(playableDateStr)
|
||||
{
|
||||
nn::xml::simple::SimpleXmlParser parser(common::GetAllocator());
|
||||
parser.parse(reinterpret_cast<u8*>(const_cast<char*>(xml.c_str())), xml.size());
|
||||
GetContentOfElement(parser, "playable_date", playableDateStr, BUF_SIZE);
|
||||
std::string playableDate;
|
||||
nn::xml::simple::SimpleXmlParser parser(common::GetAllocator());
|
||||
parser.parse(reinterpret_cast<u8*>(const_cast<char*>(xml.c_str())), xml.size());
|
||||
GetContentOfElement(parser, "playable_date", playableDate);
|
||||
|
||||
// playable_date は YYYY-MM-DD 形式
|
||||
std::string yearStr(std::string(playableDateStr).substr(0, 4));
|
||||
std::string monthStr(std::string(playableDateStr).substr(5, 2));
|
||||
std::string dayStr(std::string(playableDateStr).substr(8, 2));
|
||||
char* end = '\0';
|
||||
s32 year = std::strtol(yearStr.c_str(),&end, 10);
|
||||
s32 month = std::strtol(monthStr.c_str(),&end, 10);
|
||||
s32 day = std::strtol(dayStr.c_str(),&end, 10);
|
||||
nn::fnd::DateTime playableDate = nn::fnd::DateTime::FromParameters(year, month, day);
|
||||
return playableDate;
|
||||
}
|
||||
|
||||
return nn::fnd::DateTime::MIN_DATETIME;
|
||||
// playable_date は YYYY-MM-DD 形式
|
||||
std::string yearStr(playableDate.substr(0, 4));
|
||||
std::string monthStr(playableDate.substr(5, 2));
|
||||
std::string dayStr(playableDate.substr(8, 2));
|
||||
char* end = '\0';
|
||||
s32 year = std::strtol(yearStr.c_str(),&end, 10);
|
||||
s32 month = std::strtol(monthStr.c_str(),&end, 10);
|
||||
s32 day = std::strtol(dayStr.c_str(),&end, 10);
|
||||
return nn::fnd::DateTime::FromParameters(year, month, day);
|
||||
}
|
||||
|
||||
bool NinjaXmlReader::HasElement(std::string xml, const char* element)
|
||||
@ -99,7 +90,7 @@ bool NinjaXmlReader::HasElement(std::string xml, const char* element)
|
||||
return GetElement(parser, element);
|
||||
}
|
||||
|
||||
bool NinjaXmlReader::GetContentOfElement(nn::xml::simple::SimpleXmlParser& parser, const char* target, char* content, size_t bufSize)
|
||||
bool NinjaXmlReader::GetContentOfElement(nn::xml::simple::SimpleXmlParser& parser, const char* target, std::string& content)
|
||||
{
|
||||
if ( !parser.isError() )
|
||||
{
|
||||
@ -112,7 +103,7 @@ bool NinjaXmlReader::GetContentOfElement(nn::xml::simple::SimpleXmlParser& parse
|
||||
delete pRootName;
|
||||
|
||||
bool found = false;
|
||||
GetNodes(pRootNode, target, content, bufSize, found);
|
||||
GetNodes(pRootNode, target, content, found);
|
||||
return found;
|
||||
}
|
||||
|
||||
@ -121,18 +112,12 @@ bool NinjaXmlReader::GetContentOfElement(nn::xml::simple::SimpleXmlParser& parse
|
||||
|
||||
bool NinjaXmlReader::GetElement(nn::xml::simple::SimpleXmlParser& parser, const char* element)
|
||||
{
|
||||
const size_t BUF_SIZE = 1024 * 1024;
|
||||
common::HeapManager manager(BUF_SIZE);
|
||||
void* addr = manager.GetAddr();
|
||||
if(addr)
|
||||
{
|
||||
return GetContentOfElement(parser, element, reinterpret_cast<char*>(addr), BUF_SIZE);
|
||||
}
|
||||
return false;
|
||||
std::string content;
|
||||
return GetContentOfElement(parser, element, content);
|
||||
}
|
||||
|
||||
|
||||
void NinjaXmlReader::GetNodes( const nn::xml::simple::SimpleXmlParser::Node* topNodes, const char* target, char* content, size_t bufSize, bool& found)
|
||||
void NinjaXmlReader::GetNodes( const nn::xml::simple::SimpleXmlParser::Node* topNodes, const char* target, std::string& content, bool& found)
|
||||
{
|
||||
const nn::xml::simple::SimpleXmlParser::Node* pTargetNode = topNodes->firstChild;
|
||||
|
||||
@ -151,11 +136,11 @@ void NinjaXmlReader::GetNodes( const nn::xml::simple::SimpleXmlParser::Node* top
|
||||
*/
|
||||
if(pTargetNode->contentSize > 0)
|
||||
{
|
||||
GetNodeContent(pTargetNode, targetIsCurrentNode, content, bufSize);
|
||||
GetNodeContent(pTargetNode, targetIsCurrentNode, content);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetNodes(pTargetNode, target, content, bufSize, found);
|
||||
GetNodes(pTargetNode, target, content, found);
|
||||
}
|
||||
|
||||
pTargetNode = pTargetNode->next;
|
||||
@ -183,7 +168,7 @@ bool NinjaXmlReader::GetNodeName( const nn::xml::simple::SimpleXmlParser::Node*
|
||||
}
|
||||
}
|
||||
|
||||
void NinjaXmlReader::GetNodeContent( const nn::xml::simple::SimpleXmlParser::Node* pNode, bool found, char* content, size_t bufSize )
|
||||
void NinjaXmlReader::GetNodeContent( const nn::xml::simple::SimpleXmlParser::Node* pNode, bool found, std::string& content)
|
||||
{
|
||||
if(pNode->contentSize > 0)
|
||||
{
|
||||
@ -193,18 +178,11 @@ void NinjaXmlReader::GetNodeContent( const nn::xml::simple::SimpleXmlParser::Nod
|
||||
*/
|
||||
char* pNodeContent = new char[ pNode->contentSize+1 ];
|
||||
std::strlcpy( pNodeContent, (char*)pNode->content, pNode->contentSize+1);
|
||||
//行頭タブ挿し入れ
|
||||
NN_LOG( "Node content: %s\n", pNodeContent );
|
||||
if(found)
|
||||
{
|
||||
if(pNode->contentSize+1 < bufSize)
|
||||
{
|
||||
std::strlcpy(content, (char*)pNode->content, pNode->contentSize+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::strlcpy(content, (char*)pNode->content, bufSize);
|
||||
}
|
||||
std::string targetContent(reinterpret_cast<char*>(const_cast<u8*>(pNode->content)));
|
||||
content = targetContent.substr(0, pNode->contentSize);
|
||||
}
|
||||
delete pNodeContent;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ public:
|
||||
//!@param[out] pNsUid ns_uidを格納するためのバッファ
|
||||
//!@param[in] size pNsUidのバッファサイズ
|
||||
//!@param[in] xml Ninjaから取得したXMLデータ
|
||||
void GetNsUid(char* pNsUid, size_t size, std::string xml);
|
||||
void GetNsUid(std::string& nsUid, std::string xml);
|
||||
|
||||
//!@brief XMLをパースしてcontent_lock要素があるかどうかを返します
|
||||
//!@param[in] xml Ninjaから取得したXMLデータ
|
||||
@ -53,11 +53,11 @@ public:
|
||||
|
||||
private:
|
||||
bool HasElement(std::string xml, const char* element);
|
||||
bool GetContentOfElement(nn::xml::simple::SimpleXmlParser& parser, const char* element, char* content, size_t bufSize);
|
||||
bool GetContentOfElement(nn::xml::simple::SimpleXmlParser& parser, const char* element, std::string& content);
|
||||
bool GetElement(nn::xml::simple::SimpleXmlParser& parser, const char* element);
|
||||
void GetNodes( const nn::xml::simple::SimpleXmlParser::Node* topNodes, const char* target, char* content, size_t bufSize, bool& found);
|
||||
void GetNodes( const nn::xml::simple::SimpleXmlParser::Node* topNodes, const char* target, std::string& content, bool& found);
|
||||
bool GetNodeName( const nn::xml::simple::SimpleXmlParser::Node* pNode, const char* target);
|
||||
void GetNodeContent( const nn::xml::simple::SimpleXmlParser::Node* pNode, bool found, char* content, size_t bufSize );
|
||||
void GetNodeContent( const nn::xml::simple::SimpleXmlParser::Node* pNode, bool found, std::string& content);
|
||||
};
|
||||
|
||||
} /* namespace ConsoleRestore */
|
||||
|
||||
@ -90,13 +90,13 @@ void TestNinjaXmlReader::FinalizeSuite()
|
||||
|
||||
void TestNinjaXmlReader::GetNsUid()
|
||||
{
|
||||
char nsUid[32];
|
||||
std::string nsUid;
|
||||
ConsoleRestore::NinjaXmlReader reader;
|
||||
std::string xml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><eshop><title_id_pairs><title_id_pair><ns_uid>50010000041101</ns_uid><title_id>000400000FECD000</title_id><type>T</type></title_id_pair></title_id_pairs></eshop>");
|
||||
reader.GetNsUid(nsUid, sizeof(nsUid) / sizeof(nsUid[0]), xml);
|
||||
reader.GetNsUid(nsUid, xml);
|
||||
NN_TEST_ASSERT(
|
||||
!std::strcmp(nsUid, "50010000041101"));
|
||||
NN_LOG("ns_uid = %s\n", nsUid);
|
||||
!std::strcmp(nsUid.c_str(), "50010000041101"));
|
||||
NN_LOG("ns_uid = %s\n", nsUid.c_str());
|
||||
}
|
||||
|
||||
void TestNinjaXmlReader::HasContentLock()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user