Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
L
Lichtsteuerung
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
21
Issues
21
List
Boards
Labels
Service Desk
Milestones
Iterations
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leander Schulten
Lichtsteuerung
Commits
765540d2
Commit
765540d2
authored
Jan 16, 2020
by
Leander Schulten
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updater: The updater can now follow any number of redirects
parent
dfbf22d3
Pipeline
#228482
passed with stage
in 6 minutes and 18 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
107 deletions
+85
-107
src/updater.cpp
src/updater.cpp
+85
-107
No files found.
src/updater.cpp
View file @
765540d2
...
...
@@ -28,52 +28,43 @@ void Updater::checkForUpdate(){
if
(
state
==
UpdaterState
::
IDE_ENV
){
return
;
}
if
(
!
QFile
::
exists
(
VERSION_FILE_NAME
))
{
if
(
!
QFile
::
exists
(
VERSION_FILE_NAME
))
{
qDebug
()
<<
"version file does not exists in application folder"
;
state
=
UpdaterState
::
UpdateAvailible
;
emit
stateChanged
();
emit
needUpdate
();
return
;
}
auto
redirect
=
http
->
get
(
QNetworkRequest
(
QUrl
(
versionDownloadURL
)));
QObject
::
connect
(
redirect
,
&
QNetworkReply
::
finished
,[
this
,
redirect
](){
redirect
->
deleteLater
();
auto
redirectURL
=
redirect
->
header
(
QNetworkRequest
::
KnownHeaders
::
LocationHeader
);
if
(
!
redirectURL
.
isValid
()){
state
=
UpdaterState
::
DownloadUpdateFailed
;
emit
stateChanged
();
qDebug
()
<<
"can not redirect version.zip"
;
return
;
}
auto
response
=
http
->
get
(
QNetworkRequest
(
redirectURL
.
toUrl
()));
QObject
::
connect
(
response
,
&
QNetworkReply
::
finished
,[
this
,
response
](){
QFile
version
(
QDir
::
tempPath
()
+
QStringLiteral
(
"/version.zip"
));
version
.
open
(
QFile
::
WriteOnly
);
version
.
write
(
response
->
readAll
());
version
.
close
();
response
->
deleteLater
();
Zip
::
unzip
(
QFileInfo
(
version
),
QFileInfo
(
version
).
absolutePath
(),[
this
,
version
=
QFileInfo
(
version
)](
auto
success
){
if
(
!
success
){
qDebug
()
<<
"not successful when unzipping version.zip"
;
state
=
UpdaterState
::
NoUpdateAvailible
;
emit
stateChanged
();
return
;
}
if
(
!
QFile
::
exists
(
version
.
absolutePath
()
+
"/"
+
VERSION_FILE_NAME
)){
qDebug
()
<<
"version file does not exists in version.zip"
;
state
=
UpdaterState
::
NoUpdateAvailible
;
emit
stateChanged
();
return
;
}
if
(
getFileContent
(
VERSION_FILE_NAME
)
!=
getFileContent
(
version
.
absolutePath
()
+
"/"
+
VERSION_FILE_NAME
)){
state
=
UpdaterState
::
UpdateAvailible
;
emit
stateChanged
();
emit
needUpdate
();
}
else
{
state
=
UpdaterState
::
NoUpdateAvailible
;
emit
stateChanged
();
}
});
QNetworkRequest
request
{
QUrl
(
versionDownloadURL
)};
request
.
setAttribute
(
QNetworkRequest
::
FollowRedirectsAttribute
,
true
);
auto
response
=
http
->
get
(
request
);
QObject
::
connect
(
response
,
&
QNetworkReply
::
finished
,
[
this
,
response
]()
{
QFile
version
(
QDir
::
tempPath
()
+
QStringLiteral
(
"/version.zip"
));
version
.
open
(
QFile
::
WriteOnly
);
version
.
write
(
response
->
readAll
());
version
.
close
();
response
->
deleteLater
();
Zip
::
unzip
(
QFileInfo
(
version
),
QFileInfo
(
version
).
absolutePath
(),
[
this
,
version
=
QFileInfo
(
version
)](
auto
success
)
{
if
(
!
success
)
{
qDebug
()
<<
"not successful when unzipping version.zip"
;
state
=
UpdaterState
::
NoUpdateAvailible
;
emit
stateChanged
();
return
;
}
if
(
!
QFile
::
exists
(
version
.
absolutePath
()
+
"/"
+
VERSION_FILE_NAME
))
{
qDebug
()
<<
"version file does not exists in version.zip"
;
state
=
UpdaterState
::
NoUpdateAvailible
;
emit
stateChanged
();
return
;
}
if
(
getFileContent
(
VERSION_FILE_NAME
)
!=
getFileContent
(
version
.
absolutePath
()
+
"/"
+
VERSION_FILE_NAME
))
{
state
=
UpdaterState
::
UpdateAvailible
;
emit
stateChanged
();
emit
needUpdate
();
}
else
{
state
=
UpdaterState
::
NoUpdateAvailible
;
emit
stateChanged
();
}
});
});
}
...
...
@@ -85,83 +76,70 @@ void Updater::update(){
}
state
=
UpdaterState
::
DownloadingUpdate
;
emit
stateChanged
();
auto
redirect
=
http
->
get
(
QNetworkRequest
(
QUrl
(
deployDownloadURL
)));
QObject
::
connect
(
redirect
,
static_cast
<
void
(
QNetworkReply
::*
)(
QNetworkReply
::
NetworkError
)
>
(
&
QNetworkReply
::
error
),[
this
,
redirect
](
auto
error
){
qWarning
()
<<
"Error while redirecting to deploy.zip! "
<<
error
<<
redirect
->
errorString
();
redirect
->
deleteLater
();
QNetworkRequest
request
{
QUrl
(
deployDownloadURL
)};
request
.
setAttribute
(
QNetworkRequest
::
FollowRedirectsAttribute
,
true
);
auto
response
=
http
->
get
(
request
);
QObject
::
connect
(
response
,
static_cast
<
void
(
QNetworkReply
::*
)(
QNetworkReply
::
NetworkError
)
>
(
&
QNetworkReply
::
error
),
[
this
,
response
](
auto
error
)
{
qWarning
()
<<
"Error while redirecting to deploy.zip! "
<<
error
<<
response
->
errorString
();
response
->
deleteLater
();
state
=
UpdaterState
::
DownloadUpdateFailed
;
emit
stateChanged
();
});
QObject
::
connect
(
redirect
,
&
QNetworkReply
::
finished
,[
this
,
redirect
](){
redirect
->
deleteLater
();
auto
redirectURL
=
redirect
->
header
(
QNetworkRequest
::
KnownHeaders
::
LocationHeader
);
if
(
!
redirectURL
.
isValid
()){
qDebug
()
<<
"can not redirect deploy.zip"
;
state
=
UpdaterState
::
DownloadUpdateFailed
;
emit
stateChanged
();
return
;
}
auto
response
=
http
->
get
(
QNetworkRequest
(
redirectURL
.
toUrl
()));
QFile
*
deploy
=
new
QFile
(
QDir
::
tempPath
()
+
QStringLiteral
(
"/deploy.zip"
));
deploy
->
open
(
QFile
::
WriteOnly
);
QObject
::
connect
(
response
,
static_cast
<
void
(
QNetworkReply
::*
)(
QNetworkReply
::
NetworkError
)
>
(
&
QNetworkReply
::
error
),[
this
,
response
,
deploy
](
auto
error
){
qWarning
()
<<
"Error while downloading deploy.zip! "
<<
error
<<
response
->
errorString
();
deploy
->
close
();
deploy
->
deleteLater
();
response
->
deleteLater
();
state
=
UpdaterState
::
DownloadUpdateFailed
;
emit
stateChanged
();
});
QObject
::
connect
(
response
,
&
QNetworkReply
::
readyRead
,[
response
,
deploy
](){
deploy
->
write
(
response
->
readAll
());
});
QObject
::
connect
(
response
,
&
QNetworkReply
::
downloadProgress
,[
this
](
auto
rec
,
auto
max
){
progress
=
100
*
rec
/
max
;
qDebug
()
<<
progress
;
emit
updateProgressChanged
();
});
QObject
::
connect
(
response
,
&
QNetworkReply
::
finished
,[
this
,
response
,
deploy
](){
qDebug
()
<<
response
->
atEnd
();
response
->
deleteLater
();
deploy
->
close
();
state
=
UpdaterState
::
UnzippingUpdate
;
emit
stateChanged
();
Zip
::
unzip
(
QFileInfo
(
*
deploy
),
QFileInfo
(
*
deploy
).
absolutePath
(),[
this
,
deploy
](
auto
success
){
std
::
unique_ptr
<
QFile
>
deleteMe
(
deploy
);
if
(
!
success
){
qDebug
()
<<
"not successful when unzipping deploy.zip"
;
state
=
UpdaterState
::
UnzippingFailed
;
emit
stateChanged
();
return
;
}
deployPath
=
QFileInfo
(
*
deploy
).
absolutePath
()
+
"/"
+
NAME_OF_DEPLOY_FOLDER
;
// if old installer exists, delete these
QString
targetInstallerPath
=
QFileInfo
(
*
deploy
).
absolutePath
()
+
"/"
+
WINDOWS_INSTALLER_NAME
;
if
(
QFile
::
exists
(
targetInstallerPath
)){
if
(
!
QFile
::
remove
(
targetInstallerPath
)){
qWarning
()
<<
"Failed to remove old Windows Installer"
;
state
=
UpdaterState
::
PreparationForInstallationFailed
;
emit
stateChanged
();
return
;
}
}
if
(
!
QFile
::
rename
(
deployPath
+
"/"
+
WINDOWS_INSTALLER_NAME
,
targetInstallerPath
)){
qWarning
()
<<
"Failed to rename Windows Installer"
;
QFile
*
deploy
=
new
QFile
(
QDir
::
tempPath
()
+
QStringLiteral
(
"/deploy.zip"
));
deploy
->
open
(
QFile
::
WriteOnly
);
QObject
::
connect
(
response
,
static_cast
<
void
(
QNetworkReply
::*
)(
QNetworkReply
::
NetworkError
)
>
(
&
QNetworkReply
::
error
),
[
this
,
response
,
deploy
](
auto
error
)
{
qWarning
()
<<
"Error while downloading deploy.zip! "
<<
error
<<
response
->
errorString
();
deploy
->
close
();
deploy
->
deleteLater
();
response
->
deleteLater
();
state
=
UpdaterState
::
DownloadUpdateFailed
;
emit
stateChanged
();
});
QObject
::
connect
(
response
,
&
QNetworkReply
::
readyRead
,
[
response
,
deploy
]()
{
deploy
->
write
(
response
->
readAll
());
});
QObject
::
connect
(
response
,
&
QNetworkReply
::
downloadProgress
,
[
this
](
auto
rec
,
auto
max
)
{
progress
=
100
*
rec
/
max
;
emit
updateProgressChanged
();
});
QObject
::
connect
(
response
,
&
QNetworkReply
::
finished
,
[
this
,
response
,
deploy
]()
{
qDebug
()
<<
response
->
atEnd
();
response
->
deleteLater
();
deploy
->
close
();
state
=
UpdaterState
::
UnzippingUpdate
;
emit
stateChanged
();
Zip
::
unzip
(
QFileInfo
(
*
deploy
),
QFileInfo
(
*
deploy
).
absolutePath
(),
[
this
,
deploy
](
auto
success
)
{
std
::
unique_ptr
<
QFile
>
deleteMe
(
deploy
);
if
(
!
success
)
{
qDebug
()
<<
"not successful when unzipping deploy.zip"
;
state
=
UpdaterState
::
UnzippingFailed
;
emit
stateChanged
();
return
;
}
deployPath
=
QFileInfo
(
*
deploy
).
absolutePath
()
+
"/"
+
NAME_OF_DEPLOY_FOLDER
;
// if old installer exists, delete these
QString
targetInstallerPath
=
QFileInfo
(
*
deploy
).
absolutePath
()
+
"/"
+
WINDOWS_INSTALLER_NAME
;
if
(
QFile
::
exists
(
targetInstallerPath
))
{
if
(
!
QFile
::
remove
(
targetInstallerPath
))
{
qWarning
()
<<
"Failed to remove old Windows Installer"
;
state
=
UpdaterState
::
PreparationForInstallationFailed
;
emit
stateChanged
();
return
;
}
// all important files like QTJSONFile.json
auto
entries
=
QDir
(
QDir
::
currentPath
()).
entryInfoList
(
QStringList
()
<<
QStringLiteral
(
"QTJSONFile.json*"
),
QDir
::
Filter
::
Files
);
for
(
const
auto
&
e
:
entries
){
QFile
::
copy
(
e
.
absoluteFilePath
()
,
deployPath
+
"/"
+
e
.
fileName
());
}
state
=
UpdaterState
::
ReadyToInstall
;
}
if
(
!
QFile
::
rename
(
deployPath
+
"/"
+
WINDOWS_INSTALLER_NAME
,
targetInstallerPath
))
{
qWarning
()
<<
"Failed to rename Windows Installer"
;
state
=
UpdaterState
::
PreparationForInstallationFailed
;
emit
stateChanged
();
});
return
;
}
// all important files like QTJSONFile.json
auto
entries
=
QDir
(
QDir
::
currentPath
()).
entryInfoList
(
QStringList
()
<<
QStringLiteral
(
"QTJSONFile.json*"
),
QDir
::
Filter
::
Files
);
for
(
const
auto
&
e
:
entries
)
{
QFile
::
copy
(
e
.
absoluteFilePath
(),
deployPath
+
"/"
+
e
.
fileName
());
}
state
=
UpdaterState
::
ReadyToInstall
;
emit
stateChanged
();
});
});
}
void
Updater
::
runUpdateInstaller
(){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment