Pack downloader a bit better now
This commit is contained in:
@@ -387,20 +387,29 @@ auto DownloadManager::downloadPack(const QString &id) -> void
|
|||||||
)
|
)
|
||||||
.onFailed
|
.onFailed
|
||||||
(
|
(
|
||||||
[this, tempFile] (const NetworkException &e)
|
[this, tempFile] (const std::filesystem::filesystem_error &e)
|
||||||
{
|
{
|
||||||
QFile::remove(QStringLiteral("/tmp/") + tempFile);
|
QFile::remove(QStringLiteral("/tmp/") + tempFile);
|
||||||
reset();
|
reset();
|
||||||
setError(QStringLiteral("Network Exception %1").arg(QString::number(e.errorCode)), e.message);
|
setError(QStringLiteral("Network Exception %1").arg(QString::number(e.code().value())), e.what());
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.onFailed
|
.onFailed
|
||||||
(
|
(
|
||||||
[this, tempFile] (const FileException &e)
|
[this, tempFile] (const std::logic_error &e)
|
||||||
{
|
{
|
||||||
QFile::remove(QStringLiteral("/tmp/") + tempFile);
|
QFile::remove(QStringLiteral("/tmp/") + tempFile);
|
||||||
reset();
|
reset();
|
||||||
setError(QStringLiteral("File Exception %1").arg(QString::number(e.errorCode)), e.message);
|
setError(QStringLiteral("Logic Exception %1"), e.what());
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.onFailed
|
||||||
|
(
|
||||||
|
[this, tempFile] (const std::exception &e)
|
||||||
|
{
|
||||||
|
QFile::remove(QStringLiteral("/tmp/") + tempFile);
|
||||||
|
reset();
|
||||||
|
setError(QStringLiteral("Logic Exception %1"), e.what());
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.onFailed
|
.onFailed
|
||||||
@@ -501,10 +510,7 @@ auto DownloadManager::setDownloadProgress(qreal progress) -> void
|
|||||||
|
|
||||||
auto DownloadManager::install(const QUrl &uri) noexcept(false) -> QUrl
|
auto DownloadManager::install(const QUrl &uri) noexcept(false) -> QUrl
|
||||||
{
|
{
|
||||||
if(!uri.isLocalFile())
|
validateUri(uri);
|
||||||
{
|
|
||||||
throw FileException(QStringLiteral("URI is not a local file"));
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir tempDirectory(uri.toLocalFile());
|
QDir tempDirectory(uri.toLocalFile());
|
||||||
|
|
||||||
@@ -633,7 +639,7 @@ auto DownloadManager::download(const QNetworkRequest &request, const QString &id
|
|||||||
reply,
|
reply,
|
||||||
&QNetworkReply::readyRead,
|
&QNetworkReply::readyRead,
|
||||||
this,
|
this,
|
||||||
[this, downloadUri/*, reply, &downloadFile*/]()
|
[this, downloadUri]()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_fileMutex);
|
QMutexLocker locker(&m_fileMutex);
|
||||||
QFile downloadFile(downloadUri.toLocalFile());
|
QFile downloadFile(downloadUri.toLocalFile());
|
||||||
@@ -647,9 +653,14 @@ auto DownloadManager::download(const QNetworkRequest &request, const QString &id
|
|||||||
|
|
||||||
if(reply == nullptr)
|
if(reply == nullptr)
|
||||||
{
|
{
|
||||||
throw NetworkException
|
throw std::system_error
|
||||||
{
|
{
|
||||||
QStringLiteral("Reply is not a qobject")
|
std::error_code
|
||||||
|
(
|
||||||
|
ENOENT,
|
||||||
|
std::system_category()
|
||||||
|
),
|
||||||
|
QStringLiteral("Reply is not a qobject").toStdString()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,29 +692,61 @@ auto DownloadManager::download(const QNetworkRequest &request, const QString &id
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto DownloadManager::validateUri(const QUrl &uri) noexcept(false) -> void
|
||||||
|
{
|
||||||
|
if(!uri.isValid() || !uri.isLocalFile())
|
||||||
|
{
|
||||||
|
throw std::filesystem::filesystem_error
|
||||||
|
(
|
||||||
|
QStringLiteral("URI %1 is not a local file uri").arg
|
||||||
|
(
|
||||||
|
uri.toString()
|
||||||
|
).toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
ENOENT,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto DownloadManager::readShaderToyEntry(const QUrl &uri) noexcept(false) -> ShaderToyEntry
|
auto DownloadManager::readShaderToyEntry(const QUrl &uri) noexcept(false) -> ShaderToyEntry
|
||||||
{
|
{
|
||||||
if(!uri.isLocalFile())
|
validateUri(uri);
|
||||||
{
|
|
||||||
throw FileException(QStringLiteral("URI is not a local file"));
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir packDir(uri.toLocalFile());
|
QDir packDir(uri.toLocalFile());
|
||||||
|
|
||||||
if(!packDir.exists(QStringLiteral("pack.json")))
|
if(!packDir.exists(QStringLiteral("pack.json")))
|
||||||
{
|
{
|
||||||
throw FileException(QStringLiteral("Pack file not found"));
|
throw std::filesystem::filesystem_error
|
||||||
|
(
|
||||||
|
QStringLiteral("Pack file not found").arg
|
||||||
|
(
|
||||||
|
uri.toString()
|
||||||
|
).toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
ENOENT,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile packFile(packDir.absoluteFilePath(QStringLiteral("pack.json")));
|
QFile packFile(packDir.absoluteFilePath(QStringLiteral("pack.json")));
|
||||||
|
|
||||||
if(!packFile.open(QFile::ReadOnly))
|
if(!packFile.open(QFile::ReadOnly))
|
||||||
{
|
{
|
||||||
throw FileException
|
throw std::filesystem::filesystem_error
|
||||||
(
|
(
|
||||||
QStringLiteral("Could not open pack file: %1").arg
|
QStringLiteral("Could not open pack file").arg
|
||||||
(
|
(
|
||||||
packFile.errorString()
|
uri.toString()
|
||||||
|
).toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -715,11 +758,16 @@ auto DownloadManager::readShaderToyEntry(const QUrl &uri) noexcept(false) -> Sha
|
|||||||
|
|
||||||
if(jsonError.error != QJsonParseError::NoError)
|
if(jsonError.error != QJsonParseError::NoError)
|
||||||
{
|
{
|
||||||
throw FileException
|
throw std::filesystem::filesystem_error
|
||||||
(
|
(
|
||||||
QStringLiteral("Could parse pack file: %1").arg
|
QStringLiteral("URI %1 is not a local file uri").arg
|
||||||
(
|
(
|
||||||
jsonError.errorString()
|
uri.toString()
|
||||||
|
).toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
EIO,
|
||||||
|
std::system_category()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ private:
|
|||||||
auto install(const QUrl &uri) noexcept(false) -> QUrl;
|
auto install(const QUrl &uri) noexcept(false) -> QUrl;
|
||||||
auto download(const QNetworkRequest &request, const QString &id, RequestType type = Get, const QString &filename = QString()) -> QFuture<QUrl>;
|
auto download(const QNetworkRequest &request, const QString &id, RequestType type = Get, const QString &filename = QString()) -> QFuture<QUrl>;
|
||||||
auto readShaderToyEntry(const QUrl &uri) noexcept(false) -> ShaderToyEntry;
|
auto readShaderToyEntry(const QUrl &uri) noexcept(false) -> ShaderToyEntry;
|
||||||
|
auto validateUri(const QUrl &uri) noexcept(false) -> void;
|
||||||
|
|
||||||
QString m_lastInstalledFile;
|
QString m_lastInstalledFile;
|
||||||
|
|
||||||
|
|||||||
+378
-253
@@ -60,15 +60,6 @@ auto PackCompiler::process(const QUrl &uri) -> QFuture<QUrl>
|
|||||||
setStatus(QStringLiteral("Compiling %1").arg(uri.fileName()));
|
setStatus(QStringLiteral("Compiling %1").arg(uri.fileName()));
|
||||||
setState(Compiling);
|
setState(Compiling);
|
||||||
|
|
||||||
// this was a leftover from ThumbnailGenerator
|
|
||||||
// if(!validateDirectory(uri))
|
|
||||||
// {
|
|
||||||
// throw FileException
|
|
||||||
// (
|
|
||||||
// QStringLiteral("Source directory is invalid")
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
QFileInfo info(uri.toLocalFile());
|
QFileInfo info(uri.toLocalFile());
|
||||||
|
|
||||||
QUrl buildUri;
|
QUrl buildUri;
|
||||||
@@ -79,21 +70,29 @@ auto PackCompiler::process(const QUrl &uri) -> QFuture<QUrl>
|
|||||||
prepareShaders(buildUri);
|
prepareShaders(buildUri);
|
||||||
compile(buildUri);
|
compile(buildUri);
|
||||||
}
|
}
|
||||||
catch (FileException e)
|
catch (const std::filesystem::filesystem_error &e)
|
||||||
{
|
{
|
||||||
removeDirectory(buildUri);
|
removeDirectory(buildUri);
|
||||||
setError(QStringLiteral("File Error"), e.message);
|
setError(QStringLiteral("File Error"), e.what());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch (ShaderCompilerException e)
|
catch (const std::logic_error &e)
|
||||||
{
|
{
|
||||||
removeDirectory(buildUri);
|
removeDirectory(buildUri);
|
||||||
setError(QStringLiteral("Compiler Error"), e.message);
|
setError(QStringLiteral("Compiler Error"), e.what());
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
removeDirectory(buildUri);
|
||||||
|
setError(QStringLiteral("Generic Error"), e.what());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
removeDirectory(buildUri);
|
removeDirectory(buildUri);
|
||||||
|
setError(QStringLiteral("Unknown Error"), QString());
|
||||||
|
throw std::exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildUri;
|
return buildUri;
|
||||||
@@ -105,11 +104,16 @@ auto PackCompiler::prepareShaders(const QUrl &uri) noexcept(false) -> void
|
|||||||
{
|
{
|
||||||
if(!uri.isLocalFile())
|
if(!uri.isLocalFile())
|
||||||
{
|
{
|
||||||
throw FileException
|
throw std::filesystem::filesystem_error
|
||||||
(
|
(
|
||||||
QStringLiteral("URI %1 is not a local file uri").arg
|
QStringLiteral("URI %1 is not a local file uri").arg
|
||||||
(
|
(
|
||||||
uri.toString()
|
uri.toString()
|
||||||
|
).toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
ENOENT,
|
||||||
|
std::system_category()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -172,11 +176,16 @@ auto PackCompiler::prepareShaders(const QUrl &uri) noexcept(false) -> void
|
|||||||
|
|
||||||
if(!file.open(QFile::ReadWrite))
|
if(!file.open(QFile::ReadWrite))
|
||||||
{
|
{
|
||||||
throw FileException
|
throw std::filesystem::filesystem_error
|
||||||
(
|
(
|
||||||
QStringLiteral("Could not open file %1 for preperation").arg
|
QStringLiteral("Could not open file %1 for preperation").arg
|
||||||
(
|
(
|
||||||
shaderDirectory.absoluteFilePath(entry)
|
shaderDirectory.absoluteFilePath(entry)
|
||||||
|
).toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -185,11 +194,16 @@ auto PackCompiler::prepareShaders(const QUrl &uri) noexcept(false) -> void
|
|||||||
|
|
||||||
if(fileData.length() != file.size())
|
if(fileData.length() != file.size())
|
||||||
{
|
{
|
||||||
throw FileException
|
throw std::filesystem::filesystem_error
|
||||||
(
|
(
|
||||||
QStringLiteral("Could not read file %1 for preperation").arg
|
QStringLiteral("Could not read file %1 for preperation").arg
|
||||||
(
|
(
|
||||||
shaderDirectory.absoluteFilePath(entry)
|
shaderDirectory.absoluteFilePath(entry)
|
||||||
|
).toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
EIO,
|
||||||
|
std::system_category()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -208,12 +222,12 @@ auto PackCompiler::prepareShaders(const QUrl &uri) noexcept(false) -> void
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw FileException
|
throw std::logic_error
|
||||||
(
|
(
|
||||||
QStringLiteral("File %1 is an unrecognized shader type (frag/vert)").arg
|
QStringLiteral("File %1 is an unrecognized shader type (frag/vert)").arg
|
||||||
(
|
(
|
||||||
shaderDirectory.absoluteFilePath(entry)
|
shaderDirectory.absoluteFilePath(entry)
|
||||||
)
|
).toStdString()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,22 +258,32 @@ auto PackCompiler::prepareShaders(const QUrl &uri) noexcept(false) -> void
|
|||||||
|
|
||||||
if(!file.open(QFile::ReadWrite | QFile::Truncate))
|
if(!file.open(QFile::ReadWrite | QFile::Truncate))
|
||||||
{
|
{
|
||||||
throw FileException
|
throw std::filesystem::filesystem_error
|
||||||
(
|
(
|
||||||
QStringLiteral("Could not open file %1 for writing preperation").arg
|
QStringLiteral("Could not open file %1 for writing preperation").arg
|
||||||
(
|
(
|
||||||
shaderDirectory.absoluteFilePath(entry)
|
shaderDirectory.absoluteFilePath(entry)
|
||||||
|
).toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(file.write(preparedData) != preparedData.length())
|
if(file.write(preparedData) != preparedData.length())
|
||||||
{
|
{
|
||||||
throw FileException
|
throw std::filesystem::filesystem_error
|
||||||
(
|
(
|
||||||
QStringLiteral("Could not write file %1 preperation").arg
|
QStringLiteral("Could not write file %1 preperation").arg
|
||||||
(
|
(
|
||||||
shaderDirectory.absoluteFilePath(entry)
|
shaderDirectory.absoluteFilePath(entry)
|
||||||
|
).toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -271,16 +295,7 @@ auto PackCompiler::prepareShaders(const QUrl &uri) noexcept(false) -> void
|
|||||||
|
|
||||||
auto PackCompiler::loadCommonFragmentData(const QUrl &uri) -> QByteArray
|
auto PackCompiler::loadCommonFragmentData(const QUrl &uri) -> QByteArray
|
||||||
{
|
{
|
||||||
if(!uri.isLocalFile())
|
localCheck(uri);
|
||||||
{
|
|
||||||
throw FileException
|
|
||||||
(
|
|
||||||
QStringLiteral("URI %1 is not a local file uri").arg
|
|
||||||
(
|
|
||||||
uri.toString()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir sourceDirectory
|
QDir sourceDirectory
|
||||||
(
|
(
|
||||||
@@ -308,14 +323,30 @@ auto PackCompiler::loadCommonFragmentData(const QUrl &uri) -> QByteArray
|
|||||||
|
|
||||||
if(!file.open(QFile::ReadWrite))
|
if(!file.open(QFile::ReadWrite))
|
||||||
{
|
{
|
||||||
throw FileException(QStringLiteral("Could not open common shader data"));
|
throw std::filesystem::filesystem_error
|
||||||
|
(
|
||||||
|
QStringLiteral("Could not open common shader data").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
data = file.readAll();
|
data = file.readAll();
|
||||||
|
|
||||||
if(data.length() != file.size())
|
if(data.length() != file.size())
|
||||||
{
|
{
|
||||||
throw FileException(QStringLiteral("Common fragment shader file read error"));
|
throw std::filesystem::filesystem_error
|
||||||
|
(
|
||||||
|
QStringLiteral("Common file read error").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
@@ -327,16 +358,7 @@ auto PackCompiler::loadCommonFragmentData(const QUrl &uri) -> QByteArray
|
|||||||
|
|
||||||
auto PackCompiler::loadCommonVertexData(const QUrl &uri) -> QByteArray
|
auto PackCompiler::loadCommonVertexData(const QUrl &uri) -> QByteArray
|
||||||
{
|
{
|
||||||
if(!uri.isLocalFile())
|
localCheck(uri);
|
||||||
{
|
|
||||||
throw FileException
|
|
||||||
(
|
|
||||||
QStringLiteral("URI %1 is not a local file uri").arg
|
|
||||||
(
|
|
||||||
uri.toString()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir sourceDirectory
|
QDir sourceDirectory
|
||||||
(
|
(
|
||||||
@@ -364,14 +386,30 @@ auto PackCompiler::loadCommonVertexData(const QUrl &uri) -> QByteArray
|
|||||||
|
|
||||||
if(!file.open(QFile::ReadWrite))
|
if(!file.open(QFile::ReadWrite))
|
||||||
{
|
{
|
||||||
throw FileException(QStringLiteral("Could not open common vertex shader data"));
|
throw std::filesystem::filesystem_error
|
||||||
|
(
|
||||||
|
QStringLiteral("Common vertex file open error").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
data = file.readAll();
|
data = file.readAll();
|
||||||
|
|
||||||
if(data.length() != file.size())
|
if(data.length() != file.size())
|
||||||
{
|
{
|
||||||
throw FileException(QStringLiteral("Common vertex shader file read error"));
|
throw std::filesystem::filesystem_error
|
||||||
|
(
|
||||||
|
QStringLiteral("Common vertex file read error").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
EIO,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
@@ -383,16 +421,7 @@ auto PackCompiler::loadCommonVertexData(const QUrl &uri) -> QByteArray
|
|||||||
|
|
||||||
auto PackCompiler::loadGlobalData(const QUrl &uri) -> QByteArray
|
auto PackCompiler::loadGlobalData(const QUrl &uri) -> QByteArray
|
||||||
{
|
{
|
||||||
if(!uri.isLocalFile())
|
localCheck(uri);
|
||||||
{
|
|
||||||
throw FileException
|
|
||||||
(
|
|
||||||
QStringLiteral("URI %1 is not a local file uri").arg
|
|
||||||
(
|
|
||||||
uri.toString()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir sourceDirectory
|
QDir sourceDirectory
|
||||||
(
|
(
|
||||||
@@ -420,9 +449,14 @@ auto PackCompiler::loadGlobalData(const QUrl &uri) -> QByteArray
|
|||||||
|
|
||||||
if(!file.open(QFile::ReadWrite))
|
if(!file.open(QFile::ReadWrite))
|
||||||
{
|
{
|
||||||
throw FileException
|
throw std::filesystem::filesystem_error
|
||||||
(
|
(
|
||||||
QStringLiteral("Could not open global shader data")
|
QStringLiteral("Common global file open error").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,9 +464,9 @@ auto PackCompiler::loadGlobalData(const QUrl &uri) -> QByteArray
|
|||||||
|
|
||||||
if(data.length() != file.size())
|
if(data.length() != file.size())
|
||||||
{
|
{
|
||||||
throw FileException
|
throw std::underflow_error
|
||||||
(
|
(
|
||||||
QStringLiteral("Global shader file read error")
|
QStringLiteral("Common vertex file read error").toStdString()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,10 +490,7 @@ auto PackCompiler::validateDirectory(const QUrl &uri) -> bool
|
|||||||
|
|
||||||
auto PackCompiler::createDirectory(const QUrl &uri) -> void
|
auto PackCompiler::createDirectory(const QUrl &uri) -> void
|
||||||
{
|
{
|
||||||
if(!uri.isLocalFile() || !uri.isValid())
|
localCheck(uri);
|
||||||
{
|
|
||||||
throw FileException(QStringLiteral("Uri needs to be a local file"), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList arguments =
|
QStringList arguments =
|
||||||
{
|
{
|
||||||
@@ -467,68 +498,103 @@ auto PackCompiler::createDirectory(const QUrl &uri) -> void
|
|||||||
uri.toLocalFile()
|
uri.toLocalFile()
|
||||||
};
|
};
|
||||||
|
|
||||||
QProcess *process = new QProcess(this);
|
QProcess process;
|
||||||
|
|
||||||
QObject::connect
|
// QObject::connect
|
||||||
(
|
// (
|
||||||
process,
|
// &process,
|
||||||
&QProcess::readyReadStandardOutput,
|
// &QProcess::readyReadStandardOutput,
|
||||||
this,
|
// this,
|
||||||
[this, process]()
|
// [this, &process]()
|
||||||
{
|
// {
|
||||||
QByteArray processData = process->readAllStandardOutput();
|
// QByteArray processData = process.readAllStandardOutput();
|
||||||
setCompilerOutput(m_compilerOutput + processData);
|
// setCompilerOutput(m_compilerOutput + processData);
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
QObject::connect
|
// QObject::connect
|
||||||
(
|
// (
|
||||||
process,
|
// &process,
|
||||||
&QProcess::readyReadStandardError,
|
// &QProcess::readyReadStandardError,
|
||||||
this,
|
// this,
|
||||||
[this, process]()
|
// [this, &process]()
|
||||||
{
|
// {
|
||||||
QByteArray processData = process->readAllStandardError();
|
// QByteArray processData = process.readAllStandardError();
|
||||||
|
|
||||||
if(!processData.isValidUtf8())
|
// if(!processData.isValidUtf8())
|
||||||
{
|
// {
|
||||||
qWarning() << QStringLiteral("Process output not valid UTF8 data");
|
// qWarning() << QStringLiteral("Process output not valid UTF8 data");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
setCompilerOutput(m_compilerOutput + processData);
|
// setCompilerOutput(m_compilerOutput + processData);
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
process->start(QStringLiteral("mkdir"), arguments);
|
process.start(QStringLiteral("mkdir"), arguments);
|
||||||
|
|
||||||
if(!process->waitForStarted(3000))
|
if(!process.waitForStarted(3000))
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::filesystem::filesystem_error
|
||||||
throw FileException(QStringLiteral("Could not start preprocessor"));
|
(
|
||||||
|
QStringLiteral("Could not start process for create directory").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!process->waitForFinished())
|
if(!process.waitForFinished())
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::filesystem::filesystem_error
|
||||||
throw FileException(QStringLiteral("Preprocessor timeout"));
|
(
|
||||||
|
QStringLiteral("Process timeout for create directory").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(process->exitCode() != 0)
|
if(process.exitCode() != 0)
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::ios_base::failure
|
||||||
throw ShaderCompilerException(m_compilerOutput);
|
(
|
||||||
|
QStringLiteral("Process exited abnormally").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
process.exitCode(),
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
process->deleteLater();
|
auto PackCompiler::localCheck(const QUrl &uri) noexcept(false) -> void
|
||||||
|
{
|
||||||
|
if(!uri.isValid() || !uri.isLocalFile())
|
||||||
|
{
|
||||||
|
throw std::filesystem::filesystem_error
|
||||||
|
(
|
||||||
|
QStringLiteral("URI %1 is not a local file uri").arg
|
||||||
|
(
|
||||||
|
uri.toString()
|
||||||
|
).toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
ENOENT,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto PackCompiler::extract(const QUrl &sourceUri) noexcept(false) -> QUrl
|
auto PackCompiler::extract(const QUrl &sourceUri) noexcept(false) -> QUrl
|
||||||
{
|
{
|
||||||
if(!sourceUri.isLocalFile() || !sourceUri.isValid())
|
localCheck(sourceUri);
|
||||||
{
|
|
||||||
throw FileException(QStringLiteral("Uri needs to be a local file"), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
QFileInfo info(sourceUri.toLocalFile());
|
QFileInfo info(sourceUri.toLocalFile());
|
||||||
|
|
||||||
@@ -555,61 +621,83 @@ auto PackCompiler::extract(const QUrl &sourceUri) noexcept(false) -> QUrl
|
|||||||
createDirectory(outputUri);
|
createDirectory(outputUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
QProcess *process = new QProcess(this);
|
QProcess process;
|
||||||
|
|
||||||
QObject::connect
|
// QObject::connect
|
||||||
(
|
// (
|
||||||
process,
|
// &process,
|
||||||
&QProcess::readyReadStandardOutput,
|
// &QProcess::readyReadStandardOutput,
|
||||||
this,
|
// this,
|
||||||
[this, process]()
|
// [this, &process]()
|
||||||
{
|
// {
|
||||||
QByteArray processData = process->readAllStandardOutput();
|
// QByteArray processData = process.readAllStandardOutput();
|
||||||
setCompilerOutput(m_compilerOutput + processData);
|
// setCompilerOutput(m_compilerOutput + processData);
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
QObject::connect
|
// QObject::connect
|
||||||
(
|
// (
|
||||||
process,
|
// &process,
|
||||||
&QProcess::readyReadStandardError,
|
// &QProcess::readyReadStandardError,
|
||||||
this,
|
// this,
|
||||||
[this, process]()
|
// [this, &process]()
|
||||||
{
|
// {
|
||||||
QByteArray processData = process->readAllStandardError();
|
// QByteArray processData = process.readAllStandardError();
|
||||||
|
|
||||||
if(!processData.isValidUtf8())
|
// if(!processData.isValidUtf8())
|
||||||
{
|
// {
|
||||||
qWarning() << QStringLiteral("Process output not valid UTF8 data");
|
// qWarning() << QStringLiteral("Process output not valid UTF8 data");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
setCompilerOutput(m_compilerOutput + processData);
|
// setCompilerOutput(m_compilerOutput + processData);
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
process->start(QStringLiteral("tar"), arguments);
|
process.start(QStringLiteral("tar"), arguments);
|
||||||
|
|
||||||
if(!process->waitForStarted(3000))
|
if(!process.waitForStarted(3000))
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::filesystem::filesystem_error
|
||||||
throw FileException(QStringLiteral("Could not start preprocessor"));
|
(
|
||||||
|
QStringLiteral("Could not start process for extract").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!process->waitForFinished())
|
if(!process.waitForFinished())
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::filesystem::filesystem_error
|
||||||
throw FileException(QStringLiteral("Preprocessor timeout"));
|
(
|
||||||
|
QStringLiteral("Process timeout for extract").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(process->exitCode() != 0)
|
if(process.exitCode() != 0)
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::ios_base::failure
|
||||||
throw ShaderCompilerException(m_compilerOutput);
|
(
|
||||||
|
QStringLiteral("Extract process exited abnormally: %1").arg
|
||||||
|
(
|
||||||
|
process.readAllStandardError()
|
||||||
|
).toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
process.exitCode(),
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
process->deleteLater();
|
|
||||||
|
|
||||||
QFile::remove(sourceUri.toLocalFile());
|
QFile::remove(sourceUri.toLocalFile());
|
||||||
|
|
||||||
return outputUri;
|
return outputUri;
|
||||||
@@ -630,10 +718,7 @@ auto PackCompiler::copyFile(const QUrl &sourceUri, const QUrl &destinationUri) n
|
|||||||
|
|
||||||
auto PackCompiler::compile(const QUrl &uri) noexcept(false) -> void
|
auto PackCompiler::compile(const QUrl &uri) noexcept(false) -> void
|
||||||
{
|
{
|
||||||
if(!uri.isLocalFile() || !uri.isValid())
|
localCheck(uri);
|
||||||
{
|
|
||||||
throw FileException(QStringLiteral("Uri needs to be a local file"), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
setState(Compiling);
|
setState(Compiling);
|
||||||
|
|
||||||
@@ -704,77 +789,101 @@ auto PackCompiler::preprocess(const QUrl &uri) noexcept(false) -> void
|
|||||||
outputUri.toLocalFile()
|
outputUri.toLocalFile()
|
||||||
};
|
};
|
||||||
|
|
||||||
QProcess *process = new QProcess(this);
|
QProcess process;
|
||||||
|
|
||||||
QObject::connect
|
// QObject::connect
|
||||||
(
|
// (
|
||||||
process,
|
// &process,
|
||||||
&QProcess::readyReadStandardOutput,
|
// &QProcess::readyReadStandardOutput,
|
||||||
this,
|
// this,
|
||||||
[this, process]()
|
// [this, &process]()
|
||||||
{
|
// {
|
||||||
QByteArray processData = process->readAllStandardOutput();
|
// QByteArray processData = process.readAllStandardOutput();
|
||||||
setCompilerOutput(m_compilerOutput + processData);
|
// setCompilerOutput(m_compilerOutput + processData);
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
QObject::connect
|
// QObject::connect
|
||||||
(
|
// (
|
||||||
process,
|
// &process,
|
||||||
&QProcess::readyReadStandardError,
|
// &QProcess::readyReadStandardError,
|
||||||
this,
|
// this,
|
||||||
[this, process]()
|
// [this, &process]()
|
||||||
{
|
// {
|
||||||
QByteArray processData = process->readAllStandardError();
|
// QByteArray processData = process.readAllStandardError();
|
||||||
|
|
||||||
if(!processData.isValidUtf8())
|
// if(!processData.isValidUtf8())
|
||||||
{
|
// {
|
||||||
qWarning() << QStringLiteral("Process output not valid UTF8 data");
|
// qWarning() << QStringLiteral("Process output not valid UTF8 data");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
setCompilerOutput(m_compilerOutput + processData);
|
// setCompilerOutput(m_compilerOutput + processData);
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
process->start(QStringLiteral("cpp"), arguments);
|
process.start(QStringLiteral("cpp"), arguments);
|
||||||
|
|
||||||
if(!process->waitForStarted(3000))
|
if(!process.waitForStarted(3000))
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::filesystem::filesystem_error
|
||||||
throw FileException(QStringLiteral("Could not start preprocessor"));
|
(
|
||||||
|
QStringLiteral("Could not start preprocessor").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!process->waitForFinished())
|
if(!process.waitForFinished())
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::filesystem::filesystem_error
|
||||||
throw FileException(QStringLiteral("Preprocessor timeout"));
|
(
|
||||||
|
QStringLiteral("Process timeout for preprocessor").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(process->exitCode() != 0)
|
if(process.exitCode() != 0)
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::ios_base::failure
|
||||||
throw ShaderCompilerException(m_compilerOutput);
|
(
|
||||||
|
QStringLiteral("Preprocessor exited abnormally").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
process.exitCode(),
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
process->deleteLater();
|
|
||||||
|
|
||||||
QFile::remove(uri.toLocalFile());
|
QFile::remove(uri.toLocalFile());
|
||||||
QFile::rename(outputUri.toLocalFile(), uri.toLocalFile());
|
QFile::rename(outputUri.toLocalFile(), uri.toLocalFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto PackCompiler::appendVersion(const QUrl &uri) noexcept(false) -> void
|
auto PackCompiler::appendVersion(const QUrl &uri) noexcept(false) -> void
|
||||||
{
|
{
|
||||||
if(!uri.isValid() || !uri.isLocalFile())
|
localCheck(uri);
|
||||||
{
|
|
||||||
throw FileException(QStringLiteral("File is not a valid local file"));
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile file(uri.toLocalFile());
|
QFile file(uri.toLocalFile());
|
||||||
|
|
||||||
if(!file.open(QFile::ReadWrite))
|
if(!file.open(QFile::ReadWrite))
|
||||||
{
|
{
|
||||||
throw FileException(QStringLiteral("Could not open file for appending"));
|
throw std::filesystem::filesystem_error
|
||||||
|
(
|
||||||
|
QStringLiteral("Could not open file for appending").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray data = file.readAll();
|
QByteArray data = file.readAll();
|
||||||
@@ -790,13 +899,7 @@ auto PackCompiler::appendVersion(const QUrl &uri) noexcept(false) -> void
|
|||||||
|
|
||||||
auto PackCompiler::compileShader(const QUrl &uri) noexcept(false) -> void
|
auto PackCompiler::compileShader(const QUrl &uri) noexcept(false) -> void
|
||||||
{
|
{
|
||||||
if(!uri.isLocalFile())
|
localCheck(uri);
|
||||||
{
|
|
||||||
throw FileException
|
|
||||||
(
|
|
||||||
QStringLiteral("Uri needs to be a local file")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString qsb = QStringLiteral("/usr/lib/qt6/bin/qsb");
|
QString qsb = QStringLiteral("/usr/lib/qt6/bin/qsb");
|
||||||
|
|
||||||
@@ -822,66 +925,93 @@ auto PackCompiler::compileShader(const QUrl &uri) noexcept(false) -> void
|
|||||||
uri.toLocalFile()
|
uri.toLocalFile()
|
||||||
};
|
};
|
||||||
|
|
||||||
QProcess *process = new QProcess(this);
|
QProcess process;
|
||||||
QString path = uri.toDisplayString(QUrl::RemoveFilename | QUrl::RemoveScheme).remove(QStringLiteral("//"));
|
QString path = uri.toDisplayString(QUrl::RemoveFilename | QUrl::RemoveScheme).remove(QStringLiteral("//"));
|
||||||
process->setWorkingDirectory(path);
|
process.setWorkingDirectory(path);
|
||||||
|
|
||||||
QObject::connect
|
// QObject::connect
|
||||||
(
|
// (
|
||||||
process,
|
// &process,
|
||||||
&QProcess::readyReadStandardOutput,
|
// &QProcess::readyReadStandardOutput,
|
||||||
this,
|
// this,
|
||||||
[this, process]()
|
// [this, &process]()
|
||||||
{
|
// {
|
||||||
QByteArray processData = process->readAllStandardOutput();
|
// QByteArray processData = process.readAllStandardOutput();
|
||||||
setCompilerOutput(m_compilerOutput + processData);
|
// setCompilerOutput(m_compilerOutput + processData);
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
QObject::connect
|
// QObject::connect
|
||||||
(
|
// (
|
||||||
process,
|
// &process,
|
||||||
&QProcess::readyReadStandardError,
|
// &QProcess::readyReadStandardError,
|
||||||
this,
|
// this,
|
||||||
[this, process]()
|
// [this, &process]()
|
||||||
{
|
// {
|
||||||
QByteArray processData = process->readAllStandardError();
|
// QByteArray processData = process.readAllStandardError();
|
||||||
|
|
||||||
if(!processData.isValidUtf8())
|
// if(!processData.isValidUtf8())
|
||||||
{
|
// {
|
||||||
qWarning() << QStringLiteral("Process output not valid UTF8 data");
|
// qWarning() << QStringLiteral("Process output not valid UTF8 data");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
setCompilerOutput(m_compilerOutput + processData);
|
// setCompilerOutput(m_compilerOutput + processData);
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
process->start(qsb, arguments);
|
process.start(qsb, arguments);
|
||||||
|
|
||||||
if(!process->waitForStarted(3000))
|
if(!process.waitForStarted(3000))
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::filesystem::filesystem_error
|
||||||
throw FileException(QStringLiteral("Could not start shader compiler"));
|
(
|
||||||
|
QStringLiteral("Could not start preprocessor").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!process->waitForFinished())
|
if(!process.waitForFinished())
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::filesystem::filesystem_error
|
||||||
throw FileException(QStringLiteral("Shader compiler timeout"));
|
(
|
||||||
|
QStringLiteral("Process timeout for preprocessor").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(process->exitCode() != 0)
|
if(process.exitCode() != 0)
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
throw std::ios_base::failure
|
||||||
throw ShaderCompilerException(m_compilerOutput);
|
(
|
||||||
|
QStringLiteral("Preprocessor exited abnormally").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
process.exitCode(),
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
process->deleteLater();
|
|
||||||
|
|
||||||
if(!QFile::remove(uri.toLocalFile()))
|
if(!QFile::remove(uri.toLocalFile()))
|
||||||
{
|
{
|
||||||
throw FileException(QStringLiteral("Could not clean up"));
|
throw std::filesystem::filesystem_error
|
||||||
|
(
|
||||||
|
QStringLiteral("Could not cleanup").toStdString(),
|
||||||
|
std::error_code
|
||||||
|
(
|
||||||
|
errno,
|
||||||
|
std::system_category()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,29 +1023,24 @@ auto PackCompiler::removeDirectory(const QUrl &uri) -> bool
|
|||||||
uri.toLocalFile()
|
uri.toLocalFile()
|
||||||
};
|
};
|
||||||
|
|
||||||
QProcess *process = new QProcess(this);
|
QProcess process;
|
||||||
|
process.start(QStringLiteral("rm"), arguments);
|
||||||
|
|
||||||
process->start(QStringLiteral("rm"), arguments);
|
if(!process.waitForStarted(3000))
|
||||||
|
|
||||||
if(!process->waitForStarted(3000))
|
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!process->waitForFinished())
|
if(!process.waitForFinished())
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(process->exitCode() != 0)
|
if(process.exitCode() != 0)
|
||||||
{
|
{
|
||||||
process->deleteLater();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
process->deleteLater();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ protected:
|
|||||||
|
|
||||||
auto createDirectory(const QUrl &uri) -> void;
|
auto createDirectory(const QUrl &uri) -> void;
|
||||||
|
|
||||||
|
auto localCheck(const QUrl &uri) noexcept(false) -> void;
|
||||||
auto extract(const QUrl &sourceUri) noexcept(false) -> QUrl;
|
auto extract(const QUrl &sourceUri) noexcept(false) -> QUrl;
|
||||||
auto copyFile(const QUrl &sourceUri, const QUrl &destinationUri) noexcept(false) -> void;
|
auto copyFile(const QUrl &sourceUri, const QUrl &destinationUri) noexcept(false) -> void;
|
||||||
auto compile(const QUrl &uri) noexcept(false) -> void;
|
auto compile(const QUrl &uri) noexcept(false) -> void;
|
||||||
|
|||||||
Reference in New Issue
Block a user