1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2008 by Dominik Riebeling
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 ****************************************************************************/
23 #include "bootloaderinstallfile.h"
27 BootloaderInstallFile::BootloaderInstallFile(QObject
*parent
)
28 : BootloaderInstallBase(parent
)
33 bool BootloaderInstallFile::install(void)
35 emit
logItem(tr("Downloading bootloader"), LOGINFO
);
36 qDebug() << "[BootloaderInstallFile] installing bootloader";
37 downloadBlStart(m_blurl
);
38 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
42 void BootloaderInstallFile::installStage2(void)
44 emit
logItem(tr("Installing Rockbox bootloader"), LOGINFO
);
45 QCoreApplication::processEvents();
47 // if an old bootloader is present (Gigabeat) move it out of the way.
48 QString
fwfile(Utils::resolvePathCase(m_blfile
));
49 if(!fwfile
.isEmpty()) {
50 QString moved
= Utils::resolvePathCase(m_blfile
) + ".ORIG";
51 qDebug() << "[BootloaderInstallFile] renaming" << fwfile
<< "to" << moved
;
52 QFile::rename(fwfile
, moved
);
55 // if no old file found resolve path without basename
56 QFileInfo
fi(m_blfile
);
57 QString absPath
= Utils::resolvePathCase(fi
.absolutePath());
59 // if it's not possible to locate the base path try to create it
60 if(absPath
.isEmpty()) {
61 QStringList pathElements
= m_blfile
.split("/");
62 // remove filename from list and save last path element
63 pathElements
.removeLast();
64 QString lastElement
= pathElements
.last();
65 // remove last path element for base
66 pathElements
.removeLast();
67 QString basePath
= pathElements
.join("/");
69 // check for base and bail out if not found. Otherwise create folder.
70 absPath
= Utils::resolvePathCase(basePath
);
72 d
.mkpath(lastElement
);
73 absPath
= Utils::resolvePathCase(fi
.absolutePath());
75 if(absPath
.isEmpty()) {
76 emit
logItem(tr("Error accessing output folder"), LOGERROR
);
81 fwfile
= absPath
+ "/" + fi
.fileName();
83 // place (new) bootloader
85 qDebug() << "[BootloaderInstallFile] renaming" << m_tempfile
.fileName() << "to" << fwfile
;
87 m_tempfile
.copy(fwfile
);
89 emit
logItem(tr("Bootloader successful installed"), LOGOK
);
96 bool BootloaderInstallFile::uninstall(void)
98 qDebug() << "[BootloaderInstallFile] Uninstalling bootloader";
99 emit
logItem(tr("Removing Rockbox bootloader"), LOGINFO
);
100 // check if a .ORIG file is present, and allow moving it back.
101 QString origbl
= Utils::resolvePathCase(m_blfile
+ ".ORIG");
102 if(origbl
.isEmpty()) {
103 emit
logItem(tr("No original firmware file found."), LOGERROR
);
107 QString fwfile
= Utils::resolvePathCase(m_blfile
);
108 if(!QFile::remove(fwfile
)) {
109 emit
logItem(tr("Can't remove Rockbox bootloader file."), LOGERROR
);
113 if(!QFile::rename(origbl
, fwfile
)) {
114 emit
logItem(tr("Can't restore bootloader file."), LOGERROR
);
118 emit
logItem(tr("Original bootloader restored successfully."), LOGOK
);
119 logInstall(LogRemove
);
126 //! @brief check if bootloader is installed.
127 //! @return BootloaderRockbox, BootloaderOther or BootloaderUnknown.
128 BootloaderInstallBase::BootloaderType
BootloaderInstallFile::installed(void)
130 qDebug() << "[BootloaderInstallFile] checking installed bootloader";
131 if(!Utils::resolvePathCase(m_blfile
).isEmpty()
132 && !Utils::resolvePathCase(m_blfile
+ ".ORIG").isEmpty())
133 return BootloaderRockbox
;
134 else if(!Utils::resolvePathCase(m_blfile
).isEmpty())
135 return BootloaderOther
;
137 return BootloaderUnknown
;
141 BootloaderInstallBase::Capabilities
BootloaderInstallFile::capabilities(void)
143 qDebug() << "[BootloaderInstallFile] getting capabilities";
144 return Install
| IsFile
| CanCheckInstalled
| Backup
;