マスタエディタ:tad読み込み機能を追加。

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlToolsRED@62 7061adef-622a-194b-ae81-725974e89856
This commit is contained in:
nishikawa_takeshi 2008-12-08 07:30:42 +00:00
parent a147d8503b
commit d98efd5cde
9 changed files with 248 additions and 161 deletions

View File

@ -37,6 +37,9 @@ namespace MasterEditorTWL {
// マスタ書類
RCDeliverable ^hDeliv;
// TADを読み込んだかどうか(SRLを読み込んだ場合はfalse)
System::Boolean ^hIsLoadTad;
// 書類出力モード(ーマルXML or XML Spread Sheet)
System::Boolean ^hIsSpreadSheet;
@ -693,6 +696,7 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ colWarnCause;
//
this->hSrl = gcnew (RCSrl);
this->hDeliv = gcnew (RCDeliverable);
this->hIsLoadTad = gcnew System::Boolean(false);
this->hErrorList = gcnew System::Collections::Generic::List<RCMrcError^>();
this->hErrorList->Clear();
this->hWarnList = gcnew System::Collections::Generic::List<RCMrcError^>();
@ -705,6 +709,16 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ colWarnCause;
System::Reflection::Assembly ^ass = System::Reflection::Assembly::GetEntryAssembly();
this->labAssemblyVersion->Text = "ver." + this->getVersion();
// TAD読み込みの際に作成される一時ファイルと同名ファイルがあった場合には削除してよいか確認
System::Diagnostics::Debug::WriteLine( this->getSplitTadTmpFilename() );
if( System::IO::File::Exists( this->getSplitTadTmpFilename() ) )
{
this->sucMsg( "本プログラムで作成する一時ファイルと同名のファイルが存在します。このファイルを削除します。",
"There is the file which has same name as temporary file made by this program. That file is deleted." );
System::IO::File::Delete( this->getSplitTadTmpFilename() );
}
// デフォルト値
this->hIsSpreadSheet = gcnew System::Boolean( true );
this->hIsReadOnly = gcnew System::Boolean( false );
@ -755,6 +769,13 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ colWarnCause;
/// </summary>
~Form1()
{
// TAD読み出しの際に作成される一時SRLファイルを削除(書き出しをせずに終了したときに起こりうる)
System::String ^srlfile = this->getSplitTadTmpFilename();
if( System::IO::File::Exists( srlfile ) )
{
System::IO::File::Delete( srlfile ); // すでに存在する場合は削除
}
if (components)
{
delete components;
@ -2810,14 +2831,35 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ colWarnCause;
// 設定ファイルの読み込み
void loadInit(void);
// SRLのオープン
System::Void loadSrl( System::String ^filename );
// ファイルの読み込み (TAD/SRL読み込みをラップ)
void loadRom( System::String ^infile );
// SRLの保存と再読み出し
System::Boolean saveSrl( System::String ^filename );
// ファイルの書き出し (SRL書き出しをラップ)
System::Boolean saveRom( System::String ^outname );
// SRLの読み込み
System::Void loadSrl( System::String ^srlfile );
// SRLの保存と再読み込み
System::Boolean saveSrl( System::String ^infile, System::String ^outfile );
// SRLの保存のみ @ret 成否
System::Boolean saveSrlCore( System::String ^filename );
System::Boolean saveSrlCore( System::String ^infile, System::String ^outfile );
// tadの読み込み
System::Void loadTad( System::String ^tadfile );
// tadの読み込みで生成する一時SRLファイル名を返す
System::String ^getSplitTadTmpFilename(void)
{
System::String ^dir = System::IO::Path::GetDirectoryName( System::Reflection::Assembly::GetEntryAssembly()->Location );
if( !dir->EndsWith("\\") )
{
dir = dir + "\\";
}
System::String ^tmpfile = dir + METWL_TAD_TMP_FILENAME;
return tmpfile;
}
// ミドルウェアリストの作成(XML形式)
System::Void makeMiddlewareListXml(System::Xml::XmlDocument^ doc);
@ -2831,9 +2873,6 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ colWarnCause;
// ミドルウェアリストの保存(XSL埋め込み)
System::Boolean saveMiddlewareListXmlEmbeddedXsl( System::String ^filename );
// tadの読み出し
System::Void loadTad( System::String ^tadfile );
// 提出ファイル名をゲームコードなどから決定
System::String^ getSubmitFilePrefix(void)
{
@ -3156,14 +3195,7 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ colWarnCause;
}
// 拡張子で tad 読み込みにするかを判定
if( System::IO::Path::GetExtension( filename )->ToLower()->Equals( ".tad" ) )
{
this->loadTad( filename );
}
else
{
this->loadSrl( filename );
}
this->loadRom( filename );
this->tboxFile->Text = filename;
this->clearOtherForms();
@ -3224,7 +3256,7 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ colWarnCause;
try
{
if( !this->saveSrl( srlfile ) )
if( !this->saveRom( srlfile ) )
{
this->errMsg( "マスターROMの作成に失敗しました。",
"Making a master ROM failed." );
@ -3323,7 +3355,7 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ colWarnCause;
// 更新後のSRLを別ファイルに作成
try
{
if( !this->saveSrl( srlfile ) )
if( !this->saveRom( srlfile ) )
{
this->errMsg( "マスターROMの作成に失敗しました。作成を中止するため一部のファイルは作成されません。",
"Making a master ROM failed. Therefore, a part of files can't be made." );
@ -3471,7 +3503,7 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ colWarnCause;
"The ROM data file is not found. Therefore the file can not be opened." );
return;
}
this->loadSrl( filename ); // ドラッグアンドドロップの時点でボタンを押さなくてもファイルを開く
this->loadRom( filename );
this->tboxFile->Text = filename;
this->clearOtherForms();
//this->sucMsg( "ROMデータファイルのオープンに成功しました。", "The ROM data file is opened successfully." );

View File

@ -23,131 +23,72 @@ using namespace System::Drawing;
using namespace MasterEditorTWL;
// ----------------------------------------------
// 設定ファイルの読み込み
// ファイルの読み込み (TAD/SRL読み込みをラップ)
// ----------------------------------------------
void Form1::loadInit(void)
void Form1::loadRom( System::String ^infile )
{
System::Xml::XmlDocument ^doc = gcnew System::Xml::XmlDocument();
// xmlファイルの読み込み
try
this->hIsLoadTad = gcnew System::Boolean(false);
if( System::IO::Path::GetExtension( infile )->ToUpper()->Equals( ".TAD" ) ) // 拡張子で判別
{
doc->Load( "../resource/ini.xml" );
*this->hIsLoadTad = true;
this->loadTad( infile );
}
catch( System::IO::FileNotFoundException ^s )
else
{
(void)s;
this->errMsg( "設定ファイルが見つかりません。", "Setting file is not found." );
this->loadSrl( infile );
}
}
// ----------------------------------------------
// ファイルの書き出し (TAD/SRL書き出しをラップ)
// ----------------------------------------------
System::Boolean Form1::saveRom( System::String ^outfile )
{
System::Boolean result = false;
if( *this->hIsLoadTad )
{
// 一時ファイルにSRLを書き出しているのでその一時ファイルから出力ファイルを作成
System::String ^tmpsrl = this->getSplitTadTmpFilename();
result = this->saveSrl( tmpsrl, outfile );
System::IO::File::Delete( tmpsrl );
}
else
{
result = this->saveSrl( this->tboxFile->Text, outfile );
}
return result;
}
// ----------------------------------------------
// tadの読み込み
// ----------------------------------------------
System::Void Form1::loadTad( System::String ^tadfile )
{
// tadファイルを変換したSRLを一時ファイルに保存
System::String ^srlfile = this->getSplitTadTmpFilename();
if( System::IO::File::Exists( srlfile ) )
{
System::IO::File::Delete( srlfile ); // すでに存在する場合は削除(連続に読み込んだ場合に起こりうる)
}
if( splitTad( tadfile, srlfile ) != 0 )
{
this->errMsg( "TADファイルの読み出しに失敗しました。", "Reading TAD file failed." );
System::IO::File::Delete( srlfile );
return;
}
catch( System::Exception ^s )
{
(void)s;
this->errMsg( "設定ファイルを開くことができませんでした。", "Setting file can't be opened." );
return;
}
// <init>タグ : ルート
System::Xml::XmlElement ^root = doc->DocumentElement;
// <rw>タグ
System::Boolean bReadOnly = MasterEditorTWL::isXmlEqual( root, "rw", "r" );
this->hIsReadOnly = System::Boolean( bReadOnly );
if( bReadOnly )
{
this->readOnly();
}
// <lang>タグ
if( MasterEditorTWL::isXmlEqual( root, "lang", "E" ) )
{
this->stripItemEnglish->Checked = true;
this->stripItemJapanese->Checked = false;
this->changeEnglish();
}
// <output>タグ
System::Boolean bXML = MasterEditorTWL::isXmlEqual( root, "output", "XML" );
// <spcheck>タグ
System::Boolean bCheck = MasterEditorTWL::isXmlEqual( root, "spcheck", "ON" );
if( bCheck ) // チェックするときのみ追加チェック項目を設定
{
// チェックするかどうか
this->hSrl->hMrcSpecialList->hIsCheck = gcnew System::Boolean( true );
// SDK
try
{
u32 major = System::UInt32::Parse( MasterEditorTWL::getXPathText( root, "/init/sdk/major" ) );
u32 minor = System::UInt32::Parse( MasterEditorTWL::getXPathText( root, "/init/sdk/minor" ) );
u32 relstep = System::UInt32::Parse( MasterEditorTWL::getXPathText( root, "/init/sdk/relstep" ) );
u32 sdkver = (major << 24) | (minor << 16) | (relstep & 0xFFFF);
this->hSrl->hMrcSpecialList->hSDKVer = gcnew System::UInt32( sdkver );
}
catch ( System::Exception ^ex )
{
(void)ex;
this->errMsg( "設定ファイル中のSDKバージョンが読み込めませんでした。バージョンは0とみなされます。",
"SDK ver. can't be read from setting file. Therefore it is set by 0." );
this->hSrl->hMrcSpecialList->hSDKVer = gcnew System::UInt32( 0 );
}
// Shared2File
try
{
System::Int32 i;
for( i=0; i < METWL_NUMOF_SHARED2FILES; i++ )
{
u32 size = System::UInt32::Parse( MasterEditorTWL::getXPathText( root, "/init/shared2/size" + i.ToString() ) );
this->hSrl->hMrcSpecialList->hShared2SizeArray[i] = gcnew System::UInt32( size );
}
}
catch ( System::Exception ^ex )
{
(void)ex;
this->errMsg( "設定ファイル中のShared2ファイルサイズが読み込めませんでした。サイズはすべて0とみなされます。",
"One of shared2 file sizes can't be read from setting file. Therefore they are set by 0." );
System::Int32 i;
for( i=0; i < METWL_NUMOF_SHARED2FILES; i++ )
{
this->hSrl->hMrcSpecialList->hShared2SizeArray[i] = gcnew System::UInt32( 0 );
}
}
} //if( bCheck )
if( bReadOnly || bXML | bCheck )
{
System::String ^msgJ = gcnew System::String("[動作モード]");
System::String ^msgE = gcnew System::String("[Processing Mode]");
if( bReadOnly )
{
msgJ += "\nリードオンリーモード";
msgE += "\nRead Only Mode";
}
if( bXML )
{
msgJ += "\nXML出力モード";
msgE += "\nXML Output Mode";
}
if( bCheck )
{
msgJ += "\n追加チェックモード";
msgE += "\nExtra Check Mode";
}
this->sucMsg( msgJ, msgE );
}
} // loadInit()
this->loadSrl( srlfile ); // 一時保存したSRLを読み込み
}
// ----------------------------------------------
// SRLのオープン
// SRLの読み込み
// ----------------------------------------------
System::Void Form1::loadSrl( System::String ^filename )
System::Void Form1::loadSrl( System::String ^srlfile )
{
ECSrlResult result = this->hSrl->readFromFile( filename );
ECSrlResult result = this->hSrl->readFromFile( srlfile );
if( result != ECSrlResult::NOERROR )
{
switch( result )
@ -184,7 +125,7 @@ System::Void Form1::loadSrl( System::String ^filename )
// 全体のCRCを算出
u16 crc;
if( !getWholeCRCInFile( filename, &crc ) )
if( !getWholeCRCInFile( srlfile, &crc ) )
{
this->errMsg( "ROMデータのCRC計算に失敗しました。ROMデータの読み込みはキャンセルされました。",
"Calculating CRC of the ROM data failed. Therefore reading ROM data is canceled." );
@ -213,49 +154,43 @@ System::Void Form1::loadSrl( System::String ^filename )
// SRLの保存
// ----------------------------------------------
System::Boolean Form1::saveSrl( System::String ^filename )
System::Boolean Form1::saveSrl( System::String ^infile, System::String ^outfile )
{
if( !System::IO::File::Exists( infile ) )
{
return false;
}
// コピーしたファイルにROMヘッダを上書き
if( !this->saveSrlCore( filename ) )
if( !this->saveSrlCore( infile, outfile ) )
{
return false;
}
// 再リード
this->loadSrl( filename );
this->loadSrl( outfile );
return true;
} // saveSrl()
System::Boolean Form1::saveSrlCore( System::String ^filename )
System::Boolean Form1::saveSrlCore( System::String ^infile, System::String ^outfile )
{
// ROM情報をフォームから取得してSRLバイナリに反映させる
this->setSrlProperties();
// ファイルをコピー
if( !(filename->Equals( this->tboxFile->Text )) )
if( !(outfile->Equals( infile )) )
{
System::IO::File::Copy( this->tboxFile->Text, filename, true );
System::IO::File::Copy( infile, outfile, true );
}
// コピーしたファイルにROMヘッダを上書き
if( this->hSrl->writeToFile( filename ) != ECSrlResult::NOERROR )
if( this->hSrl->writeToFile( outfile ) != ECSrlResult::NOERROR )
{
return false;
}
return true;
}
// ----------------------------------------------
// tadのオープン
// ----------------------------------------------
System::Void Form1::loadTad( System::String ^tadfile )
{
System::String ^srlfile = System::IO::Path::GetDirectoryName( System::Reflection::Assembly::GetEntryAssembly()->Location )
+ "\\tmp.srl";
splitTad( tadfile, srlfile );
}
// ----------------------------------------------
// ミドルウェアリストの作成
// ----------------------------------------------
@ -393,3 +328,121 @@ System::Boolean Form1::saveMiddlewareListHtml( System::String ^filename )
return true;
}
// ----------------------------------------------
// 設定ファイルの読み込み
// ----------------------------------------------
void Form1::loadInit(void)
{
System::Xml::XmlDocument ^doc = gcnew System::Xml::XmlDocument();
// xmlファイルの読み込み
try
{
doc->Load( "../resource/ini.xml" );
}
catch( System::IO::FileNotFoundException ^s )
{
(void)s;
this->errMsg( "設定ファイルが見つかりません。", "Setting file is not found." );
return;
}
catch( System::Exception ^s )
{
(void)s;
this->errMsg( "設定ファイルを開くことができませんでした。", "Setting file can't be opened." );
return;
}
// <init>タグ : ルート
System::Xml::XmlElement ^root = doc->DocumentElement;
// <rw>タグ
System::Boolean bReadOnly = MasterEditorTWL::isXmlEqual( root, "rw", "r" );
this->hIsReadOnly = System::Boolean( bReadOnly );
if( bReadOnly )
{
this->readOnly();
}
// <lang>タグ
if( MasterEditorTWL::isXmlEqual( root, "lang", "E" ) )
{
this->stripItemEnglish->Checked = true;
this->stripItemJapanese->Checked = false;
this->changeEnglish();
}
// <output>タグ
System::Boolean bXML = MasterEditorTWL::isXmlEqual( root, "output", "XML" );
// <spcheck>タグ
System::Boolean bCheck = MasterEditorTWL::isXmlEqual( root, "spcheck", "ON" );
if( bCheck ) // チェックするときのみ追加チェック項目を設定
{
// チェックするかどうか
this->hSrl->hMrcSpecialList->hIsCheck = gcnew System::Boolean( true );
// SDK
try
{
u32 major = System::UInt32::Parse( MasterEditorTWL::getXPathText( root, "/init/sdk/major" ) );
u32 minor = System::UInt32::Parse( MasterEditorTWL::getXPathText( root, "/init/sdk/minor" ) );
u32 relstep = System::UInt32::Parse( MasterEditorTWL::getXPathText( root, "/init/sdk/relstep" ) );
u32 sdkver = (major << 24) | (minor << 16) | (relstep & 0xFFFF);
this->hSrl->hMrcSpecialList->hSDKVer = gcnew System::UInt32( sdkver );
}
catch ( System::Exception ^ex )
{
(void)ex;
this->errMsg( "設定ファイル中のSDKバージョンが読み込めませんでした。バージョンは0とみなされます。",
"SDK ver. can't be read from setting file. Therefore it is set by 0." );
this->hSrl->hMrcSpecialList->hSDKVer = gcnew System::UInt32( 0 );
}
// Shared2File
try
{
System::Int32 i;
for( i=0; i < METWL_NUMOF_SHARED2FILES; i++ )
{
u32 size = System::UInt32::Parse( MasterEditorTWL::getXPathText( root, "/init/shared2/size" + i.ToString() ) );
this->hSrl->hMrcSpecialList->hShared2SizeArray[i] = gcnew System::UInt32( size );
}
}
catch ( System::Exception ^ex )
{
(void)ex;
this->errMsg( "設定ファイル中のShared2ファイルサイズが読み込めませんでした。サイズはすべて0とみなされます。",
"One of shared2 file sizes can't be read from setting file. Therefore they are set by 0." );
System::Int32 i;
for( i=0; i < METWL_NUMOF_SHARED2FILES; i++ )
{
this->hSrl->hMrcSpecialList->hShared2SizeArray[i] = gcnew System::UInt32( 0 );
}
}
} //if( bCheck )
if( bReadOnly || bXML | bCheck )
{
System::String ^msgJ = gcnew System::String("[動作モード]");
System::String ^msgE = gcnew System::String("[Processing Mode]");
if( bReadOnly )
{
msgJ += "\nリードオンリーモード";
msgE += "\nRead Only Mode";
}
if( bXML )
{
msgJ += "\nXML出力モード";
msgE += "\nXML Output Mode";
}
if( bCheck )
{
msgJ += "\n追加チェックモード";
msgE += "\nExtra Check Mode";
}
this->sucMsg( msgJ, msgE );
}
} // loadInit()

View File

@ -115,7 +115,7 @@ System::Void Form1::saveTmp( System::String ^filename )
}
} //saveTmp()
// 一時ファイルの読み出し
// 一時ファイルの読み込み
void Form1::loadTmp( System::String ^filename )
{
System::Xml::XmlDocument ^doc = gcnew System::Xml::XmlDocument;

View File

@ -21,3 +21,4 @@
#define METWL_MASK_REGION_ALL 0xffffffff
#define METWL_NUMOF_SHARED2FILES 6
#define METWL_SEG3_CRC 0x0254
#define METWL_TAD_TMP_FILENAME "tmp.srl" // TAD読み込みの際に split_tad で一時的に作成するファイル名

View File

@ -60,6 +60,17 @@ ECSrlResult RCSrl::readFromFile( System::String ^filename )
{
return (ECSrlResult::ERROR_FILE_READ);
}
#ifdef METWL_WHETHER_SIGN_DECRYPT
// まず署名チェック
r = this->decryptRomHeader();
if( r != ECSrlResult::NOERROR )
{
(void)fclose(fp);
return r;
}
#endif //#ifdef METWL_WHETHER_SIGN_DECRYPT
{
// ファイルを閉じる前にROMヘッダ以外の領域から設定を取り出す
(void)this->hasDSDLPlaySign( fp );
@ -77,16 +88,6 @@ ECSrlResult RCSrl::readFromFile( System::String ^filename )
}
}
#ifdef METWL_WHETHER_SIGN_DECRYPT
// まず署名チェック
r = this->decryptRomHeader();
if( r != ECSrlResult::NOERROR )
{
(void)fclose(fp);
return r;
}
#endif //#ifdef METWL_WHETHER_SIGN_DECRYPT
// エラーリストをクリア
this->hErrorList = gcnew System::Collections::Generic::List<RCMrcError^>;
this->hWarnList = gcnew System::Collections::Generic::List<RCMrcError^>;