//
// Irrlicht Wrapper for Imperative Languages
// Frank Dodd (2006)
//
// Additional Work
// Michael Taupitz (2006)
//
// This wrapper DLL encapsulates a sub-set of the features of the powerful
// Irrlicht 3D Graphics Engine exposing the Object Oriented architecture and
// providing a functional 3D SDK for languages that are not object oriented.
//
// This source was created with the help of the great examples in the Irrlicht
// SDK and the excellent Irrlicht documentation. This software was developed
// using the GCC compiler and Code::Blocks IDE
//

/* ////////////////////////////////////////////////////////////////////////////
includes
*/
#include "irrlichtwrapper.h"
#include "CCallbackFileSystem.h"


/* ////////////////////////////////////////////////////////////////////////////
global variables
*/

/* ////////////////////////////////////////////////////////////////////////////
external variables
*/
extern IrrlichtDevice *device;
extern IVideoDriver* driver;
extern ISceneManager* smgr;
extern IGUIEnvironment* guienv;


/* ////////////////////////////////////////////////////////////////////////////
Global Function Declarations

all of the below functions are declared as C functions and are exposed without
any mangled names so that they can be easily imported into imperative
languages like FreeBasic
*/
extern "C"
{

/* ////////////////////////////////////////////////////////////////////////////
FILING SYSTEM FUNCTIONS
*/
/* ----------------------------------------------------------------------------
add zip archive to the filing system allowing you to load files straight out of
the zip file.
*/
/****f* Filing/IrrAddZipFile
* NAME
*    IrrAddZipFile - Adds an zip archive to the file system.
* SYNOPSIS
*    IrrAddZipFile(filename.s, bIgnoreCase.l, bIgnorePaths.l)
* INPUTS
*   filename.s          - Filename of the zip archive to add to the file system.
*   bIgnoreCase.l       - If set to true, files in the archive can be accessed without writing all letters in the right case.
*  bIgnorePaths         - If set to true, files in the added archive can be accessed without its complete path.
* FUNCTION
*   Adds an zip archive to the file system.
*   After calling this, the Irrlicht Engine will search and open files directly from
*   this archive too. This is useful for hiding data from the end user, speeding up
*   file access and making it possible to access for example Quake3 .pk3 files, which
*   are nothing different than .zip files.
* RESULT
*    Returns #True if the archive was added successful, #False if not
* HISTORY
*   Added return-value in Version 1.05 by M.Taupitz
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrAddZipFile(filename.p-ascii, bIgnoreCase.l, bIgnorePaths.l)
*/
STATIC_EXPORT bool DLL_EXPORT IrrAddZipFile( char *cptrFile, bool boIgnoreCase, bool boIgnorePaths )
{
    // add an archive to the file system
    return device->getFileSystem()->addZipFileArchive( cptrFile, boIgnoreCase, boIgnorePaths);
}

/****f* Filing/IrrAddPakFile
* NAME
*    IrrAddPakFile - Adds an pak archive to the file system.
* SYNOPSIS
*    IrrAddPakFile(filename.s, bIgnoreCase.l, bIgnorePaths.l)
* INPUTS
*   filename.s          - Filename of the zip archive to add to the file system.
*   bIgnoreCase.l       - If set to true, files in the archive can be accessed without writing all letters in the right case.
*  bIgnorePaths         - If set to true, files in the added archive can be accessed without its complete path.
* FUNCTION
*   After calling this, the Irrlicht Engine will search and open files directly from this archive too.
*   This is useful for hiding data from the end user, speeding up file access and making it possible to
*    access for example Quake2/KingPin/Hexen2 .pak files.
* RESULT
*    Returns #True if the archive was added successful, #False if not
* HISTORY
*   Added in Version 1.05 by M.Taupitz
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrAddPakFile(filename.p-ascii, bIgnoreCase.l, bIgnorePaths.l)
*/
STATIC_EXPORT bool DLL_EXPORT IrrAddPakFile( char *cptrFile, bool boIgnoreCase, bool boIgnorePaths )
{
    // add an archive to the file system
    return device->getFileSystem()->addPakFileArchive( cptrFile, boIgnoreCase, boIgnorePaths);
}


/****f* Filing/IrrAddUnzipFile
* NAME
*    IrrAddUnzipFile - Adds an unzipped archive to the file system.
* SYNOPSIS
*    IrrAddUnzipFile(filename.s, bIgnoreCase.l, bIgnorePaths.l)
* INPUTS
*   filename.s          - Filename of the zip archive to add to the file system.
*   bIgnoreCase.l       - If set to true, files in the archive can be accessed without writing all letters in the right case.
*  bIgnorePaths         - If set to true, files in the added archive can be accessed without its complete path.
* FUNCTION
*   Adds an unzipped archive ( or basedirectory with subdirectories..) to the file system.
* RESULT
*    Returns #True if the archive was added successful, #False if not
* HISTORY
*   Added in Version 1.05 by M.Taupitz
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrAddUnzipFile(filename.p-ascii, bIgnoreCase.l, bIgnorePaths.l)
*/
STATIC_EXPORT bool DLL_EXPORT IrrAddUnzipFile( char *cptrFile, bool boIgnoreCase, bool boIgnorePaths )
{
    // add an archive to the file system
//    return device->getFileSystem()->addUnZipFileArchive( cptrFile, boIgnoreCase, boIgnorePaths);
    return device->getFileSystem()->addFolderFileArchive( cptrFile, boIgnoreCase, boIgnorePaths);
}


//1.3
STATIC_EXPORT bool DLL_EXPORT IrrAddFolderFileArchive( char *cptrFile, bool boIgnoreCase, bool boIgnorePaths )
{
    // add an archive to the file system
    return device->getFileSystem()->addFolderFileArchive( cptrFile, boIgnoreCase, boIgnorePaths);
}


/****f* Filing/IrrChangeWorkingDirectory
* NAME
*    IrrChangeWorkingDirectory - set irrlicht current working directory
* SYNOPSIS
*    IrrChangeWorkingDirectory(path.s)
* INPUTS
*   path.s          - new working directory
* FUNCTION
*   Changes the current Working Directory to the overgiven string.
* RESULT
*    nothing
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrChangeWorkingDirectory(path.p-ascii)
*/
STATIC_EXPORT void DLL_EXPORT IrrChangeWorkingDirectory( char *cptrPath )
{
    // Changes the current Working Directory to the overgiven string.
    device->getFileSystem()->changeWorkingDirectoryTo( cptrPath );
}

/****f* Filing/IrrGetWorkingDirectory
* NAME
*    IrrGetWorkingDirectory - get irrlicht current working directory
* SYNOPSIS
*    *path.l = IrrGetWorkingDirectory()
* INPUTS
* FUNCTION
*   retrieves the current Working Directory
* RESULT
*    pointer to a String, with the working directory
****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrGetWorkingDirectory()
*/
STATIC_EXPORT const char * DLL_EXPORT IrrGetWorkingDirectory( void )
{
    // Returns the string of the current working directory.
    return device->getFileSystem()->getWorkingDirectory();
}


/****
* This is for creating the PB-Importfile, and avoiding to make everything manual
#PBIMPORT:IrrCreateCallbackFileSystem(*ptrToFSCallback)
*/
STATIC_EXPORT bool DLL_EXPORT IrrCreateCallbackFileSystem( FileSystemCallbackPtr callBack )
{
    IExternFileSystem* efs = new CCallbackFileSystem(callBack);
    if (efs)
    {
        device->getFileSystem()->addExternFileSysten(efs);
        return true;
    }
    return false;
}


/* ////////////////////////////////////////////////////////////////////////////
all of the above functions are declared as C functions and are exposed without
any mangled names
*/
}
