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
);
41 void Uninstaller::uninstall(ProgressloggerInterface
* dp
)
44 m_dp
->setProgressMax(0);
45 m_dp
->addItem(tr("Starting Uninstallation"),LOGINFO
);
47 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, this);
49 for(int i
=0; i
< uninstallSections
.size() ; i
++)
51 m_dp
->addItem(tr("Uninstalling ") + uninstallSections
.at(i
) + " ...",LOGINFO
);
52 // create list of all other install sections
53 QStringList sections
= installlog
.childGroups();
54 sections
.removeAt(sections
.indexOf(uninstallSections
.at(i
)));
55 installlog
.beginGroup(uninstallSections
.at(i
));
56 QStringList toDeleteList
= installlog
.allKeys();
58 installlog
.endGroup();
60 // iterate over all entries
61 for(int j
=0; j
< toDeleteList
.size(); j
++ )
63 // check if current file is in use by another section
64 bool deleteFile
= true;
65 for(int s
= 0; s
< sections
.size(); s
++)
67 installlog
.beginGroup(sections
.at(s
));
68 if(installlog
.contains(toDeleteList
.at(j
)))
71 qDebug() << "file still in use:" << toDeleteList
.at(j
);
73 installlog
.endGroup();
76 installlog
.beginGroup(uninstallSections
.at(i
));
77 QFileInfo
toDelete(m_mountpoint
+ "/" + toDeleteList
.at(j
));
78 if(toDelete
.isFile()) // if it is a file remove it
80 if(deleteFile
&& !QFile::remove(toDelete
.filePath()))
81 m_dp
->addItem(tr("Could not delete: ")+ toDelete
.filePath(),LOGWARNING
);
82 installlog
.remove(toDeleteList
.at(j
));
84 else // if it is a dir, remember it for later deletion
86 // no need to keep track on folders still in use -- only empty
87 // folders will be rm'ed.
88 dirList
<< toDeleteList
.at(j
);
90 installlog
.endGroup();
93 installlog
.beginGroup(uninstallSections
.at(i
));
94 for(int j
=0; j
< dirList
.size(); j
++ )
96 installlog
.remove(dirList
.at(j
));
97 QDir
dir(m_mountpoint
);
98 dir
.rmdir(dirList
.at(j
)); // rm works only on empty folders
101 installlog
.endGroup();
102 //installlog.removeGroup(uninstallSections.at(i))
104 uninstallSections
.clear();
106 m_dp
->setProgressMax(1);
107 m_dp
->setProgressValue(1);
108 m_dp
->addItem(tr("Uninstallation finished"),LOGOK
);
112 QStringList
Uninstaller::getAllSections()
114 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
115 QStringList allSections
= installlog
.childGroups();
116 allSections
.removeAt(allSections
.lastIndexOf("Bootloader"));
121 bool Uninstaller::uninstallPossible()
123 return QFileInfo(m_mountpoint
+"/.rockbox/rbutil.log").exists();