]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/vfswad/vfswad.cpp
uncrustify! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / plugins / vfswad / vfswad.cpp
1 /*
2    Copyright (c) 2001, Loki software, inc.
3    All rights reserved.
4
5    Redistribution and use in source and binary forms, with or without modification,
6    are permitted provided that the following conditions are met:
7
8    Redistributions of source code must retain the above copyright notice, this list
9    of conditions and the following disclaimer.
10
11    Redistributions in binary form must reproduce the above copyright notice, this
12    list of conditions and the following disclaimer in the documentation and/or
13    other materials provided with the distribution.
14
15    Neither the name of Loki software nor the names of its contributors may be used
16    to endorse or promote products derived from this software without specific prior
17    written permission.
18
19    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
20    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22    DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
23    DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26    ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 //
32 // HalfLife Virtual FileSystem - reads files from different dirs and inside wad files
33 //
34 // Coding by Dominic Clifton - Hydra - hydra@hydras-world.com
35 //
36 // based on code by Leonardo Zide (leo@lokigames.com)
37 //
38
39 #ifdef _WIN32
40 #include <wtypes.h>
41 #endif
42
43 #include <stdio.h>
44 #include "vfswad.h"
45 #include "vfs.h"
46
47 // =============================================================================
48 // SYNAPSE
49
50 _QERFuncTable_1 g_FuncTable;
51
52 CSynapseServer* g_pSynapseServer = NULL;
53 CSynapseClientVFS g_SynapseClient;
54
55 #if __GNUC__ >= 4
56 #pragma GCC visibility push(default)
57 #endif
58 extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
59 #if __GNUC__ >= 4
60 #pragma GCC visibility pop
61 #endif
62         if ( strcmp( version, SYNAPSE_VERSION ) ) {
63                 Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
64                 return NULL;
65         }
66         g_pSynapseServer = pServer;
67         g_pSynapseServer->IncRef();
68         Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
69
70         g_SynapseClient.AddAPI( VFS_MAJOR, "wad", sizeof( _QERFileSystemTable ) );
71         g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( _QERFuncTable_1 ), SYN_REQUIRE, &g_FuncTable );
72
73         return &g_SynapseClient;
74 }
75
76 bool CSynapseClientVFS::RequestAPI( APIDescriptor_t *pAPI ){
77         if ( !strcmp( pAPI->major_name, VFS_MAJOR ) ) {
78                 _QERFileSystemTable* pTable = static_cast<_QERFileSystemTable*>( pAPI->mpTable );
79                 pTable->m_pfnInitDirectory = &vfsInitDirectory;
80                 pTable->m_pfnShutdown = &vfsShutdown;
81                 pTable->m_pfnFreeFile = &vfsFreeFile;
82                 pTable->m_pfnGetDirList = &vfsGetDirList;
83                 pTable->m_pfnGetFileList = &vfsGetFileList;
84                 pTable->m_pfnClearFileDirList = &vfsClearFileDirList;
85                 pTable->m_pfnGetFileCount = &vfsGetFileCount;
86                 pTable->m_pfnLoadFile = &vfsLoadFile;
87                 pTable->m_pfnLoadFullPathFile = &vfsLoadFullPathFile;
88                 pTable->m_pfnExtractRelativePath = &vfsExtractRelativePath;
89                 pTable->m_pfnGetFullPath = &vfsGetFullPath;
90                 pTable->m_pfnBasePromptPath = &vfsBasePromptPath;
91                 return true;
92         }
93
94         Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
95         return false;
96 }
97
98 #include "version.h"
99
100 const char* CSynapseClientVFS::GetInfo(){
101         return "WAD VFS module built " __DATE__ " " RADIANT_VERSION;
102 }