From 6c5a2d9c5cfdc9ecbea37418b343b92d95b676e7 Mon Sep 17 00:00:00 2001 From: Sakari Poussa Date: Sat, 5 Jun 2010 14:22:12 +0300 Subject: [PATCH] Store user data under user home directory so that it is not lost during re-flash. Also move the old data from /opt to home --- debian/postinst | 2 ++ src/main-window.cpp | 41 ++++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/debian/postinst b/debian/postinst index e720b3d..6e66897 100644 --- a/debian/postinst +++ b/debian/postinst @@ -3,5 +3,7 @@ gtk-update-icon-cache -f /usr/share/icons/hicolor mkdir -p /opt/scorecard/data chown user.users /opt/scorecard/data +#mkdir -p /home/user/.scorecard +#chown user.users /home/user/.scorecard #chown user.users /opt/scorecard/data/club.xml exit 0 diff --git a/src/main-window.cpp b/src/main-window.cpp index 7d7c5c6..0b53fd4 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -24,6 +24,7 @@ QString topDir("/opt"); QString mmcDir("/media/mmc1"); QString dataDirName("data"); QString dataDir; +QString userDataDir; QString imgDir(topDir + "/pixmaps"); QString scoreFileName("score.xml"); QString scoreFile; @@ -231,17 +232,43 @@ void MainWindow::loadSettings(void) dataDir = topDir + "/" + appName + "/" + dataDirName; } #endif - scoreFile = dataDir + "/" + scoreFileName; - clubFile = dataDir + "/" + clubFileName; - masterFile = dataDir + "/" + masterFileName; - QDir dir(dataDir); + userDataDir = QDir::homePath() + "/." + appName; + QDir dir(userDataDir); if (!dir.exists()) - if (!dir.mkpath(dataDir)) { - qWarning() << "Unable to create: " + dataDir; + if (!dir.mkpath(userDataDir)) { + qWarning() << "Unable to create: " + userDataDir; return; } - qDebug() << "Data is at:" + dataDir; + + masterFile = dataDir + "/" + masterFileName; + + // Store user data files under $HOME so they are not lost in + // re-flash + scoreFile = userDataDir + "/" + scoreFileName; + clubFile = userDataDir + "/" + clubFileName; + + // Start of 0.19 migration + // Copy existing user data to new location + // 0.18 and earlier: score.xml and club.xml are in /opt/scorecard/data + // 0.19 and later: score.xml and club.xml are in /home/user/.scorecard + QString scoreFileOld = dataDir + "/" + scoreFileName; + QString clubFileOld = dataDir + "/" + clubFileName; + + QFile file1(scoreFileOld); + QFile file2(clubFileOld); + QDir move; + if (file1.exists()) { + move.rename(scoreFileOld, scoreFile); + qDebug() << "Moved: " << scoreFileOld << "->" << scoreFile; + } + if (file2.exists()) { + move.rename(clubFileOld, clubFile); + qDebug() << "Moved: " << clubFileOld << "->" << clubFile; + } + // End of 0.19 migration + + qDebug() << "User data is at:" + userDataDir; settings.beginGroup(settingsGroup); conf.hcp = settings.value(settingsHcp); -- 1.7.9.5