forked from len0rd/rockbox
Rockbox Utility: make chinachippatch translateable + update Dutch translation
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22450 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
f6999b8f2a
commit
11826e9040
3 changed files with 718 additions and 350 deletions
|
@ -27,6 +27,8 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "chinachip.h"
|
#include "chinachip.h"
|
||||||
|
|
||||||
|
#define tr(x) x /* Qt translation support */
|
||||||
|
|
||||||
/* From http://www.rockbox.org/wiki/ChinaChip */
|
/* From http://www.rockbox.org/wiki/ChinaChip */
|
||||||
struct header
|
struct header
|
||||||
{
|
{
|
||||||
|
@ -89,42 +91,42 @@ int chinachip_patch(const char* firmware, const char* bootloader,
|
||||||
fd = fopen(firmware, "rb");
|
fd = fopen(firmware, "rb");
|
||||||
if(!fd)
|
if(!fd)
|
||||||
{
|
{
|
||||||
ERR("Can't open file %s!", firmware);
|
ERR(tr("Can't open file %s!"), firmware);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
bd = fopen(bootloader, "rb");
|
bd = fopen(bootloader, "rb");
|
||||||
if(!bd)
|
if(!bd)
|
||||||
{
|
{
|
||||||
ERR("Can't open file %s!", bootloader);
|
ERR(tr("Can't open file %s!"), bootloader);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bsize = filesize(bd);
|
bsize = filesize(bd);
|
||||||
INFO("Bootloader size is %d bytes", bsize);
|
INFO(tr("Bootloader size is %d bytes"), bsize);
|
||||||
FCLOSE(bd);
|
FCLOSE(bd);
|
||||||
|
|
||||||
fsize = filesize(fd);
|
fsize = filesize(fd);
|
||||||
INFO("Firmware size is %d bytes", fsize);
|
INFO(tr("Firmware size is %d bytes"), fsize);
|
||||||
|
|
||||||
buf = malloc(TOTAL_SIZE);
|
buf = malloc(TOTAL_SIZE);
|
||||||
if(buf == NULL)
|
if(buf == NULL)
|
||||||
{
|
{
|
||||||
ERR("Can't allocate %d bytes!", fsize);
|
ERR(tr("Can't allocate %d bytes!"), fsize);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
memset(buf, 0, TOTAL_SIZE);
|
memset(buf, 0, TOTAL_SIZE);
|
||||||
|
|
||||||
INFO("Reading %s into memory...", firmware);
|
INFO(tr("Reading %s into memory..."), firmware);
|
||||||
if(fread(buf, fsize, 1, fd) != 1)
|
if(fread(buf, fsize, 1, fd) != 1)
|
||||||
{
|
{
|
||||||
ERR("Can't read file %s to memory!", firmware);
|
ERR(tr("Can't read file %s to memory!"), firmware);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
FCLOSE(fd);
|
FCLOSE(fd);
|
||||||
|
|
||||||
if(memcmp(buf, "WADF", 4))
|
if(memcmp(buf, "WADF", 4))
|
||||||
{
|
{
|
||||||
ERR("File %s isn't a valid ChinaChip firmware!", firmware);
|
ERR(tr("File %s isn't a valid ChinaChip firmware!"), firmware);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,30 +148,30 @@ int chinachip_patch(const char* firmware, const char* bootloader,
|
||||||
|
|
||||||
if(i >= fsize)
|
if(i >= fsize)
|
||||||
{
|
{
|
||||||
ERR("Couldn't find ccpmp.bin in %s!", firmware);
|
ERR(tr("Couldn't find ccpmp.bin in %s!"), firmware);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
INFO("Found ccpmp.bin at %d bytes", ccpmp_pos);
|
INFO(tr("Found ccpmp.bin at %d bytes"), ccpmp_pos);
|
||||||
|
|
||||||
if(ccpmp_backup)
|
if(ccpmp_backup)
|
||||||
{
|
{
|
||||||
bd = fopen(ccpmp_backup, "wb");
|
bd = fopen(ccpmp_backup, "wb");
|
||||||
if(!bd)
|
if(!bd)
|
||||||
{
|
{
|
||||||
ERR("Can't open file %s!", ccpmp_backup);
|
ERR(tr("Can't open file %s!"), ccpmp_backup);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
INFO("Writing %d bytes to %s...", ccpmp_size, ccpmp_backup);
|
INFO(tr("Writing %d bytes to %s..."), ccpmp_size, ccpmp_backup);
|
||||||
if(fwrite(&buf[ccpmp_pos], ccpmp_size, 1, bd) != 1)
|
if(fwrite(&buf[ccpmp_pos], ccpmp_size, 1, bd) != 1)
|
||||||
{
|
{
|
||||||
ERR("Can't write to file %s!", ccpmp_backup);
|
ERR(tr("Can't write to file %s!"), ccpmp_backup);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
FCLOSE(bd);
|
FCLOSE(bd);
|
||||||
}
|
}
|
||||||
|
|
||||||
INFO("Renaming it to ccpmp.old...");
|
INFO(tr("Renaming it to ccpmp.old..."));
|
||||||
buf[ccpmp_pos + 6] = 'o';
|
buf[ccpmp_pos + 6] = 'o';
|
||||||
buf[ccpmp_pos + 7] = 'l';
|
buf[ccpmp_pos + 7] = 'l';
|
||||||
buf[ccpmp_pos + 8] = 'd';
|
buf[ccpmp_pos + 8] = 'd';
|
||||||
|
@ -177,27 +179,27 @@ int chinachip_patch(const char* firmware, const char* bootloader,
|
||||||
bd = fopen(bootloader, "rb");
|
bd = fopen(bootloader, "rb");
|
||||||
if(!bd)
|
if(!bd)
|
||||||
{
|
{
|
||||||
ERR("Can't open file %s!", bootloader);
|
ERR(tr("Can't open file %s!"), bootloader);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Also include path size */
|
/* Also include path size */
|
||||||
ccpmp_pos -= sizeof(uint32_t);
|
ccpmp_pos -= sizeof(uint32_t);
|
||||||
|
|
||||||
INFO("Making place for ccpmp.bin...");
|
INFO(tr("Making place for ccpmp.bin..."));
|
||||||
memmove(&buf[ccpmp_pos + bsize + CCPMPBIN_HEADER_SIZE],
|
memmove(&buf[ccpmp_pos + bsize + CCPMPBIN_HEADER_SIZE],
|
||||||
&buf[ccpmp_pos], fsize - ccpmp_pos);
|
&buf[ccpmp_pos], fsize - ccpmp_pos);
|
||||||
|
|
||||||
INFO("Reading %s into memory...", bootloader);
|
INFO(tr("Reading %s into memory..."), bootloader);
|
||||||
if(fread(&buf[ccpmp_pos + CCPMPBIN_HEADER_SIZE],
|
if(fread(&buf[ccpmp_pos + CCPMPBIN_HEADER_SIZE],
|
||||||
bsize, 1, bd) != 1)
|
bsize, 1, bd) != 1)
|
||||||
{
|
{
|
||||||
ERR("Can't read file %s to memory!", bootloader);
|
ERR(tr("Can't read file %s to memory!"), bootloader);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
FCLOSE(bd);
|
FCLOSE(bd);
|
||||||
|
|
||||||
INFO("Adding header to %s...", bootloader);
|
INFO(tr("Adding header to %s..."), bootloader);
|
||||||
int2le(&buf[ccpmp_pos ], 9); /* Pathname Size */
|
int2le(&buf[ccpmp_pos ], 9); /* Pathname Size */
|
||||||
memcpy(&buf[ccpmp_pos + 4 ], "ccpmp.bin", 9); /* Pathname */
|
memcpy(&buf[ccpmp_pos + 4 ], "ccpmp.bin", 9); /* Pathname */
|
||||||
memset(&buf[ccpmp_pos + 4 + 9 ], 0x20, sizeof(uint8_t)); /* File Type */
|
memset(&buf[ccpmp_pos + 4 + 9 ], 0x20, sizeof(uint8_t)); /* File Type */
|
||||||
|
@ -207,7 +209,7 @@ int chinachip_patch(const char* firmware, const char* bootloader,
|
||||||
time_info = localtime(&cur_time);
|
time_info = localtime(&cur_time);
|
||||||
if(time_info == NULL)
|
if(time_info == NULL)
|
||||||
{
|
{
|
||||||
ERR("Can't obtain current time!");
|
ERR(tr("Can't obtain current time!"));
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,11 +219,11 @@ int chinachip_patch(const char* firmware, const char* bootloader,
|
||||||
time_info->tm_hour,
|
time_info->tm_hour,
|
||||||
time_info->tm_min);
|
time_info->tm_min);
|
||||||
|
|
||||||
INFO("Computing checksum...");
|
INFO(tr("Computing checksum..."));
|
||||||
for(i = sizeof(struct header); i < TOTAL_SIZE; i+=4)
|
for(i = sizeof(struct header); i < TOTAL_SIZE; i+=4)
|
||||||
checksum += le2int(&buf[i]);
|
checksum += le2int(&buf[i]);
|
||||||
|
|
||||||
INFO("Updating main header...");
|
INFO(tr("Updating main header..."));
|
||||||
memcpy(&buf[offsetof(struct header, timestamp)], header_time, 12);
|
memcpy(&buf[offsetof(struct header, timestamp)], header_time, 12);
|
||||||
int2le(&buf[offsetof(struct header, size) ], TOTAL_SIZE);
|
int2le(&buf[offsetof(struct header, size) ], TOTAL_SIZE);
|
||||||
int2le(&buf[offsetof(struct header, checksum) ], checksum);
|
int2le(&buf[offsetof(struct header, checksum) ], checksum);
|
||||||
|
@ -229,14 +231,14 @@ int chinachip_patch(const char* firmware, const char* bootloader,
|
||||||
od = fopen(output, "wb");
|
od = fopen(output, "wb");
|
||||||
if(!od)
|
if(!od)
|
||||||
{
|
{
|
||||||
ERR("Can't open file %s!", output);
|
ERR(tr("Can't open file %s!"), output);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
INFO("Writing output to %s...", output);
|
INFO(tr("Writing output to %s..."), output);
|
||||||
if(fwrite(buf, TOTAL_SIZE, 1, od) != 1)
|
if(fwrite(buf, TOTAL_SIZE, 1, od) != 1)
|
||||||
{
|
{
|
||||||
ERR("Can't write to file %s!", output);
|
ERR(tr("Can't write to file %s!"), output);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
fclose(od);
|
fclose(od);
|
||||||
|
|
|
@ -45,9 +45,9 @@ QString BootloaderInstallChinaChip::ofHint()
|
||||||
|
|
||||||
void BootloaderInstallChinaChip::logString(char* format, va_list args, int type)
|
void BootloaderInstallChinaChip::logString(char* format, va_list args, int type)
|
||||||
{
|
{
|
||||||
QString buffer;
|
QString translation = QCoreApplication::translate("", format, NULL, QCoreApplication::UnicodeUTF8);
|
||||||
|
|
||||||
emit logItem(buffer.vsprintf(format, args), type);
|
emit logItem(QString().vsprintf(translation.toLocal8Bit(), args), type);
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue