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 Jan 21, 2022
1 parent 35bee5b commit 6be7c43
Show file tree
Hide file tree
Showing 6 changed files with 24 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
10 changes: 8 additions & 2 deletions base/platform/linux/base_file_utilities_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

#include "base/platform/base_platform_file_utilities.h"
#include "base/algorithm.h"
#include "base/integration.h"

#include <QtCore/QProcess>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/QStandardPaths>
#include <QtGui/QDesktopServices>

#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
Expand Down Expand Up @@ -216,8 +218,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 6be7c43

Please sign in to comment.