Switching to binary resources

This commit is contained in:
Brad Davis 2018-01-10 13:39:56 -08:00
parent 10a67fd9f8
commit 7a7aee770c
6 changed files with 93 additions and 54 deletions

View file

@ -12,9 +12,14 @@ function(GENERATE_QRC)
foreach(GLOB ${GENERATE_QRC_GLOBS}) foreach(GLOB ${GENERATE_QRC_GLOBS})
file(GLOB_RECURSE FOUND_FILES RELATIVE ${GENERATE_QRC_PATH} ${GLOB}) file(GLOB_RECURSE FOUND_FILES RELATIVE ${GENERATE_QRC_PATH} ${GLOB})
foreach(FILENAME ${FOUND_FILES}) foreach(FILENAME ${FOUND_FILES})
if (${FILENAME} MATCHES "^\\.\\.")
continue()
endif()
list(APPEND ALL_FILES "${GENERATE_QRC_PATH}/${FILENAME}")
set(QRC_CONTENTS "${QRC_CONTENTS}<file alias=\"${FILENAME}\">${GENERATE_QRC_PATH}/${FILENAME}</file>\n") set(QRC_CONTENTS "${QRC_CONTENTS}<file alias=\"${FILENAME}\">${GENERATE_QRC_PATH}/${FILENAME}</file>\n")
endforeach() endforeach()
endforeach() endforeach()
set(GENERATE_QRC_DEPENDS ${ALL_FILES} PARENT_SCOPE)
configure_file("${HF_CMAKE_DIR}/templates/resources.qrc.in" ${GENERATE_QRC_OUTPUT}) configure_file("${HF_CMAKE_DIR}/templates/resources.qrc.in" ${GENERATE_QRC_OUTPUT})
endfunction() endfunction()

View file

@ -11,8 +11,21 @@ function(JOIN VALUES GLUE OUTPUT)
set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE) set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
endfunction() endfunction()
set(INTERFACE_QML_QRC ${CMAKE_CURRENT_BINARY_DIR}/qml.qrc) set(RESOURCES_QRC ${CMAKE_CURRENT_BINARY_DIR}/resources.qrc)
generate_qrc(OUTPUT ${INTERFACE_QML_QRC} PATH ${CMAKE_CURRENT_SOURCE_DIR}/resources GLOBS *.qml *.qss *.js *.html *.ttf *.gif *.svg *.png *.jpg) set(RESOURCES_RCC ${CMAKE_CURRENT_BINARY_DIR}/resources.rcc)
generate_qrc(OUTPUT ${RESOURCES_QRC} PATH ${CMAKE_CURRENT_SOURCE_DIR}/resources GLOBS *)
add_custom_command(
OUTPUT ${RESOURCES_RCC}
COMMAND "${QT_DIR}/bin/rcc"
ARGS ${RESOURCES_QRC} -binary -o ${RESOURCES_RCC}
MAIN_DEPENDENCY ${RESOURCES_QRC}
DEPENDS ${GENERATE_QRC_DEPENDS}
)
list(APPEND GENERATE_QRC_DEPENDS ${RESOURCES_RCC})
add_custom_target(resources ALL DEPENDS ${GENERATE_QRC_DEPENDS})
# set a default root dir for each of our optional externals if it was not passed # set a default root dir for each of our optional externals if it was not passed
set(OPTIONAL_EXTERNALS "LeapMotion") set(OPTIONAL_EXTERNALS "LeapMotion")
@ -71,16 +84,6 @@ qt5_wrap_ui(QT_UI_HEADERS "${QT_UI_FILES}")
# add them to the interface source files # add them to the interface source files
set(INTERFACE_SRCS ${INTERFACE_SRCS} "${QT_UI_HEADERS}" "${QT_RESOURCES}") set(INTERFACE_SRCS ${INTERFACE_SRCS} "${QT_UI_HEADERS}" "${QT_RESOURCES}")
list(APPEND INTERFACE_SRCS ${INTERFACE_QML_QRC})
if (UNIX)
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/interface/resources/qml"
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/resources
COMPONENT ${CLIENT_COMPONENT}
)
endif()
# translation disabled until we strip out the line numbers # translation disabled until we strip out the line numbers
# set(QM ${TARGET_NAME}_en.qm) # set(QM ${TARGET_NAME}_en.qm)
# set(TS ${TARGET_NAME}_en.ts) # set(TS ${TARGET_NAME}_en.ts)
@ -160,6 +163,8 @@ else ()
add_executable(${TARGET_NAME} ${INTERFACE_SRCS} ${QM}) add_executable(${TARGET_NAME} ${INTERFACE_SRCS} ${QM})
endif () endif ()
add_dependencies(${TARGET_NAME} resources)
if (WIN32) if (WIN32)
# These are external plugins, but we need to do the 'add dependency' here so that their # These are external plugins, but we need to do the 'add dependency' here so that their
# binary directories get added to the fixup path # binary directories get added to the fixup path
@ -235,7 +240,7 @@ foreach(EXTERNAL ${OPTIONAL_EXTERNALS})
if (NOT APPLE OR NOT ${${EXTERNAL}_UPPERCASE} MATCHES "SIXENSE") if (NOT APPLE OR NOT ${${EXTERNAL}_UPPERCASE} MATCHES "SIXENSE")
target_link_libraries(${TARGET_NAME} ${${${EXTERNAL}_UPPERCASE}_LIBRARIES}) target_link_libraries(${TARGET_NAME} ${${${EXTERNAL}_UPPERCASE}_LIBRARIES})
elseif (APPLE AND NOT INSTALLER_BUILD) elseif (APPLE AND NOT INSTALLER_BUILD)
add_definitions(-DSIXENSE_LIB_FILENAME=\"${${${EXTERNAL}_UPPERCASE}_LIBRARY_RELEASE}\") #add_definitions(-DSIXENSE_LIB_FILENAME=\"${${${EXTERNAL}_UPPERCASE}_LIBRARY_RELEASE}\")
endif () endif ()
endif () endif ()
endforeach() endforeach()
@ -294,12 +299,12 @@ if (APPLE)
# call the fixup_interface macro to add required bundling commands for installation # call the fixup_interface macro to add required bundling commands for installation
fixup_interface() fixup_interface()
else (APPLE) else()
# copy the resources files beside the executable # copy the resources files beside the executable
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_directory COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${PROJECT_SOURCE_DIR}/resources" "${RESOURCES_RCC}"
"$<TARGET_FILE_DIR:${TARGET_NAME}>/resources" "$<TARGET_FILE_DIR:interface>"
COMMAND "${CMAKE_COMMAND}" -E copy_directory COMMAND "${CMAKE_COMMAND}" -E copy_directory
"${CMAKE_SOURCE_DIR}/scripts" "${CMAKE_SOURCE_DIR}/scripts"
"$<TARGET_FILE_DIR:${TARGET_NAME}>/scripts" "$<TARGET_FILE_DIR:${TARGET_NAME}>/scripts"
@ -325,7 +330,7 @@ else (APPLE)
optional_win_executable_signing() optional_win_executable_signing()
endif() endif()
endif (APPLE) endif()
if (SCRIPTS_INSTALL_DIR) if (SCRIPTS_INSTALL_DIR)

View file

@ -21,6 +21,7 @@
#include <glm/gtx/vector_angle.hpp> #include <glm/gtx/vector_angle.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
#include <QtCore/QResource>
#include <QtCore/QAbstractNativeEventFilter> #include <QtCore/QAbstractNativeEventFilter>
#include <QtCore/QCommandLineParser> #include <QtCore/QCommandLineParser>
#include <QtCore/QMimeData> #include <QtCore/QMimeData>
@ -804,6 +805,18 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
_sampleSound(nullptr) _sampleSound(nullptr)
{ {
{
#if defined(Q_OS_ANDROID)
const QString resourcesBinaryFile = "assets:resources.rcc";
#else
const QString resourcesBinaryFile = QFileInfo(argv[0]).absolutePath() + "/resources.rcc";
#endif
if (!QResource::registerResource(resourcesBinaryFile)) {
throw std::runtime_error("Unable to load primary resources");
}
}
auto steamClient = PluginManager::getInstance()->getSteamClientPlugin(); auto steamClient = PluginManager::getInstance()->getSteamClientPlugin();
setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning())); setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning()));
setProperty(hifi::properties::CRASHED, _previousSessionCrashed); setProperty(hifi::properties::CRASHED, _previousSessionCrashed);

View file

@ -11,17 +11,20 @@
#include "PathUtils.h" #include "PathUtils.h"
#include <QCoreApplication>
#include <QString>
#include <QVector>
#include <QDateTime>
#include <QFileInfo>
#include <QDir>
#include <QDirIterator>
#include <QUrl>
#include <QtCore/QStandardPaths>
#include <QRegularExpression>
#include <mutex> // std::once #include <mutex> // std::once
#include <QtCore/QCoreApplication>
#include <QtCore/QDateTime>
#include <QtCore/QDir>
#include <QtCore/QDirIterator>
#include <QtCore/QFileInfo>
#include <QtCore/QProcessEnvironment>
#include <QtCore/QRegularExpression>
#include <QtCore/QStandardPaths>
#include <QtCore/QString>
#include <QtCore/QUrl>
#include <QtCore/QVector>
#include "shared/GlobalAppProperties.h" #include "shared/GlobalAppProperties.h"
#include "SharedUtil.h" #include "SharedUtil.h"
@ -29,16 +32,10 @@
// Example: ... // Example: ...
QString TEMP_DIR_FORMAT { "%1-%2-%3" }; QString TEMP_DIR_FORMAT { "%1-%2-%3" };
const QString& PathUtils::resourcesPath() { #if !defined(Q_OS_ANDROID) && defined(DEV_BUILD)
#ifdef Q_OS_MAC static const QString USE_SOURCE_TREE_RESOURCES_FLAG("HIFI_USE_SOURCE_TREE_RESOURCES");
static const QString staticResourcePath = QCoreApplication::applicationDirPath() + "/../Resources/"; static bool USE_SOURCE_TREE_RESOURCES = QProcessEnvironment::systemEnvironment().contains(USE_SOURCE_TREE_RESOURCES_FLAG);
#elif defined (ANDROID)
static const QString staticResourcePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/resources/";
#else
static const QString staticResourcePath = QCoreApplication::applicationDirPath() + "/resources/";
#endif #endif
return staticResourcePath;
}
#ifdef DEV_BUILD #ifdef DEV_BUILD
const QString& PathUtils::projectRootPath() { const QString& PathUtils::projectRootPath() {
@ -52,15 +49,28 @@ const QString& PathUtils::projectRootPath() {
} }
#endif #endif
const QString& PathUtils::qmlBasePath() { const QString& PathUtils::resourcesPath() {
#ifdef Q_OS_ANDROID #if !defined(Q_OS_ANDROID) && defined(DEV_BUILD)
static const QString staticResourcePath = "qrc:///qml/"; // For dev builds, load
#elif defined (DEV_BUILD) if (USE_SOURCE_TREE_RESOURCES) {
static const QString staticResourcePath = QUrl::fromLocalFile(projectRootPath() + "/interface/resources/qml/").toString(); static const QString staticResourcePath = projectRootPath() + "/interface/resources/";
#else return staticResourcePath;
static const QString staticResourcePath = "qrc:///qml/"; }
#endif #endif
static const QString staticResourcePath = ":/";
return staticResourcePath;
}
// FIXME rename to qmlBaseUrl
const QString& PathUtils::qmlBasePath() {
#if !defined(Q_OS_ANDROID) && defined(DEV_BUILD)
// For dev builds, load
if (USE_SOURCE_TREE_RESOURCES) {
static const QString staticResourcePath = QUrl::fromLocalFile(projectRootPath() + "/interface/resources/qml").toString();
return staticResourcePath;
}
#endif
static const QString staticResourcePath = "qrc:///qml/";
return staticResourcePath; return staticResourcePath;
} }

View file

@ -79,12 +79,14 @@ FileStorage::FileStorage(const QString& filename) : _file(filename) {
} }
if (opened) { if (opened) {
_mapped = _file.map(0, _file.size()); _size = _file.size();
if (_mapped) { _mapped = _file.map(0, _size);
_valid = true; if (!_mapped) {
} else { qCDebug(storagelogging) << "Failed to map file, falling back to memory storage " << filename;
qCWarning(storagelogging) << "Failed to map file " << filename; _fallback = _file.readAll();
_mapped = (uint8_t*)_fallback.data();
} }
_valid = true;
} else { } else {
qCWarning(storagelogging) << "Failed to open file " << filename; qCWarning(storagelogging) << "Failed to open file " << filename;
} }
@ -92,7 +94,9 @@ FileStorage::FileStorage(const QString& filename) : _file(filename) {
FileStorage::~FileStorage() { FileStorage::~FileStorage() {
if (_mapped) { if (_mapped) {
if (_fallback.isEmpty()) {
_file.unmap(_mapped); _file.unmap(_mapped);
}
_mapped = nullptr; _mapped = nullptr;
} }
if (_file.isOpen()) { if (_file.isOpen()) {

View file

@ -61,10 +61,12 @@ namespace storage {
const uint8_t* data() const override { return _mapped; } const uint8_t* data() const override { return _mapped; }
uint8_t* mutableData() override { return _hasWriteAccess ? _mapped : nullptr; } uint8_t* mutableData() override { return _hasWriteAccess ? _mapped : nullptr; }
size_t size() const override { return _file.size(); } size_t size() const override { return _size; }
operator bool() const override { return _valid; } operator bool() const override { return _valid; }
private: private:
// For compressed QRC files we can't map the file object, so we need to read it into memory
QByteArray _fallback;
size_t _size { 0 };
bool _valid { false }; bool _valid { false };
bool _hasWriteAccess { false }; bool _hasWriteAccess { false };
QFile _file; QFile _file;