2012-02-22 16:25:23 -06:00
|
|
|
/*
|
2012-05-21 23:27:44 -05:00
|
|
|
FileHandler - General-purpose file handling library for Niotso
|
|
|
|
FileHandler.hpp - Copyright (c) 2011-2012 Niotso Project <http://niotso.org/>
|
|
|
|
Author(s): Fatbag <X-Fi6@phppoll.org>
|
2012-02-22 16:25:23 -06:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2012-02-27 02:55:53 -06:00
|
|
|
#ifndef FILEHANDLER_HPP
|
|
|
|
#define FILEHANDLER_HPP
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
2012-04-29 00:44:41 -05:00
|
|
|
#include <string.h>
|
2012-02-27 02:55:53 -06:00
|
|
|
|
2012-06-28 07:00:45 -05:00
|
|
|
#ifdef WIN32
|
2024-05-02 20:32:10 +02:00
|
|
|
#define fhexport __declspec(dllexport);
|
2012-06-28 07:00:45 -05:00
|
|
|
#else
|
2024-04-28 09:04:43 -04:00
|
|
|
#define fhexport __attribute__((visibility("default")));
|
2012-06-28 07:00:45 -05:00
|
|
|
#endif
|
2012-04-29 00:44:41 -05:00
|
|
|
|
2024-04-29 03:04:46 -04:00
|
|
|
struct Asset_t
|
2024-04-28 09:04:43 -04:00
|
|
|
{
|
2024-04-29 03:04:46 -04:00
|
|
|
uint32_t Group;
|
|
|
|
uint32_t File;
|
|
|
|
uint32_t Type;
|
|
|
|
};
|
2024-04-28 09:04:43 -04:00
|
|
|
|
2024-04-29 03:04:46 -04:00
|
|
|
enum FErr
|
|
|
|
{
|
|
|
|
FERR_NOT_FOUND,
|
|
|
|
FERR_OPEN,
|
|
|
|
FERR_BLANK,
|
|
|
|
FERR_MEMORY,
|
|
|
|
FERR_READ,
|
|
|
|
FERR_UNRECOGNIZED,
|
|
|
|
FERR_INVALIDDATA
|
|
|
|
};
|
2024-04-28 09:04:43 -04:00
|
|
|
|
2024-04-29 03:04:46 -04:00
|
|
|
enum ImageFormat_t
|
|
|
|
{
|
|
|
|
FIMG_BGR24,
|
|
|
|
FIMG_BGRA32
|
|
|
|
};
|
2024-04-28 09:04:43 -04:00
|
|
|
|
2024-04-29 03:04:46 -04:00
|
|
|
struct Image_t
|
|
|
|
{
|
|
|
|
unsigned Width, Height;
|
|
|
|
ImageFormat_t Format;
|
|
|
|
uint8_t *Data;
|
|
|
|
};
|
2024-04-28 09:04:43 -04:00
|
|
|
|
2024-04-29 03:04:46 -04:00
|
|
|
struct Sound_t
|
|
|
|
{
|
|
|
|
unsigned Channels;
|
|
|
|
unsigned SamplingRate;
|
|
|
|
unsigned BitDepth;
|
|
|
|
unsigned Duration;
|
|
|
|
uint8_t *Data;
|
|
|
|
};
|
2012-02-22 16:25:23 -06:00
|
|
|
|
2024-05-02 20:32:10 +02:00
|
|
|
namespace File {
|
|
|
|
inline size_t GetFileSize(FILE * hFile){
|
|
|
|
fseek(hFile, 0, SEEK_END);
|
|
|
|
size_t FileSize = ftell(hFile);
|
|
|
|
fseek(hFile, 0, SEEK_SET);
|
|
|
|
return FileSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int Error;
|
|
|
|
extern size_t FileSize;
|
|
|
|
|
2024-05-03 02:40:50 +02:00
|
|
|
uint8_t * ReadFile(const char * Filename);
|
|
|
|
Image_t * ReadImageFile(const char * Filename);
|
|
|
|
Sound_t * ReadSoundFile(const char * Filename);
|
2024-05-02 20:32:10 +02:00
|
|
|
}
|
|
|
|
|
2012-02-27 02:55:53 -06:00
|
|
|
#endif
|