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