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 ****************************************************************************/
21 #include "uninstall.h"
24 Uninstaller::Uninstaller(QObject
* parent
,QString mountpoint
): QObject(parent
)
26 m_mountpoint
= mountpoint
;
29 void Uninstaller::deleteAll(void)
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
);
40 void Uninstaller::uninstall(void)
42 emit
logProgress(0, 0);
43 emit
logItem(tr("Starting Uninstallation"), LOGINFO
);
45 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, this);
47 for(int i
=0; i
< uninstallSections
.size() ; i
++)
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();
57 installlog
.endGroup();
59 // iterate over all entries
60 for(int j
=0; j
< toDeleteList
.size(); j
++ )
62 // check if current file is in use by another section
63 bool deleteFile
= true;
64 for(int s
= 0; s
< sections
.size(); s
++)
66 installlog
.beginGroup(sections
.at(s
));
67 if(installlog
.contains(toDeleteList
.at(j
)))
70 qDebug() << "file still in use:" << toDeleteList
.at(j
);
72 installlog
.endGroup();
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
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 qDebug() << "deleted: " << toDelete
.filePath() ;
85 else // if it is a dir, remember it for later deletion
87 // no need to keep track on folders still in use -- only empty
88 // folders will be rm'ed.
89 dirList
<< toDeleteList
.at(j
);
91 installlog
.endGroup();
92 QCoreApplication::processEvents();
95 installlog
.beginGroup(uninstallSections
.at(i
));
96 for(int j
=0; j
< dirList
.size(); j
++ )
98 installlog
.remove(dirList
.at(j
));
99 QDir
dir(m_mountpoint
);
100 dir
.rmdir(dirList
.at(j
)); // rm works only on empty folders
103 installlog
.endGroup();
104 //installlog.removeGroup(uninstallSections.at(i))
106 uninstallSections
.clear();
108 emit
logProgress(1, 1);
109 emit
logItem(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();