出力ファイルチェックツール:エラー処理を返り値ベースから例外ベースに変更。

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlToolsRED@163 7061adef-622a-194b-ae81-725974e89856
This commit is contained in:
nishikawa_takeshi 2009-02-12 12:03:14 +00:00
parent 284c4ae675
commit b2386ea646
7 changed files with 35 additions and 71 deletions

View File

@ -7,22 +7,21 @@ using namespace System;
int main(array<System::String ^> ^args) int main(array<System::String ^> ^args)
{ {
try
{
FilenameItem ^fItem = gcnew FilenameItem; FilenameItem ^fItem = gcnew FilenameItem;
fItem->parseFilename( args[0] ); fItem->parseFilename( args[0] );
SheetItem ^sItem = gcnew SheetItem; SheetItem ^sItem = gcnew SheetItem;
sItem->readSheet( args[0] ); sItem->readSheet( args[0] );
System::String^ errmsg = checkSheet( fItem, sItem ); checkSheet( fItem, sItem );
if( errmsg != nullptr )
{
Console::WriteLine( "NG " + errmsg );
} }
else catch( System::Exception ^ex )
{ {
Console::WriteLine( "NG - " + ex->Message);
return -1;
}
Console::WriteLine( "OK" ); Console::WriteLine( "OK" );
}
Console::WriteLine(L"Hello World");
return 0; return 0;
} }

View File

@ -7,7 +7,7 @@ using namespace System;
// ファイル名の解析 // ファイル名の解析
// ------------------------------------------------------------------ // ------------------------------------------------------------------
System::Boolean FilenameItem::parseFilename( System::String ^filepath ) System::Void FilenameItem::parseFilename( System::String ^filepath )
{ {
System::String ^filename = System::IO::Path::GetFileNameWithoutExtension(filepath); System::String ^filename = System::IO::Path::GetFileNameWithoutExtension(filepath);
@ -22,6 +22,5 @@ System::Boolean FilenameItem::parseFilename( System::String ^filepath )
Console::WriteLine( "Ogn: " + this->ogn ); Console::WriteLine( "Ogn: " + this->ogn );
Console::WriteLine( "Rating: " + this->rating ); Console::WriteLine( "Rating: " + this->rating );
Console::WriteLine( "Lang: " + this->lang ); Console::WriteLine( "Lang: " + this->lang );
return;
return true;
} }

View File

@ -13,7 +13,7 @@ public:
public: public:
FilenameItem(){} FilenameItem(){}
public: public:
System::Boolean parseFilename( System::String ^filepath ); System::Void parseFilename( System::String ^filepath );
}; };
// //
@ -34,7 +34,8 @@ public:
public: public:
SheetItem(){} SheetItem(){}
public: public:
System::Boolean readSheet( System::String ^sheetfile ); System::Void readSheet( System::String ^sheetfile );
}; };
System::String^ checkSheet( FilenameItem ^fItem, SheetItem ^sItem ); // 提出確認書の文字列と真値を比較
System::Void checkSheet( FilenameItem ^fItem, SheetItem ^sItem );

View File

@ -13,41 +13,24 @@ using namespace System;
// 提出確認書の読み込み // 提出確認書の読み込み
// ------------------------------------------------------------------ // ------------------------------------------------------------------
System::Boolean SheetItem::readSheet( System::String ^sheetfile ) System::Void SheetItem::readSheet( System::String ^sheetfile )
{ {
// XSLによってXML変換 // XSLによってXML変換
System::String ^tmpfile = ".\\temp" + System::DateTime::Now.ToString("yyyyMMddHHmmss") + ".xml"; System::String ^tmpfile = ".\\temp" + System::DateTime::Now.ToString("yyyyMMddHHmmss") + ".xml";
System::Xml::Xsl::XslCompiledTransform ^xslt = gcnew System::Xml::Xsl::XslCompiledTransform; System::Xml::Xsl::XslCompiledTransform ^xslt = gcnew System::Xml::Xsl::XslCompiledTransform;
System::String ^xslpath = System::IO::Path::GetDirectoryName( System::Reflection::Assembly::GetEntryAssembly()->Location ) System::String ^xslpath = System::IO::Path::GetDirectoryName( System::Reflection::Assembly::GetEntryAssembly()->Location )
+ "\\extract_sheet.xsl"; + "\\extract_sheet.xsl";
try
{
//Console::WriteLine( "xslpath: " + xslpath ); //Console::WriteLine( "xslpath: " + xslpath );
xslt->Load( xslpath ); xslt->Load( xslpath );
xslt->Transform( sheetfile, tmpfile ); xslt->Transform( sheetfile, tmpfile );
}
catch( System::Exception ^ex )
{
(void)ex;
//Console::WriteLine( "XSLT Error" );
return false;
}
// 変換したXMLを読み込み // 変換したXMLを読み込み
System::Xml::XmlDocument ^doc = gcnew System::Xml::XmlDocument; System::Xml::XmlDocument ^doc = gcnew System::Xml::XmlDocument;
try
{
doc->Load( tmpfile ); doc->Load( tmpfile );
}
catch( System::Exception ^ex )
{
(void)ex;
//Console::WriteLine( "Load error" );
return false;
}
// XMLからデータを抽出 // XMLからデータを抽出
System::Xml::XmlElement ^root = doc->DocumentElement; System::Xml::XmlElement ^root = doc->DocumentElement;
try
{ {
this->region = MasterEditorTWL::getXPathText( root, "/Sheet/Region" ); this->region = MasterEditorTWL::getXPathText( root, "/Sheet/Region" );
this->CERO = MasterEditorTWL::getXPathText( root, "/Sheet/RatingCERO" ); this->CERO = MasterEditorTWL::getXPathText( root, "/Sheet/RatingCERO" );
@ -79,19 +62,12 @@ System::Boolean SheetItem::readSheet( System::String ^sheetfile )
Console::WriteLine( "OFLC: " + this->OFLC ); Console::WriteLine( "OFLC: " + this->OFLC );
Console::WriteLine( "Unnecessary: " + this->IsUnnecessaryRating.ToString() ); Console::WriteLine( "Unnecessary: " + this->IsUnnecessaryRating.ToString() );
} }
catch( System::Exception ^ex )
{
//(void)ex;
Console::WriteLine( ex->Message );
return false;
}
// 中間ファイルを削除 // 中間ファイルを削除
if( System::IO::File::Exists( tmpfile ) ) if( System::IO::File::Exists( tmpfile ) )
{ {
System::IO::File::Delete( tmpfile ); System::IO::File::Delete( tmpfile );
} }
return true;
} }
@ -101,23 +77,13 @@ System::Boolean SheetItem::readSheet( System::String ^sheetfile )
// @arg [in] ファイル情報 // @arg [in] ファイル情報
// @arg [in] 提出確認書の情報 // @arg [in] 提出確認書の情報
// System::Void checkSheet( FilenameItem ^fItem, SheetItem ^sItem )
// @ret エラーメッセージ (エラーなしのときnullptr)
System::String^ checkSheet( FilenameItem ^fItem, SheetItem ^sItem )
{ {
System::Xml::XmlDocument ^doc = gcnew System::Xml::XmlDocument; System::Xml::XmlDocument ^doc = gcnew System::Xml::XmlDocument;
try
{
System::String ^cfgfile = System::IO::Path::GetDirectoryName( System::Reflection::Assembly::GetEntryAssembly()->Location ) System::String ^cfgfile = System::IO::Path::GetDirectoryName( System::Reflection::Assembly::GetEntryAssembly()->Location )
+ "\\config.xml"; + "\\config.xml";
doc->Load( cfgfile ); doc->Load( cfgfile );
}
catch( System::Exception ^ex )
{
(void)ex;
//Console::WriteLine( "Load error" );
return (gcnew System::String("Failed to load XML"));
}
// XMLからデータを抽出 // XMLからデータを抽出
System::Xml::XmlElement ^root = doc->DocumentElement; System::Xml::XmlElement ^root = doc->DocumentElement;
@ -134,7 +100,7 @@ System::String^ checkSheet( FilenameItem ^fItem, SheetItem ^sItem )
// リージョンの文字列をチェック // リージョンの文字列をチェック
if( sItem->region != region ) if( sItem->region != region )
{ {
return (gcnew System::String("In Sheet, region is illegal string.")); throw (gcnew System::Exception("In Sheet, region is illegal string."));
} }
// レーティングの文字列をチェック // レーティングの文字列をチェック
if( fItem->region == "JP" ) if( fItem->region == "JP" )
@ -240,8 +206,7 @@ System::String^ checkSheet( FilenameItem ^fItem, SheetItem ^sItem )
} }
if( errmsg != nullptr ) if( errmsg != nullptr )
{ {
return errmsg; throw (gcnew System::Exception(errmsg));
} }
return;
return nullptr;
} }