File: 2007-Packed-resources.patch

package info (click to toggle)
telegram-desktop 5.7.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 63,488 kB
  • sloc: cpp: 756,228; python: 4,383; ansic: 1,505; javascript: 1,366; sh: 884; makefile: 820; objc: 652; xml: 565
file content (249 lines) | stat: -rw-r--r-- 10,040 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
Description: Dynamically load packed resources from separate file
 This reduces amount of main memory required for linking stage.
Author: Nicholas Guriev <guriev-ns@ya.ru>
Forwarded: https://github.com/telegramdesktop/tdesktop/pull/17339
Last-Update: Thu, 28 Dec 2023 18:15:35 +0300

--- a/Telegram/CMakeLists.txt
+++ b/Telegram/CMakeLists.txt
@@ -1909,7 +1909,12 @@ if (WIN32 AND CMAKE_CXX_COMPILER_FRONTEN
     endif()
 endif()
 
-target_prepare_qrc(Telegram)
+if (LINUX)
+    # Do not repeat app name in path of a resource archive.
+    target_prepare_qrc(Telegram tresources.rcc)
+else()
+    target_prepare_qrc(Telegram)
+endif()
 
 if (NOT DESKTOP_APP_DISABLE_AUTOUPDATE AND NOT build_macstore AND NOT build_winstore)
     add_executable(Updater WIN32)
@@ -2004,7 +2009,11 @@ if (LINUX AND DESKTOP_APP_USE_PACKAGED)
     configure_file("../lib/xdg/org.telegram.desktop.service" "${CMAKE_CURRENT_BINARY_DIR}/org.telegram.desktop.service" @ONLY)
     configure_file("../lib/xdg/org.telegram.desktop.metainfo.xml" "${CMAKE_CURRENT_BINARY_DIR}/org.telegram.desktop.metainfo.xml" @ONLY)
     generate_appdata_changelog(Telegram "${CMAKE_SOURCE_DIR}/changelog.txt" "${CMAKE_CURRENT_BINARY_DIR}/org.telegram.desktop.metainfo.xml")
-    install(TARGETS Telegram RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}")
+    install(TARGETS Telegram
+        RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+        BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}"
+        RESOURCE DESTINATION "${CMAKE_INSTALL_DATADIR}/TelegramDesktop"
+    )
     install(FILES "Resources/art/icon16.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/16x16/apps" RENAME "telegram.png")
     install(FILES "Resources/art/icon32.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/32x32/apps" RENAME "telegram.png")
     install(FILES "Resources/art/icon48.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps" RENAME "telegram.png")
--- a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp
+++ b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesk
 */
 #include "platform/linux/launcher_linux.h"
 
+#include "base/base_file_utilities.h"
 #include "core/crash_reports.h"
 #include "core/update_checker.h"
 #include "webview/platform/linux/webview_linux_webkitgtk.h"
@@ -33,6 +34,10 @@ int Launcher::exec() {
 	return Core::Launcher::exec();
 }
 
+void Launcher::initHook() {
+	base::RegisterResourceArchive(u"tresources.rcc"_q);
+}
+
 bool Launcher::launchUpdater(UpdaterLaunch action) {
 	if (cExeName().isEmpty()) {
 		return false;
--- a/Telegram/SourceFiles/platform/linux/launcher_linux.h
+++ b/Telegram/SourceFiles/platform/linux/launcher_linux.h
@@ -18,6 +18,7 @@ public:
 	int exec() override;
 
 private:
+	void initHook() override;
 	bool launchUpdater(UpdaterLaunch action) override;
 
 	bool _updating = false;
--- a/Telegram/SourceFiles/platform/mac/launcher_mac.mm
+++ b/Telegram/SourceFiles/platform/mac/launcher_mac.mm
@@ -24,7 +24,7 @@ Launcher::Launcher(int argc, char *argv[
 }
 
 void Launcher::initHook() {
-	base::RegisterBundledResources(u"Telegram.rcc"_q);
+	base::RegisterResourceArchive(u"Telegram.rcc"_q);
 }
 
 bool Launcher::launchUpdater(UpdaterLaunch action) {
--- a/Telegram/lib_base/CMakeLists.txt
+++ b/Telegram/lib_base/CMakeLists.txt
@@ -309,6 +309,13 @@ if (DESKTOP_APP_USE_ALLOCATION_TRACER)
     )
 endif()
 
+if (DESKTOP_APP_USE_PACKED_RESOURCES)
+    target_compile_definitions(lib_base
+    PRIVATE
+        DESKTOP_APP_USE_PACKED_RESOURCES
+    )
+endif()
+
 #target_precompile_headers(lib_base_crash_report_writer REUSE_FROM lib_base)
 target_precompile_headers(lib_base_crash_report_writer PRIVATE ${src_loc}/base/base_pch.h)
 nice_target_sources(lib_base_crash_report_writer ${src_loc}
--- a/Telegram/lib_base/base/base_file_utilities.cpp
+++ b/Telegram/lib_base/base/base_file_utilities.cpp
@@ -37,11 +37,15 @@ QString FileNameFromUserString(QString n
 	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
--- a/Telegram/lib_base/base/base_file_utilities.h
+++ b/Telegram/lib_base/base/base_file_utilities.h
@@ -10,6 +10,6 @@ namespace base {
 
 [[nodiscard]] QString FileNameFromUserString(QString name);
 
-void RegisterBundledResources(const QString &name);
+void RegisterResourceArchive(const QString &name);
 
 } // namespace base
--- a/Telegram/lib_base/base/platform/base_platform_file_utilities.h
+++ b/Telegram/lib_base/base/platform/base_platform_file_utilities.h
@@ -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);
--- a/Telegram/lib_base/base/platform/linux/base_file_utilities_linux.cpp
+++ b/Telegram/lib_base/base/platform/linux/base_file_utilities_linux.cpp
@@ -10,6 +10,7 @@
 #include "base/platform/linux/base_linux_xdp_utilities.h"
 #include "base/platform/linux/base_linux_xdg_activation_token.h"
 #include "base/algorithm.h"
+#include "base/integration.h"
 
 #include <QtCore/QFile>
 #include <QtCore/QFileInfo>
@@ -159,8 +160,12 @@ QString CurrentExecutablePath(int argc,
 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);
 }
 
 QString FileNameFromUserString(QString name) {
--- a/Telegram/lib_base/base/platform/mac/base_file_utilities_mac.mm
+++ b/Telegram/lib_base/base/platform/mac/base_file_utilities_mac.mm
@@ -34,7 +34,7 @@ void RemoveQuarantine(const QString &pat
 	removexattr(local.data(), kQuarantineAttribute, 0);
 }
 
-QString BundledResourcesPath() {
+QStringList PackedResourcesPaths() {
 	@autoreleasepool {
 
 	NSString *path = @"";
@@ -44,7 +44,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.");
--- a/Telegram/lib_base/base/platform/win/base_file_utilities_win.cpp
+++ b/Telegram/lib_base/base/platform/win/base_file_utilities_win.cpp
@@ -9,6 +9,7 @@
 #include "base/platform/win/base_windows_safe_library.h"
 #include "base/platform/win/base_windows_shlobj_h.h"
 #include "base/algorithm.h"
+#include "base/integration.h"
 
 #include <QtCore/QString>
 #include <QtCore/QDir>
@@ -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[]) {
--- a/Telegram/lib_ui/ui/style/style_core_font.cpp
+++ b/Telegram/lib_ui/ui/style/style_core_font.cpp
@@ -20,7 +20,7 @@
 void style_InitFontsResource() {
 #ifdef Q_OS_MAC // Use resources from the .app bundle on macOS.
 
-	base::RegisterBundledResources(u"lib_ui.rcc"_q);
+	base::RegisterResourceArchive(u"lib_ui.rcc"_q);
 
 #else // Q_OS_MAC
 
--- a/cmake/target_prepare_qrc.cmake
+++ b/cmake/target_prepare_qrc.cmake
@@ -17,7 +17,13 @@ function(target_add_resource target_name
 endfunction()
 
 function(target_prepare_qrc target_name)
-    if (NOT APPLE)
+    if (ARGC GREATER 1)
+        set(rcc_file ${ARGV1})
+    else()
+        set(rcc_file ${target_name}.rcc)
+    endif()
+
+    if (NOT DESKTOP_APP_USE_PACKED_RESOURCES)
         set_target_properties(${target_name} PROPERTIES AUTORCC ON)
     else()
         set(rcc_flags --binary "$<TARGET_PROPERTY:${target_name},AUTORCC_OPTIONS>")
@@ -34,7 +40,6 @@ function(target_prepare_qrc target_name)
         if (NOT qrc_files)
             return()
         endif()
-        set(rcc_file ${target_name}.rcc)
         set(rcc_path "${CMAKE_BINARY_DIR}/${rcc_file}")
         source_group(TREE ${CMAKE_BINARY_DIR} PREFIX Resources FILES ${rcc_path})
         add_custom_command(OUTPUT ${rcc_path}
--- a/cmake/variables.cmake
+++ b/cmake/variables.cmake
@@ -27,6 +27,7 @@ cmake_dependent_option(DESKTOP_APP_USE_A
 cmake_dependent_option(DESKTOP_APP_USE_PACKAGED_LAZY "Bundle recommended Qt plugins for self-contained packages." OFF LINUX OFF)
 option(DESKTOP_APP_USE_PACKAGED_FONTS "Use preinstalled fonts instead of bundled patched ones." OFF)
 option(DESKTOP_APP_USE_PACKAGED_RLOTTIE "Find rlottie using CMake instead of bundled patched one." OFF)
+option(DESKTOP_APP_USE_PACKED_RESOURCES "Whether to pack resources into a separate archive." ${APPLE})
 option(DESKTOP_APP_DISABLE_CRASH_REPORTS "Disable crash report generation." ${no_special_target})
 option(DESKTOP_APP_DISABLE_AUTOUPDATE "Disable autoupdate." ${disable_autoupdate})
 option(DESKTOP_APP_USE_HUNSPELL_ONLY "Disable system spellchecker and use bundled Hunspell only. (For debugging purposes)" OFF)