commit e49cda71
Remove all the libphsyfs2 functions and replaced them with the same versions for the physfs3 library
Changed files
| M | CMakeLists.txt before |
| M | source/code/sago/SagoDataHolder.cpp before |
| M | source/code/sago/SagoMisc.cpp before |
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9027c51..150021e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,7 +46,7 @@ add_definitions(-DLOCALEDIR=\"${CMAKE_INSTALL_PREFIX}/${INSTALL_LOCALE_DIR}\")
endif()
#Compiler options
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++11 -Wno-deprecated-declarations")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} -g -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -O2")
diff --git a/source/code/sago/SagoDataHolder.cpp b/source/code/sago/SagoDataHolder.cpp
index f24f7e4..4818efa 100644
--- a/source/code/sago/SagoDataHolder.cpp
+++ b/source/code/sago/SagoDataHolder.cpp
@@ -104,7 +104,7 @@ SDL_Texture* SagoDataHolder::getTexturePtr(const std::string& textureName) const
return ret;
}
std::string path = "textures/"+textureName+".png";
- if (data->verbose) {
+ if (data->verbose) {
printFileWeLoad(path);
}
if (!PHYSFS_exists(path.c_str())) {
@@ -113,10 +113,10 @@ SDL_Texture* SagoDataHolder::getTexturePtr(const std::string& textureName) const
PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
unsigned int m_size = PHYSFS_fileLength(myfile);
std::unique_ptr<char[]> m_data(new char[m_size]);
- int length_read = PHYSFS_read (myfile, m_data.get(), 1, m_size);
+ int length_read = PHYSFS_readBytes (myfile, m_data.get(), m_size);
if (length_read != (int)m_size) {
PHYSFS_close(myfile);
- std::cerr << "Error: Curropt data file: " << path << "\n";
+ std::cerr << "Error: Corrupt data file: " << path << "\n";
return ret;
}
PHYSFS_close(myfile);
@@ -124,7 +124,7 @@ SDL_Texture* SagoDataHolder::getTexturePtr(const std::string& textureName) const
//The above might fail an return null.
if (!rw) {
PHYSFS_close(myfile);
- std::cerr << "Error. Curropt data file!\n";
+ std::cerr << "Error. Corrupt data file!\n";
return NULL;
}
SDL_Surface* surface = IMG_Load_RW(rw,true);
@@ -145,7 +145,7 @@ TTF_Font* SagoDataHolder::getFontPtr(const std::string& fontName, int ptsize) co
return ret;
}
std::string path = "fonts/"+fontName+".ttf";
- if (data->verbose) {
+ if (data->verbose) {
printFileWeLoad(path);
}
if (!PHYSFS_exists(path.c_str())) {
@@ -155,10 +155,10 @@ TTF_Font* SagoDataHolder::getFontPtr(const std::string& fontName, int ptsize) co
PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
unsigned int m_size = PHYSFS_fileLength(myfile);
std::unique_ptr<char[]> m_data(new char[m_size]);
- int length_read = PHYSFS_read (myfile, m_data.get(), 1, m_size);
+ int length_read = PHYSFS_readBytes (myfile, m_data.get(), m_size);
if (length_read != (int)m_size) {
PHYSFS_close(myfile);
- std::cerr << "Error: Curropt data file: " << path << "\n";
+ std::cerr << "Error: Corrupt data file: " << path << "\n";
return ret;
}
PHYSFS_close(myfile);
@@ -168,7 +168,7 @@ TTF_Font* SagoDataHolder::getFontPtr(const std::string& fontName, int ptsize) co
//The above might fail an return null.
if (!rw) {
PHYSFS_close(myfile);
- std::cerr << "Error: Curropt data file!\n";
+ std::cerr << "Error: Corrupt data file!\n";
return ret;
}
@@ -188,7 +188,7 @@ Mix_Music* SagoDataHolder::getMusicPtr(const std::string& musicName) const {
return ret;
}
std::string path = "music/"+musicName+".ogg";
- if (data->verbose) {
+ if (data->verbose) {
printFileWeLoad(path);
}
if (!PHYSFS_exists(path.c_str())) {
@@ -198,10 +198,10 @@ Mix_Music* SagoDataHolder::getMusicPtr(const std::string& musicName) const {
PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
unsigned int m_size = PHYSFS_fileLength(myfile);
std::unique_ptr<char[]> m_data(new char[m_size]);
- int length_read = PHYSFS_read (myfile, m_data.get(), 1, m_size);
+ int length_read = PHYSFS_readBytes (myfile, m_data.get(), m_size);
if (length_read != (int)m_size) {
PHYSFS_close(myfile);
- std::cerr << "Error: Curropt data file: " << path << "\n";
+ std::cerr << "Error: Corrupt data file: " << path << "\n";
return ret;
}
PHYSFS_close(myfile);
@@ -210,7 +210,7 @@ Mix_Music* SagoDataHolder::getMusicPtr(const std::string& musicName) const {
//The above might fail an return null.
if (!rw) {
PHYSFS_close(myfile);
- std::cerr << "Error. Curropt data file!\n";
+ std::cerr << "Error. Corrupt data file!\n";
return NULL;
}
@@ -231,7 +231,7 @@ Mix_Chunk* SagoDataHolder::getSoundPtr(const std::string& soundName) const {
return ret;
}
std::string path = "sounds/"+soundName+".ogg";
- if (data->verbose) {
+ if (data->verbose) {
printFileWeLoad(path);
}
if (!PHYSFS_exists(path.c_str())) {
@@ -241,10 +241,10 @@ Mix_Chunk* SagoDataHolder::getSoundPtr(const std::string& soundName) const {
PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
unsigned int m_size = PHYSFS_fileLength(myfile);
std::unique_ptr<char[]> m_data(new char[m_size]);
- int length_read = PHYSFS_read (myfile, m_data.get(), 1, m_size);
+ int length_read = PHYSFS_readBytes (myfile, m_data.get(), m_size);
if (length_read != (int)m_size) {
PHYSFS_close(myfile);
- std::cerr << "Error: Curropt data file: " << path << "\n";
+ std::cerr << "Error: Corrupt data file: " << path << "\n";
return ret;
}
PHYSFS_close(myfile);
@@ -253,7 +253,7 @@ Mix_Chunk* SagoDataHolder::getSoundPtr(const std::string& soundName) const {
//The above might fail an return null.
if (!rw) {
PHYSFS_close(myfile);
- std::cerr << "Error. Curropt data file!\n";
+ std::cerr << "Error. Corrupt data file!\n";
return NULL;
}
diff --git a/source/code/sago/SagoMisc.cpp b/source/code/sago/SagoMisc.cpp
index fc0b960..0ec9c0f 100644
--- a/source/code/sago/SagoMisc.cpp
+++ b/source/code/sago/SagoMisc.cpp
@@ -59,7 +59,7 @@ std::string GetFileContent(const char* filename) {
PHYSFS_file* myfile = PHYSFS_openRead(filename);
unsigned int m_size = PHYSFS_fileLength(myfile);
std::unique_ptr<char[]> m_data(new char[m_size]);
- int length_read = PHYSFS_read (myfile, m_data.get(), 1, m_size);
+ int length_read = PHYSFS_readBytes (myfile, m_data.get(), m_size);
if (length_read != (int)m_size) {
PHYSFS_close(myfile);
cerr << "Error: Curropt data file: " << filename << "\n";
@@ -85,10 +85,11 @@ void WriteFileContent(const char* filename, const std::string& content) {
CreatePathToFile(filename);
PHYSFS_file* myfile = PHYSFS_openWrite(filename);
if (!myfile) {
- cerr << "Failed to open file for writing, " << PHYSFS_getLastError() << "\n";
+ PHYSFS_ErrorCode code = PHYSFS_getLastErrorCode();
+ cerr << "Failed to open file for writing, " << PHYSFS_getErrorByCode(code) << " (" << code << ")\n";
return;
}
- PHYSFS_write(myfile, content.c_str(), sizeof(char), content.length());
+ PHYSFS_writeBytes(myfile, content.c_str(), sizeof(char)*content.length());
PHYSFS_close(myfile);
}