YAWM-ModMii-Edition/source/fileops.c
0verjoY 31d2402d59 - FAT stuff:
- Refactored almost everything
  - Will mount available devices at start and unmount at exit app
  - Device select screen will now only show avialable devices
  - Added option to remount devices in the select screen
  - Will now warn if region checks are disabled in select screen
  - Added option to reenable region checks in select screen
  - Probably even more changes

- SM wad installation:
  - Changed the region check functions (WIP)
  - While you install a SM you'll now be able to retain Priiloader

- Bug fixes
- Refactoring
- Even more bug fixes
2023-02-19 20:47:31 +01:00

81 lines
1.1 KiB
C

#include <stdio.h>
#include <malloc.h>
#include "fileops.h"
bool FSOPFileExists(const char* file)
{
FILE* f;
f = fopen(file, "rb");
if (f)
{
fclose(f);
return true;
}
return false;
}
bool FSOPFolderExists(const char* path)
{
DIR* dir;
dir = opendir(path);
if (dir)
{
closedir(dir);
return true;
}
return false;
}
size_t FSOPGetFileSizeBytes(const char* path)
{
FILE* f;
size_t size = 0;
f = fopen(path, "rb");
if (!f)
return 0;
fseek(f, 0, SEEK_END);
size = ftell(f);
fclose(f);
return size;
}
void FSOPDeleteFile(const char* file)
{
if (!FSOPFileExists(file))
return;
remove(file);
}
void FSOPMakeFolder(const char* path)
{
if (FSOPFolderExists(path))
return;
mkdir(path, S_IREAD | S_IWRITE);
}
s32 FSOPReadOpenFile(FILE* fp, void* buffer, u32 offset, u32 length)
{
fseek(fp, offset, SEEK_SET);
return fread(buffer, length, 1, fp);
}
s32 FSOPReadOpenFileA(FILE* fp, void** buffer, u32 offset, u32 length)
{
*buffer = memalign(32, length);
if (!*buffer)
return -1;
s32 ret = FSOPReadOpenFile(fp, *buffer, offset, length);
if (ret < 0)
free(*buffer);
return ret;
}