diff --git a/androidprojectmodifier.cpp b/androidprojectmodifier.cpp index 6e85e6b..f87be63 100644 --- a/androidprojectmodifier.cpp +++ b/androidprojectmodifier.cpp @@ -72,7 +72,7 @@ QString AndroidProjectModifier::getFileContent(const QString filepath) { QFile file(m_directory.absolutePath() + filepath); if(!file.exists() || !file.open(QIODevice::ReadOnly | QIODevice::Text)) { - throw QString("The file does not exist or could not be opened for reading"); + throw QString("The file '" + file.fileName() + "' does not exist or could not be opened for reading"); } QTextStream stream(&file); @@ -88,7 +88,7 @@ void AndroidProjectModifier::updateFileContent(const QString filepath, const QSt { QFile file(m_directory.absolutePath() + filepath); if(!file.exists() || !file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) { - throw QString("The file does not exist or could not be opened for writing"); + throw QString("The file '" + file.fileName() + "' does not exist or could not be opened for writing"); } QTextStream stream(&file); diff --git a/githelper.cpp b/githelper.cpp index 9683ca8..20de7b0 100644 --- a/githelper.cpp +++ b/githelper.cpp @@ -19,7 +19,7 @@ void GitHelper::clone(QDir directory) { directory = QDir(directory); if (directory.exists()) { - throw QString("The directory already exists"); + throw QString("The directory '" + directory.absolutePath() + "' already exists"); } git_repository *repository = nullptr; @@ -34,8 +34,8 @@ void GitHelper::checkout(QString directory) void GitHelper::checkout(QDir directory) { - if(!directory.exists()) { - throw QString("The directory does not exist"); + if (!directory.exists()) { + throw QString("The directory '" + directory.path() + "' does not exist"); } git_checkout_options options = GIT_CHECKOUT_OPTIONS_INIT; @@ -64,7 +64,7 @@ void GitHelper::reinitGitDirectory(QString directory) void GitHelper::reinitGitDirectory(QDir directory) { if(!directory.exists()) { - throw QString("The directory does not exist"); + throw QString("The directory '" + directory.path() + "' does not exist"); } QDir gitDir = directory.filePath(".git"); @@ -86,7 +86,7 @@ void GitHelper::initialCommit(QString directory) void GitHelper::initialCommit(QDir directory) { if(!directory.exists()) { - throw QString("The directory does not exist"); + throw QString("The directory '" + directory.path() + "' does not exist"); } git_index *index = nullptr; @@ -134,6 +134,6 @@ void GitHelper::gitError(int status) { if(status < 0) { const git_error *e = giterr_last(); - throw QString::fromUtf8(e->message); + throw "[Git Error]: " + QString::fromUtf8(e->message); } } diff --git a/inputoutput.cpp b/inputoutput.cpp index a304476..fcfcbf5 100644 --- a/inputoutput.cpp +++ b/inputoutput.cpp @@ -14,18 +14,3 @@ void InputOutput::writeln(QString text) { write(text + "\n"); } - -/*QString InputOutput::readStdin() -{ - std::string result; - std::cin >> result; - - return QString::fromStdString(result); -} - -QString InputOutput::ask(QString question) -{ - write(question + ": "); - return readStdin(); -} -*/ diff --git a/main.cpp b/main.cpp index 6d8757a..c4256a8 100644 --- a/main.cpp +++ b/main.cpp @@ -41,9 +41,9 @@ int main(int argc, char *argv[]) WebsiteParser parser(url, manifestPath); - auto icons = parser.getImages(); auto basicData = parser.getData(); basicData.insert("package", packageName); + auto icons = parser.getImages(); AndroidProjectModifier androidProject(outputDirectory); androidProject.addSupportLibrary(); diff --git a/pwa-to-twa.pro b/pwa-to-twa.pro index d9a4bae..7734544 100644 --- a/pwa-to-twa.pro +++ b/pwa-to-twa.pro @@ -5,7 +5,7 @@ CONFIG += c++14 console CONFIG -= app_bundle INCLUDEPATH += libgit/include -LIBS += -lgit2 -lssl -lcrypto +LIBS += -lgit2 -lssl -lcrypto -L"$$_PRO_FILE_PWD_/libgit/build" exists(pwa-to-twa.local.pro) { include(pwa-to-twa.local.pro) diff --git a/websiteparser.cpp b/websiteparser.cpp index bcaef1a..cb9fec9 100644 --- a/websiteparser.cpp +++ b/websiteparser.cpp @@ -38,7 +38,7 @@ const QString WebsiteParser::getManifestUrl() if(!m_manifestPath.isNull() && !m_manifestPath.isEmpty()) { manifestUrl = m_manifestPath; } else { - QRegularExpression regex("("); + QRegularExpression regex("(]*?rel=['\"]manifest['\"]).*?>"); auto matches = regex.match(getWebsiteContent()); if(!matches.hasMatch()) { throw QString("Could not detect the manifest automatically, try using --manifest option"); @@ -89,6 +89,28 @@ const QHash WebsiteParser::getData() auto json = getManifestContent().object(); + QStringList missingKeys; + + if (!json.contains("short_name")) { + missingKeys << "short_name"; + } + + if (!json.contains("theme_color")) { + missingKeys << "theme_color"; + } + + if (!json.contains("background_color")) { + missingKeys << "background_color"; + } + + if (!json.contains("start_url")) { + missingKeys << "start_url"; + } + + if(!missingKeys.empty()) { + throw QString("The manifest at url '" + getManifestUrl() + "' is missing these keys: " + missingKeys.join(", ")); + } + result.insert("hostname", m_url.host()); result.insert("short_name", json.take("short_name").toString()); result.insert("theme_color", json.take("theme_color").toString()); @@ -104,21 +126,26 @@ const QList> WebsiteParser::getImages() auto json = getManifestContent().object().take("icons").toArray(); + if (json.empty()) { + throw QString("The manifest at url '" + getManifestUrl() + "' does not contain any icons"); + } + QJsonArray::const_iterator iterator; for(iterator = json.constBegin(); iterator != json.constEnd(); ++iterator) { auto icon = (*iterator).toObject(); auto sizes = icon.take("sizes").toString().split("x"); + auto url = icon.take("src").toString(); if(sizes.length() != 2 || sizes.at(0) != sizes.at(1)) { - qWarning() << "[Warning] The icon does not have a valid size attribute, ignoring"; + qWarning() << "[Warning] The icon with url '" + url + "' does not have a valid size attribute, ignoring"; continue; } QHash iconHash; iconHash.insert("size", sizes.at(0)); - iconHash.insert("url", getUrl(icon.take("src").toString())); + iconHash.insert("url", getUrl(url)); result.append(iconHash); }