1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by 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
)
31 QString
rbdir(m_mountpoint
+ ".rockbox/");
32 m_dp
->addItem(tr("Starting Uninstallation"),LOGINFO
);
33 m_dp
->setProgressMax(0);
35 m_dp
->setProgressMax(1);
36 m_dp
->setProgressValue(1);
37 m_dp
->addItem(tr("Finished Uninstallation"),LOGOK
);
40 // recursiv function to delete a dir with files
41 bool Uninstaller::recRmdir( QString
&dirName
)
43 QString dirN
= dirName
;
45 QStringList list
= dir
.entryList(QDir::AllEntries
); // make list of entries in directory
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
56 QFile::remove(curItem
); // ok, delete file
60 return dir
.rmdir(dirN
); // delete empty dir and return if (now empty) dir-removing was successfull
64 void Uninstaller::uninstall(ProgressloggerInterface
* 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();
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
);
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();
107 m_dp
->setProgressMax(1);
108 m_dp
->setProgressValue(1);
109 m_dp
->addItem(tr("Uninstallation finished"),LOGOK
);
113 QStringList
Uninstaller::getAllSections()
115 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
116 QStringList allSections
= installlog
.childGroups();
117 allSections
.removeAt(allSections
.lastIndexOf("Bootloader"));
122 bool Uninstaller::uninstallPossible()
124 return QFileInfo(m_mountpoint
+"/.rockbox/rbutil.log").exists();