- fixes for the portable build of Magic.TXD (using an embedded .zip archive)
@@ -31,7 +31,7 @@ | ||
31 | 31 | frame_path += QString::number( nframe ); |
32 | 32 | frame_path += img_ext; |
33 | 33 | |
34 | - if ( fileRoot->Exists( qt_to_filePath( frame_path ) ) == false ) | |
34 | + if ( RawGlobalFileExists( qt_to_filePath( frame_path ) ) == false ) | |
35 | 35 | break; |
36 | 36 | |
37 | 37 | QPixmap frame; |
@@ -106,7 +106,12 @@ | ||
106 | 106 | |
107 | 107 | if ( this->isRunningAnimation ) |
108 | 108 | { |
109 | - this->targetWidget->updatePixmap( frameStore->frames[ this->currentFrame ] ); | |
109 | + size_t curFrameCount = this->frameStore->frames.GetCount(); | |
110 | + | |
111 | + if ( this->currentFrame < curFrameCount ) | |
112 | + { | |
113 | + this->targetWidget->updatePixmap( frameStore->frames[ this->currentFrame ] ); | |
114 | + } | |
110 | 115 | } |
111 | 116 | else |
112 | 117 | { |
@@ -122,8 +127,13 @@ | ||
122 | 127 | { |
123 | 128 | this->animTimer->start(); |
124 | 129 | |
125 | - this->targetWidget->updatePixmap( this->frameStore->frames[ this->currentFrame ] ); | |
130 | + size_t curFrameCount = this->frameStore->frames.GetCount(); | |
126 | 131 | |
132 | + if ( this->currentFrame < curFrameCount ) | |
133 | + { | |
134 | + this->targetWidget->updatePixmap( this->frameStore->frames[ this->currentFrame ] ); | |
135 | + } | |
136 | + | |
127 | 137 | this->isRunningAnimation = true; |
128 | 138 | } |
129 | 139 | } |
@@ -13,7 +13,7 @@ | ||
13 | 13 | #ifndef _RENDERWARE_FILESYSTEM_STREAM_WRAP_ |
14 | 14 | #define _RENDERWARE_FILESYSTEM_STREAM_WRAP_ |
15 | 15 | |
16 | -CFile* RawOpenGlobalFile( CFileSystem *fileSys, const filePath& path, const filePath& mode ); | |
16 | +bool RawGlobalFileExists( const filePath& thePath ); | |
17 | 17 | CFile* OpenGlobalFile( MainWindow *mainWnd, const filePath& path, const filePath& mode ); |
18 | 18 | |
19 | 19 | rw::Stream* RwStreamCreateTranslated( rw::Interface *rwEngine, CFile *stream ); |
@@ -140,11 +140,6 @@ | ||
140 | 140 | } |
141 | 141 | }; |
142 | 142 | |
143 | -// Global plugins. | |
144 | -extern void registerQtFileSystem( void ); | |
145 | - | |
146 | -extern void unregisterQtFileSystem( void ); | |
147 | - | |
148 | 143 | // Main window plugin entry points. |
149 | 144 | extern void InitializeRWFileSystemWrap( void ); |
150 | 145 | extern void InitializeTaskCompletionWindowEnv( void ); |
@@ -326,43 +321,6 @@ | ||
326 | 321 | |
327 | 322 | rwEngine->SetApplicationInfo( metaInfo ); |
328 | 323 | |
329 | - struct qtfswrap_init | |
330 | - { | |
331 | - inline qtfswrap_init( void ) { registerQtFileSystem(); } | |
332 | - inline ~qtfswrap_init( void ) { unregisterQtFileSystem(); } | |
333 | - }; | |
334 | - | |
335 | - // Initialize global plugins. | |
336 | - qtfswrap_init _qtfswrap_init; | |
337 | - | |
338 | - // Create a translator whose root is placed in the application's directory. | |
339 | - FileSystem::fileTrans sysAppRoot = fileSystem->CreateTranslator( "//" ); | |
340 | - | |
341 | - if ( !sysAppRoot.is_good() ) | |
342 | - { | |
343 | - throw std::exception(); | |
344 | - } | |
345 | - | |
346 | - ::sysAppRoot = sysAppRoot; | |
347 | - | |
348 | - if ( fileRoot == nullptr ) | |
349 | - { | |
350 | - throw std::exception(); | |
351 | - } | |
352 | - | |
353 | - // Put our application path as first source of fresh files. | |
354 | - register_file_translator( fileRoot ); | |
355 | - | |
356 | - struct embedded_resources_init | |
357 | - { | |
358 | - inline embedded_resources_init( void ) { initialize_embedded_resources(); } | |
359 | - inline ~embedded_resources_init( void ) { shutdown_embedded_resources(); } | |
360 | - }; | |
361 | - | |
362 | - // Register embedded resources if present. | |
363 | - // Those are queried if files in our folder are not present. | |
364 | - embedded_resources_init _embedded_resources_init; | |
365 | - | |
366 | 324 | // removed library path stuff, because we statically link. |
367 | 325 | |
368 | 326 | MagicTXDApplication a(argc, argv); |
@@ -211,20 +211,11 @@ | ||
211 | 211 | // Just kick it off already. |
212 | 212 | rw::ResumeThread( rwEngine, execThread ); |
213 | 213 | |
214 | + LabelTaskCompletionWindow *waitWnd; | |
215 | + | |
214 | 216 | try |
215 | 217 | { |
216 | - // Tell the user that we are waiting. | |
217 | - LabelTaskCompletionWindow *waitWnd = new LabelTaskCompletionWindow( this, execThread, "ModifiedState.WaitingTitle", "ModifiedState.WaitingText", 150, true ); | |
218 | - | |
219 | - waitWnd->setCloseOnCompletion( true ); | |
220 | - | |
221 | - if ( blocking ) | |
222 | - { | |
223 | - QEventLoop loop; | |
224 | - connect( waitWnd, &QDialog::destroyed, &loop, &QEventLoop::quit ); | |
225 | - | |
226 | - loop.exec(); | |
227 | - } | |
218 | + waitWnd = new LabelTaskCompletionWindow( this, execThread, "ModifiedState.WaitingTitle", "ModifiedState.WaitingText", 150, true ); | |
228 | 219 | } |
229 | 220 | catch( ... ) |
230 | 221 | { |
@@ -232,4 +223,14 @@ | ||
232 | 223 | |
233 | 224 | throw; |
234 | 225 | } |
226 | + | |
227 | + waitWnd->setCloseOnCompletion( true ); | |
228 | + | |
229 | + if ( blocking ) | |
230 | + { | |
231 | + QEventLoop loop; | |
232 | + connect( waitWnd, &QDialog::destroyed, &loop, &QEventLoop::quit ); | |
233 | + | |
234 | + loop.exec(); | |
235 | + } | |
235 | 236 | } |
@@ -68,6 +68,76 @@ | ||
68 | 68 | // Translators that are visited in-order for files. |
69 | 69 | static optional_struct_space <eir::Vector <CFileTranslator*, FileSysCommonAllocator>> translators; |
70 | 70 | |
71 | +static inline filePath get_app_path( const filePath& input ) | |
72 | +{ | |
73 | + filePath relpath_appRoot; | |
74 | + | |
75 | + if ( sysAppRoot != nullptr && sysAppRoot->GetRelativePathFromRoot( input, true, relpath_appRoot ) ) | |
76 | + { | |
77 | + // Prepend the global translator root descriptor. | |
78 | + return "//" + std::move( relpath_appRoot ); | |
79 | + } | |
80 | + | |
81 | + return input; | |
82 | +} | |
83 | + | |
84 | +// Helper function for accessing the global filesystem. | |
85 | +CFile* RawOpenGlobalFileEx( const filePath& thePath, const filesysOpenMode& mode ) | |
86 | +{ | |
87 | + if ( has_file_system_registered == false ) | |
88 | + { | |
89 | + return nullptr; | |
90 | + } | |
91 | + | |
92 | + return filePath_dispatch( | |
93 | + get_app_path( thePath ), | |
94 | + [&]( auto path ) -> CFile* | |
95 | + { | |
96 | + size_t transCount = translators.get().GetCount(); | |
97 | + | |
98 | + for ( size_t n = 0; n < transCount; n++ ) | |
99 | + { | |
100 | + CFileTranslator *trans = translators.get()[ n ]; | |
101 | + | |
102 | + CFile *openFile = trans->Open( path, mode ); | |
103 | + | |
104 | + if ( openFile != nullptr ) | |
105 | + { | |
106 | + return openFile; | |
107 | + } | |
108 | + } | |
109 | + | |
110 | + return nullptr; | |
111 | + }); | |
112 | +} | |
113 | + | |
114 | +bool RawGlobalFileExists( const filePath& thePath ) | |
115 | +{ | |
116 | + if ( has_file_system_registered == false ) | |
117 | + { | |
118 | + return false; | |
119 | + } | |
120 | + | |
121 | + return filePath_dispatch( | |
122 | + get_app_path( thePath ), | |
123 | + [&]( auto path ) -> bool | |
124 | + { | |
125 | + size_t transCount = translators.get().GetCount(); | |
126 | + | |
127 | + for ( size_t n = 0; n < transCount; n++ ) | |
128 | + { | |
129 | + CFileTranslator *trans = translators.get()[ n ]; | |
130 | + | |
131 | + if ( trans->Exists( path ) ) | |
132 | + { | |
133 | + return true; | |
134 | + } | |
135 | + } | |
136 | + | |
137 | + return false; | |
138 | + }); | |
139 | +} | |
140 | + | |
71 | 141 | struct FileSystemQtFileEngine final : public QAbstractFileEngine |
72 | 142 | { |
73 | 143 | // Since there is no reason to access files outside of our executable, |
@@ -123,19 +193,6 @@ | ||
123 | 193 | close_all_references(); |
124 | 194 | |
125 | 195 | LIST_REMOVE( this->regNode ); |
126 | - } | |
127 | - | |
128 | - static inline filePath get_app_path( const filePath& input ) | |
129 | - { | |
130 | - filePath relpath_appRoot; | |
131 | - | |
132 | - if ( sysAppRoot != nullptr && sysAppRoot->GetRelativePathFromRoot( input, true, relpath_appRoot ) ) | |
133 | - { | |
134 | - // Prepend the global translator root descriptor. | |
135 | - return "//" + std::move( relpath_appRoot ); | |
136 | - } | |
137 | - | |
138 | - return input; | |
139 | 196 | } |
140 | 197 | |
141 | 198 | static inline bool is_valid_path_for_translators( const filePath& thePath ) |
@@ -159,28 +216,7 @@ | ||
159 | 216 | |
160 | 217 | inline CFile* open_first_translator_file( const filePath& thePath, const filesysOpenMode& mode ) noexcept |
161 | 218 | { |
162 | - if ( has_file_system_registered == false ) | |
163 | - { | |
164 | - return nullptr; | |
165 | - } | |
166 | - | |
167 | - filePath appPath = get_app_path( thePath ); | |
168 | - | |
169 | - size_t transCount = translators.get().GetCount(); | |
170 | - | |
171 | - for ( size_t n = 0; n < transCount; n++ ) | |
172 | - { | |
173 | - CFileTranslator *trans = translators.get()[ n ]; | |
174 | - | |
175 | - CFile *openFile = trans->Open( appPath, mode ); | |
176 | - | |
177 | - if ( openFile != nullptr ) | |
178 | - { | |
179 | - return openFile; | |
180 | - } | |
181 | - } | |
182 | - | |
183 | - return nullptr; | |
219 | + return RawOpenGlobalFileEx( thePath, mode ); | |
184 | 220 | } |
185 | 221 | |
186 | 222 | bool open( QIODevice::OpenMode openMode ) noexcept override |
@@ -1161,11 +1197,20 @@ | ||
1161 | 1197 | |
1162 | 1198 | static optional_struct_space <FileSystemQtFileEngineHandler> filesys_qt_wrap; |
1163 | 1199 | |
1164 | -void registerQtFileSystem( void ) | |
1200 | +void registerQtFileSystemTranslators( void ) | |
1165 | 1201 | { |
1166 | 1202 | translators.Construct(); |
1167 | 1203 | FileSystemQtFileEngine::listOfEngines.Construct(); |
1204 | +} | |
1168 | 1205 | |
1206 | +void unregisterQtFileSystemTranslators( void ) | |
1207 | +{ | |
1208 | + FileSystemQtFileEngine::listOfEngines.Destroy(); | |
1209 | + translators.Destroy(); | |
1210 | +} | |
1211 | + | |
1212 | +void registerQtFileSystem( void ) | |
1213 | +{ | |
1169 | 1214 | filesys_qt_wrap.Construct(); |
1170 | 1215 | |
1171 | 1216 | has_file_system_registered = true; |
@@ -1176,7 +1221,4 @@ | ||
1176 | 1221 | has_file_system_registered = false; |
1177 | 1222 | |
1178 | 1223 | filesys_qt_wrap.Destroy(); |
1179 | - | |
1180 | - FileSystemQtFileEngine::listOfEngines.Destroy(); | |
1181 | - translators.Destroy(); | |
1182 | 1224 | } |
@@ -12,26 +12,30 @@ | ||
12 | 12 | |
13 | 13 | #include "mainwindow.h" |
14 | 14 | |
15 | -// Helper function for accessing the global filesystem. | |
16 | -template <typename charType> | |
17 | -inline CFile* RawOpenGlobalFile( CFileSystem *fileSys, const charType *path, const charType *mode ) | |
15 | +// Global plugins. | |
16 | +extern void registerQtFileSystemTranslators( void ); | |
17 | +extern void registerQtFileSystem( void ); | |
18 | + | |
19 | +extern void unregisterQtFileSystemTranslators( void ); | |
20 | +extern void unregisterQtFileSystem( void ); | |
21 | + | |
22 | +extern CFile* RawOpenGlobalFileEx( const filePath& path, const filesysOpenMode& mode ); | |
23 | + | |
24 | +CFile* RawOpenGlobalFile( const filePath& path, const filePath& mode ) | |
18 | 25 | { |
19 | - return fileRoot->Open( path, mode ); | |
20 | -} | |
21 | - | |
22 | -CFile* RawOpenGlobalFile( CFileSystem *fileSys, const filePath& path, const filePath& mode ) | |
23 | -{ | |
24 | - return filePath_dispatchTrailing( | |
25 | - path, mode, | |
26 | - [&]( auto path, auto mode ) -> CFile* | |
26 | + filesysOpenMode openMode; | |
27 | + | |
28 | + if ( !FileSystem::ParseOpenMode( mode, openMode ) ) | |
27 | 29 | { |
28 | - return RawOpenGlobalFile( fileSys, path, mode ); | |
29 | - }); | |
30 | + return nullptr; | |
31 | + } | |
32 | + | |
33 | + return RawOpenGlobalFileEx( path, openMode ); | |
30 | 34 | } |
31 | 35 | |
32 | 36 | CFile* OpenGlobalFile( MainWindow *mainWnd, const filePath& path, const filePath& mode ) |
33 | 37 | { |
34 | - CFile *theFile = RawOpenGlobalFile( fileSystem, path, mode ); | |
38 | + CFile *theFile = RawOpenGlobalFile( path, mode ); | |
35 | 39 | |
36 | 40 | if ( theFile ) |
37 | 41 | { |
@@ -153,7 +157,7 @@ | ||
153 | 157 | // *** rw::FileInterface IMPL. |
154 | 158 | filePtr_t OpenStream( const char *streamPath, const char *mode ) override |
155 | 159 | { |
156 | - return (filePtr_t)RawOpenGlobalFile( this->nativeFileSystem, streamPath, mode ); | |
160 | + return (filePtr_t)RawOpenGlobalFile( streamPath, mode ); | |
157 | 161 | } |
158 | 162 | |
159 | 163 | void CloseStream( filePtr_t ptr ) override |
@@ -165,7 +169,7 @@ | ||
165 | 169 | |
166 | 170 | filePtr_t OpenStreamW( const wchar_t *streamPath, const wchar_t *mode ) override |
167 | 171 | { |
168 | - return (filePtr_t)RawOpenGlobalFile( this->nativeFileSystem, streamPath, mode ); | |
172 | + return (filePtr_t)RawOpenGlobalFile( streamPath, mode ); | |
169 | 173 | } |
170 | 174 | |
171 | 175 | size_t ReadStream( filePtr_t ptr, void *outBuf, size_t readCount ) override |
@@ -261,6 +265,33 @@ | ||
261 | 265 | // This is important because we need full access to the machine. |
262 | 266 | fileRoot->SetOutbreakEnabled( true ); |
263 | 267 | |
268 | + // Initialize global plugins. | |
269 | + registerQtFileSystemTranslators(); | |
270 | + | |
271 | + // Create a translator whose root is placed in the application's directory. | |
272 | + CFileTranslator *sysAppRoot = fileSystem->CreateTranslator( "//" ); | |
273 | + | |
274 | + if ( sysAppRoot == nullptr ) | |
275 | + { | |
276 | + throw std::exception(); | |
277 | + } | |
278 | + | |
279 | + ::sysAppRoot = sysAppRoot; | |
280 | + | |
281 | + if ( fileRoot == nullptr ) | |
282 | + { | |
283 | + throw std::exception(); | |
284 | + } | |
285 | + | |
286 | + // Put our application path as first source of fresh files. | |
287 | + register_file_translator( fileRoot ); | |
288 | + | |
289 | + // Register embedded resources if present. | |
290 | + // Those are queried if files in our folder are not present. | |
291 | + initialize_embedded_resources(); | |
292 | + | |
293 | + registerQtFileSystem(); | |
294 | + | |
264 | 295 | // Register the native file system wrapper type. |
265 | 296 | eirfs_file_wrap.nativeFileSystem = fileSys; |
266 | 297 |
@@ -275,6 +306,14 @@ | ||
275 | 306 | { |
276 | 307 | rwEngine->SetFileInterface( nullptr ); |
277 | 308 | |
309 | + unregisterQtFileSystem(); | |
310 | + | |
311 | + shutdown_embedded_resources(); | |
312 | + | |
313 | + delete sysAppRoot; | |
314 | + | |
315 | + unregisterQtFileSystemTranslators(); | |
316 | + | |
278 | 317 | // Shutdown the FileSystem module. |
279 | 318 | CFileSystem::Destroy( eirfs_file_wrap.nativeFileSystem ); |
280 | 319 |