returns a list of files and folders that must be deleted when deleting this instance
| 333 | // this instance |
| 334 | // |
| 335 | std::vector<Instance::Object> Instance::objectsForDeletion() const |
| 336 | { |
| 337 | // native separators and ending slash |
| 338 | auto prettyDir = [](auto s) { |
| 339 | if (!s.endsWith("/") || !s.endsWith("\\")) { |
| 340 | s += "/"; |
| 341 | } |
| 342 | |
| 343 | return QDir::toNativeSeparators(s); |
| 344 | }; |
| 345 | |
| 346 | // native separators |
| 347 | auto prettyFile = [](auto s) { |
| 348 | return QDir::toNativeSeparators(s); |
| 349 | }; |
| 350 | |
| 351 | // lowercase, native separators and ending slash |
| 352 | auto canonicalDir = [](QString s) { |
| 353 | s = s.toLower(); |
| 354 | |
| 355 | if (!s.endsWith("/") || !s.endsWith("\\")) { |
| 356 | s += "/"; |
| 357 | } |
| 358 | |
| 359 | return QDir::toNativeSeparators(s); |
| 360 | }; |
| 361 | |
| 362 | // lower and native separators |
| 363 | auto canonicalFile = [](auto s) { |
| 364 | return QDir::toNativeSeparators(s.toLower()); |
| 365 | }; |
| 366 | |
| 367 | // whether the given directory is contained in the root |
| 368 | auto dirInRoot = [&](const QString& root, const QString& dir) { |
| 369 | return canonicalDir(dir).startsWith(canonicalDir(root)); |
| 370 | }; |
| 371 | |
| 372 | // whether the given file is contained in the root |
| 373 | auto fileInRoot = [&](const QString& root, const QString& file) { |
| 374 | return canonicalFile(file).startsWith(canonicalDir(root)); |
| 375 | }; |
| 376 | |
| 377 | Settings settings(iniPath()); |
| 378 | |
| 379 | if (settings.iniStatus() != QSettings::NoError) { |
| 380 | log::error("can't read ini {}", iniPath()); |
| 381 | return {}; |
| 382 | } |
| 383 | |
| 384 | const QString loc = directory(); |
| 385 | const QString base = settings.paths().base(); |
| 386 | |
| 387 | // directories that might contain the individual files and directories |
| 388 | // set in the path settings |
| 389 | std::vector<Object> roots; |
| 390 | |
| 391 | // a portable instance has its location in the installation directory, |
| 392 | // don't delete that |
no test coverage detected