summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base/uninstall.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/base/uninstall.cpp')
-rw-r--r--rbutil/rbutilqt/base/uninstall.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/base/uninstall.cpp b/rbutil/rbutilqt/base/uninstall.cpp
new file mode 100644
index 0000000000..ae5ece7da5
--- /dev/null
+++ b/rbutil/rbutilqt/base/uninstall.cpp
@@ -0,0 +1,129 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id$
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <QtCore>
21#include "uninstall.h"
22#include "utils.h"
23
24Uninstaller::Uninstaller(QObject* parent,QString mountpoint): QObject(parent)
25{
26 m_mountpoint = mountpoint;
27}
28
29void Uninstaller::deleteAll(ProgressloggerInterface* dp)
30{
31 m_dp = dp;
32 QString rbdir(m_mountpoint + ".rockbox/");
33 m_dp->addItem(tr("Starting Uninstallation"),LOGINFO);
34 m_dp->setProgressMax(0);
35 recRmdir(rbdir);
36 m_dp->setProgressMax(1);
37 m_dp->setProgressValue(1);
38 m_dp->addItem(tr("Finished Uninstallation"),LOGOK);
39 m_dp->abort();
40}
41
42void Uninstaller::uninstall(ProgressloggerInterface* dp)
43{
44 m_dp = dp;
45 m_dp->setProgressMax(0);
46 m_dp->addItem(tr("Starting Uninstallation"),LOGINFO);
47
48 QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
49
50 for(int i=0; i< uninstallSections.size() ; i++)
51 {
52 m_dp->addItem(tr("Uninstalling ") + uninstallSections.at(i) + " ...",LOGINFO);
53 QCoreApplication::processEvents();
54 // create list of all other install sections
55 QStringList sections = installlog.childGroups();
56 sections.removeAt(sections.indexOf(uninstallSections.at(i)));
57 installlog.beginGroup(uninstallSections.at(i));
58 QStringList toDeleteList = installlog.allKeys();
59 QStringList dirList;
60 installlog.endGroup();
61
62 // iterate over all entries
63 for(int j =0; j < toDeleteList.size(); j++ )
64 {
65 // check if current file is in use by another section
66 bool deleteFile = true;
67 for(int s = 0; s < sections.size(); s++)
68 {
69 installlog.beginGroup(sections.at(s));
70 if(installlog.contains(toDeleteList.at(j)))
71 {
72 deleteFile = false;
73 qDebug() << "file still in use:" << toDeleteList.at(j);
74 }
75 installlog.endGroup();
76 }
77
78 installlog.beginGroup(uninstallSections.at(i));
79 QFileInfo toDelete(m_mountpoint + "/" + toDeleteList.at(j));
80 if(toDelete.isFile()) // if it is a file remove it
81 {
82 if(deleteFile && !QFile::remove(toDelete.filePath()))
83 m_dp->addItem(tr("Could not delete: ")+ toDelete.filePath(),LOGWARNING);
84 installlog.remove(toDeleteList.at(j));
85 qDebug() << "deleted: " << toDelete.filePath() ;
86 }
87 else // if it is a dir, remember it for later deletion
88 {
89 // no need to keep track on folders still in use -- only empty
90 // folders will be rm'ed.
91 dirList << toDeleteList.at(j);
92 }
93 installlog.endGroup();
94 QCoreApplication::processEvents();
95 }
96 // delete the dirs
97 installlog.beginGroup(uninstallSections.at(i));
98 for(int j=0; j < dirList.size(); j++ )
99 {
100 installlog.remove(dirList.at(j));
101 QDir dir(m_mountpoint);
102 dir.rmdir(dirList.at(j)); // rm works only on empty folders
103 }
104
105 installlog.endGroup();
106 //installlog.removeGroup(uninstallSections.at(i))
107 }
108 uninstallSections.clear();
109 installlog.sync();
110 m_dp->setProgressMax(1);
111 m_dp->setProgressValue(1);
112 m_dp->addItem(tr("Uninstallation finished"),LOGOK);
113 m_dp->abort();
114}
115
116QStringList Uninstaller::getAllSections()
117{
118 QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
119 QStringList allSections = installlog.childGroups();
120 allSections.removeAt(allSections.lastIndexOf("Bootloader"));
121 return allSections;
122}
123
124
125bool Uninstaller::uninstallPossible()
126{
127 return QFileInfo(m_mountpoint +"/.rockbox/rbutil.log").exists();
128}
129