| 1250 | } |
| 1251 | |
| 1252 | FilePath ProjectFileIO::SafetyFileName(const FilePath &src) |
| 1253 | { |
| 1254 | wxFileNameWrapper fn{ src }; |
| 1255 | |
| 1256 | // Extra characters inserted into filename before extension |
| 1257 | wxString extra = |
| 1258 | #ifdef __WXGTK__ |
| 1259 | wxT("~") |
| 1260 | #else |
| 1261 | wxT(".bak") |
| 1262 | #endif |
| 1263 | ; |
| 1264 | |
| 1265 | int nn = 1; |
| 1266 | auto numberString = [](int num) -> wxString { |
| 1267 | return num == 1 ? wxString{} : wxString::Format(".%d", num); |
| 1268 | }; |
| 1269 | |
| 1270 | auto suffixes = AuxiliaryFileSuffixes(); |
| 1271 | suffixes.push_back({}); |
| 1272 | |
| 1273 | // Find backup paths not already occupied; check all auxiliary suffixes |
| 1274 | const auto name = fn.GetName(); |
| 1275 | FilePath result; |
| 1276 | do { |
| 1277 | fn.SetName( name + numberString(nn++) + extra ); |
| 1278 | result = fn.GetFullPath(); |
| 1279 | } |
| 1280 | while( std::any_of(suffixes.begin(), suffixes.end(), [&](auto &suffix){ |
| 1281 | return wxFileExists(result + suffix); |
| 1282 | }) ); |
| 1283 | |
| 1284 | return result; |
| 1285 | } |
| 1286 | |
| 1287 | bool ProjectFileIO::RenameOrWarn(const FilePath &src, const FilePath &dst) |
| 1288 | { |