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
190 lines
5.0 KiB
C++
190 lines
5.0 KiB
C++
/*---------------------------------------------------------------------------*
|
||
Project: Horizon
|
||
File: irp.h
|
||
|
||
Copyright (C)2009 Nintendo Co., Ltd. All rights reserved.
|
||
|
||
These coded instructions, statements, and computer programs contain
|
||
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||
Company Ltd., and are protected by Federal copyright law. They may
|
||
not be disclosed to third parties or copied or duplicated in any form,
|
||
in whole or in part, without the prior written consent of Nintendo.
|
||
|
||
$Rev$
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
#ifndef MEMBAK_H_
|
||
#define MEMBAK_H_
|
||
|
||
#include <nn/types.h>
|
||
#include <nn/Result.h>
|
||
#include "../my_defs.h"
|
||
#include "savefile.h"
|
||
#include <nn/math.h>
|
||
|
||
class MemBak
|
||
{
|
||
public:
|
||
s64 FileSize;
|
||
NN_PADDING4;
|
||
nn::Result LastNnResult;
|
||
private:
|
||
struct EntryHeader
|
||
{
|
||
s16 nameSize;
|
||
NN_PADDING2;
|
||
s32 dataSize;
|
||
s32 nextOffset;
|
||
|
||
EntryHeader* GetNext()
|
||
{
|
||
return reinterpret_cast<EntryHeader*>(
|
||
reinterpret_cast<bit8*>(this) + nextOffset);
|
||
}
|
||
bit8* GetDataPointer()
|
||
{
|
||
return reinterpret_cast<bit8*>(this + 1) + nameSize;
|
||
}
|
||
const wchar_t* GetName() const
|
||
{
|
||
return reinterpret_cast<const wchar_t*>(
|
||
reinterpret_cast<const bit8*>(this + 1));
|
||
}
|
||
void SetName(const wchar_t* name)
|
||
{
|
||
s32 len = std::wcslen(name);
|
||
nameSize = len * 2 + 2;
|
||
std::memcpy(this + 1, name, nameSize);
|
||
}
|
||
void SetSize(size_t size)
|
||
{
|
||
dataSize = size;
|
||
}
|
||
s32 GetSize() const
|
||
{
|
||
return dataSize;
|
||
}
|
||
void SetNext()
|
||
{
|
||
nextOffset = nn::math::RoundUp(sizeof(*this) + nameSize + dataSize, 4);
|
||
}
|
||
bool Match(const wchar_t* p)
|
||
{
|
||
return std::wcscmp(p, GetName()) == 0;
|
||
}
|
||
bool IsEnd() const
|
||
{
|
||
return nameSize == 0;
|
||
}
|
||
};
|
||
struct FileState
|
||
{
|
||
EntryHeader* pE;
|
||
s32 pos;
|
||
|
||
void Init(EntryHeader* p)
|
||
{
|
||
pE = p;
|
||
pos = 0;
|
||
}
|
||
void Set(const wchar_t* name, size_t size)
|
||
{
|
||
pE->SetName(name);
|
||
pE->SetSize(size);
|
||
pE->SetNext();
|
||
pE->GetNext()->nameSize = 0;
|
||
}
|
||
s32 GetSize() const { return pE->GetSize(); }
|
||
EntryHeader* GetNext()
|
||
{
|
||
return pE->GetNext();
|
||
}
|
||
bit8* GetCurrentPointer()
|
||
{
|
||
return pE->GetDataPointer() + pos;
|
||
}
|
||
s32 GetRemain() const
|
||
{
|
||
return pE->dataSize - pos;
|
||
}
|
||
void Advance(s32 size)
|
||
{
|
||
pos += size;
|
||
}
|
||
s32 Write(const void* p, size_t size)
|
||
{
|
||
s32 remain = GetRemain();
|
||
if( remain <= 0 )
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
s32 copySize = nn::math::Min<s32>(remain, size);
|
||
std::memcpy(GetCurrentPointer(), p, copySize);
|
||
Advance(copySize);
|
||
|
||
return copySize;
|
||
}
|
||
s32 Read(void* p, size_t size)
|
||
{
|
||
s32 remain = GetRemain();
|
||
if( remain <= 0 )
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
s32 copySize = nn::math::Min<s32>(remain, size);
|
||
std::memcpy(p, GetCurrentPointer(), copySize);
|
||
Advance(copySize);
|
||
|
||
return copySize;
|
||
}
|
||
};
|
||
|
||
tArcInfo m_ArcInfo;
|
||
FileState m_ForRead;
|
||
FileState m_ForWrite;
|
||
|
||
bool m_Exists;
|
||
bool m_IsMounted;
|
||
NN_PADDING2;
|
||
bit8* m_pBuffer;
|
||
size_t m_pBufferSize;
|
||
bit8* m_pBufferPos;
|
||
EntryHeader* m_pFind;
|
||
|
||
u32 m_NumDirEntry;
|
||
u32 m_NumFileEntry;
|
||
|
||
public:
|
||
MemBak();
|
||
~MemBak();
|
||
void Finalize();
|
||
myResult Create(const void* icon,size_t iconSize,u32 entryDir,u32 entryFile);
|
||
myResult CreateSys(const void* icon,size_t iconSize);
|
||
myResult Mount();
|
||
// myResult MountSys();
|
||
bool IsExist();
|
||
void Unmount();
|
||
bool Delete();
|
||
void CloseW();
|
||
bool OpenW(wchar_t *path,s64 size);
|
||
bool OpenSysW();//<2F>b<EFBFBD><62>
|
||
void CloseSysW();//<2F>b<EFBFBD><62>
|
||
// bool OpenSysR();//<2F>b<EFBFBD><62>
|
||
// void CloseSysR();//<2F>b<EFBFBD><62>
|
||
s32 Write(char *buffer,size_t size);
|
||
bool WriteSys(tArcInfo *pinfo);
|
||
// bool ReadSys(tArcInfo *pinfo);
|
||
void ResetPath();
|
||
s32 Read(char *buffer,size_t size);
|
||
void Close();
|
||
bool Open(wchar_t *path);
|
||
myResult GetPath(wchar_t *path);
|
||
bool GetInfo(tArcInfo *pinfo);
|
||
};
|
||
|
||
|
||
|
||
#endif
|