Skip to content

Commit

Permalink
Packed resources
Browse files Browse the repository at this point in the history
Dynamically load packed resources from a separate file. This
reduces amount of main memory required for linking stage.
  • Loading branch information
mymedia2 committed Aug 13, 2022
1 parent 37fab6b commit aa55f5b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
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

0 comments on commit aa55f5b

Please sign in to comment.