mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
SDからPhotoへのデータコピーツールのコミット
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@2020 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
parent
927af0d016
commit
1e8a33abc7
129
debugSoft/Jpeg/SdToPhoto/Makefile
Normal file
129
debugSoft/Jpeg/SdToPhoto/Makefile
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
#! make -f
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Project: TwlSDK - tools - NandFiler
|
||||||
|
# File: Makefile
|
||||||
|
#
|
||||||
|
# Copyright 2008 Nintendo. 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.
|
||||||
|
#
|
||||||
|
# $Date:: $
|
||||||
|
# $Rev$
|
||||||
|
# $Author$
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
override TARGET_PLATFORM = TWL
|
||||||
|
override TARGET_CODEGEN = ARM
|
||||||
|
override TWL_ARCHGEN = LIMITED
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
TARGET_PLATFORM := TWL
|
||||||
|
TWL_ARCHGEN := LIMITED
|
||||||
|
SRCS = main.cpp
|
||||||
|
TARGET_NAME = sd2photo
|
||||||
|
TWLNMENU_ROOT ?= .
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
#-- バナーデータを生成します
|
||||||
|
BANNER = ./banner/banner.bnr
|
||||||
|
BANNERSRC := $(wildcard ./banner/data/Cell/*.nce)
|
||||||
|
MAKEBANNER = $(TWL_TOOLSDIR)/bin/makebanner.TWL.exe
|
||||||
|
BANNERCVTR = $(TWL_TOOLSDIR)/bin/bannercvtr.exe
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
#-- NAND アプリではいくつかのパラメータの指定のために固有の RSF ファイルが必要です。
|
||||||
|
|
||||||
|
ROM_SPEC = $(TARGET_NAME)$(ROM_SPEC_NAME_PART).autogen.rsf
|
||||||
|
ROM_SPEC_TEMPLATE = $(ROOT)/include/twl/specfiles/ROM-TS_sys.rsf
|
||||||
|
ROM_SPEC_PARAM = MakerCode=01 \
|
||||||
|
GameCode=4S01 \
|
||||||
|
Secure=TRUE \
|
||||||
|
BannerFile=./banner/banner.bnr \
|
||||||
|
NANDAccess=TRUE \
|
||||||
|
SDCardAccess=TRUE \
|
||||||
|
TitleName=$(TARGET_NAME)
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
#-- CARD, NANDによるオプションの指定
|
||||||
|
|
||||||
|
TWL_NANDAPP = TRUE
|
||||||
|
|
||||||
|
ifeq ($(APP_TYPE),)
|
||||||
|
APP_TYPE = CARD
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(APP_TYPE),CARD)
|
||||||
|
MEDIA = GameCard
|
||||||
|
SUFFIX = .srl
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(APP_TYPE),NAND)
|
||||||
|
MEDIA = NAND
|
||||||
|
SUFFIX = .tad
|
||||||
|
ROM_SPEC_NAME_PART := $(ROM_SPEC_NAME_PART).nand
|
||||||
|
endif
|
||||||
|
|
||||||
|
ROM_SPEC_PARAM += Media=$(MEDIA)
|
||||||
|
TARGET_BIN = $(TARGET_NAME)$(SUFFIX)
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
# 対象拡張子のためのインクルードファイルを決定
|
||||||
|
ifneq ($(SUFFIX_DEFINE),)
|
||||||
|
SUFFIX_FILE = $(SUFFIX_DEFINE)
|
||||||
|
else
|
||||||
|
SUFFIX_FILE = default_suffix.h
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
# セキュア用
|
||||||
|
MAKEROM := $(TWL_TOOLSDIR)/bin/makerom.TWL.secure.exe
|
||||||
|
MAKETAD_OPTION := -s
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
# ビルドパラメータ
|
||||||
|
INCDIR = $(TWLSYSTEM_ROOT)/include \
|
||||||
|
./include
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
# 対象拡張子のためのインクルードファイルをビルドディレクトリにコピー
|
||||||
|
.PHONY: suffix
|
||||||
|
|
||||||
|
suffix:
|
||||||
|
cp $(SUFFIX_FILE) ./include/suffix.h
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
# ビルド
|
||||||
|
do-build: suffix $(TARGETS)
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
#-- SRL を作成する前にバナーが作成されるようにします。
|
||||||
|
|
||||||
|
ifdef MAKE_BANNER
|
||||||
|
$(BINDIR)/$(TARGET_NAME)$(ROM_SPEC_NAME_PART).srl: $(BANNER)
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------
|
||||||
|
#-- バナー作成用ターゲット
|
||||||
|
|
||||||
|
$(BANNER): $(BANNER:.bnr=.bin) $(BANNER:.bnr=.bsf)
|
||||||
|
$(MAKEBANNER) -A $(BANNER:.bnr=.bin) $(BANNER:.bnr=.bsf) $@
|
||||||
|
|
||||||
|
$(BANNER:.bnr=.bin): $(BANNERSRC)
|
||||||
|
$(BANNERCVTR) -o $@ $<
|
||||||
|
|
||||||
|
include $(TWLSDK_ROOT)/build/buildtools/modulerules
|
||||||
|
|
||||||
|
#===== End of Makefile =====
|
||||||
BIN
debugSoft/Jpeg/SdToPhoto/banner/banner.bnr
Normal file
BIN
debugSoft/Jpeg/SdToPhoto/banner/banner.bnr
Normal file
Binary file not shown.
9
debugSoft/Jpeg/SdToPhoto/default_suffix.h
Normal file
9
debugSoft/Jpeg/SdToPhoto/default_suffix.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace{
|
||||||
|
const char* SUFFIX[] =
|
||||||
|
{
|
||||||
|
".jpg",
|
||||||
|
".jpeg",
|
||||||
|
".JPG",
|
||||||
|
".JPEG",
|
||||||
|
};
|
||||||
|
}
|
||||||
28
debugSoft/Jpeg/SdToPhoto/readme.txt
Normal file
28
debugSoft/Jpeg/SdToPhoto/readme.txt
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
sd2photo
|
||||||
|
|
||||||
|
*概要
|
||||||
|
SDカード内を走査して、指定した拡張子のファイルを探し、
|
||||||
|
"photo:/"以下へコピーするツールです。
|
||||||
|
|
||||||
|
*拡張子の指定方法
|
||||||
|
コピー対象とする拡張子を記述したファイルをビルド時に指定します。
|
||||||
|
具体的な指定はmake時に下記の変数を渡すことで行ってください。
|
||||||
|
|
||||||
|
SUFFIX_DEFINE=hoge
|
||||||
|
|
||||||
|
省略すると、default_suffix.h が指定されます。(".jpg", ".jpeg", ".JPG", "JPEG"に対応します。)
|
||||||
|
|
||||||
|
*操作方法
|
||||||
|
SDカードを挿入した状態でデバッガ等で起動してください。
|
||||||
|
(SDを指さずに起動すると画面が赤くなり、SDが挿されるまで待ちます)
|
||||||
|
|
||||||
|
自動的に、ファイルの検索とコピーが始まります。
|
||||||
|
|
||||||
|
検索、コピー中は、画面の色が緑色になっています。
|
||||||
|
(SDを抜いたり電源を切ったりしないほうが無難です。)
|
||||||
|
処理が終わったら青色になります。
|
||||||
|
|
||||||
|
*仕様
|
||||||
|
・フォルダ構成をそのままコピーします。例えば、SD上で"/test/aa.jpg"があったとすれば、NAND上で"photo:/test/aa.jpg"が作成されます。
|
||||||
|
・NAND上に同名のファイルが存在する場合、問答無用に上書きされます。
|
||||||
|
・残り容量が少ない場合、上書きになる場合でもファイルをコピーできないことがあります。
|
||||||
286
debugSoft/Jpeg/SdToPhoto/src/main.cpp
Normal file
286
debugSoft/Jpeg/SdToPhoto/src/main.cpp
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: TwlSDK - tools - NandFiler
|
||||||
|
File: main.cpp
|
||||||
|
|
||||||
|
Copyright 2008 Nintendo. 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.
|
||||||
|
|
||||||
|
$Date:: $
|
||||||
|
$Rev$
|
||||||
|
$Author$
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
#include <twl.h>
|
||||||
|
#include <nitro/fs.h>
|
||||||
|
#include <nitro/std.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
#include "suffix.h"
|
||||||
|
|
||||||
|
inline void* operator new(size_t size) { return OS_Alloc(size); }
|
||||||
|
inline void* operator new[](size_t size) { return OS_Alloc(size); }
|
||||||
|
inline void operator delete(void* ptr) { OS_Free(ptr); }
|
||||||
|
inline void operator delete[](void* ptr) { OS_Free(ptr); }
|
||||||
|
|
||||||
|
typedef std::list<std::string> PathList;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
void
|
||||||
|
InitInterrupt(void)
|
||||||
|
{
|
||||||
|
OS_EnableIrq();
|
||||||
|
OS_EnableInterrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
InitAlloc(void)
|
||||||
|
{
|
||||||
|
OSHeapHandle hHeap;
|
||||||
|
void* lo = OS_GetMainArenaLo();
|
||||||
|
void* hi = OS_GetMainArenaHi();
|
||||||
|
|
||||||
|
lo = OS_InitAlloc(OS_ARENA_MAIN, lo, hi, 1);
|
||||||
|
OS_SetArenaLo(OS_ARENA_MAIN, lo);
|
||||||
|
|
||||||
|
hHeap = OS_CreateHeap(OS_ARENA_MAIN, lo, hi);
|
||||||
|
SDK_ASSERT( hHeap >= 0 );
|
||||||
|
|
||||||
|
OS_SetCurrentHeap(OS_ARENA_MAIN, hHeap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void InitInteruptSystem();
|
||||||
|
static void InitFileSystem();
|
||||||
|
|
||||||
|
static void PickupTargetPath(const char* root, const char* suffix, PathList& out);
|
||||||
|
static void CopyTarget(const char* to, const char* header, PathList& out);
|
||||||
|
static void CopyFile(const char* src, const char* dest);
|
||||||
|
|
||||||
|
void
|
||||||
|
TwlStartUp()
|
||||||
|
{
|
||||||
|
OS_Init();
|
||||||
|
InitAlloc();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: TwlMain
|
||||||
|
|
||||||
|
Description: メイン関数です。
|
||||||
|
|
||||||
|
Arguments: なし。
|
||||||
|
|
||||||
|
Returns: なし。
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
void TwlMain(void)
|
||||||
|
{
|
||||||
|
InitInteruptSystem();
|
||||||
|
InitFileSystem();
|
||||||
|
|
||||||
|
GX_DispOn();
|
||||||
|
GXS_DispOn();
|
||||||
|
|
||||||
|
// SDがささってなかったら刺さるまで待つ
|
||||||
|
{
|
||||||
|
FSArchiveResource res;
|
||||||
|
while(!FS_GetArchiveResource("sdmc:/", &res))
|
||||||
|
{
|
||||||
|
*(u16*)HW_PLTT = static_cast<u16>(0x001f);
|
||||||
|
*(u16*)HW_DB_PLTT = static_cast<u16>(0x001f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PathList path;
|
||||||
|
|
||||||
|
for(u32 i = 0; i < sizeof(SUFFIX) / sizeof(char*); ++i)
|
||||||
|
{
|
||||||
|
PickupTargetPath("sdmc:/", SUFFIX[i], path);
|
||||||
|
}
|
||||||
|
CopyTarget("nand2:/photo", "sdmc:", path);
|
||||||
|
|
||||||
|
|
||||||
|
*(u16*)HW_PLTT = 0x001f << 10;
|
||||||
|
*(u16*)HW_DB_PLTT = 0x001f << 10;
|
||||||
|
// ランチャーに戻れるように、 終了しない
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
// フレーム更新。
|
||||||
|
{
|
||||||
|
OS_WaitVBlankIntr();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OS_Terminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: InitInteruptSystem
|
||||||
|
|
||||||
|
Description: 割り込みを初期化します。
|
||||||
|
|
||||||
|
Arguments: なし。
|
||||||
|
|
||||||
|
Returns: なし。
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
static void InitInteruptSystem()
|
||||||
|
{
|
||||||
|
// 個別割り込みフラグを全て不許可に
|
||||||
|
(void)OS_SetIrqMask(0);
|
||||||
|
|
||||||
|
// マスター割り込みフラグを許可に
|
||||||
|
(void)OS_EnableIrq();
|
||||||
|
|
||||||
|
// IRQ 割り込みを許可します
|
||||||
|
(void)OS_EnableInterrupts();
|
||||||
|
|
||||||
|
(void)OS_EnableIrqMask(OS_IE_SPFIFO_RECV);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: InitFileSystem
|
||||||
|
|
||||||
|
Description: FS を初期化して rom にアクセスできるようにします。
|
||||||
|
この関数を呼び出す前に InitInteruptSystem() が
|
||||||
|
呼ばれている必要があります。
|
||||||
|
|
||||||
|
Arguments: なし。
|
||||||
|
|
||||||
|
Returns: なし。
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
static void InitFileSystem()
|
||||||
|
{
|
||||||
|
// ARM7との通信FIFO割り込み許可
|
||||||
|
(void)OS_EnableIrqMask(OS_IE_SPFIFO_RECV);
|
||||||
|
|
||||||
|
// ファイルシステム初期化
|
||||||
|
FS_Init( FS_DMA_NOT_USE );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void PickupTargetPath(const char* root, const char* suffix, PathList& out)
|
||||||
|
{
|
||||||
|
FSFile fp;
|
||||||
|
FSDirectoryEntryInfo fdei;
|
||||||
|
BOOL result;
|
||||||
|
|
||||||
|
FS_InitFile(&fp);
|
||||||
|
// ディレクトリのオープン
|
||||||
|
result = FS_OpenDirectory(&fp, root, NULL);
|
||||||
|
if(!result)
|
||||||
|
{
|
||||||
|
OS_TPrintf("%s: Fail Open\nErrorCode:%d\n", root, FS_GetArchiveResultCode(root));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(FS_ReadDirectory(&fp, &fdei))
|
||||||
|
{
|
||||||
|
if(STD_StrCmp(fdei.longname, ".") == 0 || STD_StrCmp(fdei.longname, "..") == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
OS_TPrintf("%s:\n", fdei.longname);
|
||||||
|
// ディレクトリなら子を読む
|
||||||
|
if(fdei.attributes & FS_ATTRIBUTE_IS_DIRECTORY)
|
||||||
|
{
|
||||||
|
PickupTargetPath((std::string(root) + fdei.longname + "/").c_str(), suffix, out);
|
||||||
|
}
|
||||||
|
else // ファイルならoutに追加
|
||||||
|
{
|
||||||
|
// 拡張子を判定
|
||||||
|
if(std::string(fdei.longname).rfind(suffix) + STD_StrLen(suffix) == STD_StrLen(fdei.longname))
|
||||||
|
{
|
||||||
|
out.push_back(std::string(root) + fdei.longname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_CloseDirectory(&fp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CopyTarget(const char* to, const char* header, PathList& list)
|
||||||
|
{
|
||||||
|
PathList::iterator itr = list.begin(), end = list.end();
|
||||||
|
u16 color = 0;
|
||||||
|
for(; itr != end; ++itr)
|
||||||
|
{
|
||||||
|
std::string dest = std::string(to) + (*itr).substr(static_cast<u32>(STD_StrLen(header)));
|
||||||
|
|
||||||
|
CopyFile((*itr).c_str(), dest.c_str());
|
||||||
|
color = static_cast<u16>((color + 2) & 0x001f);
|
||||||
|
*(u16*)HW_PLTT = static_cast<u16>(color << 5);
|
||||||
|
*(u16*)HW_DB_PLTT = static_cast<u16>(color << 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CopyFile(const char* src, const char* dest)
|
||||||
|
{
|
||||||
|
FSFile sfp, dfp;
|
||||||
|
BOOL result;
|
||||||
|
std::string tmp_name = dest;
|
||||||
|
|
||||||
|
tmp_name += "___tmp";
|
||||||
|
|
||||||
|
OS_TPrintf("Copying %s...", dest);
|
||||||
|
|
||||||
|
// テンポラリファイルにコピー
|
||||||
|
FS_DeleteFile(tmp_name.c_str());
|
||||||
|
result = FS_CreateFileAuto(tmp_name.c_str(), FS_PERMIT_R | FS_PERMIT_W);
|
||||||
|
// result = FS_CreateFileAuto(dest, FS_PERMIT_R | FS_PERMIT_W);
|
||||||
|
if(!result)
|
||||||
|
{
|
||||||
|
OS_TPrintf("%s:Cant create\n", tmp_name.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = FS_OpenFileEx(&sfp, src, FS_FILEMODE_R);
|
||||||
|
if(!result)
|
||||||
|
{
|
||||||
|
OS_TPrintf("%s:Cant open\n", src);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = FS_OpenFileEx(&dfp, tmp_name.c_str(), FS_FILEMODE_W);
|
||||||
|
if(!result)
|
||||||
|
{
|
||||||
|
OS_TPrintf("%s:Cant open\n", src);
|
||||||
|
FS_CloseFile(&sfp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const u32 BUFSIZE = 4096;
|
||||||
|
u8 buf[BUFSIZE];
|
||||||
|
s32 count = 0;
|
||||||
|
while((count = FS_ReadFile(&sfp, buf, BUFSIZE)) > 0)
|
||||||
|
{
|
||||||
|
s32 write = FS_WriteFile(&dfp, buf, count);
|
||||||
|
if(write <= 0)
|
||||||
|
{
|
||||||
|
OS_TPrintf("Cant Write\n");
|
||||||
|
FS_CloseFile(&sfp);
|
||||||
|
FS_CloseFile(&dfp);
|
||||||
|
FS_DeleteFile(tmp_name.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FS_CloseFile(&sfp);
|
||||||
|
FS_CloseFile(&dfp);
|
||||||
|
|
||||||
|
// テンポラリファイルをリネーム
|
||||||
|
// すでにファイルが存在するなら削除
|
||||||
|
FS_DeleteFileAuto(dest);
|
||||||
|
FS_RenameFile(tmp_name.c_str(), dest);
|
||||||
|
|
||||||
|
OS_TPrintf("...ok\n");
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user