Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packed resources #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions base/base_file_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ QString FileNameFromUserString(QString name) {
return Platform::FileNameFromUserString(std::move(name));
}

void RegisterBundledResources(const QString &name) {
const auto location = Platform::BundledResourcesPath();
if (!QResource::registerResource(location + '/' + name)) {
Unexpected("Packed resources not found.");
void RegisterResourceArchive(const QString &name) {
#ifdef DESKTOP_APP_USE_PACKED_RESOURCES
for (const QString &location : Platform::PackedResourcesPaths()) {
if (QResource::registerResource(location + '/' + name)) {
return; // found
}
}
Unexpected("Packed resources not found.");
#endif // DESKTOP_APP_USE_PACKED_RESOURCES
}

} // namespace base
2 changes: 1 addition & 1 deletion base/base_file_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace base {

[[nodiscard]] QString FileNameFromUserString(QString name);

void RegisterBundledResources(const QString &name);
void RegisterResourceArchive(const QString &name);

} // namespace base
2 changes: 1 addition & 1 deletion base/platform/base_platform_file_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bool DeleteDirectory(QString path);
void RemoveQuarantine(const QString &path);

[[nodiscard]] QString CurrentExecutablePath(int argc, char *argv[]);
[[nodiscard]] QString BundledResourcesPath();
[[nodiscard]] QStringList PackedResourcesPaths();

bool RenameWithOverwrite(const QString &from, const QString &to);
void FlushFileData(QFile &file);
Expand Down
9 changes: 7 additions & 2 deletions base/platform/linux/base_file_utilities_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/platform/base_platform_file_utilities.h"
#include "base/platform/linux/base_linux_wayland_integration.h"
#include "base/algorithm.h"
#include "base/integration.h"

#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include "base/platform/linux/base_linux_app_launch_context.h"
Expand Down Expand Up @@ -190,8 +191,12 @@ QString CurrentExecutablePath(int argc, char *argv[]) {
void RemoveQuarantine(const QString &path) {
}

QString BundledResourcesPath() {
Unexpected("BundledResourcesPath not implemented.");
QStringList PackedResourcesPaths() {
return QStringList{
#ifdef _DEBUG
Integration::Instance().executableDir(),
#endif
} + QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
}

// From http://stackoverflow.com/questions/2256945/removing-a-non-empty-directory-programmatically-in-c-or-c
Expand Down
4 changes: 2 additions & 2 deletions base/platform/mac/base_file_utilities_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void RemoveQuarantine(const QString &path) {
removexattr(local.data(), kQuarantineAttribute, 0);
}

QString BundledResourcesPath() {
QStringList PackedResourcesPaths() {
@autoreleasepool {

NSString *path = @"";
Expand All @@ -47,7 +47,7 @@ QString BundledResourcesPath() {
Unexpected("Could not get bundled path!");
}
path = [path stringByAppendingString:@"/Contents/Resources"];
return QFile::decodeName([path fileSystemRepresentation]);
return { QFile::decodeName([path fileSystemRepresentation]) };
}
@catch (NSException *exception) {
Unexpected("Exception in resource registering.");
Expand Down
6 changes: 4 additions & 2 deletions base/platform/win/base_file_utilities_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/platform/win/base_windows_safe_library.h"
#include "base/algorithm.h"
#include "base/integration.h"

#include <QtCore/QString>
#include <QtCore/QDir>
Expand Down Expand Up @@ -142,8 +143,9 @@ bool DeleteDirectory(QString path) {
void RemoveQuarantine(const QString &path) {
}

QString BundledResourcesPath() {
Unexpected("BundledResourcesPath not implemented.");
QStringList PackedResourcesPaths() {
// Is verification of loaded resources really needed?
return { Integration::Instance().executableDir() };
}

QString CurrentExecutablePath(int argc, char *argv[]) {
Expand Down