| 1257 | } |
| 1258 | |
| 1259 | String 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 | |
| 1301 | void StartFileChangeNotifications() { sgMountSystem.startFileChangeNotifications(); } |
| 1302 | void StopFileChangeNotifications() { sgMountSystem.stopFileChangeNotifications(); } |
no test coverage detected