40 #ifndef _resourcemanager_cpp
41 #define _resourcemanager_cpp
48 #include "Graphics/meshmanager.h"
49 #include "stringtool.h"
52 #include "Internal/ogredatastreambuf.h.cpp"
54 #include "Resource/resourceenumerations.h"
57 #include <btBulletWorldImporter.h>
58 #include <btBulletDynamicsCommon.h>
67 #include <CoreServices/CoreServices.h>
71 #include <sys/types.h>
73 #include <mach-o/dyld.h>
78 #include <sys/types.h>
87 #ifdef CreateDirectory
88 #undef CreateDirectory
91 #ifdef RemoveDirectory
92 #undef RemoveDirectory
97 template<> ResourceManager* Singleton<ResourceManager>::SingletonPtr = NULL;
101 this->
OgreResource = Ogre::ResourceGroupManager::getSingletonPtr();
109 OgreResource = Ogre::ResourceGroupManager::getSingletonPtr();
117 for(std::vector<ResourceInputStream*>::iterator Iter =
DeleteList.begin(); Iter !=
DeleteList.end(); Iter++)
123 this->
ArgC = ArgCount;
124 this->
ArgV = ArgVars;
133 if(::CreateDirectoryA(DirectoryPath.c_str(),NULL) < 0)
135 if(ERROR_ALREADY_EXISTS == ::GetLastError())
140 ExceptionStream <<
"Unable to create directory. Error follows:" << std::endl;
141 if(ERROR_PATH_NOT_FOUND == ::GetLastError())
143 ExceptionStream <<
"Path to requested directory does not exist.";
147 ExceptionStream <<
"Error Unknown. :(";
153 if(::mkdir(DirectoryPath.c_str(),0777) < 0)
155 if( EEXIST == errno )
160 ExceptionStream <<
"Unable to create directory. Error follows:" << std::endl;
161 ExceptionStream << strerror(errno);
171 if((stat(DirectoryPath.c_str(),&st) == 0))
173 return S_ISDIR(st.st_mode);
182 if(!rmdir(DirectoryPath.c_str()))
192 Whole Last(FileName.find_last_of(
"\\/"));
193 if(FileName.npos == Last)
197 if(Last<FileName.size())
198 {
return FileName.substr(0,Last+1); }
200 {
return FileName.substr(0,Last+1); }
206 Whole Last(FileName.find_last_of(
"\\/"));
207 if(FileName.npos == Last)
211 if(Last<FileName.size())
212 {
return FileName.substr(Last+1,FileName.npos); }
242 for(String::const_iterator Current = PATH.begin();
248 Results.push_back(OneEntry);
261 for(StringVector::const_iterator Iter = PATH.begin();
266 if(Entries.find(ExecutableName)!=Entries.end())
303 char Results[FILENAME_MAX];
305 MaxInt Length = ::readlink(
"/proc/self/exe", Results,
sizeof(Results)-1);
308 Results[Length] =
'\0';
315 GetModuleFileName( NULL, Results, FILENAME_MAX );
319 uint32_t size =
sizeof(Results);
320 if (_NSGetExecutablePath(Results, &size) == 0)
347 if(_chdir(ChangeTo.c_str()))
349 if(chdir(ChangeTo.c_str()))
363 size_t StartIndex = 0;
368 if(FolderVec->at(0).find(
':') != String::npos)
370 PathAttempt.append( FolderVec->at(0) );
371 PathAttempt.append( 1, SysSlash );
375 PathAttempt.append( 1, SysSlash );
377 for(
size_t VecIndex = StartIndex ; VecIndex < FolderVec->size() ; ++VecIndex )
379 PathAttempt.append( FolderVec->at(VecIndex) );
380 PathAttempt.append( 1, SysSlash );
390 struct dirent *DirEntry;
391 if((Directory = opendir(Dir.c_str())))
393 while((DirEntry = readdir(Directory)))
395 Results.insert(DirEntry->d_name);
408 char cCurrentPath[FILENAME_MAX];
411 String Results (_getcwd(cCurrentPath,
sizeof(cCurrentPath)));
413 String Results (getcwd(cCurrentPath,
sizeof(cCurrentPath)));
425 String LowerVar = PathVar;
440 TCHAR path_local_appdata[MAX_PATH];
441 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, path_local_appdata))) {
442 return path_local_appdata;
445 struct passwd* pw = getpwuid(getuid());
447 return String(pw->pw_dir);
467 TCHAR path_appdata[MAX_PATH];
468 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, path_appdata))) {
472 struct passwd* pw = getpwuid(getuid());
474 return String(pw->pw_dir);
485 TCHAR path_personal[MAX_PATH];
486 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL, 0, path_personal))) {
487 return path_personal;
490 struct passwd* pw = getpwuid(getuid());
492 return String(pw->pw_dir);
503 TCHAR path_common_personal[MAX_PATH];
504 if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS|CSIDL_FLAG_CREATE, NULL, 0, path_common_personal))) {
505 return path_common_personal;
508 struct passwd* pw = getpwuid(getuid());
510 return String(pw->pw_dir);
528 return (*StreamIt).second;
531 Char8* AssetBuffer =
new Char8[ OgreStream->size() ];
532 OgreStream->read( (
void*)AssetBuffer, OgreStream->size() );
547 this->
NamedDataStreams.insert(std::pair<String,Resource::DataStreamPtr>(AssetName,NewStream));
590 if(GroupName == (*it))
597 Ogre::StringVectorPtr ResourceNames = this->
OgreResource->listResourceNames(GroupName,
false);
598 for(
Whole X = 0 ; X < ResourceNames->size() ; ++X )
600 if(ResourceNames->at(X).find(
".mesh"))
623 Ogre::FileInfoListPtr FileList = this->
OgreResource->listResourceFileInfo(Group);
624 for(
Whole X = 0 ; X < FileList->size() ; ++X )
626 if( FileName == FileList->at(X).filename ) {
628 return FileList->at(X).archive->getName() +
"/" + FileList->at(X).path;
653 Internal::OgreDataStreamBuf *TempBuffer =
new Internal::OgreDataStreamBuf(
OgreResource->openResource(FileName));
677 return String(
"FileSystem");
688 if(
String(
"FileSystem")==FromString)
690 if(
String(
"Zip")==FromString)
700 {
return ManagerBase::MT_ResourceManager; }
703 {
return "DefaultResourceManager"; }
718 return "DefaultResourceManager";
733 for( NameValuePairList::iterator ParIt = Params.begin() ; ParIt != Params.end() ; ++ParIt )
735 String Lower = (*ParIt).first;
737 if(
"enginedatapath" == Lower )
739 EngineDataPath = (*ParIt).second;
741 else if(
"archivetype" == Lower )
762 delete ToBeDestroyed;