mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 03:40:14 +00:00
Validate version of resources
This commit is contained in:
parent
f260fa006e
commit
d39552962f
1
.gitignore
vendored
1
.gitignore
vendored
@ -68,7 +68,6 @@ apps/wizard/ui_intropage.h
|
|||||||
apps/wizard/ui_languageselectionpage.h
|
apps/wizard/ui_languageselectionpage.h
|
||||||
apps/wizard/ui_methodselectionpage.h
|
apps/wizard/ui_methodselectionpage.h
|
||||||
components/ui_contentselector.h
|
components/ui_contentselector.h
|
||||||
components/version/version.cpp
|
|
||||||
docs/mainpage.hpp
|
docs/mainpage.hpp
|
||||||
docs/Doxyfile
|
docs/Doxyfile
|
||||||
docs/DoxyfilePages
|
docs/DoxyfilePages
|
||||||
|
@ -225,6 +225,10 @@ if(APPLE AND BUILD_OPENCS)
|
|||||||
MACOSX_PACKAGE_LOCATION Resources/resources)
|
MACOSX_PACKAGE_LOCATION Resources/resources)
|
||||||
set_source_files_properties(${OPENCS_OPENMW_CFG} PROPERTIES
|
set_source_files_properties(${OPENCS_OPENMW_CFG} PROPERTIES
|
||||||
MACOSX_PACKAGE_LOCATION Resources)
|
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()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(openmw-cs-lib
|
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}/openmw.cfg" ${BUNDLE_RESOURCES_DIR} COPYONLY)
|
||||||
configure_file("${OpenMW_BINARY_DIR}/gamecontrollerdb.txt" ${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(COCOA_FRAMEWORK Cocoa)
|
||||||
find_library(IOKIT_FRAMEWORK IOKit)
|
find_library(IOKIT_FRAMEWORK IOKit)
|
||||||
target_link_libraries(openmw ${COCOA_FRAMEWORK} ${IOKIT_FRAMEWORK})
|
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)
|
void OMW::Engine::setResourceDir(const std::filesystem::path& parResDir)
|
||||||
{
|
{
|
||||||
mResDir = 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
|
// Set start cell name
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
execute_process (
|
execute_process (
|
||||||
COMMAND ${GIT_EXECUTABLE} rev-list --tags --max-count=1
|
COMMAND ${GIT_EXECUTABLE} rev-list --tags --max-count=1
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
WORKING_DIRECTORY ${OpenMW_SOURCE_DIR}
|
||||||
RESULT_VARIABLE EXITCODE1
|
RESULT_VARIABLE EXITCODE1
|
||||||
OUTPUT_VARIABLE TAGHASH
|
OUTPUT_VARIABLE TAGHASH
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
@ -8,7 +8,7 @@ execute_process (
|
|||||||
|
|
||||||
execute_process (
|
execute_process (
|
||||||
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
|
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
WORKING_DIRECTORY ${OpenMW_SOURCE_DIR}
|
||||||
RESULT_VARIABLE EXITCODE2
|
RESULT_VARIABLE EXITCODE2
|
||||||
OUTPUT_VARIABLE COMMITHASH
|
OUTPUT_VARIABLE COMMITHASH
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
@ -28,4 +28,5 @@ endif ()
|
|||||||
|
|
||||||
include(${MACROSFILE})
|
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}")
|
list (APPEND cppfiles "${f}")
|
||||||
endforeach (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)
|
endforeach (u)
|
||||||
|
|
||||||
if (OPENMW_UNITY_BUILD)
|
if (OPENMW_UNITY_BUILD)
|
||||||
|
@ -6,18 +6,22 @@ if(APPLE)
|
|||||||
endif(APPLE)
|
endif(APPLE)
|
||||||
|
|
||||||
# Version file
|
# Version file
|
||||||
set (VERSION_IN_FILE "${OpenMW_SOURCE_DIR}/components/version/version.cpp.in")
|
set (VERSION_RESOURCE_FILE_IN "${OpenMW_SOURCE_DIR}/files/version.in")
|
||||||
set (VERSION_FILE "${OpenMW_SOURCE_DIR}/components/version/version.cpp")
|
set (VERSION_RESOURCE_FILE_RELATIVE "resources/version")
|
||||||
|
set (VERSION_CPP_FILE "components/version/version.cpp")
|
||||||
|
|
||||||
if (GIT_CHECKOUT)
|
if (GIT_CHECKOUT)
|
||||||
get_generator_is_multi_config(multi_config)
|
get_generator_is_multi_config(multi_config)
|
||||||
add_custom_command (
|
add_custom_command (
|
||||||
OUTPUT ${VERSION_FILE}
|
OUTPUT "${OpenMW_BINARY_DIR}/${VERSION_CPP_FILE}"
|
||||||
DEPENDS ${VERSION_IN_FILE}
|
DEPENDS "${OpenMW_SOURCE_DIR}/${VERSION_CPP_FILE}.in"
|
||||||
COMMAND ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
|
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
|
||||||
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
|
-DOpenMW_SOURCE_DIR=${OpenMW_SOURCE_DIR}
|
||||||
-DVERSION_IN_FILE=${VERSION_IN_FILE}
|
-DOpenMW_BINARY_DIR=${OpenMW_BINARY_DIR}
|
||||||
-DVERSION_FILE=${VERSION_FILE}
|
-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_MAJOR=${OPENMW_VERSION_MAJOR}
|
||||||
-DOPENMW_VERSION_MINOR=${OPENMW_VERSION_MINOR}
|
-DOPENMW_VERSION_MINOR=${OPENMW_VERSION_MINOR}
|
||||||
-DOPENMW_VERSION_RELEASE=${OPENMW_VERSION_RELEASE}
|
-DOPENMW_VERSION_RELEASE=${OPENMW_VERSION_RELEASE}
|
||||||
@ -29,9 +33,12 @@ if (GIT_CHECKOUT)
|
|||||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/GitVersion.cmake
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/GitVersion.cmake
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
else (GIT_CHECKOUT)
|
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)
|
endif (GIT_CHECKOUT)
|
||||||
|
|
||||||
|
list (APPEND COMPONENT_FILES "${OpenMW_BINARY_DIR}/${VERSION_CPP_FILE}")
|
||||||
|
|
||||||
# source files
|
# source files
|
||||||
|
|
||||||
add_component_dir (lua
|
add_component_dir (lua
|
||||||
@ -312,7 +319,6 @@ add_component_dir (sdlutil
|
|||||||
|
|
||||||
add_component_dir (version
|
add_component_dir (version
|
||||||
version
|
version
|
||||||
version.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (fallback
|
add_component_dir (fallback
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
#include "version.hpp"
|
#include <components/version/version.hpp>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
namespace Version
|
namespace Version
|
||||||
{
|
{
|
||||||
@ -33,4 +36,15 @@ namespace Version
|
|||||||
}
|
}
|
||||||
return str;
|
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
|
#ifndef VERSION_HPP
|
||||||
#define VERSION_HPP
|
#define VERSION_HPP
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
@ -13,6 +14,8 @@ namespace Version
|
|||||||
|
|
||||||
// Prepares string that contains version and commit hash.
|
// Prepares string that contains version and commit hash.
|
||||||
std::string getOpenmwVersionDescription();
|
std::string getOpenmwVersionDescription();
|
||||||
|
|
||||||
|
bool checkResourcesVersion(const std::filesystem::path& resourcePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // VERSION_HPP
|
#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…
x
Reference in New Issue
Block a user