summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZephiles <cae222@yahoo.com>2022-05-06 16:47:52 -0500
committerZephiles <cae222@yahoo.com>2022-05-06 16:47:52 -0500
commit5239faff5ac45a76deef6f6afc07799768c4e564 (patch)
treee5a0bee8cf02811f266aa6e9540bd5b185f40ac5
parent0d01c735382137ee5ad8333babf365cc47d14bf3 (diff)
Optimize ReadNAND
-rw-r--r--source/tools.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/source/tools.cpp b/source/tools.cpp
index 10eb644..222d1ec 100644
--- a/source/tools.cpp
+++ b/source/tools.cpp
@@ -193,41 +193,41 @@ namespace libtp::tools
using namespace libtp::gc_wii::nand;
NANDFileInfo fileInfo;
- int32_t result = NAND_RESULT_READY;
-
- // Since we can only read in and at increments of NAND_READ_SIZE do this to calculate the region we require
-
- int32_t adjustedOffset = ( offset / NAND_READ_SIZE ) * NAND_READ_SIZE;
- int32_t adjustedLength = ( 1 + ( ( offset - adjustedOffset + length - 1 ) / NAND_READ_SIZE ) ) * NAND_READ_SIZE;
-
- // Buffer might not be adjusted to the new length so create a temporary data buffer
- uint8_t* data = new uint8_t[adjustedLength];
+ int32_t result;
- memset( buffer, 0, length );
- memset( data, 0, adjustedLength );
+ int32_t adjustedOffset;
+ int32_t adjustedLength;
+ uint8_t* data;
// Read data
- result = NANDOpen( const_cast<char*>( fileName ), &fileInfo, NAND_OPEN_READ );
-
+ result = NANDOpen( fileName, &fileInfo, NAND_OPEN_READ );
if ( result == NAND_RESULT_READY )
{
- // result = storage_read( &fileInfo, data, adjustedLength, adjustedOffset, NAND_OPEN_READ );
result = NANDSeek( &fileInfo, adjustedOffset, NAND_SEEK_START );
if ( result == NAND_RESULT_READY )
{
+ // Since we can only read in and at increments of NAND_READ_SIZE do this to calculate the region we require
+ adjustedOffset = ( offset / NAND_READ_SIZE ) * NAND_READ_SIZE;
+ adjustedLength = ( 1 + ( ( offset - adjustedOffset + length - 1 ) / NAND_READ_SIZE ) ) * NAND_READ_SIZE;
+
+ // Buffer might not be adjusted to the new length so create a temporary data buffer
+ data = new uint8_t[adjustedLength];
+
int32_t r = NANDRead( &fileInfo, data, adjustedLength );
result = ( r > 0 ) ? NAND_RESULT_READY : r;
+
+ if ( result == NAND_RESULT_READY )
+ {
+ // Copy data to the user's buffer
+ memcpy( buffer, data + ( offset - adjustedOffset ), length );
+ }
+
+ delete[] data;
}
NANDClose( &fileInfo );
-
- // Copy data to the user's buffer
- memcpy( buffer, data + ( offset - adjustedOffset ), length );
}
// NANDOpen
- // Clean up
- delete[] data;
-
return result;
}