Commit fa2ca2de authored by Robert Loehning's avatar Robert Loehning
Browse files

Trk: Checking for write errors when writing file to device.

Reviewed-by: con
parent 961fe9ed
......@@ -628,6 +628,7 @@ void S60DeviceRunControlBase::signsisProcessFinished()
connect(m_launcher, SIGNAL(finished()), this, SLOT(launcherFinished()));
connect(m_launcher, SIGNAL(copyingStarted()), this, SLOT(printCopyingNotice()));
connect(m_launcher, SIGNAL(canNotCreateFile(QString,QString)), this, SLOT(printCreateFileFailed(QString,QString)));
connect(m_launcher, SIGNAL(canNotWriteFile(QString,QString)), this, SLOT(printWriteFileFailed(QString,QString)));
connect(m_launcher, SIGNAL(installingStarted()), this, SLOT(printInstallingNotice()));
connect(m_launcher, SIGNAL(copyProgress(int)), this, SLOT(printCopyProgress(int)));
......@@ -655,10 +656,14 @@ void S60DeviceRunControlBase::printCreateFileFailed(const QString &filename, con
emit addToOutputWindow(this, tr("Could not create file %1 on device: %2").arg(filename, errorMessage));
}
void S60DeviceRunControlBase::printWriteFileFailed(const QString &filename, const QString &errorMessage)
{
emit addToOutputWindow(this, tr("Could not write to file %1 on device: %2").arg(filename, errorMessage));
}
void S60DeviceRunControlBase::printCopyingNotice()
{
emit addToOutputWindow(this, tr("Copying install file..."));
emit addToOutputWindow(this, tr("0% copied."));
}
void S60DeviceRunControlBase::printCopyProgress(int progress)
......
......@@ -172,6 +172,7 @@ private slots:
void signsisProcessFinished();
void printCopyingNotice();
void printCreateFileFailed(const QString &filename, const QString &errorMessage);
void printWriteFileFailed(const QString &filename, const QString &errorMessage);
void printCopyProgress(int progress);
void printInstallingNotice();
void launcherFinished();
......
......@@ -299,7 +299,7 @@ void Launcher::handleTrkVersion(const TrkResult &result)
void Launcher::handleFileCreation(const TrkResult &result)
{
if (result.errorCode() || result.data.size() < 6) {
emit canNotCreateFile(d->m_copyState.destinationFileName, errorMessage(result.errorCode()));
emit canNotCreateFile(d->m_copyState.destinationFileName, result.errorString());
emit finished();
return;
}
......@@ -315,15 +315,19 @@ void Launcher::handleFileCreation(const TrkResult &result)
void Launcher::handleCopy(const TrkResult &result)
{
Q_UNUSED(result)
continueCopying();
if (result.errorCode() || result.data.size() < 4) {
closeRemoteFile(true);
emit canNotWriteFile(d->m_copyState.destinationFileName, result.errorString());
emit finished();
} else {
continueCopying(extractShort(result.data.data() + 2));
}
}
void Launcher::continueCopying()
void Launcher::continueCopying(uint lastCopiedBlockSize)
{
static const int BLOCKSIZE = 1024;
int size = d->m_copyState.data->length();
d->m_copyState.position += lastCopiedBlockSize;
if (size == 0)
emit copyProgress(100);
else {
......@@ -333,18 +337,24 @@ void Launcher::continueCopying()
if (d->m_copyState.position < size) {
QByteArray ba;
appendInt(&ba, d->m_copyState.copyFileHandle, TargetByteOrder);
appendString(&ba, d->m_copyState.data->mid(d->m_copyState.position, BLOCKSIZE), TargetByteOrder, false);
d->m_copyState.position += BLOCKSIZE;
appendString(&ba, d->m_copyState.data->mid(d->m_copyState.position, 2048), TargetByteOrder, false);
d->m_device.sendTrkMessage(TrkWriteFile, TrkCallback(this, &Launcher::handleCopy), ba);
} else {
QByteArray ba;
appendInt(&ba, d->m_copyState.copyFileHandle, TargetByteOrder);
appendInt(&ba, QDateTime::currentDateTime().toTime_t(), TargetByteOrder);
d->m_device.sendTrkMessage(TrkCloseFile, TrkCallback(this, &Launcher::handleFileCopied), ba);
d->m_copyState.data.reset();
closeRemoteFile();
}
}
void Launcher::closeRemoteFile(bool failed)
{
QByteArray ba;
appendInt(&ba, d->m_copyState.copyFileHandle, TargetByteOrder);
appendInt(&ba, QDateTime::currentDateTime().toTime_t(), TargetByteOrder);
d->m_device.sendTrkMessage(TrkCloseFile,
failed ? TrkCallback() : TrkCallback(this, &Launcher::handleFileCopied),
ba);
d->m_copyState.data.reset();
}
void Launcher::handleFileCopied(const TrkResult &result)
{
Q_UNUSED(result)
......@@ -372,7 +382,7 @@ void Launcher::handleCpuType(const TrkResult &result)
void Launcher::handleCreateProcess(const TrkResult &result)
{
if (result.errorCode()) {
emit canNotRun(errorMessage(result.errorCode()));
emit canNotRun(result.errorString());
emit finished();
return;
}
......
......@@ -58,6 +58,7 @@ public:
signals:
void copyingStarted();
void canNotCreateFile(const QString &filename, const QString &errorMessage);
void canNotWriteFile(const QString &filename, const QString &errorMessage);
void installingStarted();
void startingApplication();
void applicationRunning(uint pid);
......@@ -78,7 +79,8 @@ private:
void handleFileCreation(const TrkResult &result);
void handleCopy(const TrkResult &result);
void continueCopying();
void continueCopying(uint lastCopiedBlockSize = 0);
void closeRemoteFile(bool failed = false);
void handleFileCopied(const TrkResult &result);
void handleInstallPackageFinished(const TrkResult &result);
void handleCpuType(const TrkResult &result);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment