mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
231 lines
3.9 KiB
C++
231 lines
3.9 KiB
C++
#include <wchar.h>
|
|
#include <string.h>
|
|
#include <nn/fs.h>
|
|
#include <nn/fs/fs_ResultPrivate.h>
|
|
#include "membak.h"
|
|
|
|
using namespace nn;
|
|
|
|
namespace
|
|
{
|
|
const size_t BUFFER_SIZE = MEM_BKUP_SIZE;
|
|
bit8 s_Buffer[BUFFER_SIZE] NN_ATTRIBUTE_ALIGN(4096);
|
|
}
|
|
|
|
//bool info_alive;
|
|
|
|
//--------------------------------------------------------------------
|
|
//
|
|
|
|
|
|
//コンストラクタ
|
|
MemBak::MemBak()
|
|
{
|
|
m_Exists = false;
|
|
m_pBuffer = s_Buffer;
|
|
m_pBufferPos = s_Buffer;
|
|
m_pBufferSize = sizeof(s_Buffer);
|
|
LastNnResult = ResultSuccess();
|
|
ResetPath();
|
|
|
|
// info_alive = false;
|
|
}
|
|
|
|
void MemBak::Finalize()
|
|
{
|
|
}
|
|
//デストラクタ
|
|
MemBak::~MemBak()
|
|
{
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
// mount, unmount, create, delete
|
|
|
|
//存在確認
|
|
bool MemBak::IsExist()
|
|
{
|
|
return m_Exists;
|
|
}
|
|
|
|
//セーブ作成、成功時はマウント状態
|
|
myResult MemBak::Create(u32 entryDir,u32 entryFile)
|
|
{
|
|
if ( m_IsMounted )
|
|
{
|
|
return RESULT_ALREADY_MOUNT;
|
|
}
|
|
|
|
m_NumDirEntry = entryDir;
|
|
m_ArcInfo.DirEntry = entryDir;
|
|
m_NumFileEntry = entryFile;
|
|
m_ArcInfo.FileEntry = entryFile;
|
|
|
|
m_Exists = true;
|
|
m_IsMounted = true;
|
|
m_pBufferPos = m_pBuffer;
|
|
return RESULT_OK;
|
|
}
|
|
|
|
//削除
|
|
bool MemBak::Delete()
|
|
{
|
|
m_Exists = false;
|
|
// info_alive = false;
|
|
m_pBufferPos = m_pBuffer;
|
|
m_IsMounted = false;
|
|
return true;
|
|
}
|
|
|
|
//マウント
|
|
myResult MemBak::Mount()
|
|
{
|
|
if (m_Exists == false)return RESULT_FAIL_MOUNT;
|
|
if ( m_IsMounted )
|
|
{
|
|
return RESULT_ALREADY_MOUNT;
|
|
}
|
|
|
|
m_IsMounted = true;
|
|
return RESULT_OK;
|
|
}
|
|
|
|
void MemBak::Unmount()
|
|
{
|
|
m_IsMounted = false;
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
// SetInfo, GetInfo
|
|
|
|
//アーカイブ情報の取得
|
|
bool MemBak::GetInfo(tArcInfo *pinfo)
|
|
{
|
|
*pinfo = m_ArcInfo;
|
|
return m_Exists;
|
|
}
|
|
|
|
/*
|
|
//管理用ファイル
|
|
//ライト属性で開く
|
|
bool MemBak::OpenSysW()
|
|
{
|
|
return true;
|
|
}
|
|
//ライト属性ファイルを閉じる
|
|
void MemBak::CloseSysW()
|
|
{
|
|
}
|
|
|
|
|
|
//システムファイルライト
|
|
bool MemBak::WriteSys(tArcInfo *pinfo)
|
|
{
|
|
info_alive = true;
|
|
pinfo->Ver = INFO_VERSION;
|
|
m_ArcInfo = *pinfo;
|
|
return true;
|
|
}
|
|
*/
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
// Traverse
|
|
|
|
//パス検索位置のリセット
|
|
void MemBak::ResetPath()
|
|
{
|
|
m_pFind = reinterpret_cast<EntryHeader*>(m_pBuffer);
|
|
}
|
|
|
|
|
|
myResult MemBak::GetPath(wchar_t *path)
|
|
{
|
|
if( m_pFind->IsEnd() )
|
|
{
|
|
path[0] = '\0';
|
|
return RESULT_OK;
|
|
}
|
|
|
|
std::wcscpy(path, m_pFind->GetName());
|
|
m_pFind = m_pFind->GetNext();
|
|
|
|
return RESULT_OK;
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
// Write
|
|
|
|
//ライト属性ファイルを閉じる
|
|
void MemBak::CloseW()
|
|
{
|
|
}
|
|
|
|
//ファイルライト
|
|
s32 MemBak::Write(char *buffer,size_t size)
|
|
{
|
|
return m_ForWrite.Write(buffer, size);
|
|
}
|
|
|
|
|
|
|
|
//ライト属性ファイルを開く
|
|
bool MemBak::OpenW(wchar_t *path,s64 size)
|
|
{
|
|
m_ForWrite.Init(reinterpret_cast<EntryHeader*>(m_pBufferPos));
|
|
m_ForWrite.Set(path, size);
|
|
m_pBufferPos = reinterpret_cast<bit8*>(m_ForWrite.GetNext());
|
|
return true;
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
// Read
|
|
|
|
//ファイルリード
|
|
s32 MemBak::Read(char *buffer,size_t size)
|
|
{
|
|
return m_ForRead.Read(buffer, size);
|
|
}
|
|
|
|
|
|
void MemBak::Close()
|
|
{
|
|
}
|
|
|
|
|
|
//ファイルを開く
|
|
//パス指定はルート以降
|
|
//(ex)data:/dir/file -> dir/file
|
|
bool MemBak::Open(wchar_t *path)
|
|
{
|
|
EntryHeader* pE = reinterpret_cast<EntryHeader*>(m_pBuffer);
|
|
|
|
while( ! pE->IsEnd() )
|
|
{
|
|
if( pE->Match(path) )
|
|
{
|
|
m_ForRead.Init(pE);
|
|
FileSize = m_ForRead.GetSize();
|
|
return true;
|
|
}
|
|
|
|
pE = pE->GetNext();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
|