mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
SDに出力するResult用マクロの整理 git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@3 385bec56-5757-e545-9c3a-d8741f4650f1
154 lines
3.7 KiB
C++
154 lines
3.7 KiB
C++
/*---------------------------------------------------------------------------*
|
|
Project: Horizon
|
|
File: SdReaderWriter.cpp
|
|
|
|
Copyright 2009 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.
|
|
|
|
$Rev$
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
#include "SdReaderWriter.h"
|
|
#include "SdMountManager.h"
|
|
#include "CommonLogger.h"
|
|
|
|
namespace common
|
|
{
|
|
|
|
nn::Result SdReaderWriter::Initialize()
|
|
{
|
|
nn::Result result;
|
|
|
|
// 初期化済みなら何もしない
|
|
if(m_IsInitialized)
|
|
{
|
|
return nn::ResultSuccess();
|
|
}
|
|
|
|
result = SdMountManager::Mount();
|
|
if(result.IsSuccess())
|
|
{
|
|
m_IsInitialized = true;
|
|
return nn::ResultSuccess();
|
|
}
|
|
else
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
nn::Result SdReaderWriter::Finalize()
|
|
{
|
|
nn::Result result;
|
|
result = SdMountManager::Unmount();
|
|
|
|
m_IsInitialized = false;
|
|
return result;
|
|
}
|
|
|
|
nn::Result SdReaderWriter::WriteBuf(const wchar_t* path, void* buf, size_t size)
|
|
{
|
|
NN_ASSERT(path != NULL);
|
|
NN_ASSERT(size > 0);
|
|
|
|
nn::Result result;
|
|
result = Initialize();
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
|
|
result = file.TryInitialize(path, nn::fs::OPEN_MODE_WRITE | nn::fs::OPEN_MODE_CREATE);
|
|
if (result.IsSuccess())
|
|
{
|
|
s32 writeSize;
|
|
result = file.TryWrite(&writeSize, buf, size, true);
|
|
if (result.IsSuccess())
|
|
{
|
|
result = file.TryFlush();
|
|
if (result.IsFailure())
|
|
{
|
|
NN_LOG("SD TryFlush failed\n");
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NN_LOG("SD TryWrite failed\n");
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NN_LOG("SD TryInitialize failed\n");
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
}
|
|
|
|
file.Finalize();
|
|
|
|
result = Finalize();
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
|
|
return result;
|
|
}
|
|
|
|
nn::Result SdReaderWriter::ReadBuf(const wchar_t* path, void* buf, size_t size, size_t* totalSize)
|
|
{
|
|
NN_ASSERT(path != NULL);
|
|
NN_ASSERT(size > 0);
|
|
|
|
nn::Result result;
|
|
if(!m_IsInitialized)
|
|
{
|
|
Initialize();
|
|
}
|
|
|
|
result = file.TryInitialize(path, nn::fs::OPEN_MODE_READ);
|
|
if (result.IsSuccess())
|
|
{
|
|
s32 readSize;
|
|
result = file.TryRead(&readSize, buf, size);
|
|
if (result.IsSuccess())
|
|
{
|
|
// TODO バッファを超えるサイズのファイル読み込み
|
|
*totalSize = readSize;
|
|
}
|
|
else
|
|
{
|
|
NN_LOG("SD TryRead failed\n");
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NN_LOG("SD TryInitialize failed\n");
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
}
|
|
|
|
file.Finalize();
|
|
return result;
|
|
}
|
|
|
|
void SdReaderWriter::CreateDirectory(const wchar_t* path)
|
|
{
|
|
nn::Result result;
|
|
|
|
if(!m_IsInitialized)
|
|
{
|
|
Initialize();
|
|
}
|
|
|
|
NN_LOG("Create Directory %ls\n", path);
|
|
result = nn::fs::TryCreateDirectory(path);
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
|
|
result = Finalize();
|
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
|
|
|
}
|
|
|
|
}
|