MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / handleDataMigration

Method handleDataMigration

launcher/Application.cpp:1799–1883  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1797}
1798
1799bool Application::handleDataMigration(const QString& currentData,
1800 const QString& oldData,
1801 const QString& name,
1802 const QString& configFile) const
1803{
1804 QString nomigratePath = FS::PathCombine(currentData, name + "_nomigrate.txt");
1805 QStringList configPaths = { FS::PathCombine(oldData, configFile), FS::PathCombine(oldData, BuildConfig.LAUNCHER_CONFIGFILE) };
1806
1807 QLocale locale;
1808
1809 // Is there a valid config at the old location?
1810 bool configExists = false;
1811 for (QString configPath : configPaths) {
1812 configExists |= QFileInfo::exists(configPath);
1813 }
1814
1815 if (!configExists || QFileInfo::exists(nomigratePath)) {
1816 qDebug() << "<> No migration needed from" << name;
1817 return false;
1818 }
1819
1820 QString message;
1821 bool currentExists = QFileInfo::exists(FS::PathCombine(currentData, BuildConfig.LAUNCHER_CONFIGFILE));
1822
1823 if (currentExists) {
1824 message = tr("Old data from %1 was found, but you already have existing data for %2. Sadly you will need to migrate yourself. Do "
1825 "you want to be reminded of the pending data migration next time you start %2?")
1826 .arg(name, BuildConfig.LAUNCHER_DISPLAYNAME);
1827 } else {
1828 message = tr("It looks like you used %1 before. Do you want to migrate your data to the new location of %2?")
1829 .arg(name, BuildConfig.LAUNCHER_DISPLAYNAME);
1830
1831 QFileInfo logInfo(FS::PathCombine(oldData, name + "-0.log"));
1832 if (logInfo.exists()) {
1833 QString lastModified = logInfo.lastModified().toString(locale.dateFormat());
1834 message = tr("It looks like you used %1 on %2 before. Do you want to migrate your data to the new location of %3?")
1835 .arg(name, lastModified, BuildConfig.LAUNCHER_DISPLAYNAME);
1836 }
1837 }
1838
1839 QMessageBox::StandardButton askMoveDialogue =
1840 QMessageBox::question(nullptr, BuildConfig.LAUNCHER_DISPLAYNAME, message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
1841
1842 auto setDoNotMigrate = [&nomigratePath] {
1843 QFile file(nomigratePath);
1844 file.open(QIODevice::WriteOnly);
1845 };
1846
1847 // create no-migrate file if user doesn't want to migrate
1848 if (askMoveDialogue != QMessageBox::Yes) {
1849 qDebug() << "<> Migration declined for" << name;
1850 setDoNotMigrate();
1851 return currentExists; // cancel further migrations, if we already have a data directory
1852 }
1853
1854 if (!currentExists) {
1855 // Migrate!
1856 auto matcher = std::make_shared<MultiMatcher>();

Callers

nothing calls this directly

Calls 7

PathCombineFunction · 0.85
existsMethod · 0.80
openMethod · 0.80
execWithTaskMethod · 0.80
failReasonMethod · 0.80
toStringMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected