Packard Bell Vibe 500: correct the path to a proper one in rbutil (proper directory...
[kugel-rb.git] / rbutil / rbutilqt / base / uninstall.cpp
blob15ada35c5ef723746a9e3f6e147e1166ac3c4587
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id$
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <QtCore>
21 #include "uninstall.h"
22 #include "utils.h"
24 Uninstaller::Uninstaller(QObject* parent,QString mountpoint): QObject(parent)
26 m_mountpoint = mountpoint;
29 void Uninstaller::deleteAll(ProgressloggerInterface* dp)
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->setFinished();
42 void Uninstaller::uninstall(ProgressloggerInterface* dp)
44 m_dp = dp;
45 m_dp->setProgressMax(0);
46 m_dp->addItem(tr("Starting Uninstallation"),LOGINFO);
48 QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
50 for(int i=0; i< uninstallSections.size() ; i++)
52 m_dp->addItem(tr("Uninstalling %1...").arg(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();
62 // iterate over all entries
63 for(int j =0; j < toDeleteList.size(); j++ )
65 // check if current file is in use by another section
66 bool deleteFile = true;
67 for(int s = 0; s < sections.size(); s++)
69 installlog.beginGroup(sections.at(s));
70 if(installlog.contains(toDeleteList.at(j)))
72 deleteFile = false;
73 qDebug() << "file still in use:" << toDeleteList.at(j);
75 installlog.endGroup();
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
82 if(deleteFile && !QFile::remove(toDelete.filePath()))
83 m_dp->addItem(tr("Could not delete %1")
84 .arg(toDelete.filePath()),LOGWARNING);
85 installlog.remove(toDeleteList.at(j));
86 qDebug() << "deleted: " << toDelete.filePath() ;
88 else // if it is a dir, remember it for later deletion
90 // no need to keep track on folders still in use -- only empty
91 // folders will be rm'ed.
92 dirList << toDeleteList.at(j);
94 installlog.endGroup();
95 QCoreApplication::processEvents();
97 // delete the dirs
98 installlog.beginGroup(uninstallSections.at(i));
99 for(int j=0; j < dirList.size(); j++ )
101 installlog.remove(dirList.at(j));
102 QDir dir(m_mountpoint);
103 dir.rmdir(dirList.at(j)); // rm works only on empty folders
106 installlog.endGroup();
107 //installlog.removeGroup(uninstallSections.at(i))
109 uninstallSections.clear();
110 installlog.sync();
111 m_dp->setProgressMax(1);
112 m_dp->setProgressValue(1);
113 m_dp->addItem(tr("Uninstallation finished"),LOGOK);
114 m_dp->setFinished();
117 QStringList Uninstaller::getAllSections()
119 QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
120 QStringList allSections = installlog.childGroups();
121 allSections.removeAt(allSections.lastIndexOf("Bootloader"));
122 return allSections;
126 bool Uninstaller::uninstallPossible()
128 return QFileInfo(m_mountpoint +"/.rockbox/rbutil.log").exists();