rbutilQt:Ups.. the forgotten uninstall files.
[kugel-rb.git] / rbutil / rbutilqt / uninstall.cpp
blobce9995370d797d77ce5b0b2ee204be8425681b33
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: uninstall.cpp 13990 2007-07-25 22:26:10Z Dominik Wenger $
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 "uninstall.h"
23 Uninstaller::Uninstaller(QObject* parent,QString mountpoint): QObject(parent)
25 m_mountpoint = mountpoint;
28 void Uninstaller::deleteAll(ProgressloggerInterface* dp)
30 m_dp = dp;
31 QString rbdir(m_mountpoint + ".rockbox/");
32 m_dp->addItem(tr("Starting Uninstallation"),LOGINFO);
33 m_dp->setProgressMax(0);
34 recRmdir(rbdir);
35 m_dp->setProgressMax(1);
36 m_dp->setProgressValue(1);
37 m_dp->addItem(tr("Finished Uninstallation"),LOGOK);
38 m_dp->abort();
40 // recursiv function to delete a dir with files
41 bool Uninstaller::recRmdir( QString &dirName )
43 QString dirN = dirName;
44 QDir dir(dirN);
45 QStringList list = dir.entryList(QDir::AllEntries); // make list of entries in directory
46 QFileInfo fileInfo;
47 QString curItem, lstAt;
48 for(int i = 0; i < list.size(); i++){ // loop through all items of list
49 QString name = list.at(i);
50 if(!(name == ".") && !(name == "..")){
51 curItem = dirN + "/" + name;
52 fileInfo.setFile(curItem);
53 if(fileInfo.isDir()) // is directory
54 recRmdir(curItem); // call recRmdir() recursively for deleting subdirectory
55 else // is file
56 QFile::remove(curItem); // ok, delete file
59 dir.cdUp();
60 return dir.rmdir(dirN); // delete empty dir and return if (now empty) dir-removing was successfull
64 void Uninstaller::uninstall(ProgressloggerInterface* dp)
66 m_dp = dp;
67 m_dp->setProgressMax(0);
68 m_dp->addItem(tr("Starting Uninstallation"),LOGINFO);
70 QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
72 for(int i=0; i< uninstallSections.size() ; i++)
74 m_dp->addItem(tr("Uninstalling ") + uninstallSections.at(i) + " ...",LOGINFO);
75 installlog.beginGroup(uninstallSections.at(i));
76 QStringList toDeleteList = installlog.allKeys();
77 QStringList dirList;
79 // iterate over all entrys
80 for(int j =0; j < toDeleteList.size(); j++ )
82 QFileInfo toDelete(m_mountpoint + "/" + toDeleteList.at(j));
83 if(toDelete.isFile()) // if it is a file remove it
85 if(!QFile::remove(toDelete.filePath()))
86 m_dp->addItem(tr("Could not delete: ")+ toDelete.filePath(),LOGWARNING);
87 installlog.remove(toDeleteList.at(j));
89 else // if it is a dir, remember it for later deletion
91 dirList << toDeleteList.at(j);
94 // delete the dirs
95 for(int j=0; j < dirList.size(); j++ )
97 installlog.remove(dirList.at(j));
98 QDir dir(m_mountpoint);
99 dir.rmdir(dirList.at(j));
102 installlog.endGroup();
103 //installlog.removeGroup(uninstallSections.at(i))
105 uninstallSections.clear();
106 installlog.sync();
107 m_dp->setProgressMax(1);
108 m_dp->setProgressValue(1);
109 m_dp->addItem(tr("Uninstallation finished"),LOGOK);
110 m_dp->abort();
113 QStringList Uninstaller::getAllSections()
115 QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
116 return installlog.childGroups();
120 bool Uninstaller::uninstallPossible()
122 return QFileInfo(m_mountpoint +"/.rockbox/rbutil.log").exists();