#ifndef SAVEFILE_H_ #define SAVEFILE_H_ #include #include #include #include "../my_defs.h" #include #include //******************************** defines ********** //パス名長 :SDK制限はアーカイブ名抜いて253文字 //アーカイブ名およびSD格納ディレクトリの余裕分をみとく #define MAX_PATH_LENGTH 512 //パス階層上限 //ファイル検索時に使用、"/"+1文字が最短なので128で十分 #define MAX_LEVEL 128 //******************************** functions ********** //パス名チェック //FAT違反の半角スペースあるかチェック //文字、予約名、パス長はAPIエラー(INVALID_ARGUMENT)で判定 bool CheckPath(wchar_t *s); //デリミタ("/")位置を返す int GetPosDelmLast(wchar_t *s,int top); //パス結合 void ChainPath(wchar_t *p1,wchar_t *p2); //******************************** Types ********** //セーブに関する情報 #define INFO_VERSION 0 struct tArcInfo{ u32 DirEntry,FileEntry;//フォーマット u32 DirCount,FileCount;//登録数 char Pcode[20];//product code SDKのサイズを下回らないこと bool Dup;//2重化 u8 Ver; u8 yobi;//パディング }; //******************************** Class *************** class SaveFileBase { public: nn::Result LastNnResult; protected: wchar_t root_w[MAX_PATH_LENGTH];//基底パス(デバイス名含) wchar_t path_w[MAX_PATH_LENGTH];//パス名 wchar_t pathw_w[MAX_PATH_LENGTH];//ワーク wchar_t pathw_w2[MAX_PATH_LENGTH]; s32 RootLength; wchar_t *pPathTop; char devName[16]; bool IsMounted; char dumy[3]; public: //基底パス設定 void SetRootPath(wchar_t *path) {// 最後に"/"はつけない 例) "data:" wcscpy(root_w,path); RootLength = wcslen(path); pPathTop = (wchar_t*)((u32)&path_w+RootLength*2); } void GetRootPath(wchar_t *path) { wcscpy(path,root_w); } virtual bool MountCore() = 0; myResult Mount(){ if ( IsMounted )return RESULT_ALREADY_MOUNT; if (MountCore()){ IsMounted = true; return RESULT_OK; } return RESULT_FAIL_MOUNT; }; void Unmount(){ if(IsMounted){ IsMounted = false; nn::fs::Unmount(devName); } }; SaveFileBase(){IsMounted = false;root_w[0]=0;RootLength=0;}; ~SaveFileBase(){Unmount();}; }; //ライト class SaveFileWrite :public virtual SaveFileBase { private: nn::fs::FileWriter writer; public: SaveFileWrite(){RootLength=0;}; ~SaveFileWrite(){}; bool DeleteDir(const wchar_t *dir); bool OpenW(const wchar_t *path); bool OpenC(wchar_t *path,s64 size,bool *mkdir); bool OpenAdd(wchar_t *path); void CloseW(); s32 Write(char *buffer,size_t size); bool CreateDir(const wchar_t *dir); }; //リード class SaveFileRead :public virtual SaveFileBase { public: s64 FileSize; private: int dc_readed[MAX_LEVEL];//リード済みエントリ数 wchar_t pathu_w[MAX_LEVEL][MAX_PATH_LENGTH];//パス名履歴 nn::fs::FileReader reader; int s_lv; tArcInfo m_info; bool s_serch; u8 pad[3];//padding public: virtual void GetFormatInfoCore(tArcInfo *ifo) = 0; myResult IsExist(); bool Open(const wchar_t *path); void Close(); myResult GetPath(wchar_t *path); void ResetPath(); bool GetInfo(tArcInfo *pinfo); s32 Read(char *buffer,size_t size); SaveFileRead(){ s_lv=0; m_info.DirCount = 0; m_info.FileCount = 0; m_info.DirEntry = 0; m_info.FileEntry = 0; }; ~SaveFileRead(){}; }; #endif