mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 02:15:34 +00:00
Validate version of resources
This commit is contained in:
parent
f260fa006e
commit
d39552962f
10 changed files with 51 additions and 21 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -68,7 +68,6 @@ apps/wizard/ui_intropage.h
|
|||
apps/wizard/ui_languageselectionpage.h
|
||||
apps/wizard/ui_methodselectionpage.h
|
||||
components/ui_contentselector.h
|
||||
components/version/version.cpp
|
||||
docs/mainpage.hpp
|
||||
docs/Doxyfile
|
||||
docs/DoxyfilePages
|
||||
|
|
|
@ -225,6 +225,10 @@ if(APPLE AND BUILD_OPENCS)
|
|||
MACOSX_PACKAGE_LOCATION Resources/resources)
|
||||
set_source_files_properties(${OPENCS_OPENMW_CFG} PROPERTIES
|
||||
MACOSX_PACKAGE_LOCATION Resources)
|
||||
|
||||
add_custom_command(TARGET openmw-cs
|
||||
POST_BUILD
|
||||
COMMAND cp "${OpenMW_BINARY_DIR}/resources/version" "${OPENCS_BUNDLE_RESOURCES_DIR}/resources")
|
||||
endif()
|
||||
|
||||
target_link_libraries(openmw-cs-lib
|
||||
|
|
|
@ -210,6 +210,10 @@ if(APPLE)
|
|||
configure_file("${OpenMW_BINARY_DIR}/openmw.cfg" ${BUNDLE_RESOURCES_DIR} COPYONLY)
|
||||
configure_file("${OpenMW_BINARY_DIR}/gamecontrollerdb.txt" ${BUNDLE_RESOURCES_DIR} COPYONLY)
|
||||
|
||||
add_custom_command(TARGET openmw
|
||||
POST_BUILD
|
||||
COMMAND cp "${OpenMW_BINARY_DIR}/resources/version" "${BUNDLE_RESOURCES_DIR}/resources")
|
||||
|
||||
find_library(COCOA_FRAMEWORK Cocoa)
|
||||
find_library(IOKIT_FRAMEWORK IOKit)
|
||||
target_link_libraries(openmw ${COCOA_FRAMEWORK} ${IOKIT_FRAMEWORK})
|
||||
|
|
|
@ -423,6 +423,9 @@ void OMW::Engine::addArchive(const std::string& archive)
|
|||
void OMW::Engine::setResourceDir(const std::filesystem::path& parResDir)
|
||||
{
|
||||
mResDir = parResDir;
|
||||
if (!Version::checkResourcesVersion(mResDir))
|
||||
Log(Debug::Error) << "Resources dir " << mResDir
|
||||
<< " doesn't match OpenMW binary, the game may work incorrectly.";
|
||||
}
|
||||
|
||||
// Set start cell name
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
execute_process (
|
||||
COMMAND ${GIT_EXECUTABLE} rev-list --tags --max-count=1
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
WORKING_DIRECTORY ${OpenMW_SOURCE_DIR}
|
||||
RESULT_VARIABLE EXITCODE1
|
||||
OUTPUT_VARIABLE TAGHASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
|
@ -8,7 +8,7 @@ execute_process (
|
|||
|
||||
execute_process (
|
||||
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
WORKING_DIRECTORY ${OpenMW_SOURCE_DIR}
|
||||
RESULT_VARIABLE EXITCODE2
|
||||
OUTPUT_VARIABLE COMMITHASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
@ -28,4 +28,5 @@ endif ()
|
|||
|
||||
include(${MACROSFILE})
|
||||
|
||||
configure_file(${VERSION_IN_FILE} ${VERSION_FILE})
|
||||
configure_resource_file(${VERSION_RESOURCE_FILE_IN} ${OpenMW_BINARY_DIR} ${VERSION_RESOURCE_FILE_RELATIVE})
|
||||
configure_file("${OpenMW_SOURCE_DIR}/${VERSION_CPP_FILE}.in" "${OpenMW_BINARY_DIR}/${VERSION_CPP_FILE}")
|
||||
|
|
|
@ -62,13 +62,6 @@ macro (add_component_dir dir)
|
|||
list (APPEND cppfiles "${f}")
|
||||
endforeach (f)
|
||||
|
||||
if (u MATCHES ".*[ch]pp")
|
||||
list (APPEND files "${dir}/${u}")
|
||||
list (APPEND COMPONENT_FILES "${dir}/${u}")
|
||||
endif()
|
||||
if (u MATCHES ".*cpp")
|
||||
list (APPEND cppfiles "${dir}/${u}")
|
||||
endif()
|
||||
endforeach (u)
|
||||
|
||||
if (OPENMW_UNITY_BUILD)
|
||||
|
|
|
@ -6,18 +6,22 @@ if(APPLE)
|
|||
endif(APPLE)
|
||||
|
||||
# Version file
|
||||
set (VERSION_IN_FILE "${OpenMW_SOURCE_DIR}/components/version/version.cpp.in")
|
||||
set (VERSION_FILE "${OpenMW_SOURCE_DIR}/components/version/version.cpp")
|
||||
set (VERSION_RESOURCE_FILE_IN "${OpenMW_SOURCE_DIR}/files/version.in")
|
||||
set (VERSION_RESOURCE_FILE_RELATIVE "resources/version")
|
||||
set (VERSION_CPP_FILE "components/version/version.cpp")
|
||||
|
||||
if (GIT_CHECKOUT)
|
||||
get_generator_is_multi_config(multi_config)
|
||||
add_custom_command (
|
||||
OUTPUT ${VERSION_FILE}
|
||||
DEPENDS ${VERSION_IN_FILE}
|
||||
OUTPUT "${OpenMW_BINARY_DIR}/${VERSION_CPP_FILE}"
|
||||
DEPENDS "${OpenMW_SOURCE_DIR}/${VERSION_CPP_FILE}.in"
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
|
||||
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
|
||||
-DVERSION_IN_FILE=${VERSION_IN_FILE}
|
||||
-DVERSION_FILE=${VERSION_FILE}
|
||||
-DOpenMW_SOURCE_DIR=${OpenMW_SOURCE_DIR}
|
||||
-DOpenMW_BINARY_DIR=${OpenMW_BINARY_DIR}
|
||||
-DVERSION_RESOURCE_FILE_IN=${VERSION_RESOURCE_FILE_IN}
|
||||
-DVERSION_RESOURCE_FILE_RELATIVE=${VERSION_RESOURCE_FILE_RELATIVE}
|
||||
-DVERSION_CPP_FILE=${VERSION_CPP_FILE}
|
||||
-DOPENMW_VERSION_MAJOR=${OPENMW_VERSION_MAJOR}
|
||||
-DOPENMW_VERSION_MINOR=${OPENMW_VERSION_MINOR}
|
||||
-DOPENMW_VERSION_RELEASE=${OPENMW_VERSION_RELEASE}
|
||||
|
@ -29,9 +33,12 @@ if (GIT_CHECKOUT)
|
|||
-P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/GitVersion.cmake
|
||||
VERBATIM)
|
||||
else (GIT_CHECKOUT)
|
||||
configure_file(${VERSION_IN_FILE} ${VERSION_FILE})
|
||||
configure_resource_file(${VERSION_RESOURCE_FILE_IN} ${OpenMW_BINARY_DIR} ${VERSION_RESOURCE_FILE_RELATIVE})
|
||||
configure_file("${OpenMW_SOURCE_DIR}/${VERSION_CPP_FILE}.in" "${OpenMW_BINARY_DIR}/${VERSION_CPP_FILE}")
|
||||
endif (GIT_CHECKOUT)
|
||||
|
||||
list (APPEND COMPONENT_FILES "${OpenMW_BINARY_DIR}/${VERSION_CPP_FILE}")
|
||||
|
||||
# source files
|
||||
|
||||
add_component_dir (lua
|
||||
|
@ -312,7 +319,6 @@ add_component_dir (sdlutil
|
|||
|
||||
add_component_dir (version
|
||||
version
|
||||
version.cpp
|
||||
)
|
||||
|
||||
add_component_dir (fallback
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#include "version.hpp"
|
||||
#include <components/version/version.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
namespace Version
|
||||
{
|
||||
|
@ -33,4 +36,15 @@ namespace Version
|
|||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
bool checkResourcesVersion(const std::filesystem::path& resourcePath)
|
||||
{
|
||||
std::ifstream stream(resourcePath / "version");
|
||||
std::string version, commitHash, tagHash;
|
||||
std::getline(stream, version);
|
||||
std::getline(stream, commitHash);
|
||||
std::getline(stream, tagHash);
|
||||
return getVersion() == version && getCommitHash() == commitHash && getTagHash() == tagHash;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef VERSION_HPP
|
||||
#define VERSION_HPP
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
|
@ -13,6 +14,8 @@ namespace Version
|
|||
|
||||
// Prepares string that contains version and commit hash.
|
||||
std::string getOpenmwVersionDescription();
|
||||
|
||||
bool checkResourcesVersion(const std::filesystem::path& resourcePath);
|
||||
}
|
||||
|
||||
#endif // VERSION_HPP
|
||||
|
|
3
files/version.in
Normal file
3
files/version.in
Normal file
|
@ -0,0 +1,3 @@
|
|||
@OPENMW_VERSION@
|
||||
@OPENMW_VERSION_COMMITHASH@
|
||||
@OPENMW_VERSION_TAGHASH@
|
Loading…
Reference in a new issue