@@ -165,65 +165,106 @@ class spCleanupTexturePaths final : public Spell
165
165
if ( iBSSTS.isValid () ) {
166
166
QModelIndex iTextures = nif->getIndex ( iBSSTS, " Textures" );
167
167
168
- for ( int i = 0 ; i < nif->rowCount ( iTextures ); i++ ) {
169
- QString iFileName = nif->get <QString>( iTextures.child ( i, 0 ) ).replace ( " /" , " \\ " );
170
- int pos = iFileName.indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
171
- nif->set <QString>( iTextures.child ( i, 0 ), iFileName.replace ( iFileName.left ( pos + 1 ), " " ) );
172
- }
168
+ if ( iTextures.isValid () ) // adjust file paths
169
+ for ( int i = 0 ; i < nif->rowCount ( iTextures ); i++ ) {
170
+ QString iFileName = nif->get <QString>( iTextures.child ( i, 0 ) ).replace ( " /" , " \\ " );
171
+ int pos = iFileName.indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
172
+ if ( pos == 0 ) {
173
+ nif->set <QString>( iTextures.child ( i, 0 ), iFileName.remove ( 0 , 1 ) );
174
+ }
175
+ else {
176
+ nif->set <QString>( iTextures.child ( i, 0 ), iFileName.replace ( iFileName.left ( pos + 1 ), " " ) );
177
+ }
178
+ }
173
179
174
180
}
175
181
176
182
if ( iBSSNLP.isValid () ) {
177
- QModelIndex iFileName = nif->getIndex ( iBSSNLP, " File Name" );
183
+ QModelIndex iTexture = nif->getIndex ( iBSSNLP, " File Name" );
184
+ QString iFileName = nif->get <QString>( iTexture ).replace ( " /" , " \\ " );
185
+ int pos = iFileName.indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
178
186
179
- if ( iFileName.isValid () ) // adjust file path
180
- nif->set <QString>( iFileName, nif->get <QString>( iFileName ).replace ( " /" , " \\ " ) );
181
- int pos = nif->get <QString>( iFileName ).indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
182
- nif->set <QString>( iFileName, nif->get <QString>( iFileName ).replace ( nif->get <QString>( iFileName ).left ( pos + 1 ), " " ) );
187
+ if ( iTexture.isValid () ) // adjust file path
188
+ if ( pos == 0 ) {
189
+ nif->set <QString>( iTexture, iFileName.remove ( 0 , 1 ) );
190
+ }
191
+ else {
192
+ nif->set <QString>( iTexture, iFileName.replace ( iFileName.left ( pos + 1 ), " " ) );
193
+ }
183
194
184
195
}
185
196
186
197
if ( iBSESP.isValid () ) {
187
- QModelIndex iFileNameSource = nif->getIndex ( iBSESP, " Source Texture" );
188
- QModelIndex iFileNameGreyscale = nif->getIndex ( iBSESP, " Greyscale Texture" );
189
- QModelIndex iFileNameEnvMap = nif->getIndex ( iBSESP, " Env Map Texture" );
190
- QModelIndex iFileNameNormal = nif->getIndex ( iBSESP, " Normal Texture" );
191
- QModelIndex iFileNameEnvMask = nif->getIndex ( iBSESP, " Env Mask Texture" );
192
-
193
- if ( iFileNameSource.isValid () ) // adjust file path
194
- nif->set <QString>( iFileNameSource, nif->get <QString>( iFileNameSource ).replace ( " /" , " \\ " ) );
195
- int posSource = nif->get <QString>( iFileNameSource ).indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
196
- nif->set <QString>( iFileNameSource, nif->get <QString>( iFileNameSource ).replace ( nif->get <QString>( iFileNameSource ).left ( posSource + 1 ), " " ) );
197
-
198
- if ( iFileNameGreyscale.isValid () ) // adjust file path
199
- nif->set <QString>( iFileNameGreyscale, nif->get <QString>( iFileNameGreyscale ).replace ( " /" , " \\ " ) );
200
- int posGreyscale = nif->get <QString>( iFileNameGreyscale ).indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
201
- nif->set <QString>( iFileNameGreyscale, nif->get <QString>( iFileNameGreyscale ).replace ( nif->get <QString>( iFileNameGreyscale ).left ( posGreyscale + 1 ), " " ) );
202
-
203
- if ( iFileNameEnvMap.isValid () ) // adjust file path
204
- nif->set <QString>( iFileNameEnvMap, nif->get <QString>( iFileNameEnvMap ).replace ( " /" , " \\ " ) );
205
- int posEnvMap = nif->get <QString>( iFileNameEnvMap ).indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
206
- nif->set <QString>( iFileNameEnvMap, nif->get <QString>( iFileNameEnvMap ).replace ( nif->get <QString>( iFileNameEnvMap ).left ( posEnvMap + 1 ), " " ) );
207
-
208
- if ( iFileNameNormal.isValid () ) // adjust file path
209
- nif->set <QString>( iFileNameNormal, nif->get <QString>( iFileNameNormal ).replace ( " /" , " \\ " ) );
210
- int posNormal = nif->get <QString>( iFileNameNormal ).indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
211
- nif->set <QString>( iFileNameNormal, nif->get <QString>( iFileNameNormal ).replace ( nif->get <QString>( iFileNameNormal ).left ( posNormal + 1 ), " " ) );
212
-
213
- if ( iFileNameEnvMask.isValid () ) // adjust file path
214
- nif->set <QString>( iFileNameEnvMask, nif->get <QString>( iFileNameEnvMask ).replace ( " /" , " \\ " ) );
215
- int posEnvMask = nif->get <QString>( iFileNameEnvMask ).indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
216
- nif->set <QString>( iFileNameEnvMask, nif->get <QString>( iFileNameEnvMask ).replace ( nif->get <QString>( iFileNameEnvMask ).left ( posEnvMask + 1 ), " " ) );
198
+ QModelIndex iTextureSource = nif->getIndex ( iBSESP, " Source Texture" );
199
+ QModelIndex iTextureGreyscale = nif->getIndex ( iBSESP, " Greyscale Texture" );
200
+ QModelIndex iTextureEnvMap = nif->getIndex ( iBSESP, " Env Map Texture" );
201
+ QModelIndex iTextureNormal = nif->getIndex ( iBSESP, " Normal Texture" );
202
+ QModelIndex iTextureEnvMask = nif->getIndex ( iBSESP, " Env Mask Texture" );
203
+ QString iFileNameSource = nif->get <QString>( iTextureSource ).replace ( " /" , " \\ " );
204
+ QString iFileNameGreyscale = nif->get <QString>( iTextureGreyscale ).replace ( " /" , " \\ " );
205
+ QString iFileNameEnvMap = nif->get <QString>( iTextureEnvMap ).replace ( " /" , " \\ " );
206
+ QString iFileNameNormal = nif->get <QString>( iTextureNormal ).replace ( " /" , " \\ " );
207
+ QString iFileNameEnvMask = nif->get <QString>( iTextureEnvMask ).replace ( " /" , " \\ " );
208
+ int posSource = iFileNameSource.indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
209
+ int posGreyscale = iFileNameGreyscale.indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
210
+ int posEnvMap = iFileNameEnvMap.indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
211
+ int posNormal = iFileNameNormal.indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
212
+ int posEnvMask = iFileNameEnvMask.indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
213
+
214
+ if ( iTextureSource.isValid () ) // adjust source file path
215
+ if ( posSource == 0 ) {
216
+ nif->set <QString>( iTextureSource, iFileNameSource.remove ( 0 , 1 ) );
217
+ }
218
+ else {
219
+ nif->set <QString>( iTextureSource, iFileNameSource.replace ( iFileNameSource.left ( posSource + 1 ), " " ) );
220
+ }
221
+
222
+ if ( iTextureGreyscale.isValid () ) // adjust greyscale file path
223
+ if ( posGreyscale == 0 ) {
224
+ nif->set <QString>( iTextureGreyscale, iFileNameGreyscale.remove ( 0 , 1 ) );
225
+ }
226
+ else {
227
+ nif->set <QString>( iTextureGreyscale, iFileNameGreyscale.replace ( iFileNameGreyscale.left ( posGreyscale + 1 ), " " ) );
228
+ }
229
+
230
+ if ( iTextureEnvMap.isValid () ) // adjust env map file path
231
+ if ( posEnvMap == 0 ) {
232
+ nif->set <QString>( iTextureEnvMap, iFileNameEnvMap.remove ( 0 , 1 ) );
233
+ }
234
+ else {
235
+ nif->set <QString>( iTextureEnvMap, iFileNameEnvMap.replace ( iFileNameEnvMap.left ( posEnvMap + 1 ), " " ) );
236
+ }
237
+
238
+ if ( iTextureNormal.isValid () ) // adjust normal file path
239
+ if ( posNormal == 0 ) {
240
+ nif->set <QString>( iTextureNormal, iFileNameNormal.remove ( 0 , 1 ) );
241
+ }
242
+ else {
243
+ nif->set <QString>( iTextureNormal, iFileNameNormal.replace ( iFileNameNormal.left ( posNormal + 1 ), " " ) );
244
+ }
245
+
246
+ if ( iTextureEnvMask.isValid () ) // adjust env mask file path
247
+ if ( posEnvMask == 0 ) {
248
+ nif->set <QString>( iTextureEnvMask, iFileNameEnvMask.remove ( 0 , 1 ) );
249
+ }
250
+ else {
251
+ nif->set <QString>( iTextureEnvMask, iFileNameEnvMask.replace ( iFileNameEnvMask.left ( posEnvMask + 1 ), " " ) );
252
+ }
217
253
218
254
}
219
255
220
256
if ( iNiST.isValid () ) {
221
- QModelIndex iFileName = nif->getIndex ( iNiST, " File Name" );
257
+ QModelIndex iTexture = nif->getIndex ( iNiST, " File Name" );
258
+ QString iFileName = nif->get <QString>( iTexture ).replace ( " /" , " \\ " );
259
+ int pos = iFileName.indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
222
260
223
- if ( iFileName.isValid () ) // adjust file path
224
- nif->set <QString>( iFileName, nif->get <QString>( iFileName ).replace ( " /" , " \\ " ) );
225
- int pos = nif->get <QString>( iFileName ).indexOf ( QString ( " \\ textures\\ " ), 0 , Qt::CaseInsensitive );
226
- nif->set <QString>( iFileName, nif->get <QString>( iFileName ).replace ( nif->get <QString>( iFileName ).left ( pos + 1 ), " " ) );
261
+ if ( iTexture.isValid () ) // adjust file path
262
+ if ( pos == 0 ) {
263
+ nif->set <QString>( iTexture, iFileName.remove ( 0 , 1 ) );
264
+ }
265
+ else {
266
+ nif->set <QString>( iTexture, iFileName.replace ( iFileName.left ( pos + 1 ), " " ) );
267
+ }
227
268
228
269
if ( nif->checkVersion ( 0x14000005 , 0x14000005 ) ) {
229
270
// adjust format options (oblivion only)
0 commit comments