mirror of
https://github.com/rvtr/GodMode9i.git
synced 2025-06-18 19:05:30 -04:00
Fix getFileSize failing (#145)
* Try to fix getFileSize failing * Fix file sizes over 2 GB
This commit is contained in:
parent
3e92e876e9
commit
750e3cbf99
@ -47,7 +47,7 @@ GRAPHICS := ../gfx
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -mthumb-interwork
|
||||
|
||||
CFLAGS := -g -Wall -O2\
|
||||
CFLAGS := -g -Wall -Wno-psabi -O2\
|
||||
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
|
||||
-ffast-math \
|
||||
$(ARCH)
|
||||
|
@ -159,13 +159,13 @@ void dm_drawBottomScreen(void) {
|
||||
switch(dmOperations[dmCursorPosition]) {
|
||||
case DriveMenuOperation::sdCard:
|
||||
font->printf(0, 0, false, Alignment::left, Palette::white, STR_SDCARD_LABEL.c_str(), sdLabel[0] == 0 ? STR_UNTITLED.c_str() : sdLabel);
|
||||
font->printf(0, 1, false, Alignment::left, Palette::white, STR_SD_FAT.c_str(), getDriveBytes(sdSize).c_str());
|
||||
font->printf(0, 2, false, Alignment::left, Palette::white, STR_N_FREE.c_str(), getDriveBytes(getBytesFree("sd:/")).c_str());
|
||||
font->printf(0, 1, false, Alignment::left, Palette::white, STR_SD_FAT.c_str(), getBytes(sdSize).c_str());
|
||||
font->printf(0, 2, false, Alignment::left, Palette::white, STR_N_FREE.c_str(), getBytes(getBytesFree("sd:/")).c_str());
|
||||
break;
|
||||
case DriveMenuOperation::flashcard:
|
||||
font->printf(0, 0, false, Alignment::left, Palette::white, STR_FLASHCARD_LABEL.c_str(), fatLabel[0] == 0 ? STR_UNTITLED.c_str() : fatLabel);
|
||||
font->printf(0, 1, false, Alignment::left, Palette::white, STR_SLOT1_FAT.c_str(), getDriveBytes(fatSize).c_str());
|
||||
font->printf(0, 2, false, Alignment::left, Palette::white, STR_N_FREE.c_str(), getDriveBytes(getBytesFree("fat:/")).c_str());
|
||||
font->printf(0, 1, false, Alignment::left, Palette::white, STR_SLOT1_FAT.c_str(), getBytes(fatSize).c_str());
|
||||
font->printf(0, 2, false, Alignment::left, Palette::white, STR_N_FREE.c_str(), getBytes(getBytesFree("fat:/")).c_str());
|
||||
break;
|
||||
case DriveMenuOperation::gbaCart:
|
||||
font->printf(0, 0, false, Alignment::left, Palette::white, STR_GBA_GAMECART.c_str(), romTitle[1]);
|
||||
@ -185,17 +185,17 @@ void dm_drawBottomScreen(void) {
|
||||
break;
|
||||
case DriveMenuOperation::ramDrive:
|
||||
font->print(0, 0, false, STR_RAMDRIVE_LABEL);
|
||||
font->printf(0, 1, false, Alignment::left, Palette::white, STR_RAMDRIVE_FAT.c_str(), getDriveBytes(ramdSize).c_str());
|
||||
font->printf(0, 2, false, Alignment::left, Palette::white, STR_N_FREE.c_str(), getDriveBytes(getBytesFree("ram:/")).c_str());
|
||||
font->printf(0, 1, false, Alignment::left, Palette::white, STR_RAMDRIVE_FAT.c_str(), getBytes(ramdSize).c_str());
|
||||
font->printf(0, 2, false, Alignment::left, Palette::white, STR_N_FREE.c_str(), getBytes(getBytesFree("ram:/")).c_str());
|
||||
break;
|
||||
case DriveMenuOperation::sysNand:
|
||||
font->print(0, 0, false, STR_SYSNAND_LABEL);
|
||||
font->printf(0, 1, false, Alignment::left, Palette::white, STR_SYSNAND_FAT.c_str(), getDriveBytes(nandSize).c_str());
|
||||
font->printf(0, 2, false, Alignment::left, Palette::white, STR_N_FREE.c_str(), getDriveBytes(getBytesFree("nand:/")).c_str());
|
||||
font->printf(0, 1, false, Alignment::left, Palette::white, STR_SYSNAND_FAT.c_str(), getBytes(nandSize).c_str());
|
||||
font->printf(0, 2, false, Alignment::left, Palette::white, STR_N_FREE.c_str(), getBytes(getBytesFree("nand:/")).c_str());
|
||||
break;
|
||||
case DriveMenuOperation::fatImage:
|
||||
font->printf(0, 0, false, Alignment::left, Palette::white, STR_FAT_LABEL.c_str(), imgLabel[0] == 0 ? STR_UNTITLED.c_str() : imgLabel);
|
||||
font->printf(0, 1, false, Alignment::left, Palette::white, STR_FAT_IMAGE.c_str(), getDriveBytes(imgSize).c_str());
|
||||
font->printf(0, 1, false, Alignment::left, Palette::white, STR_FAT_IMAGE.c_str(), getBytes(imgSize).c_str());
|
||||
break;
|
||||
case DriveMenuOperation::none:
|
||||
break;
|
||||
|
@ -50,40 +50,6 @@ u64 fatSize = 0;
|
||||
u64 imgSize = 0;
|
||||
u32 ramdSize = 0;
|
||||
|
||||
static float getGbNumber(u64 bytes) {
|
||||
float gbNumber = 0.0f;
|
||||
for (u64 i = 0; i <= bytes; i += 0x6666666) {
|
||||
gbNumber += 0.1f;
|
||||
}
|
||||
return gbNumber;
|
||||
}
|
||||
|
||||
static float getTbNumber(u64 bytes) {
|
||||
float tbNumber = 0.0f;
|
||||
for (u64 i = 0; i <= bytes; i += 0x1999999999) {
|
||||
tbNumber += 0.01f;
|
||||
}
|
||||
return tbNumber;
|
||||
}
|
||||
|
||||
std::string getDriveBytes(u64 bytes)
|
||||
{
|
||||
char buffer[32];
|
||||
if (bytes < (1024 * 1024))
|
||||
sniprintf(buffer, sizeof(buffer), STR_N_KB.c_str(), (int)bytes >> 10);
|
||||
|
||||
else if (bytes >= (1024 * 1024) && bytes < (1024 * 1024 * 1024))
|
||||
sniprintf(buffer, sizeof(buffer), STR_N_MB.c_str(), (int)bytes >> 20);
|
||||
|
||||
else if (bytes >= 0x40000000 && bytes < 0x10000000000)
|
||||
snprintf(buffer, sizeof(buffer), STR_N_GB_FLOAT.c_str(), getGbNumber(bytes));
|
||||
|
||||
else
|
||||
snprintf(buffer, sizeof(buffer), STR_N_TB_FLOAT.c_str(), getTbNumber(bytes));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
const char* getDrivePath(void) {
|
||||
switch (currentDrive) {
|
||||
case Drive::sdCard:
|
||||
|
@ -34,7 +34,6 @@ extern u64 sdSize;
|
||||
extern u64 fatSize;
|
||||
extern u64 imgSize;
|
||||
extern u32 ramdSize;
|
||||
extern std::string getDriveBytes(u64 bytes);
|
||||
|
||||
extern const char* getDrivePath(void);
|
||||
|
||||
|
@ -20,7 +20,23 @@ std::vector<ClipboardFile> clipboard;
|
||||
bool clipboardOn = false;
|
||||
bool clipboardUsed = true;
|
||||
|
||||
std::string getBytes(int bytes) {
|
||||
static float getGbNumber(u64 bytes) {
|
||||
float gbNumber = 0.0f;
|
||||
for (u64 i = 0; i <= bytes; i += 0x6666666) {
|
||||
gbNumber += 0.1f;
|
||||
}
|
||||
return gbNumber;
|
||||
}
|
||||
|
||||
static float getTbNumber(u64 bytes) {
|
||||
float tbNumber = 0.0f;
|
||||
for (u64 i = 0; i <= bytes; i += 0x1999999999) {
|
||||
tbNumber += 0.01f;
|
||||
}
|
||||
return tbNumber;
|
||||
}
|
||||
|
||||
std::string getBytes(off_t bytes) {
|
||||
char buffer[32];
|
||||
if (bytes == 1)
|
||||
sniprintf(buffer, sizeof(buffer), STR_1_BYTE.c_str());
|
||||
@ -34,23 +50,19 @@ std::string getBytes(int bytes) {
|
||||
else if (bytes < (1024 * 1024 * 1024))
|
||||
sniprintf(buffer, sizeof(buffer), STR_N_MB.c_str(), bytes >> 20);
|
||||
|
||||
else if (bytes < 0x10000000000)
|
||||
snprintf(buffer, sizeof(buffer), STR_N_GB_FLOAT.c_str(), getGbNumber(bytes));
|
||||
|
||||
else
|
||||
sniprintf(buffer, sizeof(buffer), STR_N_GB.c_str(), bytes >> 30);
|
||||
snprintf(buffer, sizeof(buffer), STR_N_TB_FLOAT.c_str(), getTbNumber(bytes));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
off_t getFileSize(const char *fileName) {
|
||||
FILE* fp = fopen(fileName, "rb");
|
||||
off_t fsize = 0;
|
||||
if (fp) {
|
||||
fseek(fp, 0, SEEK_END);
|
||||
fsize = ftell(fp); // Get source file's size
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return fsize;
|
||||
struct stat st;
|
||||
stat(fileName, &st);
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
bool calculateSHA1(const char *fileName, u8 *sha1) {
|
||||
|
@ -19,7 +19,7 @@ extern std::vector<ClipboardFile> clipboard;
|
||||
extern bool clipboardOn;
|
||||
extern bool clipboardUsed;
|
||||
|
||||
extern std::string getBytes(int bytes);
|
||||
extern std::string getBytes(off_t bytes);
|
||||
|
||||
extern off_t getFileSize(const char *fileName);
|
||||
extern bool calculateSHA1(const char *fileName, u8 *sha1);
|
||||
|
@ -1,64 +1,64 @@
|
||||
/*-----------------------------------------------------------------
|
||||
Copyright (C) 2005 - 2010
|
||||
Michael "Chishm" Chisholm
|
||||
Dave "WinterMute" Murphy
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FILE_BROWSE_H
|
||||
#define FILE_BROWSE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct DirEntry {
|
||||
DirEntry(std::string name, size_t size, bool isDirectory, bool isApp, bool selected = false) : name(name), size(size), isDirectory(isDirectory), isApp(isApp), selected(selected) {}
|
||||
DirEntry() {}
|
||||
|
||||
std::string name;
|
||||
int size;
|
||||
bool isDirectory;
|
||||
bool isApp;
|
||||
bool selected = false;
|
||||
};
|
||||
|
||||
enum class FileOperation {
|
||||
none,
|
||||
bootFile,
|
||||
bootstrapFile,
|
||||
mountNitroFS,
|
||||
ndsInfo,
|
||||
trimNds,
|
||||
mountImg,
|
||||
restoreSaveNds,
|
||||
restoreSaveGba,
|
||||
showInfo,
|
||||
copySdOut,
|
||||
copyFatOut,
|
||||
calculateSHA1,
|
||||
hexEdit,
|
||||
loadFont,
|
||||
};
|
||||
|
||||
bool extension(const std::string_view filename, const std::vector<std::string_view> &extensions);
|
||||
|
||||
std::string browseForFile (void);
|
||||
void getDirectoryContents (std::vector<DirEntry>& dirContents);
|
||||
|
||||
|
||||
|
||||
#endif //FILE_BROWSE_H
|
||||
/*-----------------------------------------------------------------
|
||||
Copyright (C) 2005 - 2010
|
||||
Michael "Chishm" Chisholm
|
||||
Dave "WinterMute" Murphy
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FILE_BROWSE_H
|
||||
#define FILE_BROWSE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct DirEntry {
|
||||
DirEntry(std::string name, off_t size, bool isDirectory, bool isApp, bool selected = false) : name(name), size(size), isDirectory(isDirectory), isApp(isApp), selected(selected) {}
|
||||
DirEntry() {}
|
||||
|
||||
std::string name;
|
||||
off_t size;
|
||||
bool isDirectory;
|
||||
bool isApp;
|
||||
bool selected = false;
|
||||
};
|
||||
|
||||
enum class FileOperation {
|
||||
none,
|
||||
bootFile,
|
||||
bootstrapFile,
|
||||
mountNitroFS,
|
||||
ndsInfo,
|
||||
trimNds,
|
||||
mountImg,
|
||||
restoreSaveNds,
|
||||
restoreSaveGba,
|
||||
showInfo,
|
||||
copySdOut,
|
||||
copyFatOut,
|
||||
calculateSHA1,
|
||||
hexEdit,
|
||||
loadFont,
|
||||
};
|
||||
|
||||
bool extension(const std::string_view filename, const std::vector<std::string_view> &extensions);
|
||||
|
||||
std::string browseForFile (void);
|
||||
void getDirectoryContents (std::vector<DirEntry>& dirContents);
|
||||
|
||||
|
||||
|
||||
#endif //FILE_BROWSE_H
|
||||
|
@ -182,10 +182,9 @@ STRING(START_RETURN_B_BACKSPACE, "(START Return, \\B Backspace)")
|
||||
|
||||
// Byte counts
|
||||
STRING(1_BYTE, "1 Byte")
|
||||
STRING(N_BYTES, "%d Bytes")
|
||||
STRING(N_KB, "%d KB")
|
||||
STRING(N_MB, "%d MB")
|
||||
STRING(N_GB, "%d GB")
|
||||
STRING(N_BYTES, "%lld Bytes")
|
||||
STRING(N_KB, "%lld KB")
|
||||
STRING(N_MB, "%lld MB")
|
||||
STRING(N_GB_FLOAT, "%.1f GB")
|
||||
STRING(N_TB_FLOAT, "%.1f TB")
|
||||
|
||||
|
@ -172,10 +172,9 @@ A_APPLY_B_CANCEL=(\A apply, \B cancel)
|
||||
START_RETURN_B_BACKSPACE=(START Return, \B Backspace)
|
||||
|
||||
1_BYTE=1 Byte
|
||||
N_BYTES=%d Bytes
|
||||
N_KB=%d KB
|
||||
N_MB=%d MB
|
||||
N_GB=%d GB
|
||||
N_BYTES=%lld Bytes
|
||||
N_KB=%lld KB
|
||||
N_MB=%lld MB
|
||||
N_GB_FLOAT=%.1f GB
|
||||
N_TB_FLOAT=%.1f TB
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user