mirror of
https://github.com/opentx/opentx.git
synced 2025-07-26 01:35:21 +03:00
Companion can now read and write Firmware in massstorage mode. Big code
refactoring (code was duplicated in many locations) around read/write firmware/eeprom/backups, who could do some more tests before next release? Thanks in advance!
This commit is contained in:
parent
a02cdca62c
commit
72dc69086c
4 changed files with 268 additions and 334 deletions
|
@ -133,39 +133,40 @@ BOOL KillProcessByName(char *szProcessToKill){
|
|||
|
||||
void avrOutputDialog::doCopy()
|
||||
{
|
||||
hasErrors=false;
|
||||
char buf[READBUF];
|
||||
char * pointer=buf;
|
||||
char buf[BLKSIZE];
|
||||
|
||||
QFile source(sourceFile);
|
||||
int blocks=(source.size()/BLKSIZE);
|
||||
int blocks = (source.size() + BLKSIZE - 1) / BLKSIZE;
|
||||
ui->progressBar->setMaximum(blocks-1);
|
||||
if (!source.open(QIODevice::ReadOnly)) {
|
||||
QMessageBox::warning(this, tr("Error"),tr("Cannot open source file"));
|
||||
hasErrors=true;
|
||||
}
|
||||
else {
|
||||
source.read(buf,READBUF);
|
||||
source.close();
|
||||
|
||||
if (source.open(QIODevice::ReadOnly)) {
|
||||
QFile dest(destFile);
|
||||
if (!dest.open(QIODevice::WriteOnly)) {
|
||||
QMessageBox::warning(this, tr("Error"),tr("Cannot write destination"));
|
||||
hasErrors=true;
|
||||
} else {
|
||||
addText(tr("Writing file: "));
|
||||
for (int i=0;i<blocks;i++) {
|
||||
if (dest.write(pointer,BLKSIZE)!=BLKSIZE) {
|
||||
hasErrors=true;
|
||||
if (dest.open(QIODevice::WriteOnly)) {
|
||||
for (int i=0; i<blocks; i++) {
|
||||
addText(tr("Writing file: "));
|
||||
int read = source.read(buf, BLKSIZE);
|
||||
if (dest.write(buf, read) == read) {
|
||||
dest.flush();
|
||||
ui->progressBar->setValue(i);
|
||||
if ((i%2) != 0)
|
||||
addText("#");
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(this, tr("Error"), tr("Write error"));
|
||||
break;
|
||||
};
|
||||
dest.flush();
|
||||
pointer+=BLKSIZE;
|
||||
ui->progressBar->setValue(i);
|
||||
if ((i%2)!=0)
|
||||
addText("#");
|
||||
}
|
||||
}
|
||||
dest.close();
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(this, tr("Error"),tr("Cannot write destination"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(this, tr("Error"),tr("Cannot open source file"));
|
||||
}
|
||||
|
||||
source.close();
|
||||
doFinished(0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue