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@337 385bec56-5757-e545-9c3a-d8741f4650f1
197 lines
5.4 KiB
C++
197 lines
5.4 KiB
C++
/*
|
|
|
|
Horizon/tools/SaveDataFiler で読めるファイルを作成
|
|
|
|
ライトのみアーカイブ使用
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <cstdio>
|
|
#include <iomanip>
|
|
#include <wchar.h>
|
|
#include <string.h>
|
|
#include <nn/fs.h>
|
|
#include "sdmcwo.h"
|
|
|
|
|
|
//SDKツールのSaveFiler用の情報ファイル
|
|
//-------ources\tools\NandFiler\nandf_Dialog.h 参照
|
|
const wchar_t *SDMC_ROOT_DIR_NAME = L"/filer";
|
|
|
|
struct FormatParameters
|
|
{
|
|
size_t m_LimitSize;
|
|
size_t m_MaxDir;
|
|
size_t m_MaxFile;
|
|
s32 m_IconSize;
|
|
bit8 *m_pIconData;
|
|
bool m_Duplicate;
|
|
|
|
FormatParameters()
|
|
: m_LimitSize(0),m_IconSize(0), m_pIconData(0) {}
|
|
//オリジナルはLimitSize不定
|
|
};
|
|
|
|
struct AdditionalInfo
|
|
{
|
|
bit64 m_Version;
|
|
bit64 m_Id;
|
|
bit64 m_Reserved[128];//オリジナルは乱数埋
|
|
AdditionalInfo()
|
|
: m_Version(0), m_Id(0) {}
|
|
};
|
|
|
|
//保存先:日時をディレクトリ名
|
|
//-------- nandf_util.cpp 参照
|
|
std::wstring Sdmcwo::GetDateName()
|
|
{
|
|
nn::fnd::DateTime tm = nn::fnd::DateTime::GetNow();
|
|
|
|
std::wostringstream name;
|
|
name << std::setw(4) << std::setfill(L'0') << tm.GetYear()
|
|
<< std::setw(2) << std::setfill(L'0') << tm.GetMonth()
|
|
<< std::setw(2) << std::setfill(L'0') << tm.GetDay()
|
|
<< std::setw(2) << std::setfill(L'0') << tm.GetHour()
|
|
<< std::setw(2) << std::setfill(L'0') << tm.GetMinute()
|
|
<< std::setw(2) << std::setfill(L'0') << tm.GetSecond();
|
|
|
|
|
|
//char型 :表示で使う
|
|
wcstombs(DirName, name.str().c_str(), 14);
|
|
DirName[14] = 0;
|
|
return name.str();
|
|
}
|
|
|
|
|
|
bit64 ChangeId(bit64 id, bit64 key)
|
|
{
|
|
return id ^ key ^ 0xce8a4d52f7105339;
|
|
}
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
bool Sdmcwo::DelDir(const wchar_t *dir)
|
|
{
|
|
//if (created==false)return true;//未作成ならなにもしない
|
|
if (Mount() == RESULT_FAIL_MOUNT)return false;
|
|
bool res = DeleteDir(dir);
|
|
Unmount();
|
|
//if (res)created==false;
|
|
return res;
|
|
}
|
|
|
|
//直前に作成したDateTimeフォルダ削除
|
|
bool Sdmcwo::Delete()
|
|
{
|
|
return DelDir(latestPath_w);
|
|
}
|
|
|
|
//全削除
|
|
bool Sdmcwo::DeleteAll()
|
|
{
|
|
std::wostringstream woss;
|
|
woss << devName << SDMC_ROOT_DIR_NAME;//sdmc:/filer
|
|
return DelDir(woss.str().c_str());
|
|
}
|
|
|
|
|
|
//保存先のディレクトリ作成
|
|
//成功時はマウント状態
|
|
bool Sdmcwo::Create()
|
|
{
|
|
std::wostringstream woss;
|
|
created = false;
|
|
if (Mount() == RESULT_FAIL_MOUNT)return false;
|
|
|
|
woss << devName << SDMC_ROOT_DIR_NAME;//sdmc:/filer
|
|
if (CreateDir(woss.str().c_str()))
|
|
{
|
|
woss << L"/" << L"UserSaveData";//sdmc:/filer/UserSaveData
|
|
if ( CreateDir(woss.str().c_str()) )
|
|
{
|
|
DateDirName = GetDateName();
|
|
woss << L"/" << DateDirName;//sdmc:/filer/UserSaveData/YearMtDtHrMtSc
|
|
if ( CreateDir(woss.str().c_str()) )
|
|
{
|
|
wcscpy(latestPath_w,woss.str().c_str());
|
|
created = true;//日時ディレクトリ作成フラグ
|
|
//コピー先ルート
|
|
woss << L"/" << "00000000";//sdmc:/filer/UserSaveData/YearMtDtHrMtSc/00000000
|
|
if ( CreateDir(woss.str().c_str()) )
|
|
{
|
|
//woss << L"/";//sdmc:/filer/UserSaveData/YearMtDtHrMtSc/00000000/
|
|
wcscpy(rootPath_w,woss.str().c_str());//格納先パス保存
|
|
SetRootPath(rootPath_w);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Unmount();
|
|
return false;
|
|
}
|
|
|
|
|
|
//パス名エラーで作成できない場合の格納先
|
|
bool Sdmcwo::OpenVnfW(wchar_t *path,s64 size)
|
|
{
|
|
tVnf vnf;
|
|
bool res=false;
|
|
//パス名&オフセット用ファイル
|
|
SetRootPath(latestPath_w);//基底パスを変更
|
|
if (OpenAdd(L"/00000000.vnf"))//追記で開く
|
|
{
|
|
wcscpy(vnf.path,path);//ヘッダ格納
|
|
vnf.size = size;
|
|
res = (Write((char*)&vnf,sizeof(tVnf)) == sizeof(tVnf));
|
|
}
|
|
SetRootPath(rootPath_w);//基底パスを戻す
|
|
return res;
|
|
}
|
|
|
|
|
|
char buff[32768*2];
|
|
//情報ファイル
|
|
//
|
|
bool Sdmcwo::WriteSys(tArcInfo *ifo)
|
|
{//SaveFilerで読むためのファイル
|
|
if (Mount() == RESULT_FAIL_MOUNT)return false;
|
|
bool res = false;
|
|
SetRootPath(latestPath_w);//基底パスを変更
|
|
// FormatParameter を保存
|
|
if(OpenW( L"/00000000.dat" ))
|
|
{
|
|
FormatParameters Fparam;
|
|
Fparam.m_MaxDir = ifo->DirEntry;
|
|
Fparam.m_MaxFile = ifo->FileEntry;
|
|
Fparam.m_Duplicate = ifo->Dup;
|
|
if ( Write((char*)&Fparam, sizeof(FormatParameters)) == sizeof(FormatParameters))
|
|
{ //AdditionalInfoを保存
|
|
CloseW();
|
|
if(OpenW( L"/00000000_.dat"))
|
|
{
|
|
AdditionalInfo Ainfo;
|
|
Ainfo.m_Version = 0;
|
|
Ainfo.m_Id = ChangeId(Ainfo.m_Id, static_cast<bit64>(std::wcstoll(DateDirName.c_str(), NULL, 10)));
|
|
res = Write((char*)&Ainfo, sizeof(AdditionalInfo)) == sizeof(AdditionalInfo);
|
|
}
|
|
}
|
|
}
|
|
CloseW();
|
|
Unmount();
|
|
SetRootPath(rootPath_w);//基底パスを戻す
|
|
return res;
|
|
}
|
|
|
|
//空き容量
|
|
bool Sdmcwo::GetFreeSize(s64 *size)
|
|
{
|
|
s64 sz;
|
|
LastNnResult = nn::fs::GetSdmcSize(&sz,size);
|
|
return LastNnResult.IsSuccess();
|
|
}
|
|
|