Panda3D
|
00001 // Filename: pandaIOSystem.cxx 00002 // Created by: rdb (29Mar11) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "pandaIOSystem.h" 00016 #include "pandaIOStream.h" 00017 00018 //////////////////////////////////////////////////////////////////// 00019 // Function: PandaIOSystem::Constructor 00020 // Access: Public 00021 // Description: Initializes the object with the given VFS, or the 00022 // global one if none was specified. 00023 //////////////////////////////////////////////////////////////////// 00024 PandaIOSystem:: 00025 PandaIOSystem(VirtualFileSystem *vfs) : _vfs(vfs) { 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: PandaIOSystem::Exists 00030 // Access: Public 00031 // Description: Returns true if the file exists, duh. 00032 //////////////////////////////////////////////////////////////////// 00033 bool PandaIOSystem:: 00034 Exists(const char *file) const { 00035 Filename fn = Filename::from_os_specific(file); 00036 return _vfs->exists(fn); 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function: PandaIOSystem::Close 00041 // Access: Public 00042 // Description: Closes the indicated file stream. 00043 //////////////////////////////////////////////////////////////////// 00044 void PandaIOSystem:: 00045 Close(Assimp::IOStream *file) { 00046 PandaIOStream *pstr = (PandaIOStream*) file; 00047 _vfs->close_read_file(&pstr->_istream); 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: PandaIOSystem::ComparePaths 00052 // Access: Public 00053 // Description: Returns true if the two paths point to the same 00054 // file, false if not. 00055 //////////////////////////////////////////////////////////////////// 00056 bool PandaIOSystem:: 00057 ComparePaths(const char *p1, const char *p2) const { 00058 Filename fn1 = Filename::from_os_specific(p1); 00059 Filename fn2 = Filename::from_os_specific(p2); 00060 fn1.make_canonical(); 00061 fn2.make_canonical(); 00062 return fn1 == fn2; 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: PandaIOSystem::getOsSeparator 00067 // Access: Public 00068 // Description: Returns the path separator for this operating 00069 // system. 00070 //////////////////////////////////////////////////////////////////// 00071 char PandaIOSystem:: 00072 getOsSeparator() const { 00073 #ifdef _WIN32 00074 return '\\'; 00075 #else 00076 return '/'; 00077 #endif 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: PandaIOSystem::Open 00082 // Access: Public 00083 // Description: Opens the indicated file. 00084 //////////////////////////////////////////////////////////////////// 00085 Assimp::IOStream *PandaIOSystem:: 00086 Open(const char *file, const char *mode) { 00087 Filename fn = Filename::from_os_specific(file); 00088 00089 if (mode[0] == 'r') { 00090 istream *stream = _vfs->open_read_file(file, true); 00091 if (stream == NULL) { 00092 return NULL; 00093 } 00094 return new PandaIOStream(*stream); 00095 00096 } else { 00097 nassertr(false, NULL); // Not implemented on purpose. 00098 } 00099 }