MPEGPlayer: Skip to next file when there is a problem with a video file in all-play...
[kugel-rb.git] / rbutil / rbutilqt / base / bootloaderinstallams.cpp
blob3bdd084c60d5cd57b0aa88770810b20453c55121
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2008 by Dominik Wenger
10 * $Id$
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 <QtCore>
21 #include "bootloaderinstallbase.h"
22 #include "bootloaderinstallams.h"
24 #include "../mkamsboot/mkamsboot.h"
26 BootloaderInstallAms::BootloaderInstallAms(QObject *parent)
27 : BootloaderInstallBase(parent)
31 QString BootloaderInstallAms::ofHint()
33 return tr("Bootloader installation requires you to provide "
34 "a firmware file of the original firmware (bin file). "
35 "You need to download this file yourself due to legal "
36 "reasons. Please browse the "
37 "<a href='http://forums.sandisk.com/sansa/'>Sansa Forums'</a> "
38 "or refer to the "
39 "<a href='http://www.rockbox.org/manual.shtml'>manual</a> and "
40 "the <a href='http://www.rockbox.org/wiki/SansaAMS'>SansaAMS</a> "
41 "wiki page on how to obtain this file.<br/>"
42 "Press Ok to continue and browse your computer for the firmware "
43 "file.");
46 bool BootloaderInstallAms::install(void)
48 if(m_offile.isEmpty())
49 return false;
51 qDebug() << "[BootloaderInstallAms] installing bootloader";
53 // download firmware from server
54 emit logItem(tr("Downloading bootloader file"), LOGINFO);
56 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
57 downloadBlStart(m_blurl);
59 return true;
62 void BootloaderInstallAms::installStage2(void)
64 qDebug() << "[BootloaderInstallAms] installStage2";
66 unsigned char* buf;
67 unsigned char* of_packed;
68 int of_packedsize;
69 unsigned char* rb_packed;
70 int rb_packedsize;
71 off_t len;
72 struct md5sums sum;
73 char md5sum[33]; /* 32 hex digits, plus terminating zero */
74 int n;
75 int model;
76 int firmware_size;
77 int bootloader_size;
78 int patchable;
79 int totalsize;
80 char errstr[200];
82 sum.md5 = md5sum;
84 m_tempfile.open();
85 QString bootfile = m_tempfile.fileName();
86 m_tempfile.close();
88 /* Load bootloader file */
89 rb_packed = load_rockbox_file(bootfile.toLocal8Bit().data(), &model,
90 &bootloader_size,&rb_packedsize,
91 errstr,sizeof(errstr));
92 if (rb_packed == NULL)
94 qDebug() << "[BootloaderInstallAms] could not load bootloader: " << bootfile;
95 emit logItem(errstr, LOGERROR);
96 emit logItem(tr("Could not load %1").arg(bootfile), LOGERROR);
97 emit done(true);
98 return;
101 /* Load original firmware file */
102 buf = load_of_file(m_offile.toLocal8Bit().data(), model, &len, &sum,
103 &firmware_size, &of_packed ,&of_packedsize,
104 errstr, sizeof(errstr));
105 if (buf == NULL)
107 qDebug() << "[BootloaderInstallAms] could not load OF: " << m_offile;
108 emit logItem(errstr, LOGERROR);
109 emit logItem(tr("Could not load %1").arg(m_offile), LOGERROR);
110 free(rb_packed);
111 emit done(true);
112 return;
115 /* check total size */
116 patchable = check_sizes(sum.model, rb_packedsize, bootloader_size,
117 of_packedsize, firmware_size, &totalsize, errstr, sizeof(errstr));
119 if (!patchable)
121 qDebug() << "[BootloaderInstallAms] No room to insert bootloader";
122 emit logItem(errstr, LOGERROR);
123 emit logItem(tr("No room to insert bootloader, try another firmware version"),
124 LOGERROR);
125 free(buf);
126 free(of_packed);
127 free(rb_packed);
128 emit done(true);
129 return;
132 /* patch the firmware */
133 emit logItem(tr("Patching Firmware..."), LOGINFO);
135 patch_firmware(sum.model,firmware_revision(sum.model),firmware_size,buf,
136 len,of_packed,of_packedsize,rb_packed,rb_packedsize);
138 /* write out file */
139 QFile out(m_blfile);
141 if(!out.open(QIODevice::WriteOnly | QIODevice::Truncate))
143 qDebug() << "[BootloaderInstallAms] Could not open" << m_blfile << "for writing";
144 emit logItem(tr("Could not open %1 for writing").arg(m_blfile),LOGERROR);
145 free(buf);
146 free(of_packed);
147 free(rb_packed);
148 emit done(true);
149 return;
152 n = out.write((char*)buf, len);
154 if (n != len)
156 qDebug() << "[BootloaderInstallAms] Could not write firmware file";
157 emit logItem(tr("Could not write firmware file"),LOGERROR);
158 free(buf);
159 free(of_packed);
160 free(rb_packed);
161 emit done(true);
162 return;
165 out.close();
167 free(buf);
168 free(of_packed);
169 free(rb_packed);
171 //end of install
172 qDebug() << "[BootloaderInstallAms] install successfull";
173 emit logItem(tr("Success: modified firmware file created"), LOGINFO);
174 logInstall(LogAdd);
175 emit done(false);
176 return;
179 bool BootloaderInstallAms::uninstall(void)
181 emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified "
182 "original firmware"), LOGINFO);
183 logInstall(LogRemove);
184 return false;
187 BootloaderInstallBase::BootloaderType BootloaderInstallAms::installed(void)
189 return BootloaderUnknown;
192 BootloaderInstallBase::Capabilities BootloaderInstallAms::capabilities(void)
194 return (Install | NeedsOf);