Skip to content

Commit

Permalink
Сделал installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
zl0i committed Oct 30, 2019
1 parent 902a755 commit 09b0664
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 1 deletion.
2 changes: 2 additions & 0 deletions QtAutoTools.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
finstaller.cpp \
lupdate.cpp \
main.cpp \
qmldir.cpp \
Expand Down Expand Up @@ -41,6 +42,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

HEADERS += \
finstaller.h \
lupdate.h \
qmldir.h \
qmlplugindump.h \
Expand Down
2 changes: 1 addition & 1 deletion QtAutoTools.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.10.1, 2019-10-26T19:29:39. -->
<!-- Written by QtCreator 4.10.1, 2019-10-30T13:06:16. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
104 changes: 104 additions & 0 deletions finstaller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include "finstaller.h"

FInstaller::FInstaller(QObject *parent) : QObject(parent)
{
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotFinished()));
}

void FInstaller::setDeployPath(QString path) {
m_deploypath = path;
}

void FInstaller::setInstallerPath(QString path) {
m_installerpath = path;
}

void FInstaller::setVendorName(QString name) {
m_vendorName = name;
}

void FInstaller::createConfig() {
QDir configDir(m_installerpath + "/config");
if(!configDir.exists()) {
bool result = configDir.mkpath(m_installerpath + "/config");
if(!result)
return;
}
QFile config(m_installerpath + "/config/" +"config.xml");
if(config.open(QIODevice::ReadWrite)) {
const QString str = configText;
config.write(str.toLocal8Bit());
config.close();
}
}

void FInstaller::createPackages() {
QDir packagesDir(m_installerpath + "/packages/" + m_vendorName);
if(!packagesDir.exists()) {
bool result = packagesDir.mkpath(m_installerpath + "/packages/" + m_vendorName + "/data");
result = result & packagesDir.mkpath(m_installerpath + "/packages/" + m_vendorName + "/meta");
if(!result)
return;
}
QFile packages(m_installerpath + "/packages/" + m_vendorName + "/meta/package.xml");
if(packages.open(QIODevice::ReadWrite)) {
const QString str = packageText;
packages.write(str.toLocal8Bit());
packages.close();
}
}

QFile *FInstaller::prepareBatFile() {
QFile *file = new QFile("temp.bat");
if(file->open(QIODevice::ReadWrite)) {
QString str = "set PATH="+ Worker::getInstance()->compl1Path() + "/bin;" +Worker::getInstance()->compl2Path() + "/bin;%PATH%\n";
file->write(str.toLocal8Bit());
return file;
}
return nullptr;
}

void FInstaller::createOffInstaller() {
copyDir(m_deploypath, m_installerpath + "/packages/" + m_vendorName + "/data");

QStringList arguments;
arguments.append("-c " + m_installerpath + "/config/config.xml");
arguments.append("-p " + m_installerpath + "/packages");
arguments.append("-f");
arguments.append(m_installerpath + "/Installer.exe");


QFile *file = prepareBatFile();
QString str = Worker::getInstance()->qtPath() + "/Tools/QtInstallerFramework/3.1/bin/binarycreator " + arguments.join(" ");
file->write(str.toLocal8Bit());
file->close();
file->deleteLater();
process->start("temp.bat");
}

void FInstaller::slotFinished() {
QFile::remove("temp.bat");
emit finished();
}

void FInstaller::copyDir(QString out, QString in) {
QDir outDir(out);
if(!outDir.exists())
return;

QStringList dirList = outDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
for(int i = 0; i < dirList.length(); ++i) {
QString in_path = in + QDir::separator() + dirList[i];
outDir.mkpath(in_path);
copyDir(out+ QDir::separator() + dirList[i], in_path);
}

QStringList fileList = outDir.entryList(QDir::Files);
for(int i = 0; i < fileList.length(); ++i) {
QFile::copy(out + QDir::separator() + fileList.at(i), in + QDir::separator() + fileList.at(i));
}
}




73 changes: 73 additions & 0 deletions finstaller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef FINSTALLER_H
#define FINSTALLER_H

#include <QObject>
#include <QFile>
#include <QDir>
#include <QProcess>
#include <QStringList>
#include <QDebug>
#include "worker.h"

class FInstaller : public QObject
{
Q_OBJECT
public:
explicit FInstaller(QObject *parent = nullptr);

Q_INVOKABLE void setDeployPath(QString);
Q_INVOKABLE void setInstallerPath(QString);
Q_INVOKABLE void setVendorName(QString);
Q_INVOKABLE void createConfig();
Q_INVOKABLE void createPackages();

Q_INVOKABLE void createOffInstaller();


private:

QString m_deploypath;
QString m_installerpath;
QString m_vendorName = "com.vendor.example";

QProcess *process = new QProcess();


void copyDir(QString out, QString in);
QFile *prepareBatFile();

QString configText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<Installer>\n"
" <Name>Installer</Name>\n"
" <Version>1.0.0</Version>\n"
" <Title>1.0.0 Installer</Title>\n"
" <Publisher>Installer</Publisher>\n"
" <StartMenuDir>Installer</StartMenuDir>\n"
" <TargetDir>@RootDir@Program Files (x86)\Installer</TargetDir>\n"
" <AllowSpaceInPath>true</AllowSpaceInPath>\n"
"</Installer>\n";

QString packageText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<Package>\n"
" <DisplayName>Installer</DisplayName>\n"
" <Description>The main component</Description>\n"
" <Version>1.0.0</Version>\n"
" <ReleaseDate>2019-01-30</ReleaseDate>\n"
" <Default>true</Default>\n"
" <Name>" + m_vendorName + "</Name>\n"
" <ForcedInstallation>true</ForcedInstallation>\n"
" <RequiresAdminRights>true</RequiresAdminRights>\n"
"</Package>\n";





signals:
void finished();

public slots:
void slotFinished();
};

#endif // FINSTALLER_H
Binary file added icon/icon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "qmldir.h"
#include "qmlplugindump.h"
#include "lupdate.h"
#include "finstaller.h"

int main(int argc, char *argv[])
{
Expand All @@ -25,6 +26,7 @@ int main(int argc, char *argv[])
qmlRegisterType<QmlDir>("AutoTools", 1, 0, "QmlDir");
qmlRegisterType<QmlPluginDump>("AutoTools", 1, 0, "QmlPluginDump");
qmlRegisterType<Lupdate>("AutoTools", 1, 0, "Lupdate");
qmlRegisterType<FInstaller>("AutoTools", 1, 0, "FInstaller");

const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
Expand Down
65 changes: 65 additions & 0 deletions qml/InstallerPage.qml
Original file line number Diff line number Diff line change
@@ -1,11 +1,76 @@
import QtQuick 2.12
import QtQuick.Controls 2.5

import Components 1.0
import AutoTools 1.0

Item {
Label {
x: 20; y: 20
font.pixelSize: 18
font.weight: Font.Bold
text: "Qt Installer Framework"
}
FInstaller {
id: _finstaller
onFinished: {
_busyDialog.close()
}
}
BusiDialog {
id: _busyDialog
}

Flickable {
x: 20; y: 50
width: parent.width; height: parent.height-y
contentHeight: _content.height+20
clip: true
Column {
id: _content
spacing: 20
SelectFolderRow {
text: "Папка с деплоем"
onSetPath: {
_finstaller.setDeployPath(path)
}
}
SelectFolderRow {
text: "Папка установки"
onSetPath: {
_finstaller.setInstallerPath(path)
}
}
SelectFolderRow {
text: qsTr("Вендор")
isFolderButton: false
path: "com.vendor.example"
onSetPath: {
_finstaller.setVendorName(path)
}
}
Row {
spacing: 20
Button {
text: qsTr("Создать config")
onClicked: {
_finstaller.createConfig()
}
}
Button {
text: qsTr("Создать packages")
onClicked: {
_finstaller.createPackages()
}
}
}
Button {
text: qsTr("Создать офлайн инсталятор")
onClicked: {
_busyDialog.open()
_finstaller.createOffInstaller()
}
}
}
}
}
1 change: 1 addition & 0 deletions qml/components/SelectFolderRow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Row {
}
Button {
width: 40; height: parent.height
visible: _root.isFolderButton
text: "..."
onClicked: {
_dialog.open()
Expand Down

0 comments on commit 09b0664

Please sign in to comment.