mirror of
https://github.com/simtactics/niotso.git
synced 2025-07-04 13:47:05 -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
|
@ -25,6 +25,9 @@ set(FILEHANDLER_SOURCES
|
|||
wav/read_wav.c
|
||||
xa/read_xa.c
|
||||
)
|
||||
if(WIN32)
|
||||
set(FILEHANDLER_SOURCES ${FILEHANDLER_SOURCES} resource.rc)
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler)
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#ifndef NOWINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define fhexport __declspec(dllexport)
|
||||
#ifdef WIN32
|
||||
#define fhexport __declspec(dllexport)
|
||||
#else
|
||||
#define fhexport __attribute__((visibility ("default")))
|
||||
#endif
|
||||
|
||||
struct Asset_t {
|
||||
uint32_t Group;
|
||||
|
@ -68,6 +68,13 @@ struct Sound_t {
|
|||
|
||||
namespace File {
|
||||
|
||||
inline unsigned GetFileSize(FILE * hFile){
|
||||
fseek(hFile, 0, SEEK_END);
|
||||
unsigned FileSize = ftell(hFile);
|
||||
fseek(hFile, 0, SEEK_SET);
|
||||
return FileSize;
|
||||
}
|
||||
|
||||
fhexport extern int Error;
|
||||
fhexport extern size_t FileSize;
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#define NOWINDOWS
|
||||
#include "FileHandler.hpp"
|
||||
#include <setjmp.h> //Used by libpng
|
||||
#include "bmp/read_bmp.h"
|
||||
|
|
|
@ -18,21 +18,9 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#else
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed long int32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef unsigned int uintptr_t;
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libfar.h"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue