1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

hopefully fixed things

This commit is contained in:
Zyx-2000 2016-01-09 21:23:55 +01:00
parent cdd50b1603
commit 203b2dccc3
19 changed files with 83 additions and 39 deletions

1
.gitignore vendored
View File

@ -14,6 +14,7 @@
*.pro.user
*.pro.user.*
*.swp
*.h.gch
*~
/CMakeLists.txt.user
CMakeCache.txt

View File

@ -49,6 +49,7 @@
</Build>
<Compiler>
<Add option="-pedantic" />
<Add option="-std=c++11" />
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-fexceptions" />

View File

@ -47,6 +47,7 @@
</Target>
</Build>
<Compiler>
<Add option="-std=c++11" />
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-fexceptions" />

View File

@ -50,6 +50,7 @@
</Target>
</Build>
<Compiler>
<Add option="-std=c++11" />
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-fexceptions" />

View File

@ -33,6 +33,7 @@
</Build>
<Compiler>
<Add option="-pedantic" />
<Add option="-std=c++11" />
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-fexceptions" />

View File

@ -3,7 +3,7 @@
<FileVersion major="1" minor="6" />
<Project>
<Option title="VCAI" />
<Option pch_mode="2" />
<Option pch_mode="0" />
<Option compiler="gcc" />
<Build>
<Target title="Debug-win32">
@ -55,6 +55,7 @@
</Build>
<Compiler>
<Add option="-pedantic" />
<Add option="-std=c++11" />
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-fexceptions" />
@ -85,6 +86,7 @@
<Unit filename="Goals.cpp" />
<Unit filename="Goals.h" />
<Unit filename="StdInc.h">
<Option compile="1" />
<Option weight="0" />
</Unit>
<Unit filename="VCAI.cpp" />

View File

@ -3,7 +3,7 @@
<FileVersion major="1" minor="6" />
<Project>
<Option title="VCMI_client" />
<Option pch_mode="2" />
<Option pch_mode="0" />
<Option compiler="gcc" />
<Build>
<Target title="Debug-win32">
@ -60,6 +60,7 @@
</Target>
</Build>
<Compiler>
<Add option="-std=c++11" />
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-fexceptions" />
@ -71,6 +72,7 @@
<Add option="-fpermissive" />
<Add option="-DBOOST_THREAD_USE_LIB" />
<Add option="-D_WIN32_WINNT=0x0501" />
<Add option="-D_WIN32" />
<Add directory="$(#boost.include)" />
<Add directory="../include" />
<Add directory="../client" />
@ -124,6 +126,7 @@
<Unit filename="NetPacksClient.cpp" />
<Unit filename="SDLMain.h" />
<Unit filename="StdInc.h">
<Option compile="1" />
<Option weight="0" />
</Unit>
<Unit filename="VCMI_client.rc">

View File

@ -18,3 +18,12 @@ inline QString pathToQString(const boost::filesystem::path & path)
return QString::fromStdString(path.string());
#endif
}
inline boost::filesystem::path qstringToPath(const QString & path)
{
#ifdef VCMI_WINDOWS
return boost::filesystem::path(path.toStdWString());
#else
return boost::filesystem::path(filename.toUtf8().data());
#endif
}

View File

@ -1,5 +1,6 @@
#include "StdInc.h"
#include "jsonutils.h"
#include "../lib/filesystem/FileStream.h"
static QVariantMap JsonToMap(const JsonMap & json)
{
@ -96,7 +97,11 @@ JsonNode toJson(QVariant object)
void JsonToFile(QString filename, QVariant object)
{
std::ofstream file(filename.toUtf8().data(), std::ofstream::binary);
#ifdef _WIN32
FileStream file(boost::filesystem::path(filename.toStdWString()), std::ios::out | std::ios_base::binary);
#else
FileStream file(boost::filesystem::path(filename.toUtf8().data()), std::ios::out | std::ios_base::binary);
#endif
file << toJson(object);
}

View File

@ -2,6 +2,7 @@
#include <QVariantMap>
#include <QVariant>
#include <QVector>
class JsonNode;

View File

@ -1,6 +1,6 @@
#pragma once
#include "../../Global.h"
#include "StdInc.h"
#include "../../lib/CConfigHandler.h"
namespace Ui {

View File

@ -11,7 +11,7 @@
static QString detectModArchive(QString path, QString modName)
{
auto files = ZipArchive::listFiles(path.toUtf8().data());
auto files = ZipArchive::listFiles(qstringToPath(path));
QString modDirName;
@ -69,8 +69,8 @@ void CModManager::loadMods()
ResourceID resID(CModInfo::getModFile(modname));
if (CResourceHandler::get()->existsResource(resID))
{
std::string name = *CResourceHandler::get()->getResourceName(resID);
auto mod = JsonUtils::JsonFromFile(QString::fromUtf8(name.c_str()));
boost::filesystem::path name = *CResourceHandler::get()->getResourceName(resID);
auto mod = JsonUtils::JsonFromFile(QString::fromUtf8(name.string().c_str()));
localMods.insert(QString::fromUtf8(modname.c_str()).toLower(), mod);
}
}
@ -243,7 +243,7 @@ bool CModManager::doInstallMod(QString modname, QString archivePath)
if (!modDirName.size())
return addError(modname, "Mod archive is invalid or corrupted");
if (!ZipArchive::extract(archivePath.toUtf8().data(), destDir.toUtf8().data()))
if (!ZipArchive::extract(qstringToPath(archivePath), qstringToPath(destDir)))
{
QDir(destDir + modDirName).removeRecursively();
return addError(modname, "Failed to extract mod data");
@ -262,7 +262,7 @@ bool CModManager::doUninstallMod(QString modname)
{
ResourceID resID(std::string("Mods/") + modname.toUtf8().data(), EResType::DIRECTORY);
// Get location of the mod, in case-insensitive way
QString modDir = QString::fromUtf8(CResourceHandler::get()->getResourceName(resID)->c_str());
QString modDir = QString::fromUtf8((*CResourceHandler::get()->getResourceName(resID)).c_str());
if (!QDir(modDir).exists())
return addError(modname, "Data with this mod was not found");

View File

@ -1,5 +1,7 @@
#pragma once
#include "StdInc.h"
namespace Ui {
class CSettingsView;
}

View File

@ -4,7 +4,7 @@
<Project>
<Option title="VCMI_lib" />
<Option execution_dir="D:/projects/vcmi/engine/VCMI_lib/" />
<Option pch_mode="2" />
<Option pch_mode="0" />
<Option compiler="gcc" />
<Build>
<Target title="Debug-win32">
@ -17,8 +17,8 @@
<Option run_host_application_in_terminal="1" />
<Option createStaticLib="1" />
<Compiler>
<Add option="-Og" />
<Add option="-g" />
<Add option="-Og" />
<Add directory="$(#zlib.include)" />
</Compiler>
<Linker>
@ -34,7 +34,7 @@
<Add option="-liconv" />
<Add option="-ldbghelp" />
<Add directory="$(#sdl2.lib)" />
<Add directory="$(#boost.lib32)" />
<Add directory="$(#boost.lib)" />
<Add directory="$(#zlib.lib)" />
</Linker>
</Target>
@ -62,7 +62,6 @@
<Add option="-lboost_locale$(#boost.libsuffix)" />
<Add option="-lboost_date_time$(#boost.libsuffix)" />
<Add option="-liconv" />
<Add option="-ldbghelp" />
<Add directory="$(#sdl2.lib)" />
<Add directory="$(#boost.lib32)" />
<Add directory="$(#zlib.lib)" />
@ -101,6 +100,7 @@
</Target>
</Build>
<Compiler>
<Add option="-std=c++11" />
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-fexceptions" />
@ -110,9 +110,13 @@
<Add option="-Wno-unused-parameter" />
<Add option="-Wno-overloaded-virtual" />
<Add option="-Wno-unused-local-typedefs" />
<Add option="-Winvalid-pch" />
<Add option="-msse2" />
<Add option="-DVCMI_DLL" />
<Add option="-DBOOST_THREAD_USE_LIB" />
<Add option="-DBOOST_SYSTEM_NO_DEPRECATED" />
<Add option="-D_WIN32_WINNT=0x0501" />
<Add option="-D_WIN32" />
<Add directory="$(#boost.include)" />
<Add directory="../include" />
<Add directory="../lib" />
@ -199,8 +203,8 @@
<Unit filename="ScopeGuard.h" />
<Unit filename="StartInfo.h" />
<Unit filename="StdInc.h">
<Option compile="1" />
<Option weight="0" />
<Option target="Debug-win64" />
</Unit>
<Unit filename="StringConstants.h" />
<Unit filename="UnlockGuard.h" />
@ -227,9 +231,12 @@
<Unit filename="filesystem/CMemoryStream.h" />
<Unit filename="filesystem/CZipLoader.cpp" />
<Unit filename="filesystem/CZipLoader.h" />
<Unit filename="filesystem/FileStream.cpp" />
<Unit filename="filesystem/FileStream.h" />
<Unit filename="filesystem/Filesystem.cpp" />
<Unit filename="filesystem/Filesystem.h" />
<Unit filename="filesystem/ISimpleResourceLoader.h" />
<Unit filename="filesystem/MinizipExtensions.h" />
<Unit filename="filesystem/ResourceID.cpp" />
<Unit filename="filesystem/ResourceID.h" />
<Unit filename="int3.h" />

View File

@ -11,6 +11,7 @@
*/
#include "CInputStream.h"
#include "FileStream.h"
class CFileInfo;
@ -94,5 +95,5 @@ private:
si64 dataSize;
/** Native c++ input file stream object. */
boost::filesystem::ifstream fileStream;
FileStream fileStream;
};

View File

@ -1,6 +1,7 @@
#include "StdInc.h"
#include "../../Global.h"
//#include "../../Global.h"
#include "CZipLoader.h"
#include "FileStream.h"
#include "../ScopeGuard.h"
@ -140,24 +141,24 @@ static bool extractCurrent(unzFile file, std::ostream & where)
return false;
}
std::vector<std::string> ZipArchive::listFiles(std::string filename)
std::vector<std::string> ZipArchive::listFiles(boost::filesystem::path filename)
{
std::vector<std::string> ret;
unzFile file = unzOpen(filename.c_str());
unzFile file = unzOpen2_64(filename.c_str(), FileStream::GetMinizipFilefunc());
if (unzGoToFirstFile(file) == UNZ_OK)
{
do
{
unz_file_info info;
unz_file_info64 info;
std::vector<char> filename;
unzGetCurrentFileInfo (file, &info, nullptr, 0, nullptr, 0, nullptr, 0);
unzGetCurrentFileInfo64 (file, &info, nullptr, 0, nullptr, 0, nullptr, 0);
filename.resize(info.size_filename);
// Get name of current file. Contrary to docs "info" parameter can't be null
unzGetCurrentFileInfo (file, &info, filename.data(), filename.size(), nullptr, 0, nullptr, 0);
unzGetCurrentFileInfo64 (file, &info, filename.data(), filename.size(), nullptr, 0, nullptr, 0);
ret.push_back(std::string(filename.data(), filename.size()));
}
@ -168,29 +169,29 @@ std::vector<std::string> ZipArchive::listFiles(std::string filename)
return ret;
}
bool ZipArchive::extract(std::string from, std::string where)
bool ZipArchive::extract(boost::filesystem::path from, boost::filesystem::path where)
{
// Note: may not be fast enough for large archives (should NOT happen with mods)
// because locating each file by name may be slow. Unlikely slower than decompression though
return extract(from, where, listFiles(from));
}
bool ZipArchive::extract(std::string from, std::string where, std::vector<std::string> what)
bool ZipArchive::extract(boost::filesystem::path from, boost::filesystem::path where, std::vector<std::string> what)
{
unzFile archive = unzOpen(from.c_str());
unzFile archive = unzOpen2_64(from.c_str(), FileStream::GetMinizipFilefunc());
auto onExit = vstd::makeScopeGuard([&]()
{
unzClose(archive);
});
for (std::string & file : what)
for (const std::string & file : what)
{
if (unzLocateFile(archive, file.c_str(), 1) != UNZ_OK)
return false;
std::string fullName = where + '/' + file;
std::string fullPath = fullName.substr(0, fullName.find_last_of("/"));
const boost::filesystem::path fullName = where / file;
const boost::filesystem::path fullPath = fullName.parent_path();
boost::filesystem::create_directories(fullPath);
// directory. No file to extract
@ -198,7 +199,7 @@ bool ZipArchive::extract(std::string from, std::string where, std::vector<std::s
if (boost::algorithm::ends_with(file, "/"))
continue;
std::ofstream destFile(fullName, std::ofstream::binary);
FileStream destFile(fullName, std::ios::out | std::ios::binary);
if (!destFile.good())
return false;

View File

@ -65,11 +65,11 @@ public:
namespace ZipArchive
{
/// List all files present in archive
std::vector<std::string> DLL_LINKAGE listFiles(std::string filename);
std::vector<std::string> DLL_LINKAGE listFiles(boost::filesystem::path filename);
/// extracts all files from archive "from" into destination directory "where". Directory must exist
bool DLL_LINKAGE extract(std::string from, std::string where);
bool DLL_LINKAGE extract(boost::filesystem::path from, boost::filesystem::path where);
///same as above, but extracts only files mentioned in "what" list
bool DLL_LINKAGE extract(std::string from, std::string where, std::vector<std::string> what);
bool DLL_LINKAGE extract(boost::filesystem::path from, boost::filesystem::path where, std::vector<std::string> what);
}

View File

@ -3,13 +3,14 @@
<FileVersion major="1" minor="6" />
<Project>
<Option title="VCMI_server" />
<Option pch_mode="2" />
<Option pch_mode="0" />
<Option compiler="gcc" />
<Build>
<Target title="Debug-win32">
<Option platforms="Windows;" />
<Option output="../VCMI_server" prefix_auto="1" extension_auto="1" />
<Option object_output="../obj/Debug/Server" />
<Option working_dir="../" />
<Option object_output="../obj/Server/Debug/x86" />
<Option type="1" />
<Option compiler="gcc" />
<Option use_console_runner="0" />
@ -25,7 +26,8 @@
<Target title="Release-win32">
<Option platforms="Windows;" />
<Option output="../VCMI_server" prefix_auto="1" extension_auto="1" />
<Option object_output="../obj/Release/Server" />
<Option working_dir="../" />
<Option object_output="../obj/Server/Release/x86" />
<Option type="1" />
<Option compiler="gcc" />
<Option use_console_runner="0" />
@ -42,7 +44,8 @@
<Target title="Debug-win64">
<Option platforms="Windows;" />
<Option output="../VCMI_server" prefix_auto="1" extension_auto="1" />
<Option object_output="../obj/Debug/Server" />
<Option working_dir="../" />
<Option object_output="../obj/Server/Debug/x86" />
<Option type="1" />
<Option compiler="gnu_gcc_compiler_x64" />
<Option use_console_runner="0" />
@ -57,6 +60,7 @@
</Target>
</Build>
<Compiler>
<Add option="-std=c++11" />
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-fexceptions" />
@ -67,6 +71,8 @@
<Add option="-Wno-overloaded-virtual" />
<Add option="-D_WIN32_WINNT=0x0501" />
<Add option="-DBOOST_THREAD_USE_LIB" />
<Add option="-DBOOST_SYSTEM_NO_DEPRECATED" />
<Add option="-D_WIN32" />
<Add directory="$(#boost.include)" />
<Add directory="../include" />
<Add directory="$(#sdl2.include)" />
@ -92,6 +98,7 @@
<Unit filename="CVCMIServer.h" />
<Unit filename="NetPacksServer.cpp" />
<Unit filename="StdInc.h">
<Option compile="1" />
<Option weight="0" />
</Unit>
<Extensions>

View File

@ -38,5 +38,6 @@
<Project filename="scripting/erm/ERM.cbp">
<Depends filename="lib/VCMI_lib.cbp" />
</Project>
<Project filename="launcher/VCMI_launcher.cbp" />
</Workspace>
</CodeBlocks_workspace_file>