Replayer::Replayer(QObject *parent, const QString &filename) :QThread(parent), m_isOldVersion(false), m_commandSeriesCounter(1), filename(filename), speed(1.0), playing(true) { QIODevice *device = NULL; if(filename.endsWith(".png")){ QByteArray *data = new QByteArray(PNG2TXT(filename)); QBuffer *buffer = new QBuffer(data); device = buffer; }else if(filename.endsWith(".txt")){ QFile *file = new QFile(filename); device = file; } if(device == NULL) return; if(!device->open(QIODevice::ReadOnly | QIODevice::Text)) return; typedef char buffer_t[1024]; initCommandPair(); while(!device->atEnd()){ buffer_t line; memset(line, 0, sizeof(buffer_t)); device->readLine(line, sizeof(buffer_t)); char *space = strchr(line, ' '); if(space == NULL) continue; *space = '\0'; QString cmd = space + 1; int elapsed = atoi(line); //@todo: There is a serious problem that the old protocol didn't has //any tag or type definition for the sent messages, and if the old protocol // wants to be translated to the new protocol, there is no information for the package type //and client will be confused of showing dialog or not. commandTranslation(cmd); Pair pair; pair.elapsed = elapsed; pair.cmd = cmd; pairs << pair; } if(m_isOldVersion){ QMessageBox::warning(NULL, tr("Warning"), tr("The replay use old protocol")); } delete device; }
Replayer::Replayer(QObject *parent, const QString &filename) :QThread(parent), filename(filename), speed(1.0), playing(true) { QIODevice *device = NULL; if(filename.endsWith(".png")){ QByteArray *data = new QByteArray(PNG2TXT(filename)); QBuffer *buffer = new QBuffer(data); device = buffer; }else if(filename.endsWith(".txt")){ QFile *file = new QFile(filename); device = file; } if(device == NULL) return; if(!device->open(QIODevice::ReadOnly | QIODevice::Text)) return; typedef char buffer_t[1024]; while(!device->atEnd()){ buffer_t line; memset(line, 0, sizeof(buffer_t)); device->readLine(line, sizeof(buffer_t)); char *space = strchr(line, ' '); if(space == NULL) continue; *space = '\0'; QString cmd = space + 1; int elapsed = atoi(line); Pair pair; pair.elapsed = elapsed; pair.cmd = cmd; pairs << pair; } delete device; }