summaryrefslogtreecommitdiff
path: root/tools/qtestlib/wince/cetcpsyncserver/commands.cpp
blob: d5008a00e280c9ae7f234618056f4c1a0e5d048d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "commands.h"
#include <QtCore/QDebug>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/QProcess>

#ifdef Q_OS_WINCE
#include <windows.h>
#endif

/////////////////////////////////////////////////////
//       Abstract Command Implementation           //
/////////////////////////////////////////////////////
AbstractCommand::AbstractCommand()
: m_socket(0)
{
}

AbstractCommand::~AbstractCommand()
{
}

void AbstractCommand::reportSuccess()
{
    m_socket->write(COMMAND_SUCCESS, strlen(COMMAND_SUCCESS));
    m_socket->waitForBytesWritten();
}

void AbstractCommand::reportError()
{
    m_socket->write(COMMAND_ERROR, strlen(COMMAND_ERROR));
    m_socket->waitForBytesWritten();
}

void AbstractCommand::dataReceived(QByteArray&)
{
    debugOutput(1, "AbstractCommand::dataReceived NOT SUPPOSED TO BE HERE");
}

void AbstractCommand::commandFinished()
{
    debugOutput(1, "AbstractCommand::commandFinished()NOT SUPPOSED TO BE HERE");
}

void AbstractCommand::setSocket(QTcpSocket* socket) 
{
    debugOutput(0, "AbstractCommand::setSocket()");
    Q_ASSERT(socket);
    m_socket = socket;
    connect(m_socket, SIGNAL(readyRead()), this, SLOT(_readData()));
    reportSuccess();
}

QTcpSocket* AbstractCommand::socket() 
{ 
    return m_socket; 
}

void AbstractCommand::_readData()
{
    QByteArray arr = m_socket->readAll();
    dataReceived(arr);
}

void AbstractCommand::_disconnect()
{
}

/////////////////////////////////////////////////////
//       Create File Command Implementation        //
/////////////////////////////////////////////////////
CreateFileCommand::CreateFileCommand()
: m_dataCount(0)
{
    debugOutput(0, "CreateFileCommand::CreateFileCommand");
    m_options.fileSize= -1;
}

CreateFileCommand::~CreateFileCommand()
{
    debugOutput(0, "CreateFileCommand::~CreateFileCommand");
    if (m_file.isOpen()) {
        fprintf(stderr, "****************FILE IS STILL OPENED AND HAVENT FINISHED WRITING**********************\n");
        fprintf(stderr, "Current: %d Expected: %d\n", m_dataCount , m_options.fileSize);
        m_file.close();
    }
}

void CreateFileCommand::dataReceived(QByteArray &data)
{
    bool successful = true;
    // If we haven't received the options yet
    if (m_options.fileSize == -1) {
        CreateFileOptions* opt = (CreateFileOptions*) data.data();
        memcpy(&m_options , opt , sizeof(CreateFileOptions));

        if (QFileInfo(QString::fromLatin1(m_options.fileName)).exists()) {
            if (m_options.overwriteExisting) {
#ifdef Q_OS_WINCE
                SetFileAttributes(QFileInfo(m_options.fileName).absoluteFilePath().utf16(), FILE_ATTRIBUTE_NORMAL);
#endif
                QFile::remove(m_options.fileName);
            } else
                successful = false;
        }
        m_file.setFileName(QString::fromLatin1(m_options.fileName));
        if (!m_file.open(QIODevice::WriteOnly))
            successful = false;
        else
            debugOutput(3, QString::fromLatin1("Creating file: %1").arg(m_options.fileName));
    } else { // write buffer on disc
        if (!m_file.isOpen())
            return;
        m_file.write(data);
        m_dataCount += data.size();
        if (m_dataCount >= m_options.fileSize) {
            // We do not care about more data than announced
            m_file.close();
        }
    }
    
    if (successful)
        reportSuccess();
    else
        reportError();
}

void CreateFileCommand::commandFinished()
{
    debugOutput(0, "CreateFileCommand::commandFinished");
#ifdef Q_OS_WIN
    // We need to set the file attributes for intelligent time comparisons
    QString tmpFile = QString::fromLatin1(m_options.fileName);
    HANDLE handle = CreateFile(tmpFile.utf16(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
    if (handle != INVALID_HANDLE_VALUE) {
        SetFileTime(handle, &(m_options.fileTime), NULL, NULL);
        CloseHandle(handle);
    }
    SetFileAttributes(tmpFile.utf16(), m_options.fileAttributes);
#endif
}

/////////////////////////////////////////////////////
//    Create Directory Command Implementation      //
/////////////////////////////////////////////////////
CreateDirectoryCommand::CreateDirectoryCommand()
        : AbstractCommand()
{
    debugOutput(0, "CreateDirectoryCommand::CreateDirectoryCommand");
}

CreateDirectoryCommand::~CreateDirectoryCommand()
{
    debugOutput(0, "CreateDirectoryCommand::~CreateDirectoryCommand()");
}

void CreateDirectoryCommand::dataReceived(QByteArray &data)
{
    debugOutput(0, "CreateDirectoryCommand::dataReceived()");
    CreateDirectoryOptions* options = (CreateDirectoryOptions*) data.data();
    debugOutput(3, QString::fromLatin1("Creating directory: %1").arg(options->dirName));
    bool success = true;
    QDir dir;
    if (options->recursively)
        success = dir.mkpath(options->dirName);
    else
        success = dir.mkdir(options->dirName);
    
    if (success)
        reportSuccess();
    else
        reportError();
}

void CreateDirectoryCommand::commandFinished()
{
    debugOutput(0, "CreateDirectoryCommand::commandFinished()");
}

/////////////////////////////////////////////////////
//        Copy File Command Implementation         //
/////////////////////////////////////////////////////
CopyFileCommand::CopyFileCommand()
        : AbstractCommand()
{
    debugOutput(0, "CopyFileCommand::CopyFileCommand()");
}

CopyFileCommand::~CopyFileCommand()
{
    debugOutput(0, "CopyFileCommand::~CopyFileCommand()");
}

void CopyFileCommand::dataReceived(QByteArray &data)
{
    debugOutput(0, "CopyFileCommand::dataReceived()");
    CopyFileOptions* options = (CopyFileOptions*) data.data();
    debugOutput(3, QString::fromLatin1("Copy File: %1 ->  %2").arg(options->from).arg(options->to));
    bool success = true;
    if (QFileInfo(options->to).exists()) {
        if (options->overwriteExisting)
            QFile::remove(options->to);
        else
            success = false;
    }
    if (success)
        if (!QFile::copy(options->from , options->to))
            success = false;
    
    if (success)
        reportSuccess();
    else
        reportError();
}

void CopyFileCommand::commandFinished()
{
    debugOutput(0, "CopyFileCommand::commandFinished()");
}

/////////////////////////////////////////////////////
//      Copy Directory Command Implementation      //
/////////////////////////////////////////////////////
CopyDirectoryCommand::CopyDirectoryCommand()
        : AbstractCommand()
{
    debugOutput(0, "CopyDirectoryCommand::CopyDirectoryCommand()");
}

CopyDirectoryCommand::~CopyDirectoryCommand()
{
    debugOutput(0, "CopyDirectoryCommand::~CopyDirectoryCommand()");
}

void CopyDirectoryCommand::dataReceived(QByteArray &data)
{
    debugOutput(0, "CopyDirectoryCommand::dataReceived()");
    CopyDirectoryOptions* options = (CopyDirectoryOptions*) data.data();
    debugOutput(3, QString::fromLatin1("Copy Directory: %1 %2").arg(options->from).arg(options->to));
    if (copyDir(QLatin1String(options->from) , QLatin1String(options->to) , options->recursive))
        reportSuccess();
    else
        reportError();
}

void CopyDirectoryCommand::commandFinished()
{
    debugOutput(0, "CopyDirectoryCommand::commandFinished()");
}

bool CopyDirectoryCommand::copyDir(const QString &from, const QString &to, bool recursive)
{
    QDir().mkpath(to);
    QDir sourceDir(from);
    QDir destDir(to);
    QStringList entries = sourceDir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
    foreach (QString item , entries) {
        QString itemFrom = sourceDir.absoluteFilePath(item);
        QString itemTo = destDir.absoluteFilePath(item);
        if (QFileInfo(item).isDir()) {
            if (recursive && !copyDir(itemFrom, itemTo, recursive))
                return false;
        } else {
            if (!QFile::copy(itemFrom, itemTo))
                return false;
        }
    }
    return true;
}

/////////////////////////////////////////////////////
//        Delete File Command Implementation       //
/////////////////////////////////////////////////////
DeleteFileCommand::DeleteFileCommand()
        : AbstractCommand()
{
    debugOutput(0, "DeleteFileCommand::DeleteFileCommand()");
}

DeleteFileCommand::~DeleteFileCommand()
{
    debugOutput(0, "DeleteFileCommand::~DeleteFileCommand()");
}

void DeleteFileCommand::dataReceived(QByteArray &data)
{
    debugOutput(0, "DeleteFileCommand::dataReceived()");
    DeleteFileOptions* options = (DeleteFileOptions*) data.data();
    debugOutput(3, QString::fromLatin1("Delete File: %1").arg(options->fileName));
    bool success = true;
    QFile file(options->fileName);
    if (file.exists()) {
#ifdef Q_OS_WINCE
        SetFileAttributes(QFileInfo(options->fileName).absoluteFilePath().utf16(), FILE_ATTRIBUTE_NORMAL);
#endif
        success = file.remove();
    } else
        success = false;

    if (success)
        reportSuccess();
    else
        reportError();
}

void DeleteFileCommand::commandFinished()
{
    debugOutput(0, "DeleteFileCommand::commandFinished()");
}

/////////////////////////////////////////////////////
//     Delete Directory Command Implementation     //
/////////////////////////////////////////////////////
DeleteDirectoryCommand::DeleteDirectoryCommand()
        : AbstractCommand()
{
    debugOutput(0, "DeleteDirectoryCommand::DeleteDirectoryCommand()");
}

DeleteDirectoryCommand::~DeleteDirectoryCommand()
{
    debugOutput(0, "DeleteDirectoryCommand::~DeleteDirectoryCommand()");
}

void DeleteDirectoryCommand::dataReceived(QByteArray &data)
{
    debugOutput(0, "DeleteDirectoryCommand::dataReceived()");
    DeleteDirectoryOptions* options = (DeleteDirectoryOptions*) data.data();
    debugOutput(3, QString::fromLatin1("Delete directory: %1").arg(options->dirName));
    if (deleteDirectory(QLatin1String(options->dirName), options->recursive, options->failIfContentExists))
        reportSuccess();
    else
        reportError();
}

void DeleteDirectoryCommand::commandFinished()
{
    debugOutput(0, "DeleteDirectoryCommand::commandFinished()");
}

bool DeleteDirectoryCommand::deleteDirectory(const QString &dirName, bool recursive, bool failIfContentExists)
{
    QDir dir(dirName);
    if (!dir.exists())
        return false;

    QStringList itemList = dir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
    if (itemList.size() > 0 && failIfContentExists)
        return false;

    foreach (QString item, itemList) {
        QString itemName = dir.absoluteFilePath(item);
        if (QFileInfo(itemName).isDir()) {
            if (recursive && !deleteDirectory(itemName, recursive, failIfContentExists))
                return false;
        } else {
            if (!dir.remove(item))
                return false;
        }
    }
    QString lastName = dir.dirName();
    dir.cdUp();
    dir.rmpath(lastName);
    return true;
}

/////////////////////////////////////////////////////
//         Execute Command Implementation          //
/////////////////////////////////////////////////////
ExecuteCommand::ExecuteCommand()
        : AbstractCommand()
        , m_argumentCount(0)
        , m_timeout(-1)
{
    debugOutput(0, "ExecuteCommand::ExecuteCommand()");
}

ExecuteCommand::~ExecuteCommand()
{
    debugOutput(0, "ExecuteCommand::~ExecuteCommand()");
}

void ExecuteCommand::dataReceived(QByteArray &data)
{
    debugOutput(0, "ExecuteCommand::dataReceived()");
    
    if (m_argumentCount == 0) {
        ExecuteOptions* options = (ExecuteOptions*) data.data();
        if (!QFileInfo(options->appName).exists()) {
            debugOutput(1, "Error execute: application does not exist");
            reportError();
            return;
        }
    
        m_program = QLatin1String(options->appName);
        m_argumentCount = options->argumentsCount;
        m_waitFinished = options->waitForFinished;
        m_timeout = options->timeout;
        if (m_argumentCount == 0)
            m_argumentCount = -1; // to trigger startup on next receive
        reportSuccess();
    } else if (m_arguments.size() < m_argumentCount) {
        m_arguments += data;
        reportSuccess();
    } else { // do the execution
        if (data == COMMAND_SUCCESS)
            _doExecute();
    }
}

void ExecuteCommand::_doExecute()
{
    debugOutput(0, "ExecuteCommand::_doExecute()");
    debugOutput(3, QString::fromLatin1("Execute: %1 %2").arg(m_program).arg(m_arguments.join(" ")));
    if (m_waitFinished) {
        QProcess process;
        process.start(m_program, m_arguments);
        if (process.waitForFinished(m_timeout) == false || process.exitCode() < 0)
            reportError();
        else
            reportSuccess();
    } else {
        if (QProcess::startDetached(m_program, m_arguments))
            reportSuccess();
        else
            reportError();
    }
}
void ExecuteCommand::commandFinished()
{
    debugOutput(0,"ExecuteCommand::commandFinished()");
}

/////////////////////////////////////////////////////
//           Read File Implementation              //
/////////////////////////////////////////////////////
ReadFileCommand::ReadFileCommand()
        : AbstractCommand()
        , m_currentPos(0)
{
    debugOutput(0, "ReadFileCommand::ReadFileCommand()");
    m_fileName.clear();
}

ReadFileCommand::~ReadFileCommand()
{
    debugOutput(0, "ReadFileCommand::~ReadFileCommand()");
    if (m_file.isOpen())
        m_file.close();
}

void ReadFileCommand::dataReceived(QByteArray &data)
{
    debugOutput(0, "ReadFileCommand::dataReceived()");
    if (m_fileName.isEmpty()) {
        ReadFileOptions* option = (ReadFileOptions*) data.data();
        m_fileName = QLatin1String(option->fileName);
        QFileInfo info(m_fileName);
        m_file.setFileName(m_fileName);
        ReadFileReply reply;
        if (!info.exists() || !info.isFile() || !m_file.open(QIODevice::ReadOnly))
            reply.fileValid = false;
        else
            reply.fileValid = true;
        reply.fileSize = info.size();
        m_fileSize = reply.fileSize;
        socket()->write((char*) &reply, sizeof(reply));
        debugOutput(3, QString::fromLatin1("Reading file: %1").arg(m_fileName));
    } else {
        QTcpSocket* sock = socket(); // design failure???
        if (data != COMMAND_SUCCESS || m_currentPos >= m_fileSize) {
            sock->disconnectFromHost();
            return;
        }
        const int bufferSize = 1024;
        QByteArray buffer = m_file.read(bufferSize);
        m_currentPos += buffer.size();
        sock->write(buffer);
        sock->waitForBytesWritten();
    }
}

void ReadFileCommand::commandFinished()
{
    debugOutput(0, "ReadFileCommand::commandFinished()");
}

/////////////////////////////////////////////////////
//        Read Directory Implementation            //
/////////////////////////////////////////////////////
ReadDirectoryCommand::ReadDirectoryCommand()
        : AbstractCommand()
        , m_iterator(0)
{
    debugOutput(0, "ReadDirectoryCommand::ReadDirectoryCommand");
    m_dirName.clear();
}

ReadDirectoryCommand::~ReadDirectoryCommand()
{
    debugOutput(0, "ReadDirectoryCommand::~ReadDirectoryCommand()");
    delete m_iterator;
}

void ReadDirectoryCommand::dataReceived(QByteArray &data)
{
    debugOutput(0, "ReadDirectoryCommand::dataReceived()");
    QTcpSocket* sock = socket();
    if (m_dirName.isEmpty()) {
        ReadDirectoryOptions* option = (ReadDirectoryOptions*) data.data();
        QFileInfo info(QLatin1String(option->dirName));
        debugOutput(3, QString::fromLatin1("Reading Directory entries: %1").arg(option->dirName));
        ReadDirectoryReply reply;
        if (!info.exists() || !info.isDir()) {
            reply.itemCount = -1;
            reply.entryValid = false;
        } else {
            m_dirName = QLatin1String(option->dirName);
            m_dir.setPath(m_dirName);
            m_iterator = new QDirIterator(m_dir);
            reply.itemCount = m_dir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot).size();
            reply.entryValid = true;
        }
        sock->write((char*) &reply, sizeof(reply));
        sock->waitForBytesWritten();
    } else {
        if (data != COMMAND_SUCCESS) {
            qDebug() << "Something went wrong in the meantime";
            return;
        }
        ReadDirectoryItem reply;
        if (m_iterator->hasNext()) {
            m_iterator->next();
            QFileInfo info = m_iterator->fileInfo();
            strcpy(reply.name, qPrintable(info.absoluteFilePath()));
            reply.isDirectory = info.isDir();
            if (!reply.isDirectory)
                reply.size = info.size();
        }
        reply.hasMore = m_iterator->hasNext();
        sock->write((char*) &reply, sizeof(reply));
        sock->waitForBytesWritten();
    }
}

void ReadDirectoryCommand::commandFinished()
{
    debugOutput(0, "ReadDirectoryCommand::commandFinished()");
}

/////////////////////////////////////////////////////
//           File Time Implementation              //
/////////////////////////////////////////////////////
FileTimeCommand::FileTimeCommand()
        : AbstractCommand()
{
    debugOutput(0, "FileTimeCommand::FileTimeCommand()");
}

FileTimeCommand::~FileTimeCommand()
{
    debugOutput(0, "FileTimeCommand::~FileTimeCommand()");
}

void FileTimeCommand::dataReceived(QByteArray &data)
{
    debugOutput(0, "FileTimeCommand::dataReceived()");
    FileTimeOptions* option = (FileTimeOptions*) data.data();

    FILETIME resultTime;
    resultTime.dwLowDateTime = -1;
    resultTime.dwHighDateTime = -1;
    
#ifdef Q_OS_WIN
    QString fileName = QLatin1String(option->fileName);
    HANDLE deviceHandle = CreateFile(fileName.utf16(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
    debugOutput(3, QString::fromLatin1("Asking FileTime: %1").arg(fileName));
    if (deviceHandle != INVALID_HANDLE_VALUE) {
        FILETIME deviceCreationTime;
        if (GetFileTime(deviceHandle, &deviceCreationTime, NULL, NULL)) {
            resultTime = deviceCreationTime;
        }
        CloseHandle(deviceHandle);
    }
#endif
    QTcpSocket* sock = socket();
    sock->write((char*) &resultTime, sizeof(resultTime));
    sock->waitForBytesWritten();
}

void FileTimeCommand::commandFinished()
{
    debugOutput(0, "FileTimeCommand::commandFinished()");
}

/////////////////////////////////////////////////////
//           Time Stamp Implementation             //
/////////////////////////////////////////////////////
TimeStampCommand::TimeStampCommand()
        : AbstractCommand()
{
    debugOutput(0, "TimeStampCommand::TimeStampCommand()");
}

TimeStampCommand::~TimeStampCommand()
{
    debugOutput(0, "TimeStampCommand::~TimeStampCommand()");
}

void TimeStampCommand::dataReceived(QByteArray &data)
{
    debugOutput(0, "TimeStampCommand::dataReceived()");
    FILETIME resultTime;
    resultTime.dwLowDateTime = -1;
    resultTime.dwHighDateTime = -1;
    
#ifdef Q_OS_WIN
    FILETIME stampTime = *((FILETIME*)data.data());
    
    QString tmpFile = QString::fromLatin1("\\qt_tmp_ftime_convert");
    HANDLE remoteHandle = CreateFile(tmpFile.utf16(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
    if (remoteHandle != INVALID_HANDLE_VALUE) {
        if (!SetFileTime(remoteHandle, &stampTime, NULL, NULL)) {
            CloseHandle(remoteHandle);
        } else {
            CloseHandle(remoteHandle);
            remoteHandle = CreateFile(tmpFile.utf16(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
            if (remoteHandle != INVALID_HANDLE_VALUE) {
                if (GetFileTime(remoteHandle, &stampTime, NULL, NULL))
                    resultTime = stampTime;
                CloseHandle(remoteHandle);
                DeleteFile(tmpFile.utf16());
            }
        }
    }
    debugOutput(3, QString::fromLatin1("Asking TimeStamp"));
#endif
    QTcpSocket* sock = socket();
    sock->write((char*) &resultTime, sizeof(resultTime));
    sock->waitForBytesWritten();
}

void TimeStampCommand::commandFinished()
{
    debugOutput(0, "TimeStampCommand::commandFinished()");
}