mirror of
https://github.com/simtactics/niotso.git
synced 2025-07-12 17:22:23 -04:00
* Fixed MP3 playback with libmpg123
* Finally removed the dependency on libstdc++ with TDM GCC, reducing the size of the exe from 153kB to 87kB
This commit is contained in:
parent
f00c41f26c
commit
56f6487206
13 changed files with 63 additions and 53 deletions
|
@ -21,38 +21,37 @@
|
|||
namespace File {
|
||||
|
||||
int Error = 0;
|
||||
unsigned FileSize = 0;
|
||||
size_t FileSize = 0;
|
||||
|
||||
uint8_t * ReadFile(const char * Filename){
|
||||
HANDLE hFile = CreateFile(Filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||
if(hFile == INVALID_HANDLE_VALUE){
|
||||
File::Error = (GetLastError() == ERROR_FILE_NOT_FOUND) ? FERR_NOT_FOUND : FERR_OPEN;
|
||||
FILE * hFile = fopen(Filename, "rb");
|
||||
if(hFile == NULL){
|
||||
File::Error = FERR_OPEN;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FileSize = GetFileSize(hFile, NULL);
|
||||
FileSize = File::GetFileSize(hFile);
|
||||
if(FileSize == 0){
|
||||
CloseHandle(hFile);
|
||||
fclose(hFile);
|
||||
File::Error = FERR_BLANK;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t * InData = (uint8_t*) malloc(FileSize);
|
||||
if(InData == NULL){
|
||||
CloseHandle(hFile);
|
||||
fclose(hFile);
|
||||
File::Error = FERR_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DWORD bytestransferred;
|
||||
BOOL result = ::ReadFile(hFile, InData, FileSize, &bytestransferred, NULL);
|
||||
CloseHandle(hFile);
|
||||
|
||||
if(!result || bytestransferred != FileSize){
|
||||
size_t bytestransferred = fread(InData, 1, FileSize, hFile);
|
||||
if(bytestransferred != FileSize){
|
||||
free(InData);
|
||||
fclose(hFile);
|
||||
File::Error = FERR_READ;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return InData;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue