mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-11-10 05:34:17 +00:00
Embed our data files inside the binary with QRC
This commit is contained in:
parent
b7116657d9
commit
c313f1a20b
7 changed files with 35 additions and 55 deletions
23
app/app.pro
23
app/app.pro
|
@ -302,18 +302,6 @@ DEPENDPATH += $$PWD/../h264bitstream/h264bitstream
|
|||
DEPENDPATH += $$PWD/../AntiHooking
|
||||
}
|
||||
|
||||
defineTest(copyToDestDir) {
|
||||
files = $$1
|
||||
|
||||
for(FILE, files) {
|
||||
!equals(PWD, $$OUT_PWD) {
|
||||
QMAKE_POST_LINK += $$QMAKE_COPY $$shell_quote($$shell_path($$PWD/$$FILE)) $$shell_quote($$shell_path($$OUT_PWD)) $$escape_expand(\\n\\t)
|
||||
}
|
||||
}
|
||||
|
||||
export(QMAKE_POST_LINK)
|
||||
}
|
||||
|
||||
unix:!macx: {
|
||||
isEmpty(PREFIX) {
|
||||
PREFIX = /usr/local
|
||||
|
@ -339,12 +327,6 @@ unix:!macx: {
|
|||
appdata.files = SDL_GameControllerDB/gamecontrollerdb.txt ModeSeven.ttf
|
||||
appdata.path = "$$PREFIX/$$DATADIR/Moonlight Game Streaming Project/Moonlight/"
|
||||
|
||||
CONFIG(debug, debug|release) {
|
||||
# Copy the required data files into the application directory only for debug builds.
|
||||
# Release builds will use the INSTALLS variable to place these in the correct folders.
|
||||
copyToDestDir(SDL_GameControllerDB/gamecontrollerdb.txt ModeSeven.ttf)
|
||||
}
|
||||
|
||||
INSTALLS += target appdata desktop icons appstream
|
||||
}
|
||||
win32 {
|
||||
|
@ -353,9 +335,6 @@ win32 {
|
|||
QMAKE_TARGET_DESCRIPTION = Moonlight Game Streaming Client
|
||||
QMAKE_TARGET_PRODUCT = Moonlight
|
||||
|
||||
# Copy the required data files into the application directory
|
||||
copyToDestDir(SDL_GameControllerDB/gamecontrollerdb.txt ModeSeven.ttf)
|
||||
|
||||
CONFIG -= embed_manifest_exe
|
||||
QMAKE_LFLAGS += /MANIFEST:embed /MANIFESTINPUT:$${PWD}/Moonlight.exe.manifest
|
||||
}
|
||||
|
@ -366,7 +345,7 @@ macx {
|
|||
|
||||
QMAKE_INFO_PLIST = $$OUT_PWD/Info.plist
|
||||
|
||||
APP_BUNDLE_RESOURCES.files = moonlight.icns SDL_GameControllerDB/gamecontrollerdb.txt ModeSeven.ttf
|
||||
APP_BUNDLE_RESOURCES.files = moonlight.icns
|
||||
APP_BUNDLE_RESOURCES.path = Contents/Resources
|
||||
|
||||
APP_BUNDLE_FRAMEWORKS.files = $$files(../libs/mac/Frameworks/*.framework, true)
|
||||
|
|
26
app/path.cpp
26
app/path.cpp
|
@ -21,6 +21,13 @@ QString Path::getBoxArtCacheDir()
|
|||
return s_BoxArtCacheDir;
|
||||
}
|
||||
|
||||
QByteArray Path::readDataFile(QString fileName)
|
||||
{
|
||||
QFile dataFile(getDataFilePath(fileName));
|
||||
dataFile.open(QIODevice::ReadOnly);
|
||||
return dataFile.readAll();
|
||||
}
|
||||
|
||||
QString Path::getDataFilePath(QString fileName)
|
||||
{
|
||||
QString candidatePath;
|
||||
|
@ -28,33 +35,28 @@ QString Path::getDataFilePath(QString fileName)
|
|||
// Check the current directory first
|
||||
candidatePath = QDir(QDir::currentPath()).absoluteFilePath(fileName);
|
||||
if (QFile::exists(candidatePath)) {
|
||||
qInfo() << "Found" << fileName << "at" << candidatePath;
|
||||
return candidatePath;
|
||||
}
|
||||
|
||||
// Now check the data directories (for Linux, in particular)
|
||||
candidatePath = QStandardPaths::locate(QStandardPaths::DataLocation, fileName);
|
||||
if (!candidatePath.isEmpty() && QFile::exists(candidatePath)) {
|
||||
qInfo() << "Found" << fileName << "at" << candidatePath;
|
||||
return candidatePath;
|
||||
}
|
||||
|
||||
// Now try the directory of our app installation (for Windows, if current dir doesn't find it)
|
||||
candidatePath = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(fileName);
|
||||
if (QFile::exists(candidatePath)) {
|
||||
qInfo() << "Found" << fileName << "at" << candidatePath;
|
||||
return candidatePath;
|
||||
}
|
||||
|
||||
// Now try the Resources folder in our app bundle for macOS
|
||||
QDir dir = QDir(QCoreApplication::applicationDirPath());
|
||||
dir.cdUp();
|
||||
dir.cd("Resources");
|
||||
dir.filePath(fileName);
|
||||
candidatePath = dir.absoluteFilePath(fileName);
|
||||
if (QFile::exists(candidatePath)) {
|
||||
return candidatePath;
|
||||
}
|
||||
|
||||
// Couldn't find it
|
||||
return QString();
|
||||
// Return the QRC embedded copy
|
||||
candidatePath = ":/data/" + fileName;
|
||||
qInfo() << "Found" << fileName << "at" << candidatePath;
|
||||
return QString(candidatePath);
|
||||
}
|
||||
|
||||
void Path::initialize(bool portable)
|
||||
|
|
|
@ -9,6 +9,9 @@ public:
|
|||
|
||||
static QString getBoxArtCacheDir();
|
||||
|
||||
static QByteArray readDataFile(QString fileName);
|
||||
|
||||
// Only safe to use directly for Qt classes
|
||||
static QString getDataFilePath(QString fileName);
|
||||
|
||||
static void initialize(bool portable);
|
||||
|
|
|
@ -16,4 +16,8 @@
|
|||
<file>res/moonlight.svg</file>
|
||||
<file>res/update.svg</file>
|
||||
</qresource>
|
||||
<qresource prefix="/data">
|
||||
<file alias="gamecontrollerdb.txt">SDL_GameControllerDB/gamecontrollerdb.txt</file>
|
||||
<file alias="ModeSeven.ttf">ModeSeven.ttf</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -54,15 +54,10 @@ void MappingManager::save()
|
|||
|
||||
void MappingManager::applyMappings()
|
||||
{
|
||||
QString mappingFile = Path::getDataFilePath("gamecontrollerdb.txt");
|
||||
if (!mappingFile.isEmpty()) {
|
||||
std::string mappingFileNative = QDir::toNativeSeparators(mappingFile).toStdString();
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Loading gamepad mappings from: %s",
|
||||
mappingFileNative.c_str());
|
||||
|
||||
int newMappings = SDL_GameControllerAddMappingsFromFile(mappingFileNative.c_str());
|
||||
QByteArray mappingData = Path::readDataFile("gamecontrollerdb.txt");
|
||||
if (!mappingData.isEmpty()) {
|
||||
int newMappings = SDL_GameControllerAddMappingsFromRW(
|
||||
SDL_RWFromConstMem(mappingData.constData(), mappingData.size()), 1);
|
||||
if (newMappings < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Error loading gamepad mappings: %s",
|
||||
|
@ -75,8 +70,8 @@ void MappingManager::applyMappings()
|
|||
}
|
||||
}
|
||||
else {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"No gamepad mapping file found");
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Unable to load gamepad mapping file");
|
||||
}
|
||||
|
||||
QList<SdlGamepadMapping> mappings = m_Mappings.values();
|
||||
|
|
|
@ -88,15 +88,16 @@ void SdlRenderer::notifyOverlayUpdated(Overlay::OverlayType type)
|
|||
{
|
||||
// Construct the required font to render the overlay
|
||||
if (m_OverlayFonts[type] == nullptr) {
|
||||
QByteArray fontPath = QDir::toNativeSeparators(Path::getDataFilePath("ModeSeven.ttf")).toUtf8();
|
||||
if (fontPath.isEmpty()) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Unable to locate SDL overlay font");
|
||||
QByteArray fontData = Path::readDataFile("ModeSeven.ttf");
|
||||
if (fontData.isEmpty()) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Unable to load SDL overlay font");
|
||||
return;
|
||||
}
|
||||
|
||||
m_OverlayFonts[type] = TTF_OpenFont(fontPath.data(),
|
||||
Session::get()->getOverlayManager().getOverlayFontSize(type));
|
||||
m_OverlayFonts[type] = TTF_OpenFontRW(SDL_RWFromConstMem(fontData.constData(), fontData.size()),
|
||||
1,
|
||||
Session::get()->getOverlayManager().getOverlayFontSize(type));
|
||||
if (m_OverlayFonts[type] == nullptr) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"TTF_OpenFont() failed: %s",
|
||||
|
|
|
@ -123,10 +123,6 @@ echo Copying GC mapping list
|
|||
copy %SOURCE_ROOT%\app\SDL_GameControllerDB\gamecontrollerdb.txt %DEPLOY_FOLDER%
|
||||
if !ERRORLEVEL! NEQ 0 goto Error
|
||||
|
||||
echo Copying SDL overlay font
|
||||
copy %SOURCE_ROOT%\app\ModeSeven.ttf %DEPLOY_FOLDER%
|
||||
if !ERRORLEVEL! NEQ 0 goto Error
|
||||
|
||||
echo Deploying Qt dependencies
|
||||
windeployqt.exe --dir %DEPLOY_FOLDER% --%BUILD_CONFIG% --qmldir %SOURCE_ROOT%\app\gui --no-opengl-sw --no-compiler-runtime %BUILD_FOLDER%\app\%BUILD_CONFIG%\Moonlight.exe
|
||||
if !ERRORLEVEL! NEQ 0 goto Error
|
||||
|
|
Loading…
Reference in a new issue