mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@679 385bec56-5757-e545-9c3a-d8741f4650f1
295 lines
11 KiB
C++
295 lines
11 KiB
C++
// sysFirmware.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
|
|
//
|
|
|
|
#include "sysSharedExtSaveData.h"
|
|
|
|
#include <nn/fs.h>
|
|
#include <nn/fs/fs_Api.h>
|
|
#include <nn/fs/fs_Parameters.h>
|
|
#include <nn/fs/fs_FileSystem.h>
|
|
#include <nn/fs/fs_ApiSharedExtSaveData.h>
|
|
#include <nn/fs/CTR/MPCore/fs_FileSystemBase.h>
|
|
//#include <nn/fs/fs_IpcFileSystem.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
namespace sys
|
|
{
|
|
namespace
|
|
{
|
|
struct Parameter
|
|
{
|
|
size_t defaultLimitSize;
|
|
size_t limitSize;
|
|
u32 entryFile;
|
|
u32 entryDirectory;
|
|
};
|
|
|
|
#if 0
|
|
// refreshLimitSize を呼ぶ場合の初期値
|
|
Parameter cPnoteMPPotoParam = { 64 * 1024 * 1024 , 0 , 501 , 505 };
|
|
Parameter cSnoteSoundParam = { 1232 * 1024 , 0 , 20 , 1 };
|
|
Parameter cNewsBossDataParam = { 0 , 0 , 100 , 1 };
|
|
Parameter cCommonDataParam = { 0 , 0 , 8 , 0 };
|
|
Parameter cBashotoryaDataParam = { 0 , 0 , 6 , 1 };
|
|
#else
|
|
// 直で呼ぶ場合の初期値 今はこっち
|
|
Parameter cPnoteMPPotoParam = { 0 , 64 * 1024 * 1024 , 511 , 511 };
|
|
Parameter cSnoteSoundParam = { 0 , 1232 * 1024 , 32 , 16 };
|
|
Parameter cNewsBossDataParam = { 0 , 4354048 , 127 , 16 };
|
|
Parameter cCommonDataParam = { 0 , 9277440 , 16 , 16 };
|
|
Parameter cBashotoryaDataParam = { 0 , 2785280 , 16 , 16 };
|
|
// = 2719744(データ5件+キャッシュ) + 64kb
|
|
// = 2498560(データ4件+おしらせ1件+キャッシュ) + 32kb + 220kb(データ-おしらせ) + 28kb
|
|
#endif
|
|
|
|
Parameter* cParams[SharedExtSaveData::cIDCount] = {
|
|
&cPnoteMPPotoParam,
|
|
&cSnoteSoundParam,
|
|
&cNewsBossDataParam,
|
|
&cCommonDataParam,
|
|
&cBashotoryaDataParam,
|
|
};
|
|
|
|
const char *cParamsString[SharedExtSaveData::cIDCount] = {
|
|
"PnoteMPPoto ",
|
|
"SnoteSound ",
|
|
"NewsBossData ",
|
|
"CommonData ",
|
|
"BashotoryaData ",
|
|
};
|
|
}
|
|
|
|
const bit32 SharedExtSaveData::cIDs[SharedExtSaveData::cIDCount] = {
|
|
SharedExtSaveData::cPnoteMPPoto,
|
|
SharedExtSaveData::cSnoteSound,
|
|
SharedExtSaveData::cNewsBossData,
|
|
SharedExtSaveData::cCommonData,
|
|
SharedExtSaveData::cBashotorya,
|
|
};
|
|
|
|
void SharedExtSaveData::refreshLimitSize()
|
|
{
|
|
for ( int i = 0; i < cIDCount; ++ i )
|
|
{
|
|
switch ( i )
|
|
{
|
|
// ファイルが 100 作れて、ファイル自体の合計は 4M になるように
|
|
case eType_BossData:
|
|
{
|
|
s64 size = 0;
|
|
const s64 filesize_table[ 1 ] = { 4 * 1024 * 1024 };
|
|
nn::Result result = nn::fs::QueryTotalQuotaSize( &size ,
|
|
cParams[ i ]->entryDirectory ,
|
|
cParams[ i ]->entryFile ,
|
|
filesize_table ,
|
|
1 );
|
|
if ( result.IsSuccess() )
|
|
{
|
|
cParams[ i ]->limitSize = static_cast< size_t > ( size );
|
|
NN_LOG( "%s dir: %d file: %d size: %d\n" , cParamsString[ i ] ,
|
|
cParams[ i ]->entryDirectory ,
|
|
cParams[ i ]->entryFile ,
|
|
cParams[ i ]->limitSize );
|
|
}
|
|
}
|
|
break;
|
|
|
|
// 汎用データ→IDB+GameCoin+LBL+GBL+BindingFolder+Mii
|
|
case eType_Common:
|
|
{
|
|
s64 size = 0;
|
|
const s64 filesize_table[ 8 ] =
|
|
{
|
|
7159808 , // idb
|
|
8200 , // idbt
|
|
20 , // gamecoin
|
|
12000 , // LBL
|
|
97328 , // GBL
|
|
4 , // BindingFolder
|
|
310560 , // Mii1
|
|
310560 , // Mii2
|
|
};
|
|
nn::Result result = nn::fs::QueryTotalQuotaSize( &size ,
|
|
cParams[ i ]->entryDirectory ,
|
|
cParams[ i ]->entryFile ,
|
|
filesize_table ,
|
|
8 );
|
|
if ( result.IsSuccess() )
|
|
{
|
|
cParams[ i ]->limitSize = static_cast< size_t > ( size );
|
|
NN_LOG( "%s dir: %d file: %d size: %d\n" , cParamsString[ i ] ,
|
|
cParams[ i ]->entryDirectory ,
|
|
cParams[ i ]->entryFile ,
|
|
cParams[ i ]->limitSize );
|
|
}
|
|
}
|
|
break;
|
|
|
|
// バショトリャー
|
|
case eType_Bashotorya:
|
|
{
|
|
s64 size = 0;
|
|
const s64 filesize_table[ 6 ] =
|
|
{
|
|
274 * 1024 + 52 ,
|
|
274 * 1024 + 52 ,
|
|
274 * 1024 + 52 ,
|
|
274 * 1024 + 52 ,
|
|
274 * 1024 + 52 ,
|
|
1096 * 1024 ,
|
|
};
|
|
nn::Result result = nn::fs::QueryTotalQuotaSize( &size ,
|
|
cParams[ i ]->entryDirectory ,
|
|
cParams[ i ]->entryFile ,
|
|
filesize_table ,
|
|
sizeof( filesize_table ) / sizeof( *filesize_table ) );
|
|
if ( result.IsSuccess() )
|
|
{
|
|
cParams[ i ]->limitSize = static_cast< size_t > ( size );
|
|
NN_LOG( "%s dir: %d file: %d size: %d\n" , cParamsString[ i ] ,
|
|
cParams[ i ]->entryDirectory ,
|
|
cParams[ i ]->entryFile ,
|
|
cParams[ i ]->limitSize );
|
|
}
|
|
}
|
|
break;
|
|
|
|
// 初期値をコピーする
|
|
default:
|
|
cParams[ i ]->limitSize = cParams[ i ]->defaultLimitSize;
|
|
NN_LOG( "%s dir: %d file: %d size: %d\n" , cParamsString[ i ] ,
|
|
cParams[ i ]->entryDirectory ,
|
|
cParams[ i ]->entryFile ,
|
|
cParams[ i ]->limitSize );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
nn::Result SharedExtSaveData::createData()
|
|
{
|
|
//refreshLimitSize(); // QueryTotalQuotaSize を計算する
|
|
|
|
nn::Result res;
|
|
|
|
for ( int i=0; i<cIDCount; i++ )
|
|
{
|
|
res = nn::fs::CreateSharedExtSaveData( cIDs[i],
|
|
cParams[i]->entryDirectory, cParams[i]->entryFile, cParams[i]->limitSize );
|
|
|
|
NN_LOG( "%d size -> %d %d\n" , i , cParams[ i ]->limitSize , res.IsSuccess() );
|
|
NN_ASSERT_RESULT( res );
|
|
|
|
if ( res.IsFailure() )
|
|
{
|
|
NN_LOG( "result = %d %d %d\n" , res.GetLevel() , res.GetSummary() , res.GetModule() );
|
|
}
|
|
NN_UTIL_RETURN_IF_FAILED(res);
|
|
}
|
|
return nn::ResultSuccess();
|
|
}
|
|
|
|
nn::Result SharedExtSaveData::deleteData()
|
|
{
|
|
nn::Result res;
|
|
|
|
for ( int i=0; i<cIDCount; i++ )
|
|
{
|
|
res = nn::fs::DeleteSharedExtSaveData( cIDs[i] );
|
|
if(res <= nn::fs::ResultNotFound())
|
|
{
|
|
continue;
|
|
}
|
|
NN_UTIL_RETURN_IF_FAILED(res);
|
|
}
|
|
return nn::ResultSuccess();
|
|
}
|
|
|
|
void SharedExtSaveData::checkData()
|
|
{
|
|
//refreshLimitSize(); // QueryTotalQuotaSize を計算する
|
|
nn::Result res;
|
|
|
|
for ( int i=0; i<cIDCount; i++ )
|
|
{
|
|
char volume[ 8 ] = { 0 };
|
|
|
|
sprintf( volume , "ex%02d" , i );
|
|
|
|
res = nn::fs::MountSharedExtSaveData( volume, cIDs[i] );
|
|
|
|
if(res.IsFailure())
|
|
{
|
|
//NN_RESULT_ASSERT( res );
|
|
|
|
if(res <= nn::fs::ResultNotFound())
|
|
{
|
|
// 存在していない。作成する。
|
|
res = nn::fs::CreateSharedExtSaveData(cIDs[i],
|
|
cParams[i]->entryDirectory, cParams[i]->entryFile, cParams[i]->limitSize);
|
|
}
|
|
else if(res <= nn::fs::ResultNotFormatted())
|
|
{
|
|
// フォーマットされていない。フォーマットを行なう。
|
|
// - まず発生しないはず。
|
|
//res = nn::fs::DeleteSharedExtSaveData( cIDs[i] );
|
|
//NN_ASSERT_RESULT( res );
|
|
|
|
res = nn::fs::CreateSharedExtSaveData(cIDs[i],
|
|
cParams[i]->entryDirectory, cParams[i]->entryFile, cParams[i]->limitSize);
|
|
}
|
|
else if(res <= nn::fs::ResultBadFormat())
|
|
{
|
|
// 不正なフォーマット。フォーマットを行なう。
|
|
// - ノイズ等の可能性もあるので、リトライしてもよい?
|
|
res = nn::fs::CreateSharedExtSaveData(cIDs[i],
|
|
cParams[i]->entryDirectory, cParams[i]->entryFile, cParams[i]->limitSize);
|
|
}
|
|
else if(res <= nn::fs::ResultVerificationFailed())
|
|
{
|
|
// 検証に失敗。フォーマットを行なう。
|
|
res = nn::fs::CreateSharedExtSaveData(cIDs[i],
|
|
cParams[i]->entryDirectory, cParams[i]->entryFile, cParams[i]->limitSize);
|
|
}
|
|
else
|
|
{
|
|
// それ以外は、発生しないはず。FATALへ。
|
|
// - ノイズ等の可能性もあるので、リトライしてもよい?
|
|
}
|
|
|
|
if(res.IsFailure())
|
|
{
|
|
// ここで失敗した場合は、さすがに FATAL へ。
|
|
}
|
|
else
|
|
{
|
|
// 再マウント
|
|
// - ここで失敗した場合は、さすがに FATAL へ。
|
|
res = nn::fs::MountSharedExtSaveData(volume, cIDs[i] );
|
|
|
|
if ( res.IsFailure() )
|
|
{
|
|
// ここも FATAL?(河野)
|
|
}else{
|
|
nn::fs::Unmount(volume);
|
|
}
|
|
}
|
|
}else{
|
|
nn::fs::Unmount(volume);
|
|
}
|
|
NN_ASSERT_RESULT( res );
|
|
}
|
|
}
|
|
|
|
// 領域の説明を返す
|
|
const char *SharedExtSaveData::getInfoString( bit32 id )
|
|
{
|
|
for ( int i = 0; i<cIDCount; i++ )
|
|
{
|
|
if ( cIDs[i]==id ) return cParamsString[i];
|
|
}
|
|
return "unknown ";
|
|
}
|
|
}
|