MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / MakeUniquePath

Function MakeUniquePath

Engine/source/core/volume.cpp:1259–1299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1257}
1258
1259String MakeUniquePath( const char *path, const char *fileName, const char *ext )
1260{
1261 Path filePath;
1262
1263 filePath.setPath( path );
1264 filePath.setFileName( fileName );
1265 filePath.setExtension( ext );
1266
1267 // First get an upper bound on the range of filenames to search. This lets us
1268 // quickly skip past a large number of existing filenames.
1269 // Note: upper limit of 2^31 added to handle the degenerate case of a folder
1270 // with files named using the powers of 2, but plenty of space in between!
1271 U32 high = 1;
1272 while ( IsFile( filePath ) && ( high < 0x80000000 ) )
1273 {
1274 high = high * 2;
1275 filePath.setFileName( String::ToString( "%s%d", fileName, high ) );
1276 }
1277
1278 // Now perform binary search for first filename in the range that doesn't exist
1279 // Note that the returned name will not be strictly numerically *first* if the
1280 // existing filenames are non-sequential (eg. 4,6,7), but it will still be unique.
1281 if ( high > 1 )
1282 {
1283 U32 low = high / 2;
1284 while ( high - low > 1 )
1285 {
1286 U32 probe = low + ( high - low ) / 2;
1287 filePath.setFileName( String::ToString( "%s%d", fileName, probe ) );
1288 if ( IsFile( filePath ) )
1289 low = probe;
1290 else
1291 high = probe;
1292 }
1293
1294 // The 'high' index is guaranteed not to exist
1295 filePath.setFileName( String::ToString( "%s%d", fileName, high ) );
1296 }
1297
1298 return filePath.getFullPath();
1299}
1300
1301void StartFileChangeNotifications() { sgMountSystem.startFileChangeNotifications(); }
1302void StopFileChangeNotifications() { sgMountSystem.stopFileChangeNotifications(); }

Callers 5

dumpShaderDisassemblyMethod · 0.85
postEffect.cppFile · 0.85
createMethod · 0.85
importMethod · 0.85
createNewFileMethod · 0.85

Calls 3

IsFileFunction · 0.85
setPathMethod · 0.45
setExtensionMethod · 0.45

Tested by

no test coverage detected