From c0606a32db2c30abf4ab8f54ab44c6624be89c32 Mon Sep 17 00:00:00 2001 From: waker Date: Tue, 1 Feb 2011 20:23:41 +0100 Subject: added vfs support to adplug (libbinio) --- plugins/adplug/adplug-db.cpp | 3 +-- plugins/adplug/libbinio/binfile.cpp | 28 ++++++++++++++++++---------- plugins/adplug/libbinio/binfile.h | 4 +++- 3 files changed, 22 insertions(+), 13 deletions(-) (limited to 'plugins/adplug') diff --git a/plugins/adplug/adplug-db.cpp b/plugins/adplug/adplug-db.cpp index fb12f12e..1f096727 100644 --- a/plugins/adplug/adplug-db.cpp +++ b/plugins/adplug/adplug-db.cpp @@ -46,8 +46,7 @@ int _Unwind_GetIPInfo; extern "C" { extern DB_decoder_t adplug_plugin; -static DB_functions_t *deadbeef; - +DB_functions_t *deadbeef; const char *adplug_exts[] = { "A2M", "ADL", "AMD", "BAM", "CFF", "CMF", "D00", "DFM", "DMO", "DRO", "DTM", "HSC", "HSP", "IMF", "KSM", "LAA", "LDS", "M", "MAD", "MKJ", "MSC", "MTK", "RAD", "RAW", "RIX", "ROL", "S3M", "SA2", "SAT", "SCI", "SNG", "XAD", "XMS", "XSM", "JBM", NULL }; diff --git a/plugins/adplug/libbinio/binfile.cpp b/plugins/adplug/libbinio/binfile.cpp index 336f1b3b..a20315ac 100644 --- a/plugins/adplug/libbinio/binfile.cpp +++ b/plugins/adplug/libbinio/binfile.cpp @@ -22,6 +22,8 @@ #include "binfile.h" +extern DB_functions_t *deadbeef; + /***** binfbase *****/ binfbase::binfbase() @@ -37,7 +39,8 @@ binfbase::~binfbase() void binfbase::close() { if(f != NULL) { - if(fclose(f) == EOF) err |= Fatal; else f = NULL; + deadbeef->fclose(f); + f = NULL; } else err |= NotOpen; } @@ -49,9 +52,9 @@ void binfbase::seek(long pos, Offset offs) if(f == NULL) { err |= NotOpen; return; } switch(offs) { - case Set: error = fseek(f, pos, SEEK_SET); break; - case Add: error = fseek(f, pos, SEEK_CUR); break; - case End: error = fseek(f, pos, SEEK_END); break; + case Set: error = deadbeef->fseek(f, pos, SEEK_SET); break; + case Add: error = deadbeef->fseek(f, pos, SEEK_CUR); break; + case End: error = deadbeef->fseek(f, pos, SEEK_END); break; } if(error == -1) err |= Fatal; @@ -63,7 +66,7 @@ long binfbase::pos() if(f == NULL) { err |= NotOpen; return 0; } - pos = ftell(f); + pos = deadbeef->ftell(f); if(pos == -1) { err |= Fatal; @@ -96,7 +99,7 @@ binifstream::~binifstream() void binifstream::open(const char *filename, const Mode mode) { - f = fopen(filename, "rb"); + f = deadbeef->fopen(filename); if(f == NULL) switch(errno) { @@ -118,8 +121,9 @@ binifstream::Byte binifstream::getByte() int read; if(f != NULL) { - read = fgetc(f); - if(read == EOF) err |= Eof; + if (1 != deadbeef->fread (&read, 1, 1, f)) { + err |= Eof; + } return (Byte)read; } else { err |= NotOpen; @@ -151,6 +155,7 @@ binofstream::~binofstream() void binofstream::open(const char *filename, const Mode mode) { +#if 0 const char *modestr = "wb"; // Check if append mode is desired @@ -168,6 +173,7 @@ void binofstream::open(const char *filename, const Mode mode) case ENOENT: err |= NotFound; break; default: err |= NotOpen; break; } +#endif } #if BINIO_ENABLE_STRING @@ -179,10 +185,12 @@ void binofstream::open(const std::string &filename, const Mode mode) void binofstream::putByte(Byte b) { +#if 0 if(f == NULL) { err |= NotOpen; return; } if(fputc(b, f) == EOF) err |= Fatal; +#endif } /***** binfstream *****/ @@ -220,11 +228,11 @@ void binfstream::open(const char *filename, const Mode mode) if(mode & Append) // Create & append modestr = "a+b"; - f = fopen(filename, modestr); + f = deadbeef->fopen(filename); // NoCreate & append (emulated -- not possible with standard C fopen()) if(f != NULL && (mode & Append) && (mode & NoCreate)) - ferror = fseek(f, 0, SEEK_END); + ferror = deadbeef->fseek(f, 0, SEEK_END); if(f == NULL || ferror == -1) { switch(errno) { diff --git a/plugins/adplug/libbinio/binfile.h b/plugins/adplug/libbinio/binfile.h index ad24baee..013e5777 100644 --- a/plugins/adplug/libbinio/binfile.h +++ b/plugins/adplug/libbinio/binfile.h @@ -24,6 +24,8 @@ #include "binio.h" +#include "../../../deadbeef.h" + class binfbase: virtual public binio { public: @@ -47,7 +49,7 @@ public: virtual long pos(); protected: - FILE *f; + DB_FILE *f; }; class binifstream: public binistream, virtual public binfbase -- cgit v1.2.3