mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
1261 lines
35 KiB
C++
1261 lines
35 KiB
C++
/*---------------------------------------------------------------------------*
|
||
Project: Horizon
|
||
File: main.cpp
|
||
|
||
Copyright (C)2010 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.
|
||
|
||
*---------------------------------------------------------------------------*/
|
||
|
||
#include <wchar.h>
|
||
#include <string.h>
|
||
#include <stdlib.h>
|
||
#include <stdio.h>
|
||
#include <nn.h>
|
||
#include <nn/hid.h>
|
||
#include "demo.h"
|
||
|
||
nn::Result res;
|
||
|
||
nn::fs::FileOutputStream fout;
|
||
nn::fs::FileInputStream fin;
|
||
|
||
nn::fs::Directory dc[256];
|
||
|
||
wchar_t file_pathw[1024];
|
||
char file_path[1024];
|
||
char file_path2[1024];
|
||
char src_buff[1024*1024];
|
||
char get_buff[1024*1024];
|
||
char str[512];
|
||
|
||
|
||
extern demo::RenderSystemDrawing s_RenderSystem;
|
||
|
||
//終了処理
|
||
extern void finish(void);
|
||
extern u32 WaitKey(u32 mask);
|
||
|
||
extern void setColor(f32 r,f32 g,f32 b,f32 a);
|
||
extern void drawText(u16 x,u16 y,char *s);
|
||
void drawText(u16 x,u16 y,char *s,int v)
|
||
{
|
||
sprintf(str,s,v);
|
||
drawText( x,y,str);
|
||
}
|
||
|
||
|
||
//---------------------------------------- テストパターン
|
||
void make_pattern()
|
||
{
|
||
int i;
|
||
int *buff;
|
||
buff = (int*)&src_buff[0];
|
||
for (i=0;i<sizeof(src_buff)/sizeof(int);i++){
|
||
buff[i] = i;
|
||
}
|
||
}
|
||
|
||
//TEST ライト
|
||
s32 size;
|
||
#define SIZE_TEST1 421888
|
||
//#define SIZE_TEST1 244736 //dup
|
||
#define DMX_TEST0 100
|
||
#define FMX_TEST0 100
|
||
#define DUP_TEST0 true
|
||
bool Test0_W(int n)//Casual
|
||
{
|
||
|
||
res = nn::fs::FormatSaveData(DMX_TEST0,FMX_TEST0,DUP_TEST0);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"format Fail");
|
||
return false;
|
||
}
|
||
res =nn::fs::MountSaveData();
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Mount Fail");
|
||
return false;
|
||
}
|
||
|
||
int num = 0,total=0,size=512;
|
||
while(1){
|
||
/*
|
||
swprintf(file_pathw,512,L"data:/空ディレクトリ%d",num);
|
||
res = nn::fs::TryCreateDirectory(file_pathw);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Dir create Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
*/
|
||
sprintf(file_path,"data:/nulldir%d",num);
|
||
res = nn::fs::TryCreateDirectory(file_path);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Dir create Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
sprintf(file_path,"data:/null%d",num);
|
||
res = nn::fs::TryCreateDirectory(file_path);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Dir create Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
sprintf(file_path,"data:/null%d/nulldir",num);
|
||
res = nn::fs::TryCreateDirectory(file_path);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Dir create Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
//swprintf(file_pathw,512,L"data:/テスト%d",num);
|
||
swprintf(file_pathw,512,L"data:/test%d",num);
|
||
res = nn::fs::TryCreateDirectory(file_pathw);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Dir create Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
//sprintf(file_path,"data:/test%d/test%d.bin",num,num);
|
||
//res = fout.TryInitialize(file_path,true);
|
||
//swprintf(file_pathw,512,L"data:/テスト%d/テスト%d.bin",num,num);
|
||
swprintf(file_pathw,512,L"data:/test%d/test%d.bin",num,num);
|
||
res = fout.TryInitialize(file_pathw,true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fout.TryWrite( &size,&src_buff[total],size);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"write Fail");
|
||
fout.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fout.Finalize();
|
||
total += size;
|
||
size += size;
|
||
num++;
|
||
sprintf(str,"size %d , num %d",total,num);
|
||
s_RenderSystem.Clear();
|
||
drawText(10,80,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
//if (size<512)break;
|
||
if (num == n)break;
|
||
}
|
||
fout.Finalize();
|
||
nn::fs::CommitSaveData();
|
||
nn::fs::Unmount("data:");
|
||
NN_LOG("total %d",total);
|
||
drawText(10,100,"end");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
|
||
bool Test0_V(int n)//Casual
|
||
{
|
||
|
||
int num = 0,total=0,size = 512;
|
||
size_t maxF,maxD;
|
||
bool isDup;
|
||
|
||
nn::fs::Directory dc;
|
||
|
||
res = nn::fs::GetSaveDataFormatInfo(&maxF,&maxD,&isDup);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"fail to get formatinfo");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
if ((maxF != FMX_TEST0)||(maxD!=DMX_TEST0)||(isDup != DUP_TEST0)){
|
||
drawText(8,100,"wrong format");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
|
||
|
||
|
||
while(1){
|
||
sprintf(file_path,"data:/nulldir%d",num);//ディレクトリ
|
||
res = dc.TryInitialize(file_path);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Dir");
|
||
dc.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
dc.Finalize();
|
||
sprintf(file_path,"data:/null%d/nulldir",num);//ディレクトリ
|
||
res = dc.TryInitialize(file_path);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Dir");
|
||
dc.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
dc.Finalize();
|
||
/*
|
||
swprintf(file_pathw,512,L"data:/空ディレクトリ%d",num);//ディレクトリ
|
||
res = dc.TryInitialize(file_pathw);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Dir");
|
||
dc.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
dc.Finalize();
|
||
*/
|
||
//swprintf(file_pathw,512,L"data:/テスト%d/テスト%d.bin",num,num);
|
||
swprintf(file_pathw,512,L"data:/test%d/test%d.bin",num,num);
|
||
res = fin.TryInitialize(file_pathw);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fin.TryRead( &size,&get_buff[total],size);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"read Fail");
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
for(int i=0;i<size;i++)if (src_buff[total+i]!=get_buff[total+i])return false;
|
||
fin.Finalize();
|
||
total += size;
|
||
size+=size;
|
||
num++;
|
||
sprintf(str,"size %d , num %d",total,num);
|
||
s_RenderSystem.Clear();
|
||
drawText(10,80,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
//if (size<512)break;
|
||
if (num == n)break;
|
||
}
|
||
fin.Finalize();
|
||
nn::fs::CommitSaveData();
|
||
nn::fs::Unmount("data:");
|
||
NN_LOG("total %d",total);
|
||
drawText(10,100,"end");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
|
||
|
||
bool Test1_W()
|
||
{
|
||
int total,size2;
|
||
|
||
res = nn::fs::FormatSaveData(1,0,false);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"format Fail");
|
||
return false;
|
||
}
|
||
res =nn::fs::MountSaveData();
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Mount Fail");
|
||
return false;
|
||
}
|
||
|
||
res = nn::fs::TryCreateFile(L"data:/test1.bin",SIZE_TEST1);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Create Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fout.TryInitialize(L"data:/test1.bin",true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
total =0;
|
||
size2 = 512;
|
||
//size2 = 4096;
|
||
//size2 = SIZE_TEST1;
|
||
while(1){
|
||
res = fout.TryWrite( &size,&src_buff[total],size2);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"write Fail");
|
||
fout.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
total += size;
|
||
sprintf(str,"size %d",total);
|
||
s_RenderSystem.Clear();
|
||
drawText(10,80,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
//if (size<512)break;
|
||
if (total >= SIZE_TEST1)break;
|
||
if ((SIZE_TEST1 - total) < 512)size2 = SIZE_TEST1 - total ;
|
||
}
|
||
fout.Finalize();
|
||
nn::fs::CommitSaveData();
|
||
nn::fs::Unmount("data:");
|
||
NN_LOG("total %d",total);
|
||
drawText(10,100,"end");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
|
||
//ベリファイ
|
||
bool Test1_V()
|
||
{
|
||
int i,total;
|
||
|
||
res = fin.TryInitialize(L"data:/test1.bin");
|
||
if (res.IsFailure())
|
||
{
|
||
//NN_LOG("%d\n",res.GetDescription());
|
||
drawText(8,100,"open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
total =0;
|
||
while(1){
|
||
res = fin.TryRead( &size,&get_buff[total],512);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"read Fail");
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
//if (size == 0)break;
|
||
for (i=0;i<size;i++) if (src_buff[total+i] != get_buff[total+i])
|
||
{
|
||
drawText(8,100,"verifi Fail at %d",total+i);
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
|
||
}
|
||
if (total >= SIZE_TEST1)break;
|
||
|
||
total += size;
|
||
s_RenderSystem.Clear();
|
||
sprintf(str,"now %d",total);
|
||
drawText(10,80,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
if (size<512)break;
|
||
}
|
||
fout.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
drawText(10,100,"end");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
|
||
#define test2_max 680
|
||
#define test2_ct test2_max
|
||
//#define test2_max 10
|
||
//#define test2_ct 5
|
||
#define test2_size 512
|
||
|
||
//ファイル数
|
||
bool Test2_W(int n)
|
||
{
|
||
int total,size2;
|
||
|
||
res = nn::fs::FormatSaveData(test2_max,1,false);//dupなしファイル680
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"format Fail");
|
||
return false;
|
||
}
|
||
res =nn::fs::MountSaveData();
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Mount Fail");
|
||
return false;
|
||
}
|
||
|
||
total =0;
|
||
int num = 0;
|
||
size2 = test2_size;
|
||
while(1){
|
||
sprintf(file_path,"data:/test%d.bin",num);
|
||
// res = nn::fs::TryCreateFile(L"data:/test2.bin",SIZE_TEST1);
|
||
// if (res.IsFailure()){
|
||
// drawText(8,100,"Create Fail");
|
||
// nn::fs::Unmount("data:");
|
||
// return false;
|
||
// }
|
||
res = fout.TryInitialize(file_path,true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fout.TryWrite( &size,&src_buff[total],size2);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"write Fail");
|
||
fout.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fout.Finalize();
|
||
total += size;
|
||
num++;
|
||
sprintf(str,"size %d , num %d",total,num);
|
||
s_RenderSystem.Clear();
|
||
drawText(10,80,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
//if (size<512)break;
|
||
if (num == n)break;
|
||
}
|
||
fout.Finalize();
|
||
nn::fs::CommitSaveData();
|
||
nn::fs::Unmount("data:");
|
||
NN_LOG("total %d",total);
|
||
drawText(10,100,"end");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
|
||
bool Test2_V(int n)
|
||
{
|
||
int total,size2,i;
|
||
|
||
total =0;
|
||
int num = 0;
|
||
size2 = 512;
|
||
while(1){
|
||
sprintf(file_path,"data:/test%d.bin",num);
|
||
res = fin.TryInitialize(file_path);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fin.TryRead( &size,&get_buff[total],size2);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"read Fail");
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
for (i=0;i<size;i++) if (src_buff[total+i] != get_buff[total+i])
|
||
{
|
||
drawText(8,100,"verifi Fail at %d",total+i);
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
|
||
}
|
||
fin.Finalize();
|
||
|
||
total += size;
|
||
num++;
|
||
sprintf(str,"size %d , num %d",total,num);
|
||
s_RenderSystem.Clear();
|
||
drawText(10,80,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
//if (size<512)break;
|
||
if (num == n)break;
|
||
}
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
NN_LOG("total %d",total);
|
||
drawText(10,100,"end");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
|
||
//85のとき252文字
|
||
#define DirDepth 85
|
||
//ファイルをパス長いものに限定
|
||
//#define DirDepthLow 80
|
||
#define DirDepthLow 0
|
||
|
||
//ディレクトリ深度とパス長
|
||
bool Test3_W()
|
||
{
|
||
int total,size2;
|
||
|
||
res = nn::fs::FormatSaveData(200,200,false);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"format Fail");
|
||
return false;
|
||
}
|
||
res =nn::fs::MountSaveData();
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Mount Fail");
|
||
return false;
|
||
}
|
||
|
||
int num = 0;
|
||
total =0;
|
||
size2 = 512;
|
||
strcpy(file_path,"data:");
|
||
while(1){
|
||
sprintf(str,"/%d",num);
|
||
strcat(file_path,str);
|
||
res = nn::fs::TryCreateDirectory(file_path);
|
||
if (res.IsFailure()){
|
||
sprintf(str,"length = %d",(int)strlen(file_path));
|
||
drawText(8,110,str);
|
||
drawText(8,100,"Dir create Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
if (num>=DirDepthLow){
|
||
strcpy(file_path2,file_path);
|
||
sprintf(str,"/t%d.bin",num);
|
||
strcat(file_path2,str);
|
||
res = fout.TryInitialize(file_path2,true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fout.TryWrite( &size,&src_buff[total],size2);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"write Fail");
|
||
fout.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fout.Finalize();
|
||
total+=size;
|
||
}
|
||
num++;
|
||
s_RenderSystem.Clear();
|
||
sprintf(str,"num %d",num);
|
||
drawText(10,80,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
if (num == DirDepth)break;
|
||
}
|
||
|
||
nn::fs::CommitSaveData();
|
||
nn::fs::Unmount("data:");
|
||
|
||
drawText(10,100,"end");
|
||
sprintf(str,"length = %d",(int)strlen(file_path2)-6);
|
||
drawText(8,110,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
|
||
|
||
bool Test3_V()
|
||
{
|
||
int i,total,size2;
|
||
|
||
int num = 0;
|
||
total =0;
|
||
size2 = 512;
|
||
strcpy(file_path,"data:");
|
||
while(1){
|
||
sprintf(str,"/%d",num);
|
||
strcat(file_path,str);
|
||
if (num>=DirDepthLow){
|
||
strcpy(file_path2,file_path);
|
||
sprintf(str,"/t%d.bin",num);
|
||
strcat(file_path2,str);
|
||
res = fin.TryInitialize(file_path2);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fin.TryRead( &size,&get_buff[total],size2);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"read Fail");
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
for (i=0;i<size;i++) if (src_buff[total+i] != get_buff[total+i])
|
||
{
|
||
drawText(8,100,"verifi Fail at %d",total+i);
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fin.Finalize();
|
||
total+=size;
|
||
}
|
||
num++;
|
||
s_RenderSystem.Clear();
|
||
sprintf(str,"num %d",num);
|
||
drawText(10,80,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
if (num == DirDepth) break;
|
||
}
|
||
|
||
nn::fs::Unmount("data:");
|
||
drawText(10,100,"end");
|
||
sprintf(str,"length = %d",(int)strlen(file_path2)-6);
|
||
drawText(8,110,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
//max size of name
|
||
bool Test4_W()
|
||
{
|
||
|
||
res = nn::fs::FormatSaveData(1,1,true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"format Fail");
|
||
return false;
|
||
}
|
||
res =nn::fs::MountSaveData();
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Mount Fail");
|
||
return false;
|
||
}
|
||
|
||
strcpy(file_path,"data:/");
|
||
while(strlen(file_path)<(16+6)){//16文字
|
||
strcat(file_path,"0");
|
||
}
|
||
res = nn::fs::TryCreateDirectory(file_path);
|
||
if (res.IsFailure()){
|
||
sprintf(str,"length = %d",(int)strlen(file_path)-6);
|
||
drawText(8,110,str);
|
||
drawText(8,100,"Dir create Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
strcat(file_path,"/123456789abc.bin");//16文字
|
||
res = fout.TryInitialize(file_path,true);
|
||
if (res.IsFailure()){
|
||
sprintf(str,"length = %d",(int)strlen(file_path)-6);
|
||
drawText(8,110,str);
|
||
drawText(8,100,"Open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fout.TryWrite( &size,&src_buff[0],512);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Write Fail");
|
||
fout.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fout.Finalize();
|
||
nn::fs::CommitSaveData();
|
||
nn::fs::Unmount("data:");
|
||
return (size == 512);
|
||
|
||
}
|
||
|
||
|
||
bool Test4_V()
|
||
{
|
||
|
||
strcpy(file_path,"data:/");
|
||
while(strlen(file_path)<(16+6)){//16文字
|
||
strcat(file_path,"0");
|
||
}
|
||
strcat(file_path,"/123456789abc.bin");//16文字
|
||
res = fin.TryInitialize(file_path);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fin.TryRead( &size,&get_buff[0],512);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Read Fail");
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
if (size != 512)return false;
|
||
|
||
for (int i=0;i<size;i++) if (src_buff[i] != get_buff[i])
|
||
{
|
||
drawText(8,100,"verifi Fail at %d",i);
|
||
return false;
|
||
}
|
||
return true;
|
||
|
||
}
|
||
/*
|
||
//max size of name
|
||
#define max_len 16
|
||
bool Test4_W()
|
||
{
|
||
int i;
|
||
|
||
res = nn::fs::FormatSaveData(1,0,true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"format Fail");
|
||
return false;
|
||
}
|
||
res =nn::fs::MountSaveData();
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Mount Fail");
|
||
return false;
|
||
}
|
||
|
||
strcpy(str,"data:/");
|
||
for (i =6;i<max_len+6;i++)str[i] = '-';
|
||
str[i] = 0;
|
||
res = fout.TryInitialize(str,true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fout.TryWrite( &size,&src_buff[0],512);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Write Fail");
|
||
fout.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fout.Finalize();
|
||
nn::fs::CommitSaveData();
|
||
nn::fs::Unmount("data:");
|
||
return (size == 512);
|
||
|
||
}
|
||
|
||
|
||
bool Test4_V()
|
||
{
|
||
int i;
|
||
|
||
strcpy(str,"data:/");
|
||
for (i =6;i<max_len+6;i++)str[i] = '-';
|
||
str[i] = 0;
|
||
res = fin.TryInitialize(str);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fin.TryRead( &size,&get_buff[0],512);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Read Fail");
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
if (size != 512)return false;
|
||
|
||
for (i=0;i<size;i++) if (src_buff[i] != get_buff[i])
|
||
{
|
||
drawText(8,100,"verifi Fail at %d",i);
|
||
return false;
|
||
}
|
||
return true;
|
||
|
||
}
|
||
*/
|
||
|
||
#define SIZE_TEST5 (512*100)
|
||
#define SIZE_TEST5_HZ 4096
|
||
#define SIZE_TEST5_START 512*16
|
||
//SDK3.1はバグで最初のアクセスでOKだと、2回目以降もOKになる
|
||
//SDK3.x より?:4096単位でハッシュ
|
||
//先頭はヘッダ2ブロック含むっぽい
|
||
//ファイル先頭~3071(512*6),3072以降は4096ごと
|
||
//ハッシュ単位間に書き込むと未書込み部分は0クリアされてる
|
||
//例)クリエート後に先頭から4096バイト目に512書き込むと、
|
||
//3072-4095(512*2)、4608-7168(512*5)は未書込みでも
|
||
//エラーなし0埋めされたデータが読める
|
||
//尚、クリエート時に先頭512書込ので先頭3072バイトは常に読める
|
||
|
||
//生成サイズに満たないデータ..未書込領域
|
||
bool Test5_W()
|
||
{
|
||
int pos;
|
||
|
||
res = nn::fs::FormatSaveData(1,0,true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"format Fail");
|
||
return false;
|
||
}
|
||
res =nn::fs::MountSaveData();
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Mount Fail");
|
||
return false;
|
||
}
|
||
|
||
res = nn::fs::TryCreateFile(L"data:/test5.bin",SIZE_TEST5);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Create Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
|
||
|
||
res = fout.TryInitialize(L"data:/test5.bin",true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
pos = SIZE_TEST5_START;
|
||
while(1){
|
||
fout.SetPosition(pos);
|
||
res = fout.TryWrite( &size,&src_buff[pos],512);
|
||
if (res.IsFailure() || (size!=512)){
|
||
drawText(8,100,"write Fail");
|
||
fout.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
sprintf(str,"position %d",pos);
|
||
s_RenderSystem.Clear();
|
||
drawText(10,80,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
pos += SIZE_TEST5_HZ;//間を飛ばす
|
||
if (pos >= SIZE_TEST5)break;
|
||
}
|
||
|
||
fout.Finalize();
|
||
nn::fs::CommitSaveData();
|
||
nn::fs::Unmount("data:");
|
||
drawText(10,100,"end");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
|
||
|
||
bool Test5_V()
|
||
{
|
||
int i;
|
||
s64 pos;
|
||
|
||
res = fin.TryInitialize(L"data:/test5.bin");
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open Fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
pos = SIZE_TEST5_START;
|
||
while(1){
|
||
fin.SetPosition(pos);
|
||
res = fin.TryRead( &size,&get_buff[pos],512);
|
||
if (res.IsFailure() || (size!=512)){
|
||
drawText(8,100,"read Fail");
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
sprintf(str,"position %d",(int)pos);
|
||
s_RenderSystem.Clear();
|
||
drawText(10,80,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
|
||
for (i=0;i<512;i++) if (src_buff[pos+i] != get_buff[pos+i])
|
||
{
|
||
drawText(8,100,"verifi Fail at %d",i);
|
||
return false;
|
||
}
|
||
pos += SIZE_TEST5_HZ;//飛ばす
|
||
if (pos >= SIZE_TEST5)break;
|
||
}
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
drawText(10,100,"end");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
|
||
const char kinsi[] = {0x22,'<','>','?','*','|',0x5c,':',' ',0};//0x22 = "",0x5c = 円マーク
|
||
// スラッシュはセーブ時に重ね("//")ても"/"になり,末尾だとエラーとなる
|
||
const char *kinsi2[] = { "CON","PRN","NUL","AUX","LPT1","LPT2","LPT3","LPT4","COM1","COM2","COM3","COM4"
|
||
,"con","prn","nul","aux","lpt1","lpt2","lpt3","lpt4","com1","com2","com3","com4",""};
|
||
|
||
|
||
//FAT違反の名前
|
||
bool Test6_W()
|
||
{
|
||
|
||
res = nn::fs::FormatSaveData(100,100,true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"format Fail");
|
||
return false;
|
||
}
|
||
res =nn::fs::MountSaveData();
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Mount Fail");
|
||
return false;
|
||
}
|
||
|
||
|
||
|
||
//禁止文字
|
||
char *base = "test6";
|
||
char dname[128],fname[128];
|
||
int ofst=0;
|
||
|
||
//頭に付ける
|
||
strcpy(dname,"data:/");
|
||
int pos = strlen(dname);
|
||
strcat(dname,"_");
|
||
strcat(dname,base);//data:/_base
|
||
int pos2 = strlen(dname)+1;
|
||
strcpy(fname,dname);
|
||
strcat(fname,"/_");
|
||
strcat(fname,base);
|
||
strcat(fname,".bin");//data:/_base/_base.bin
|
||
|
||
int i =0;
|
||
char c;
|
||
while(kinsi[i] != 0)
|
||
{
|
||
c = kinsi[i];
|
||
dname[pos] = c;
|
||
res = nn::fs::TryCreateDirectory(dname);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Dir fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fname[pos] = c;
|
||
fname[pos2] = c;
|
||
res = fout.TryInitialize(fname,true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fout.TryWrite( &size,&src_buff[ofst],512);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"write fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fout.Finalize();
|
||
i++;
|
||
ofst+=512;
|
||
}
|
||
|
||
//末尾
|
||
strcpy(dname,"data:/");
|
||
strcat(dname,base);//data:/base
|
||
pos = strlen(dname);
|
||
strcat(dname,"_");//data:/base_
|
||
strcpy(fname,dname);
|
||
strcat(fname,"/");
|
||
strcat(fname,base);//data:/base_/base
|
||
pos2 = strlen(fname);
|
||
strcat(fname,"_.bin");//data:/base_/base_.bin
|
||
|
||
i =0;
|
||
while(kinsi[i] != 0)
|
||
{
|
||
c = kinsi[i];
|
||
dname[pos] = c;
|
||
res = nn::fs::TryCreateDirectory(dname);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"dir fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fname[pos] = c;
|
||
fname[pos2] = c;
|
||
res = fout.TryInitialize(fname,true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fout.TryWrite( &size,&src_buff[ofst],512);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"write fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fout.Finalize();
|
||
i++;
|
||
ofst+=512;
|
||
}
|
||
|
||
|
||
//禁止名
|
||
i=0;
|
||
while(kinsi2[i][0] != 0)
|
||
{
|
||
strcpy(dname,"data:/");
|
||
strcat(dname,kinsi2[i]);
|
||
res = nn::fs::TryCreateDirectory(dname);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"dir fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
strcpy(fname,dname);
|
||
strcat(fname,"/");
|
||
strcat(fname,kinsi2[i]);
|
||
res = fout.TryInitialize(fname,true);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fout.TryWrite( &size,&src_buff[ofst],512);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"write fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fout.Finalize();
|
||
i++;
|
||
ofst+=512;
|
||
}
|
||
|
||
nn::fs::CommitSaveData();
|
||
nn::fs::Unmount("data:");
|
||
|
||
drawText(10,100,"end");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
|
||
|
||
bool Test6_V()
|
||
{
|
||
|
||
//禁止文字
|
||
char *base = "test6";
|
||
char fname[128];
|
||
int ofst=0;
|
||
|
||
//頭に付ける
|
||
strcpy(fname,"data:/");
|
||
int pos = strlen(fname);
|
||
strcat(fname,"_");
|
||
strcat(fname,base);//data:/_base
|
||
int pos2 = strlen(fname)+1;
|
||
strcat(fname,"/_");
|
||
strcat(fname,base);
|
||
strcat(fname,".bin");//data:/_base/_base.bin
|
||
|
||
int i =0;
|
||
int j;
|
||
char c;
|
||
while(kinsi[i] != 0)
|
||
{
|
||
c = kinsi[i];
|
||
fname[pos] = c;
|
||
fname[pos2] = c;
|
||
res = fin.TryInitialize(fname);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fin.TryRead( &size,&get_buff[ofst],512);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"read fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fin.Finalize();
|
||
|
||
for(j=0;j<512;j++)if(src_buff[ofst+i] != get_buff[ofst+i]){
|
||
drawText(8,100,"verifi fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
|
||
i++;
|
||
ofst+=512;
|
||
}
|
||
|
||
//末尾
|
||
strcpy(fname,"data:/");
|
||
strcat(fname,base);//data:/base
|
||
pos = strlen(fname);
|
||
strcat(fname,"_/");//data:/base_/
|
||
strcat(fname,base);//data:/base_/base
|
||
pos2 = strlen(fname);
|
||
strcat(fname,"_.bin");//data:/base_/base_.bin
|
||
|
||
i =0;
|
||
while(kinsi[i] != 0)//末尾スラッシュは名無しでエラー
|
||
{
|
||
c = kinsi[i];
|
||
fname[pos] = c;
|
||
fname[pos2] = c;
|
||
res = fin.TryInitialize(fname);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fin.TryRead( &size,&get_buff[ofst],512);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"write fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fout.Finalize();
|
||
|
||
for(j=0;j<512;j++)if(src_buff[ofst+i] != get_buff[ofst+i]){
|
||
drawText(8,100,"verifi fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
|
||
i++;
|
||
ofst+=512;
|
||
}
|
||
|
||
|
||
//禁止名
|
||
i=0;
|
||
while(kinsi2[i][0] != 0)
|
||
{
|
||
strcpy(fname,"data:/");
|
||
strcat(fname,kinsi2[i]);
|
||
strcat(fname,"/");
|
||
strcat(fname,kinsi2[i]);
|
||
res = fin.TryInitialize(fname);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"open fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
res = fin.TryRead( &size,&get_buff[ofst],512);
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"read fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
fin.Finalize();
|
||
|
||
for(j=0;j<512;j++)if(src_buff[ofst+i] != get_buff[ofst+i]){
|
||
drawText(8,100,"verifi fail");
|
||
nn::fs::Unmount("data:");
|
||
return false;
|
||
}
|
||
i++;
|
||
ofst+=512;
|
||
}
|
||
|
||
fin.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
drawText(10,100,"end");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
return true;
|
||
}
|
||
|
||
#define menu_ct 7
|
||
#define menu_max (menu_ct-1)
|
||
char* menu_str[menu_ct] = {"Casual check","Large size","many files","Deep directry","max size name","data < create size","fat error name"};
|
||
|
||
#define menu_top_Y 80
|
||
#define menu_top_X 60
|
||
#define menu_spc 14
|
||
|
||
//---------------------------------------------------------------- main
|
||
void TestMain()
|
||
{
|
||
u32 value;
|
||
int curs = 0;
|
||
int i;
|
||
bool sccs;
|
||
|
||
//Render
|
||
setColor(1.0f,1.0f,1.0f,1.0f);
|
||
|
||
//TEST PATTERN
|
||
make_pattern();
|
||
|
||
while(1){
|
||
|
||
//menu 表示
|
||
s_RenderSystem.Clear();
|
||
drawText(8,20," Backup Verifi for SaveDataMover Test ");
|
||
drawText(8,40," for 512KB Backup");
|
||
for (i=0;i<menu_ct;i++)drawText(menu_top_X,menu_top_Y+menu_spc*i,menu_str[i]);
|
||
drawText(menu_top_X-30,menu_top_Y+menu_spc*curs,"->");
|
||
drawText(menu_top_X,menu_top_Y+menu_spc*(menu_max+2),"push A:Write ,X:Verifi");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
|
||
//ボタン待ち
|
||
value = WaitKey(nn::hid::BUTTON_A | nn::hid::BUTTON_X |nn::hid::BUTTON_UP |nn::hid::BUTTON_DOWN);
|
||
if (value & nn::hid::BUTTON_A){//ライト
|
||
sccs = false;
|
||
s_RenderSystem.Clear();
|
||
drawText(10,70,"writing");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
switch(curs){
|
||
case 0:sccs = Test0_W(5);break;
|
||
case 1:sccs = Test1_W();break;
|
||
case 2:sccs = Test2_W(test2_ct);break;
|
||
case 3:sccs = Test3_W();break;
|
||
case 4:sccs = Test4_W();break;
|
||
case 5:sccs = Test5_W();break;
|
||
case 6:sccs = Test6_W();break;
|
||
default:break;
|
||
}
|
||
}else if (value & nn::hid::BUTTON_X)
|
||
{//ベリファイ
|
||
sccs = false;
|
||
s_RenderSystem.Clear();
|
||
drawText(10,70,"verifi");
|
||
s_RenderSystem.SwapBuffers();
|
||
nngxWaitVSync(NN_GX_DISPLAY0);
|
||
res =nn::fs::MountSaveData();
|
||
if (res.IsFailure()){
|
||
drawText(8,100,"Mount Fail");
|
||
}else
|
||
switch(curs){
|
||
case 0:sccs = Test0_V(5);break;
|
||
case 1:sccs = Test1_V();break;
|
||
case 2:sccs = Test2_V(680);break;
|
||
case 3:sccs = Test3_V();break;
|
||
case 4:sccs = Test4_V();break;
|
||
case 5:sccs = Test5_V();break;
|
||
case 6:sccs = Test6_V();break;
|
||
default:break;
|
||
}
|
||
}else if (value & nn::hid::BUTTON_UP){
|
||
if(curs > 0)curs--;
|
||
}else if(curs < menu_max)curs++;
|
||
|
||
if (value & (nn::hid::BUTTON_A | nn::hid::BUTTON_X)){
|
||
if (sccs == false){
|
||
fin.Finalize();
|
||
fout.Finalize();
|
||
nn::fs::Unmount("data:");
|
||
drawText(8,120,"Failed");
|
||
}
|
||
sprintf(str,"desc %d",res.GetDescription());
|
||
drawText(10,140,str);
|
||
s_RenderSystem.SwapBuffers();
|
||
NN_LOG("desc %d",res.GetDescription());
|
||
WaitKey(nn::hid::BUTTON_B);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/*---------------------------------------------------------------------------*
|
||
End of file
|
||
*---------------------------------------------------------------------------*/
|
||
|