• R/O
  • SSH
  • HTTPS

magic-txd: Commit


Commit MetaInfo

Revision73 (tree)
Time2020-10-31 01:34:47
Authorquiret

Log Message

- fixes for the portable build of Magic.TXD (using an embedded .zip archive)

Change Summary

Incremental Difference

--- include/mainwindow.loadinganim.h (revision 72)
+++ include/mainwindow.loadinganim.h (revision 73)
@@ -31,7 +31,7 @@
3131 frame_path += QString::number( nframe );
3232 frame_path += img_ext;
3333
34- if ( fileRoot->Exists( qt_to_filePath( frame_path ) ) == false )
34+ if ( RawGlobalFileExists( qt_to_filePath( frame_path ) ) == false )
3535 break;
3636
3737 QPixmap frame;
@@ -106,7 +106,12 @@
106106
107107 if ( this->isRunningAnimation )
108108 {
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+ }
110115 }
111116 else
112117 {
@@ -122,8 +127,13 @@
122127 {
123128 this->animTimer->start();
124129
125- this->targetWidget->updatePixmap( this->frameStore->frames[ this->currentFrame ] );
130+ size_t curFrameCount = this->frameStore->frames.GetCount();
126131
132+ if ( this->currentFrame < curFrameCount )
133+ {
134+ this->targetWidget->updatePixmap( this->frameStore->frames[ this->currentFrame ] );
135+ }
136+
127137 this->isRunningAnimation = true;
128138 }
129139 }
--- include/rwfswrap.h (revision 72)
+++ include/rwfswrap.h (revision 73)
@@ -13,7 +13,7 @@
1313 #ifndef _RENDERWARE_FILESYSTEM_STREAM_WRAP_
1414 #define _RENDERWARE_FILESYSTEM_STREAM_WRAP_
1515
16-CFile* RawOpenGlobalFile( CFileSystem *fileSys, const filePath& path, const filePath& mode );
16+bool RawGlobalFileExists( const filePath& thePath );
1717 CFile* OpenGlobalFile( MainWindow *mainWnd, const filePath& path, const filePath& mode );
1818
1919 rw::Stream* RwStreamCreateTranslated( rw::Interface *rwEngine, CFile *stream );
--- src/main.cpp (revision 72)
+++ src/main.cpp (revision 73)
@@ -140,11 +140,6 @@
140140 }
141141 };
142142
143-// Global plugins.
144-extern void registerQtFileSystem( void );
145-
146-extern void unregisterQtFileSystem( void );
147-
148143 // Main window plugin entry points.
149144 extern void InitializeRWFileSystemWrap( void );
150145 extern void InitializeTaskCompletionWindowEnv( void );
@@ -326,43 +321,6 @@
326321
327322 rwEngine->SetApplicationInfo( metaInfo );
328323
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-
366324 // removed library path stuff, because we statically link.
367325
368326 MagicTXDApplication a(argc, argv);
--- src/mainwindow.safety.cpp (revision 72)
+++ src/mainwindow.safety.cpp (revision 73)
@@ -211,20 +211,11 @@
211211 // Just kick it off already.
212212 rw::ResumeThread( rwEngine, execThread );
213213
214+ LabelTaskCompletionWindow *waitWnd;
215+
214216 try
215217 {
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 );
228219 }
229220 catch( ... )
230221 {
@@ -232,4 +223,14 @@
232223
233224 throw;
234225 }
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+ }
235236 }
--- src/qtfilesystem.cpp (revision 72)
+++ src/qtfilesystem.cpp (revision 73)
@@ -68,6 +68,76 @@
6868 // Translators that are visited in-order for files.
6969 static optional_struct_space <eir::Vector <CFileTranslator*, FileSysCommonAllocator>> translators;
7070
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+
71141 struct FileSystemQtFileEngine final : public QAbstractFileEngine
72142 {
73143 // Since there is no reason to access files outside of our executable,
@@ -123,19 +193,6 @@
123193 close_all_references();
124194
125195 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;
139196 }
140197
141198 static inline bool is_valid_path_for_translators( const filePath& thePath )
@@ -159,28 +216,7 @@
159216
160217 inline CFile* open_first_translator_file( const filePath& thePath, const filesysOpenMode& mode ) noexcept
161218 {
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 );
184220 }
185221
186222 bool open( QIODevice::OpenMode openMode ) noexcept override
@@ -1161,11 +1197,20 @@
11611197
11621198 static optional_struct_space <FileSystemQtFileEngineHandler> filesys_qt_wrap;
11631199
1164-void registerQtFileSystem( void )
1200+void registerQtFileSystemTranslators( void )
11651201 {
11661202 translators.Construct();
11671203 FileSystemQtFileEngine::listOfEngines.Construct();
1204+}
11681205
1206+void unregisterQtFileSystemTranslators( void )
1207+{
1208+ FileSystemQtFileEngine::listOfEngines.Destroy();
1209+ translators.Destroy();
1210+}
1211+
1212+void registerQtFileSystem( void )
1213+{
11691214 filesys_qt_wrap.Construct();
11701215
11711216 has_file_system_registered = true;
@@ -1176,7 +1221,4 @@
11761221 has_file_system_registered = false;
11771222
11781223 filesys_qt_wrap.Destroy();
1179-
1180- FileSystemQtFileEngine::listOfEngines.Destroy();
1181- translators.Destroy();
11821224 }
--- src/rwfswrap.cpp (revision 72)
+++ src/rwfswrap.cpp (revision 73)
@@ -12,26 +12,30 @@
1212
1313 #include "mainwindow.h"
1414
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 )
1825 {
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 ) )
2729 {
28- return RawOpenGlobalFile( fileSys, path, mode );
29- });
30+ return nullptr;
31+ }
32+
33+ return RawOpenGlobalFileEx( path, openMode );
3034 }
3135
3236 CFile* OpenGlobalFile( MainWindow *mainWnd, const filePath& path, const filePath& mode )
3337 {
34- CFile *theFile = RawOpenGlobalFile( fileSystem, path, mode );
38+ CFile *theFile = RawOpenGlobalFile( path, mode );
3539
3640 if ( theFile )
3741 {
@@ -153,7 +157,7 @@
153157 // *** rw::FileInterface IMPL.
154158 filePtr_t OpenStream( const char *streamPath, const char *mode ) override
155159 {
156- return (filePtr_t)RawOpenGlobalFile( this->nativeFileSystem, streamPath, mode );
160+ return (filePtr_t)RawOpenGlobalFile( streamPath, mode );
157161 }
158162
159163 void CloseStream( filePtr_t ptr ) override
@@ -165,7 +169,7 @@
165169
166170 filePtr_t OpenStreamW( const wchar_t *streamPath, const wchar_t *mode ) override
167171 {
168- return (filePtr_t)RawOpenGlobalFile( this->nativeFileSystem, streamPath, mode );
172+ return (filePtr_t)RawOpenGlobalFile( streamPath, mode );
169173 }
170174
171175 size_t ReadStream( filePtr_t ptr, void *outBuf, size_t readCount ) override
@@ -261,6 +265,33 @@
261265 // This is important because we need full access to the machine.
262266 fileRoot->SetOutbreakEnabled( true );
263267
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+
264295 // Register the native file system wrapper type.
265296 eirfs_file_wrap.nativeFileSystem = fileSys;
266297
@@ -275,6 +306,14 @@
275306 {
276307 rwEngine->SetFileInterface( nullptr );
277308
309+ unregisterQtFileSystem();
310+
311+ shutdown_embedded_resources();
312+
313+ delete sysAppRoot;
314+
315+ unregisterQtFileSystemTranslators();
316+
278317 // Shutdown the FileSystem module.
279318 CFileSystem::Destroy( eirfs_file_wrap.nativeFileSystem );
280319
Show on old repository browser