Installer

This commit is contained in:
Jakub Melka 2021-04-25 18:33:41 +02:00
parent 55b6c0ee11
commit a4ea87f061
10 changed files with 186 additions and 39 deletions

View File

@ -24,6 +24,7 @@ namespace pdf
// Name of the library, together with version
static constexpr const char* PDF_LIBRARY_NAME = "Pdf4Qt 1.0.0";
static constexpr const char* PDF_LIBRARY_VERSION = "1.0.0";
// Structure file constants
static constexpr const char* PDF_END_OF_FILE_MARK = "%%EOF";

View File

@ -96,3 +96,4 @@ INSTALLS += plugins
RESOURCES += \
pdf4qtviewer.qrc
DEFINES += QT_INSTALL_DIRECTORY=\"\\\"$$[QT_INSTALL_BINS]\\\"\"

View File

@ -57,5 +57,6 @@
<file>resources/squiggly.svg</file>
<file>resources/strikeout.svg</file>
<file>resources/underline.svg</file>
<file>../LICENSE.txt</file>
</qresource>
</RCC>

View File

@ -23,6 +23,7 @@
#include "pdfadvancedtools.h"
#include "pdfdrawspacecontroller.h"
#include "pdfwidgetutils.h"
#include "pdfconstants.h"
#include "pdfviewersettings.h"
#include "pdfundoredomanager.h"
@ -47,6 +48,7 @@
#include <QDesktopWidget>
#include <QMainWindow>
#include <QToolBar>
#include <QXmlStreamWriter>
#ifdef Q_OS_WIN
#pragma comment(lib, "Shell32")
@ -493,6 +495,10 @@ void PDFProgramController::initialize(Features features,
{
connect(action, &QAction::triggered, this, &PDFProgramController::onActionCloseTriggered);
}
if (QAction* action = m_actionManager->getAction(PDFActionManager::DeveloperCreateInstaller))
{
connect(action, &QAction::triggered, this, &PDFProgramController::onActionDeveloperCreateInstaller);
}
if (m_recentFileManager)
{
@ -1829,6 +1835,132 @@ void PDFProgramController::onActionCloseTriggered()
closeDocument();
}
void PDFProgramController::onActionDeveloperCreateInstaller()
{
QString directory = QFileDialog::getExistingDirectory(m_mainWindow, tr("Select Directory for Installer"));
if (directory.isEmpty())
{
return;
}
// Config.xml
{
QDir().mkpath(directory + "/config");
QFile configFile(directory + "/config/config.xml");
if (configFile.open(QFile::WriteOnly | QFile::Truncate))
{
QXmlStreamWriter configWriter(&configFile);
configWriter.setAutoFormatting(true);
configWriter.setAutoFormattingIndent(2);
configWriter.writeStartDocument();
configWriter.writeStartElement("Installer");
configWriter.writeTextElement("Name", tr("PDF4QT"));
configWriter.writeTextElement("Title", tr("PDF4QT Suite (library, viewer, editor, command line tool)"));
configWriter.writeTextElement("Version", pdf::PDF_LIBRARY_VERSION);
configWriter.writeTextElement("Publisher", tr("Jakub Melka"));
configWriter.writeTextElement("StartMenuDir", "PDF4QT");
configWriter.writeTextElement("TargetDir", "@ApplicationsDir@/PDF4QT");
configWriter.writeTextElement("CreateLocalRepository", "true");
configWriter.writeTextElement("InstallActionColumnVisible", "true");
configWriter.writeEndElement();
configWriter.writeEndDocument();
configFile.close();
}
}
// Installer project file
{
QString qtInstallDirectory = QT_INSTALL_DIRECTORY;
int indexofQtRoot = qtInstallDirectory.lastIndexOf("/Qt/");
QString binaryCreatorDirectory;
if (indexofQtRoot != -1)
{
indexofQtRoot += 4;
QString qtRootDirectory = qtInstallDirectory.left(indexofQtRoot);
QString qtInstallerFrameworkRoot = qtRootDirectory + "Tools/QtInstallerFramework/";
QDir qtInstallerFrameworkRootDir(qtInstallerFrameworkRoot);
QStringList entries = qtInstallerFrameworkRootDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
if (!entries.isEmpty())
{
binaryCreatorDirectory = QString("%1/%2/bin").arg(qtInstallerFrameworkRoot, entries.back());
binaryCreatorDirectory = QDir(binaryCreatorDirectory).absolutePath();
}
}
QFile configFile(directory + "/installer.pro");
if (configFile.open(QFile::WriteOnly | QFile::Truncate))
{
QTextStream stream(&configFile);
stream << "TEMPLATE = aux" << endl << endl;
stream << "INSTALLER_NAME = $$PWD/instpdf4qt" << endl;
stream << "INPUT = $$PWD/config/config.xml $$PWD/packages" << endl;
stream << "pdfforqtinstaller.input = INPUT" << endl;
stream << "pdfforqtinstaller.output = $$INSTALLER_NAME" << endl;
stream << QString("pdfforqtinstaller.commands = %1/binarycreator -c $$PWD/config/config.xml -p $$PWD/packages ${QMAKE_FILE_OUT}").arg(binaryCreatorDirectory) << endl;
stream << "pdfforqtinstaller.CONFIG += target_predeps no_link combine" << endl << endl;
stream << "QMAKE_EXTRA_COMPILERS += pdfforqtinstaller";
configFile.close();
}
}
// Packages
QDir().mkpath(directory + "/packages");
auto addComponentMeta = [&](QString componentName, QString displayName, QString description, QString version, QString internalName, bool forcedInstallation, bool defaultInstall, bool addDefaultLicense)
{
QString componentMetaDirectory = directory + QString("/packages/%1/meta").arg(componentName);
QDir().mkpath(componentMetaDirectory);
QString metaFileName = QString("%1/package.xml").arg(componentMetaDirectory);
QFile metaFile(metaFileName);
if (metaFile.open(QFile::WriteOnly | QFile::Truncate))
{
QXmlStreamWriter metaFileWriter(&metaFile);
metaFileWriter.setAutoFormatting(true);
metaFileWriter.setAutoFormattingIndent(2);
metaFileWriter.writeStartDocument();
metaFileWriter.writeStartElement("Package");
metaFileWriter.writeTextElement("DisplayName", displayName);
metaFileWriter.writeTextElement("Description", description);
metaFileWriter.writeTextElement("Version", version);
metaFileWriter.writeTextElement("ReleaseDate", QDateTime::currentDateTime().toString("yyyy-MM-dd"));
metaFileWriter.writeTextElement("Name", internalName);
metaFileWriter.writeTextElement("ExpandedByDefault", "true");
metaFileWriter.writeTextElement("ForcedInstallation", forcedInstallation ? "true" : "false");
metaFileWriter.writeTextElement("Default", defaultInstall ? "true" : "false");
if (addDefaultLicense)
{
QFile::copy(":/LICENSE.txt", QString("%1/LICENSE.txt").arg(componentMetaDirectory));
metaFileWriter.writeStartElement("Licenses");
metaFileWriter.writeStartElement("License");
metaFileWriter.writeAttribute("name", tr("License Agreement"));
metaFileWriter.writeAttribute("file", tr("LICENSE.txt"));
metaFileWriter.writeEndElement();
metaFileWriter.writeEndElement();
}
metaFileWriter.writeEndElement();
metaFileWriter.writeEndDocument();
metaFile.close();
}
};
// CoreLib package
addComponentMeta("pdf4qt_framework", tr("Framework (Core libraries)"), tr("Framework libraries and other data files required to run all other programs."), pdf::PDF_LIBRARY_VERSION, "pdf4qt_framework", true, true, true);
}
void PDFProgramController::onPageRenderingErrorsChanged(pdf::PDFInteger pageIndex, int errorsCount)
{
if (errorsCount > 0)

View File

@ -161,6 +161,7 @@ public:
ToolMagnifier,
ToolScreenshot,
ToolExtractImage,
DeveloperCreateInstaller,
LastAction
};
@ -329,6 +330,7 @@ private:
void onActionOptionsTriggered();
void onActionOpenTriggered();
void onActionCloseTriggered();
void onActionDeveloperCreateInstaller();
void onDrawSpaceChanged();
void onPageLayoutChanged();

View File

@ -175,6 +175,7 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
m_actionManager->setAction(PDFActionManager::ToolMagnifier, ui->actionMagnifier);
m_actionManager->setAction(PDFActionManager::ToolScreenshot, ui->actionScreenshot);
m_actionManager->setAction(PDFActionManager::ToolExtractImage, ui->actionExtractImage);
m_actionManager->setAction(PDFActionManager::DeveloperCreateInstaller, ui->actionDeveloperCreateInstaller);
m_actionManager->initActions(pdf::PDFWidgetUtils::scaleDPI(this, QSize(24, 24)), true);
for (QAction* action : m_programController->getRecentFileManager()->getActions())

View File

@ -116,6 +116,7 @@
</property>
<addaction name="actionShow_Text_Blocks"/>
<addaction name="actionShow_Text_Lines"/>
<addaction name="actionDeveloperCreateInstaller"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
@ -198,7 +199,7 @@
<widget class="QStatusBar" name="statusBar"/>
<action name="actionOpen">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/open.svg</normaloff>:/resources/open.svg</iconset>
</property>
<property name="text">
@ -212,7 +213,7 @@
</action>
<action name="actionQuit">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/quit.svg</normaloff>:/resources/quit.svg</iconset>
</property>
<property name="text">
@ -279,7 +280,7 @@
</action>
<action name="actionRendering_Errors">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/rendering-errors.svg</normaloff>:/resources/rendering-errors.svg</iconset>
</property>
<property name="text">
@ -323,7 +324,7 @@
</action>
<action name="actionOptions">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/settings.svg</normaloff>:/resources/settings.svg</iconset>
</property>
<property name="text">
@ -335,7 +336,7 @@
</action>
<action name="actionZoom_In">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/zoom-in.svg</normaloff>:/resources/zoom-in.svg</iconset>
</property>
<property name="text">
@ -344,7 +345,7 @@
</action>
<action name="actionZoom_Out">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/zoom-out.svg</normaloff>:/resources/zoom-out.svg</iconset>
</property>
<property name="text">
@ -358,7 +359,7 @@
</action>
<action name="actionFitPage">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/zoom-fit.svg</normaloff>:/resources/zoom-fit.svg</iconset>
</property>
<property name="text">
@ -367,7 +368,7 @@
</action>
<action name="actionFitWidth">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/zoom-fit-horizontal.svg</normaloff>:/resources/zoom-fit-horizontal.svg</iconset>
</property>
<property name="text">
@ -379,7 +380,7 @@
</action>
<action name="actionFitHeight">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/zoom-fit-vertical.svg</normaloff>:/resources/zoom-fit-vertical.svg</iconset>
</property>
<property name="text">
@ -391,7 +392,7 @@
</action>
<action name="actionProperties">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/info.svg</normaloff>:/resources/info.svg</iconset>
</property>
<property name="text">
@ -400,7 +401,7 @@
</action>
<action name="actionSend_by_E_Mail">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/send-mail.svg</normaloff>:/resources/send-mail.svg</iconset>
</property>
<property name="text">
@ -425,7 +426,7 @@
</action>
<action name="actionFind">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/find.svg</normaloff>:/resources/find.svg</iconset>
</property>
<property name="text">
@ -434,7 +435,7 @@
</action>
<action name="actionFindPrevious">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/find-previous.svg</normaloff>:/resources/find-previous.svg</iconset>
</property>
<property name="text">
@ -443,7 +444,7 @@
</action>
<action name="actionFindNext">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/find-next.svg</normaloff>:/resources/find-next.svg</iconset>
</property>
<property name="text">
@ -455,7 +456,7 @@
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/select-text.svg</normaloff>:/resources/select-text.svg</iconset>
</property>
<property name="text">
@ -487,7 +488,7 @@
</action>
<action name="actionRotateRight">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/rotate-right.svg</normaloff>:/resources/rotate-right.svg</iconset>
</property>
<property name="text">
@ -496,7 +497,7 @@
</action>
<action name="actionRotateLeft">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/rotate-left.svg</normaloff>:/resources/rotate-left.svg</iconset>
</property>
<property name="text">
@ -505,7 +506,7 @@
</action>
<action name="actionPrint">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/print.svg</normaloff>:/resources/print.svg</iconset>
</property>
<property name="text">
@ -522,7 +523,7 @@
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/magnifier.svg</normaloff>:/resources/magnifier.svg</iconset>
</property>
<property name="text">
@ -537,7 +538,7 @@
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/screenshot-tool.svg</normaloff>:/resources/screenshot-tool.svg</iconset>
</property>
<property name="text">
@ -549,7 +550,7 @@
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/extract-image.svg</normaloff>:/resources/extract-image.svg</iconset>
</property>
<property name="text">
@ -566,7 +567,7 @@
</action>
<action name="actionUndo">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/undo.svg</normaloff>:/resources/undo.svg</iconset>
</property>
<property name="text">
@ -575,7 +576,7 @@
</action>
<action name="actionRedo">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/redo.svg</normaloff>:/resources/redo.svg</iconset>
</property>
<property name="text">
@ -658,7 +659,7 @@
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/hyperlink.svg</normaloff>:/resources/hyperlink.svg</iconset>
</property>
<property name="text">
@ -718,7 +719,7 @@
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/highlight.svg</normaloff>:/resources/highlight.svg</iconset>
</property>
<property name="text">
@ -730,7 +731,7 @@
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/underline.svg</normaloff>:/resources/underline.svg</iconset>
</property>
<property name="text">
@ -742,7 +743,7 @@
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/strikeout.svg</normaloff>:/resources/strikeout.svg</iconset>
</property>
<property name="text">
@ -754,7 +755,7 @@
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/squiggly.svg</normaloff>:/resources/squiggly.svg</iconset>
</property>
<property name="text">
@ -763,7 +764,7 @@
</action>
<action name="actionGoToDocumentStart">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/previous-start.svg</normaloff>:/resources/previous-start.svg</iconset>
</property>
<property name="text">
@ -772,7 +773,7 @@
</action>
<action name="actionGoToDocumentEnd">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/next-end.svg</normaloff>:/resources/next-end.svg</iconset>
</property>
<property name="text">
@ -781,7 +782,7 @@
</action>
<action name="actionGoToNextPage">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/next-page.svg</normaloff>:/resources/next-page.svg</iconset>
</property>
<property name="text">
@ -790,7 +791,7 @@
</action>
<action name="actionGoToPreviousPage">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/previous-page.svg</normaloff>:/resources/previous-page.svg</iconset>
</property>
<property name="text">
@ -799,7 +800,7 @@
</action>
<action name="actionGoToNextLine">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/next.svg</normaloff>:/resources/next.svg</iconset>
</property>
<property name="text">
@ -808,17 +809,22 @@
</action>
<action name="actionGoToPreviousLine">
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<iconset resource="pdf4qtviewer.qrc">
<normaloff>:/resources/previous.svg</normaloff>:/resources/previous.svg</iconset>
</property>
<property name="text">
<string>Go to previous line</string>
</property>
</action>
<action name="actionDeveloperCreateInstaller">
<property name="text">
<string>Create Installer</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="pdfforqtviewer.qrc"/>
<include location="pdf4qtviewer.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -1,4 +1,5 @@
#include "pdfviewermainwindowlite.h"
#include "pdfconstants.h"
#include <QApplication>
#include <QCommandLineParser>
@ -12,7 +13,7 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationName("MelkaJ");
QCoreApplication::setApplicationName("PDF4QT Viewer Lite");
QCoreApplication::setApplicationVersion("1.0.0");
QCoreApplication::setApplicationVersion(pdf::PDF_LIBRARY_VERSION);
QApplication::setApplicationDisplayName(QApplication::translate("Application", "PDF4QT Viewer Lite"));
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::applicationName());

View File

@ -1,4 +1,5 @@
#include "pdfviewermainwindow.h"
#include "pdfconstants.h"
#include <QApplication>
#include <QCommandLineParser>
@ -12,7 +13,7 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationName("MelkaJ");
QCoreApplication::setApplicationName("PDF4QT Viewer Profi");
QCoreApplication::setApplicationVersion("1.0.0");
QCoreApplication::setApplicationVersion(pdf::PDF_LIBRARY_VERSION);
QApplication::setApplicationDisplayName(QApplication::translate("Application", "PDF4QT Viewer Profi"));
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::applicationName());

View File

@ -1,4 +1,4 @@
// Copyright (C) 2020 Jakub Melka
// Copyright (C) 2020-2021 Jakub Melka
//
// This file is part of Pdf4Qt.
//
@ -16,6 +16,7 @@
// along with Pdf4Qt. If not, see <https://www.gnu.org/licenses/>.
#include "pdftoolabstractapplication.h"
#include "pdfconstants.h"
#include <QGuiApplication>
#include <QCommandLineParser>
@ -26,7 +27,7 @@ int main(int argc, char *argv[])
QGuiApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity, true);
QCoreApplication::setOrganizationName("MelkaJ");
QCoreApplication::setApplicationName("PdfTool");
QCoreApplication::setApplicationVersion("1.0.0");
QCoreApplication::setApplicationVersion(pdf::PDF_LIBRARY_VERSION);
QStringList arguments = QCoreApplication::arguments();