From bf34aa7fbd87eb5e21bc1bb69fc3f53c2c92d8fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 13 Dec 2013 00:02:58 +0100 Subject: [PATCH] Use temporary files for the java checker --- logic/JavaChecker.cpp | 17 ++++++++++------- logic/JavaChecker.h | 3 +++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/logic/JavaChecker.cpp b/logic/JavaChecker.cpp index 38bbf700..2b94fbb6 100644 --- a/logic/JavaChecker.cpp +++ b/logic/JavaChecker.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #define CHECKER_FILE "JavaChecker.jar" @@ -11,14 +12,15 @@ JavaChecker::JavaChecker(QObject *parent) : QObject(parent) void JavaChecker::performCheck() { - if(QFile::exists(CHECKER_FILE)) - { - QFile::remove(CHECKER_FILE); - } - // extract the checker - QFile(":/java/checker.jar").copy(CHECKER_FILE); + checkerJar.setFileTemplate("checker_XXXXXX.jar"); + checkerJar.open(); + QFile inner(":/java/checker.jar"); + inner.open(QIODevice::ReadOnly); + checkerJar.write(inner.readAll()); + inner.close(); + checkerJar.close(); - QStringList args = {"-jar", CHECKER_FILE}; + QStringList args = {"-jar", checkerJar.fileName()}; process.reset(new QProcess()); process->setArguments(args); @@ -40,6 +42,7 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status) killTimer.stop(); QProcessPtr _process; _process.swap(process); + checkerJar.remove(); JavaCheckResult result; { diff --git a/logic/JavaChecker.h b/logic/JavaChecker.h index 4488da66..291bf46c 100644 --- a/logic/JavaChecker.h +++ b/logic/JavaChecker.h @@ -1,10 +1,12 @@ #pragma once #include #include +#include #include class JavaChecker; + struct JavaCheckResult { QString path; @@ -31,6 +33,7 @@ signals: private: QProcessPtr process; QTimer killTimer; + QTemporaryFile checkerJar; public slots: void timeout();