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

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)
{
FilenameItem ^fItem = gcnew FilenameItem;
fItem->parseFilename( args[0] );
SheetItem ^sItem = gcnew SheetItem;
sItem->readSheet( args[0] );
System::String^ errmsg = checkSheet( fItem, sItem );
if( errmsg != nullptr )
try
{
Console::WriteLine( "NG " + errmsg );
}
else
{
Console::WriteLine( "OK" );
}
FilenameItem ^fItem = gcnew FilenameItem;
fItem->parseFilename( args[0] );
Console::WriteLine(L"Hello World");
SheetItem ^sItem = gcnew SheetItem;
sItem->readSheet( args[0] );
checkSheet( fItem, sItem );
}
catch( System::Exception ^ex )
{
Console::WriteLine( "NG - " + ex->Message);
return -1;
}
Console::WriteLine( "OK" );
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);
@ -22,6 +22,5 @@ System::Boolean FilenameItem::parseFilename( System::String ^filepath )
Console::WriteLine( "Ogn: " + this->ogn );
Console::WriteLine( "Rating: " + this->rating );
Console::WriteLine( "Lang: " + this->lang );
return true;
return;
}

View File

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