Skip to content

Commit

Permalink
[0.1.0][enhancement][0][避免多处重复de读写录像代码][record|client]
Browse files Browse the repository at this point in the history
  • Loading branch information
takashiro committed Jan 13, 2015
1 parent 185d5be commit a6243e8
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 169 deletions.
2 changes: 1 addition & 1 deletion src/client/client.cpp
Expand Up @@ -162,7 +162,7 @@ Client::Client(QObject *parent, const QString &filename)
socket = NULL;

replayer = new Replayer(filename, this);
connect(replayer, &Replayer::command_parsed, this, &Client::processServerPacket);
connect(replayer, &Replayer::commandParsed, this, &Client::processServerPacket);
} else {
socket = new NativeClientSocket(this);
connect(socket, &NativeClientSocket::message_got, this, &Client::processServerPacket);
Expand Down
30 changes: 11 additions & 19 deletions src/core/record-analysis.cpp
Expand Up @@ -33,28 +33,20 @@ RecAnalysis::RecAnalysis(const QString &dir) : m_recordPlayers(0), m_currentPlay
initialize(dir);
}

void RecAnalysis::initialize(const QString &dir) {
void RecAnalysis::initialize(const QString &fileName) {
QList<QByteArray> records_line;
if (dir.isEmpty()) {
if (fileName.isEmpty()) {
records_line = ClientInstance->getRecords();
} else if (dir.endsWith(".qsgs")) {
QFile file(dir);
if (file.open(QIODevice::ReadOnly)) {
char header;
file.getChar(&header);
if (header == 0) {
QByteArray lines = file.readAll();
lines = qUncompress(lines);
records_line = lines.split('\n');
} else {
file.ungetChar(header);
while (!file.atEnd())
records_line << file.readLine();
}
}
} else {
QMessageBox::warning(NULL, tr("Warning"), tr("The file is unreadable"));
return;
Record record(fileName);
if (!record.open()) {
QMessageBox::warning(NULL, tr("Warning"), tr("The file is unreadable"));
return;
}

const QList<Record::Command> &commands = record.commands();
foreach (const Record::Command &command, commands)
records_line << command.data;
}
records_line.removeAll(QByteArray());

Expand Down
2 changes: 1 addition & 1 deletion src/core/record-analysis.h
Expand Up @@ -53,7 +53,7 @@ class RecAnalysis : public QObject {
ZeroDamaged = 0x800
};

void initialize(const QString &dir = QString());
void initialize(const QString &fileName = QString());
PlayerRecordStruct *getPlayerRecord(const Player *player) const;
QMap<QString, PlayerRecordStruct *> getRecordMap() const;
QStringList getRecordPackages() const;
Expand Down
29 changes: 8 additions & 21 deletions src/dialog/mainwindow.cpp
Expand Up @@ -1074,33 +1074,20 @@ void MainWindow::on_actionReplay_file_convert_triggered() {
return;

foreach (const QString &filename, filenames) {
QFile file(filename);
if (file.open(QIODevice::ReadOnly)) {
Record record(filename);
if (record.open()) {
QFileInfo info(filename);
QString tosave = info.absoluteDir().absoluteFilePath(info.baseName());

char header;
file.getChar(&header);
if (header == '\0') {
QByteArray content = file.readAll();
content = qUncompress(content);
QString tosave = info.dir().absoluteFilePath(info.baseName());

if (record.format() == Record::CompressedText) {
tosave.append("-uncompressed.qsgs");
QFile file(tosave);
if (file.open(QFile::WriteOnly | QFile::Text))
file.write(content);
record.setFormat(Record::PlainText);
} else {
file.ungetChar(header);
QByteArray content = file.readAll();
content = qCompress(content);

tosave.append("-compressed.qsgs");
QFile file(tosave);
if (file.open(QFile::WriteOnly)) {
file.putChar('\0');
file.write(content);
}
record.setFormat(Record::CompressedText);
}

record.saveAs(tosave);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/roomscene.cpp
Expand Up @@ -711,7 +711,7 @@ ReplayerControlBar::ReplayerControlBar(Dashboard *dashboard) {
connect(slow_down, &QSanButton::clicked, replayer, &Replayer::slowDown);
connect(speed_up, &QSanButton::clicked, replayer, &Replayer::speedUp);
connect(replayer, &Replayer::elasped, this, &ReplayerControlBar::setTime);
connect(replayer, &Replayer::speed_changed, this, &ReplayerControlBar::setSpeed);
connect(replayer, &Replayer::speedChanged, this, &ReplayerControlBar::setSpeed);

speed = replayer->getSpeed();
setParentItem(dashboard);
Expand Down

0 comments on commit a6243e8

Please sign in to comment.