mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-01-10 19:09:45 +01:00
Abstract assets mounting to FileSystemUtils.cpp
The assets mounting code was put directly in editorclass::load(), but now it's in a neat little function so it can be called from multiple places without having to call editorclass::load().
This commit is contained in:
parent
34e89bfcd3
commit
d45ff4c269
3 changed files with 40 additions and 33 deletions
|
@ -166,6 +166,44 @@ void FILESYSTEM_mount(const char *fname)
|
|||
}
|
||||
}
|
||||
|
||||
void FILESYSTEM_mountassets(const char* path)
|
||||
{
|
||||
const std::string _path(path);
|
||||
|
||||
std::string zippath = "levels/" + _path.substr(7,_path.size()-14) + ".data.zip";
|
||||
std::string dirpath = "levels/" + _path.substr(7,_path.size()-14) + "/";
|
||||
std::string zip_path;
|
||||
const char* cstr = PHYSFS_getRealDir(_path.c_str());
|
||||
|
||||
if (cstr) {
|
||||
zip_path = cstr;
|
||||
}
|
||||
|
||||
if (cstr && FILESYSTEM_directoryExists(zippath.c_str())) {
|
||||
printf("Custom asset directory exists at %s\n", zippath.c_str());
|
||||
FILESYSTEM_mount(zippath.c_str());
|
||||
graphics.reloadresources();
|
||||
} else if (zip_path != "data.zip" && !endsWith(zip_path, "/data.zip") && endsWith(zip_path, ".zip")) {
|
||||
printf("Custom asset directory is .zip at %s\n", zip_path.c_str());
|
||||
PHYSFS_File* zip = PHYSFS_openRead(zip_path.c_str());
|
||||
zip_path += ".data.zip";
|
||||
if (zip == NULL) {
|
||||
printf("error loading .zip: %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
||||
} else if (PHYSFS_mountHandle(zip, zip_path.c_str(), "/", 0) == 0) {
|
||||
printf("error mounting .zip: %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
||||
} else {
|
||||
graphics.assetdir = zip_path;
|
||||
}
|
||||
graphics.reloadresources();
|
||||
} else if (FILESYSTEM_directoryExists(dirpath.c_str())) {
|
||||
printf("Custom asset directory exists at %s\n",dirpath.c_str());
|
||||
FILESYSTEM_mount(dirpath.c_str());
|
||||
graphics.reloadresources();
|
||||
} else {
|
||||
printf("Custom asset directory does not exist\n");
|
||||
}
|
||||
}
|
||||
|
||||
void FILESYSTEM_unmountassets()
|
||||
{
|
||||
if (graphics.assetdir != "")
|
||||
|
|
|
@ -15,6 +15,7 @@ char *FILESYSTEM_getUserLevelDirectory();
|
|||
|
||||
bool FILESYSTEM_directoryExists(const char *fname);
|
||||
void FILESYSTEM_mount(const char *fname);
|
||||
void FILESYSTEM_mountassets(const char *path);
|
||||
void FILESYSTEM_unmountassets();
|
||||
|
||||
void FILESYSTEM_loadFileToMemory(const char *name, unsigned char **mem,
|
||||
|
|
|
@ -1623,39 +1623,7 @@ bool editorclass::load(std::string& _path)
|
|||
}
|
||||
|
||||
FILESYSTEM_unmountassets();
|
||||
|
||||
std::string zippath = "levels/" + _path.substr(7,_path.size()-14) + ".data.zip";
|
||||
std::string dirpath = "levels/" + _path.substr(7,_path.size()-14) + "/";
|
||||
std::string zip_path;
|
||||
const char* cstr = PHYSFS_getRealDir(_path.c_str());
|
||||
|
||||
if (cstr) {
|
||||
zip_path = cstr;
|
||||
}
|
||||
|
||||
if (cstr && FILESYSTEM_directoryExists(zippath.c_str())) {
|
||||
printf("Custom asset directory exists at %s\n", zippath.c_str());
|
||||
FILESYSTEM_mount(zippath.c_str());
|
||||
graphics.reloadresources();
|
||||
} else if (zip_path != "data.zip" && !endsWith(zip_path, "/data.zip") && endsWith(zip_path, ".zip")) {
|
||||
printf("Custom asset directory is .zip at %s\n", zip_path.c_str());
|
||||
PHYSFS_File* zip = PHYSFS_openRead(zip_path.c_str());
|
||||
zip_path += ".data.zip";
|
||||
if (zip == NULL) {
|
||||
printf("error loading .zip: %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
||||
} else if (PHYSFS_mountHandle(zip, zip_path.c_str(), "/", 0) == 0) {
|
||||
printf("error mounting .zip: %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
||||
} else {
|
||||
graphics.assetdir = zip_path;
|
||||
}
|
||||
graphics.reloadresources();
|
||||
} else if (FILESYSTEM_directoryExists(dirpath.c_str())) {
|
||||
printf("Custom asset directory exists at %s\n",dirpath.c_str());
|
||||
FILESYSTEM_mount(dirpath.c_str());
|
||||
graphics.reloadresources();
|
||||
} else {
|
||||
printf("Custom asset directory does not exist\n");
|
||||
}
|
||||
FILESYSTEM_mountassets(_path.c_str());
|
||||
|
||||
tinyxml2::XMLDocument doc;
|
||||
if (!FILESYSTEM_loadTiXml2Document(_path.c_str(), doc))
|
||||
|
|
Loading…
Reference in a new issue