mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
674 lines
18 KiB
C++
674 lines
18 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,j;
|
|
j=0;
|
|
for (i=0;i<1024*1024;i++){
|
|
src_buff[i] = j+i;
|
|
if (i & 0x100)j++;
|
|
}
|
|
}
|
|
|
|
//TEST ライト
|
|
s32 size;
|
|
#define SIZE_TEST1 421888
|
|
//#define SIZE_TEST1 244736 //dup
|
|
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()){
|
|
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;
|
|
}
|
|
|
|
|
|
//ファイル数
|
|
bool Test2_W(int n)
|
|
{
|
|
int total,size2;
|
|
|
|
res = nn::fs::FormatSaveData(680,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 = 512;
|
|
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;
|
|
}
|
|
|
|
#define DirDepth 80
|
|
|
|
//ディレクトリ深度
|
|
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;
|
|
}
|
|
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();
|
|
|
|
num++;
|
|
total+=size;
|
|
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));
|
|
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);
|
|
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();
|
|
|
|
num++;
|
|
total+=size;
|
|
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));
|
|
drawText(8,110,str);
|
|
s_RenderSystem.SwapBuffers();
|
|
nngxWaitVSync(NN_GX_DISPLAY0);
|
|
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)
|
|
//生成サイズに満たないデータ
|
|
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 =0;
|
|
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 += 1024;//512飛ばす
|
|
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,pos;
|
|
|
|
res = fin.TryInitialize(L"data:/test5.bin");
|
|
if (res.IsFailure()){
|
|
drawText(8,100,"open Fail");
|
|
nn::fs::Unmount("data:");
|
|
return false;
|
|
}
|
|
pos =0;
|
|
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",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 += 1024;//512飛ばす
|
|
if (pos >= SIZE_TEST5)break;
|
|
}
|
|
fin.Finalize();
|
|
nn::fs::Unmount("data:");
|
|
drawText(10,100,"end");
|
|
s_RenderSystem.SwapBuffers();
|
|
nngxWaitVSync(NN_GX_DISPLAY0);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
#define menu_ct 6
|
|
#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"};
|
|
|
|
#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 = Test2_W(10);break;
|
|
case 1:sccs = Test1_W();break;
|
|
case 2:sccs = Test2_W(680);break;
|
|
case 3:sccs = Test3_W();break;
|
|
case 4:sccs = Test4_W();break;
|
|
case 5:sccs = Test5_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 = Test2_V(10);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;
|
|
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)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
|
|
*---------------------------------------------------------------------------*/
|
|
|