2007-02-21 20:27:14 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* Module: rbutil
|
|
|
|
* File: bootloaders.cpp
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Dominik Wenger
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "bootloaders.h"
|
|
|
|
#include "irivertools.h"
|
|
|
|
#include "md5sum.h"
|
|
|
|
|
|
|
|
#include "rbutil.h"
|
|
|
|
#include "installlog.h"
|
|
|
|
|
|
|
|
|
|
|
|
// for ipodpatcher
|
|
|
|
int verbose = 0;
|
|
|
|
// reserves memory for ipodpatcher
|
|
|
|
bool initIpodpatcher()
|
|
|
|
{
|
|
|
|
if (ipod_alloc_buffer(§orbuf,BUFFER_SIZE) < 0) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
// uses ipodpatcher for add and rem of bootloader
|
2007-05-03 17:10:28 +00:00
|
|
|
bool ipodpatcher(int mode,wxString bootloadername)
|
2007-02-21 20:27:14 +00:00
|
|
|
{
|
|
|
|
wxString src,dest,buf;
|
|
|
|
|
|
|
|
struct ipod_t ipod;
|
|
|
|
|
|
|
|
int n = ipod_scan(&ipod);
|
|
|
|
if (n == 0)
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("[ERR] No ipods found."), wxT("Scanning for Ipods"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (n > 1)
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("[ERR] to many ipods found."), wxT("Scanning for Ipods"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:10:28 +00:00
|
|
|
// downloading files
|
|
|
|
if(mode == BOOTLOADER_ADD)
|
|
|
|
{
|
|
|
|
src.Printf(wxT("%s/ipod/%s.ipod"),gv->bootloader_url.c_str(),bootloadername.c_str());
|
|
|
|
dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s"),
|
|
|
|
gv->stdpaths->GetUserDataDir().c_str(),bootloadername.c_str());
|
|
|
|
if ( DownloadURL(src, dest) )
|
|
|
|
{
|
|
|
|
wxRemoveFile(dest);
|
|
|
|
buf.Printf(wxT("Unable to download %s"), src.c_str() );
|
|
|
|
ERR_DIALOG(buf, wxT("Install"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-21 20:27:14 +00:00
|
|
|
if (ipod_open(&ipod, 0) < 0)
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("[ERR] could not open ipod"), wxT("open Ipod"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read_partinfo(&ipod,0) < 0)
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("[ERR] could not read partitiontable"), wxT("reading partitiontable"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ipod.pinfo[0].start==0)
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("[ERR] No partition 0 on disk"), wxT("reading partitiontable"));
|
2007-02-21 20:27:14 +00:00
|
|
|
int i;
|
|
|
|
double sectors_per_MB = (1024.0*1024.0)/ipod.sector_size;
|
|
|
|
|
2007-03-15 14:02:37 +00:00
|
|
|
buf.Printf(wxT("[INFO] Part Start Sector End Sector Size (MB) Type\n"));
|
|
|
|
ERR_DIALOG(buf, wxT("reading partitiontable"));
|
2007-02-21 20:27:14 +00:00
|
|
|
for ( i = 0; i < 4; i++ ) {
|
|
|
|
if (ipod.pinfo[i].start != 0) {
|
2007-03-15 14:02:37 +00:00
|
|
|
buf.Printf(wxT("[INFO] %d %10ld %10ld %10.1f %s (0x%02x)\n"),
|
2007-02-21 20:27:14 +00:00
|
|
|
i,
|
|
|
|
ipod.pinfo[i].start,
|
|
|
|
ipod.pinfo[i].start+ipod.pinfo[i].size-1,
|
|
|
|
ipod.pinfo[i].size/sectors_per_MB,
|
|
|
|
get_parttype(ipod.pinfo[i].type),
|
|
|
|
ipod.pinfo[i].type);
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(buf, wxT("reading partitiontable"));
|
2007-02-21 20:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
read_directory(&ipod);
|
|
|
|
|
|
|
|
if (ipod.nimages <= 0)
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("[ERR] Failed to read firmware directory"), wxT("reading directory"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (getmodel(&ipod,(ipod.ipod_directory[0].vers>>8)) < 0)
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
buf.Printf(wxT("[ERR] Unknown version number in firmware (%08x)\n"),
|
2007-02-21 20:27:14 +00:00
|
|
|
ipod.ipod_directory[0].vers );
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(buf, wxT("reading directory"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ipod.macpod)
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
WARN_DIALOG(wxT("Warning this is a MacPod, Rockbox doesnt work on this. Convert it to WinPod"),wxT("MacPod"));
|
2007-02-21 20:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(mode == BOOTLOADER_ADD)
|
|
|
|
{
|
|
|
|
if (ipod_reopen_rw(&ipod) < 0) {
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("[ERR] Could not open Ipod in RW mode"), wxT("Bootloader add"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (add_bootloader(&ipod, (char*)dest.c_str(), FILETYPE_DOT_IPOD)==0) {
|
|
|
|
|
|
|
|
} else {
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("[ERR] failed to add Bootloader"), wxT("Bootloader add"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(mode == BOOTLOADER_REM)
|
|
|
|
{
|
|
|
|
if (ipod_reopen_rw(&ipod) < 0) {
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("[ERR] Could not open Ipod in RW mode"), wxT("Bootloader add"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ipod.ipod_directory[0].entryOffset==0) {
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("[ERR] No bootloader detected.\n"), wxT("Bootloader del"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (delete_bootloader(&ipod)==0) {
|
|
|
|
|
|
|
|
} else {
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("[ERR] --delete-bootloader failed.\n"), wxT("Bootloader del"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ipod_close(&ipod);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// gigabeatinstallation
|
2007-05-03 17:10:28 +00:00
|
|
|
bool gigabeatf(int mode,wxString bootloadername,wxString deviceDir)
|
2007-02-21 20:27:14 +00:00
|
|
|
{
|
|
|
|
wxString path1,path2;
|
|
|
|
wxString err;
|
|
|
|
wxString src,dest;
|
|
|
|
|
2007-05-03 17:10:28 +00:00
|
|
|
path1.Printf(wxT("%s" PATH_SEP "GBSYSTEM" PATH_SEP "FWIMG" PATH_SEP "FWIMG01.DAT"),deviceDir.c_str());
|
2007-02-21 20:27:14 +00:00
|
|
|
|
|
|
|
if(mode == BOOTLOADER_ADD)
|
|
|
|
{
|
|
|
|
//Files downloaden
|
2007-05-03 17:10:28 +00:00
|
|
|
src.Printf(wxT("%s/gigabeat/%s"), gv->bootloader_url.c_str(),bootloadername.c_str());
|
2007-03-15 14:02:37 +00:00
|
|
|
dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s"),
|
2007-05-03 17:10:28 +00:00
|
|
|
gv->stdpaths->GetUserDataDir().c_str(),bootloadername.c_str());
|
2007-02-21 20:27:14 +00:00
|
|
|
if( DownloadURL(src, dest) )
|
|
|
|
{
|
|
|
|
wxRemoveFile(dest);
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("Unable to download %s"), src.c_str() );
|
|
|
|
ERR_DIALOG(err, wxT("Install"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!wxFileExists(path1))
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("[ERR] Coud not find %s"),path1.c_str());
|
|
|
|
ERR_DIALOG(err, wxT("Bootloader add"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
path2 = path1;
|
2007-03-15 14:02:37 +00:00
|
|
|
path2.Append(wxT(".ORIG"));
|
2007-03-20 15:38:48 +00:00
|
|
|
if(!wxFileExists(path2))
|
2007-02-21 20:27:14 +00:00
|
|
|
{
|
2007-03-20 15:38:48 +00:00
|
|
|
if(!wxRenameFile(path1,path2,false))
|
|
|
|
{
|
|
|
|
err.Printf(wxT("[ERR] Coud not rename %s to %s"),path1.c_str(),path2.c_str());
|
|
|
|
ERR_DIALOG(err, wxT("Bootloader add"));
|
|
|
|
return false;
|
|
|
|
}
|
2007-02-21 20:27:14 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 15:38:48 +00:00
|
|
|
|
2007-02-21 20:27:14 +00:00
|
|
|
if(!wxCopyFile(dest,path1))
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("[ERR] Coud not copy %s to %s"),dest.c_str(),path2.c_str());
|
|
|
|
ERR_DIALOG(err, wxT("Bootloader add"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(mode == BOOTLOADER_REM)
|
|
|
|
{
|
|
|
|
path2 = path1;
|
2007-03-15 14:02:37 +00:00
|
|
|
path2.Append(wxT(".ORIG"));
|
2007-02-21 20:27:14 +00:00
|
|
|
if(!wxFileExists(path2))
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("[ERR] Coud not find %s"),path1.c_str());
|
|
|
|
ERR_DIALOG(err, wxT("Bootloader del"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!wxRenameFile(path2,path1,true))
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("[ERR] Coud not rename %s to %s"),path1.c_str(),path2.c_str());
|
|
|
|
ERR_DIALOG(err, wxT("Bootloader del"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// iaudio bootloader install
|
2007-05-03 17:10:28 +00:00
|
|
|
bool iaudiox5(int mode,wxString bootloadername,wxString deviceDir)
|
2007-02-21 20:27:14 +00:00
|
|
|
{
|
|
|
|
wxString path1,path2;
|
|
|
|
wxString err;
|
|
|
|
wxString src,dest;
|
|
|
|
|
2007-05-03 17:10:28 +00:00
|
|
|
path1.Printf(wxT("%s" PATH_SEP "FIRMWARE" PATH_SEP "%s"),deviceDir.c_str(),bootloadername.c_str());
|
2007-02-21 20:27:14 +00:00
|
|
|
|
|
|
|
if(mode == BOOTLOADER_ADD)
|
|
|
|
{
|
|
|
|
//Files downloaden
|
2007-05-03 17:10:28 +00:00
|
|
|
src.Printf(wxT("%s/iaudio/%s"),gv->bootloader_url.c_str(),bootloadername.c_str());
|
2007-03-15 14:02:37 +00:00
|
|
|
dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s"),
|
2007-05-03 17:10:28 +00:00
|
|
|
gv->stdpaths->GetUserDataDir().c_str(),bootloadername.c_str());
|
2007-02-21 20:27:14 +00:00
|
|
|
if( DownloadURL(src, dest) )
|
|
|
|
{
|
|
|
|
wxRemoveFile(dest);
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("Unable to download %s"), src.c_str() );
|
|
|
|
ERR_DIALOG(err, wxT("Install"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy file
|
|
|
|
if(!wxCopyFile(dest,path1))
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("[ERR] Coud not copy %s to %s"),dest.c_str(),path2.c_str());
|
|
|
|
ERR_DIALOG(err, wxT("Bootloader add"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true; // install ready
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false; //no uninstallation possible
|
|
|
|
}
|
|
|
|
|
|
|
|
// H10 install
|
2007-05-03 17:10:28 +00:00
|
|
|
bool h10(int mode,wxString bootloadername,wxString deviceDir)
|
2007-02-21 20:27:14 +00:00
|
|
|
{
|
|
|
|
wxString err,src,dest,path1,path2;
|
|
|
|
|
2007-05-03 17:10:28 +00:00
|
|
|
int pos = bootloadername.Find('/');
|
2007-03-01 17:22:49 +00:00
|
|
|
if(pos == wxNOT_FOUND) pos = 0;
|
2007-05-03 17:10:28 +00:00
|
|
|
wxString firmwarename = bootloadername.SubString(pos,bootloadername.Length());
|
2007-03-01 17:22:49 +00:00
|
|
|
//wxString firmDir = gv->curbootloader.SubString(0,pos);
|
2007-02-21 20:27:14 +00:00
|
|
|
|
|
|
|
if(mode == BOOTLOADER_ADD)
|
|
|
|
{
|
|
|
|
//Files downloaden
|
2007-05-03 17:10:28 +00:00
|
|
|
src.Printf(wxT("%s/iriver/%s"), gv->bootloader_url.c_str(),bootloadername.c_str());
|
2007-03-15 14:02:37 +00:00
|
|
|
dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s"),
|
2007-02-21 20:27:14 +00:00
|
|
|
gv->stdpaths->GetUserDataDir().c_str(),firmwarename.c_str());
|
|
|
|
if( DownloadURL(src, dest) )
|
|
|
|
{
|
|
|
|
wxRemoveFile(dest);
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("Unable to download %s"), src.c_str() );
|
|
|
|
ERR_DIALOG(err, wxT("Install"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:10:28 +00:00
|
|
|
path1.Printf(wxT("%sSYSTEM" PATH_SEP "%s"),deviceDir.c_str(),firmwarename.c_str());
|
|
|
|
path2.Printf(wxT("%sSYSTEM" PATH_SEP "Original.mi4"),deviceDir.c_str());
|
2007-02-21 20:27:14 +00:00
|
|
|
|
|
|
|
if(!wxFileExists(path1)) //Firmware dosent exists on player
|
|
|
|
{
|
2007-05-03 17:10:28 +00:00
|
|
|
path1.Printf(wxT("%sSYSTEM" PATH_SEP "H10EMP.mi4"),deviceDir.c_str()); //attempt other firmwarename
|
2007-02-21 20:27:14 +00:00
|
|
|
if(!wxFileExists(path1)) //Firmware dosent exists on player
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("[ERR] File %s does not Exist"),path1.c_str());
|
|
|
|
ERR_DIALOG(err, wxT("Bootloader add"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2007-03-20 15:38:48 +00:00
|
|
|
if(!wxFileExists(path2)) //there is already a original firmware
|
2007-02-21 20:27:14 +00:00
|
|
|
{
|
2007-03-20 15:38:48 +00:00
|
|
|
if(!wxRenameFile(path1,path2,false)) //rename Firmware to Original
|
|
|
|
{
|
|
|
|
err.Printf(wxT("[ERR] Coud not rename %s to %s"),path1.c_str(),path2.c_str());
|
|
|
|
ERR_DIALOG(err, wxT("Bootloader add"));
|
|
|
|
return false;
|
|
|
|
}
|
2007-02-21 20:27:14 +00:00
|
|
|
}
|
2007-03-20 15:38:48 +00:00
|
|
|
|
2007-02-21 20:27:14 +00:00
|
|
|
if(!wxCopyFile(dest,path1)) // copy file
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("[ERR] Coud not copy %s to %s"),dest.c_str(),path1.c_str());
|
|
|
|
ERR_DIALOG(err,wxT("Bootloader add"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true; //install ready
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(mode == BOOTLOADER_REM)
|
|
|
|
{
|
2007-05-03 17:10:28 +00:00
|
|
|
path1.Printf(wxT("%sSYSTEM" PATH_SEP "%s"),deviceDir.c_str(),firmwarename.c_str());
|
2007-03-15 14:02:37 +00:00
|
|
|
path2.Printf(wxT("%sSYSTEM" PATH_SEP "Original.mi4"),gv->curdestdir.c_str());
|
2007-02-21 20:27:14 +00:00
|
|
|
if(!wxFileExists(path1)) //Firmware dosent exists on player
|
|
|
|
{
|
2007-05-03 17:10:28 +00:00
|
|
|
path1.Printf(wxT("%s" PATH_SEP "SYSTEM" PATH_SEP "H10EMP.mi4"),deviceDir.c_str()); //attempt other firmwarename
|
2007-02-21 20:27:14 +00:00
|
|
|
if(!wxFileExists(path1)) //Firmware dosent exists on player
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("[ERR] File %s does not Exist"),path1.c_str());
|
|
|
|
ERR_DIALOG(err, wxT("Bootloader rem"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!wxFileExists(path2)) //Original Firmware dosent exists on player
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("[ERR] File %s does not Exist"),path2.c_str());
|
|
|
|
ERR_DIALOG(err, wxT("Bootloader rem"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!wxRenameFile(path2,path1,true)) //rename Firmware to Original
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("[ERR] Coud not rename %s to %s"),path2.c_str(),path1.c_str());
|
|
|
|
ERR_DIALOG(err, wxT("Bootloader add"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2007-03-20 14:37:36 +00:00
|
|
|
// shouldn't get here
|
|
|
|
return false;
|
2007-02-21 20:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FWPatcher
|
2007-05-03 17:10:28 +00:00
|
|
|
bool fwpatcher(int mode,wxString bootloadername,wxString deviceDir,wxString firmware)
|
2007-02-21 20:27:14 +00:00
|
|
|
{
|
|
|
|
if(mode == BOOTLOADER_ADD)
|
|
|
|
{
|
2007-03-15 18:02:15 +00:00
|
|
|
char md5sum_str[32];
|
|
|
|
wxString src,dest,err;
|
2007-02-21 20:27:14 +00:00
|
|
|
int series,table_entry;
|
|
|
|
|
2007-05-03 17:10:28 +00:00
|
|
|
if (!FileMD5(firmware, md5sum_str)) {
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("Could not open firmware"), wxT("Open Firmware"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Check firmware against md5sums in h120sums and h100sums */
|
|
|
|
series = 0;
|
|
|
|
table_entry = intable(md5sum_str, &h120pairs[0],
|
|
|
|
sizeof(h120pairs)/sizeof(struct sumpairs));
|
|
|
|
if (table_entry >= 0) {
|
|
|
|
series = 120;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
table_entry = intable(md5sum_str, &h100pairs[0],
|
|
|
|
sizeof(h100pairs)/sizeof(struct sumpairs));
|
|
|
|
if (table_entry >= 0) {
|
|
|
|
series = 100;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
table_entry =
|
|
|
|
intable(md5sum_str, &h300pairs[0],
|
|
|
|
sizeof(h300pairs)/sizeof(struct sumpairs));
|
|
|
|
if (table_entry >= 0)
|
|
|
|
series = 300;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (series == 0) {
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("Could not detect firmware type"), wxT("Detect Player out of Firmware"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Download bootloader
|
2007-05-03 17:10:28 +00:00
|
|
|
src.Printf(wxT("%s/iriver/%s"), gv->bootloader_url.c_str(),bootloadername.c_str());
|
2007-03-15 14:02:37 +00:00
|
|
|
dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s"),
|
2007-05-03 17:10:28 +00:00
|
|
|
gv->stdpaths->GetUserDataDir().c_str(),bootloadername.c_str());
|
2007-02-21 20:27:14 +00:00
|
|
|
if( DownloadURL(src, dest) )
|
|
|
|
{
|
|
|
|
wxRemoveFile(dest);
|
2007-03-15 14:02:37 +00:00
|
|
|
err.Printf(wxT("Unable to download %s"), src.c_str() );
|
|
|
|
ERR_DIALOG(err, wxT("Install"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:10:28 +00:00
|
|
|
if(!PatchFirmware(firmware,dest,series, table_entry)) // Patch firmware
|
2007-02-21 20:27:14 +00:00
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("Patching Firmware failed"), wxT("Patching Firmware"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load patched Firmware to player
|
2007-03-15 14:02:37 +00:00
|
|
|
src.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "new.hex"),
|
2007-02-21 20:27:14 +00:00
|
|
|
gv->stdpaths->GetUserDataDir().c_str());
|
|
|
|
|
2007-03-15 18:02:15 +00:00
|
|
|
if(gv->curplat == wxT("h100"))
|
2007-05-03 17:10:28 +00:00
|
|
|
dest.Printf(wxT("%s" PATH_SEP "ihp_100.hex"),deviceDir.c_str());
|
2007-03-15 18:02:15 +00:00
|
|
|
else if(gv->curplat == wxT("h120"))
|
2007-05-03 17:10:28 +00:00
|
|
|
dest.Printf(wxT("%s" PATH_SEP "ihp_120.hex"),deviceDir.c_str());
|
2007-03-15 18:02:15 +00:00
|
|
|
else if(gv->curplat == wxT("h300"))
|
2007-05-03 17:10:28 +00:00
|
|
|
dest.Printf(wxT("%s" PATH_SEP "H300.hex"),deviceDir.c_str());
|
2007-02-21 20:27:14 +00:00
|
|
|
|
|
|
|
if(!wxRenameFile(src,dest))
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(wxT("Copying Firmware to Device failed"), wxT("Copying Firmware"));
|
2007-02-21 20:27:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false; //no uninstall possible
|
|
|
|
}
|
|
|
|
}
|