Commit 58cc801b authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Andreas Traczyk

updater: increase the VERSION_STRING granularity

- sets hourly granularity to the the version string

- updates download URL

Change-Id: I5fa9db19f27d368b359d4109e3be71f060f9bf63
parent 0c3feec7
20190102542748
\ No newline at end of file
......@@ -13,15 +13,15 @@
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "downloadbar.h"
#include "downloadmanger.h"
#include <windows.h>
#include <QMessageBox>
#include "downloadbar.h"
#include "downloadmanger.h"
DownloadManager::DownloadManager(QObject* parent)
: QObject(parent)
{
......@@ -39,7 +39,7 @@ void DownloadManager::doDownload(const QUrl& url)
file_.reset(new QFile(downloadpath_ + "/" + fileName));
if (!file_->open(QIODevice::WriteOnly)) {
QMessageBox::information(0, "Error!", "Unable to Open File Path");
QMessageBox::critical(0, "Error!", "Unable to Open File Path");
file_.reset(nullptr);
return;
}
......@@ -73,9 +73,9 @@ void DownloadManager::doDownload(const QUrl& url)
void DownloadManager::downloadFinished()
{
// donload finished normally
int statusCode = currentDownload_->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (statusCode == 404) {
QMessageBox::information(0, "Error!", "DownLoaded Installer Invalid!");
statusCode_ = currentDownload_->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (statusCode_ == 404) {
QMessageBox::critical(0, "Error!", "DownLoad Failed!");
}
probar_.setMaximum(0);
probar_.setValue(0);
......@@ -98,6 +98,8 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
int presentTime = downloadTime_.elapsed();
// calculate the download speed
double speed = (bytesReceived - previousDownloadBytes_) * 1000.0 / (presentTime - previousTime_);
if (speed < 0)
speed = 0;
previousTime_ = presentTime;
previousDownloadBytes_ = bytesReceived;
......@@ -127,13 +129,18 @@ void DownloadManager::httpReadyRead()
QString DownloadManager::versionOnline()
{
QString urlstr = "https://dl.jami.net/windows/testver";
QString urlstr = "https://dl.jami.net/windows/version";
QUrl url = QUrl::fromEncoded(urlstr.toLocal8Bit());
doDownload(url);
if (statusCode_ == 404) {
QMessageBox::critical(0, "Version Check Error", "Version Cannot Be Verified");
return "Null";
}
QFile file(downloadpath_ + "/" + "testver");
QFile file(downloadpath_ + "/" + "version");
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::information(0, "Downloaded Version File Error", file.errorString());
QMessageBox::critical(0, "Version Check Error", "File cannnot be openned");
return "Null";
}
QTextStream in(&file);
QString onlineVersion = in.readLine();
......@@ -146,12 +153,18 @@ void DownloadManager::sslErrors(const QList<QSslError>& sslErrors)
{
#if QT_CONFIG(ssl)
for (const QSslError& error : sslErrors)
QMessageBox::information(0, "SSL Error ", error.errorString());
QMessageBox::critical(0, "SSL Error ", error.errorString());
return;
#else
Q_UNUSED(sslErrors);
#endif
}
int DownloadManager::getDownloadStatus()
{
return statusCode_;
}
const char* DownloadManager::WinGetEnv(const char* name)
{
const DWORD buffSize = 65535;
......
......@@ -29,6 +29,7 @@ class QSslError;
class DownloadManager : public QObject {
Q_OBJECT
QNetworkAccessManager manager_;
QNetworkReply* currentDownload_;
updateDownloadDialog probar_;
......@@ -37,13 +38,14 @@ class DownloadManager : public QObject {
int previousTime_ = 0;
qint64 previousDownloadBytes_ = 0;
QString downloadpath_;
const char* WinGetEnv(const char* name);
int statusCode_;
public:
explicit DownloadManager(QObject* parent = nullptr);
void doDownload(const QUrl& url);
QString versionOnline();
static const char* WinGetEnv(const char* name);
int getDownloadStatus();
public slots:
void sslErrors(const QList<QSslError>& sslErrors);
......
......@@ -23,22 +23,23 @@
#include <QFile>
#include "callmodel.h"
#include "globalinstances.h"
#include "media/audio.h"
#include "media/video.h"
#include "media/text.h"
#include "media/file.h"
#include "globalinstances.h"
#include "media/text.h"
#include "media/video.h"
#include <QTranslator>
#include <QLibraryInfo>
#include <QFontDatabase>
#include <QLibraryInfo>
#include <QTranslator>
#include <ciso646>
#include "downloadmanger.h"
#include "lrcinstance.h"
#include "utils.h"
#include "runguard.h"
#include "pixbufmanipulator.h"
#include "runguard.h"
#include "utils.h"
#ifdef Q_OS_WIN
#include <windows.h>
......@@ -102,7 +103,7 @@ fileDebug(QFile& debugFile)
}
int
main(int argc, char *argv[])
main(int argc, char* argv[])
{
RunGuard guard("680b3e5eaf");
if (!guard.tryToRun())
......@@ -176,8 +177,7 @@ main(int argc, char *argv[])
shm->lock();
char *to = (char*) shm->data();
QChar *data = uri.data();
while (!data->isNull())
{
while (!data->isNull()) {
memset(to, data->toLatin1(), 1);
++data;
++to;
......@@ -232,8 +232,7 @@ main(int argc, char *argv[])
#ifndef DEBUG_STYLESHEET
QFile file(":/stylesheet.css");
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
a.setStyleSheet(file.readAll());
file.close();
}
......@@ -266,6 +265,20 @@ main(int argc, char *argv[])
});
#endif
//Delet all logs and msi in the %TEMP% directory before launching
QString dir = QString(DownloadManager::WinGetEnv("TEMP"));
QDir log_dir(dir, {"jami*.log"});
for (const QString& filename : log_dir.entryList()) {
log_dir.remove(filename);
}
QDir msi_dir(dir, {"jami*.msi"});
for (const QString& filename : msi_dir.entryList()) {
msi_dir.remove(filename);
}
QDir version_dir(dir, {"version"});
for (const QString& filename : version_dir.entryList()) {
version_dir.remove(filename);
}
auto ret = a.exec();
#ifdef Q_OS_WIN
......
......@@ -686,9 +686,6 @@
<ItemGroup>
<ResourceCompile Include="ico.rc" />
</ItemGroup>
<ItemGroup>
<Text Include="Version.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
<Import Project="$(QtMsBuild)\qt.targets" />
......
......@@ -793,9 +793,4 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="Version.txt">
<Filter>Resource Files</Filter>
</Text>
</ItemGroup>
</Project>
\ No newline at end of file
</Project>
......@@ -43,7 +43,8 @@
#include "utils.h"
#include "deviceitemwidget.h"
#include "banneditemwidget.h"
#include "UpdateConfirmDialog.h"
#include "updateconfirmdialog.h"
#include "version.h"
#include "api/newdevicemodel.h"
#include "audio/inputdevicemodel.h"
......@@ -306,12 +307,11 @@ void SettingsWidget::updateAccountInfoDisplayed()
ui->bannedContactsLayoutWidget->setVisible(accInfo.contactModel->getBannedContacts().size());
}
void
SettingsWidget::setAvatar(PhotoboothWidget* avatarWidget)
void SettingsWidget::setAvatar(PhotoboothWidget* avatarWidget)
{
auto& accountInfo = LRCInstance::getCurrentAccountInfo();
auto defaultAvatar = accountInfo.profileInfo.avatar.empty();
auto avatar = Utils::accountPhoto(accountInfo, { avatarSize_ , avatarSize_ });
auto avatar = Utils::accountPhoto(accountInfo, {avatarSize_, avatarSize_});
avatarWidget->setAvatarPixmap(QPixmap::fromImage(avatar), defaultAvatar);
}
......@@ -518,39 +518,7 @@ void SettingsWidget::setAccEnableSlot(int state)
void SettingsWidget::delAccountSlot()
{
DownloadManager manager;
UpdateConfirmDialog updatedia;
QFile file("Version.txt");
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, "Version File Error", file.errorString());
}
QTextStream in(&file);
QString localVersion = in.readLine();
file.close();
QString onlineVersion = manager.versionOnline();
if (onlineVersion != localVersion) {
auto ret = updatedia.exec();
QThread::sleep(1);
if (ret == QDialog::Accepted) {
QString urlstr = "https://dl.jami.net/windows/test.exe";
QUrl url = QUrl::fromEncoded(urlstr.toLocal8Bit());
manager.doDownload(url);
auto args = QString(" /passive /norestart WIXNONUILAUNCH=1");
auto dir = QString("C:\\Users\\mzhang\\Desktop");
auto cmd = "powershell " + dir + "\\Jami.msi"
+ " /L*V " + dir + "\\jami_install.log" + args;
auto retq = QProcess::startDetached(cmd);
if (retq) {
QApplication::quit();
}
}
} else {
QMessageBox::information(this, "Update Status", "No New Version Detected");
}
/*DeleteAccountDialog delDialog(this);
DeleteAccountDialog delDialog(this);
auto ret = delDialog.exec();
if (ret == QDialog::Accepted) {
......@@ -563,7 +531,7 @@ void SettingsWidget::delAccountSlot()
LRCInstance::setSelectedConvId("");
emit NavigationRequested(ScreenEnum::CallScreen);
}
}*/
}
}
void SettingsWidget::removeDeviceSlot(int index)
......@@ -895,9 +863,38 @@ void SettingsWidget::slotSetClosedOrMin(bool state)
void SettingsWidget::checkForUpdateSlot()
{
DownloadManager manager;
UpdateConfirmDialog updateDialog(this);
QString onlineVersion = manager.versionOnline();
int currentVersion = QString(VERSION_STRING).toInt();
if (onlineVersion != "Null" && onlineVersion.toInt() > currentVersion) {
auto ret = updateDialog.exec();
QThread::sleep(1);
if (ret == QDialog::Accepted) {
QString urlstr = "https://dl.jami.net/windows/jami-x64.msi";
QUrl url = QUrl::fromEncoded(urlstr.toLocal8Bit());
manager.doDownload(url);
if (manager.getDownloadStatus() == 404) {
QMessageBox::critical(0, "Download Status", "Installer Download Failed, Please Contact Support");
return;
}
auto args = QString(" /passive /norestart WIXNONUILAUNCH=1");
auto dir = DownloadManager::WinGetEnv("TEMP");
auto cmd = "powershell " + QString(dir) + "\\jami-x64.msi"
+ " /L*V " + QString(dir) + "\\jami_x64_install.log" + args;
auto retq = QProcess::startDetached(cmd);
if (retq) {
QApplication::quit();
}
}
} else {
QMessageBox::information(0, "Update Status", "No New Version Detected");
}
/*
#ifdef Q_OS_WIN
win_sparkle_check_update_with_ui();
#endif
*/
}
void SettingsWidget::setUpdateIntervalSlot(int value)
......
......@@ -5,7 +5,6 @@
#define BUILD_YEAR_CH2 (__DATE__[ 9])
#define BUILD_YEAR_CH3 (__DATE__[10])
#define BUILD_MONTH_IS_JAN (__DATE__[0] == 'J' && __DATE__[1] == 'a' && __DATE__[2] == 'n')
#define BUILD_MONTH_IS_FEB (__DATE__[0] == 'F')
#define BUILD_MONTH_IS_MAR (__DATE__[0] == 'M' && __DATE__[1] == 'a' && __DATE__[2] == 'r')
......@@ -19,7 +18,6 @@
#define BUILD_MONTH_IS_NOV (__DATE__[0] == 'N')
#define BUILD_MONTH_IS_DEC (__DATE__[0] == 'D')
#define BUILD_MONTH_CH0 \
((BUILD_MONTH_IS_OCT || BUILD_MONTH_IS_NOV || BUILD_MONTH_IS_DEC) ? '1' : '0')
......@@ -43,10 +41,13 @@
#define BUILD_DAY_CH0 ((__DATE__[4] >= '0') ? (__DATE__[4]) : '0')
#define BUILD_DAY_CH1 (__DATE__[ 5])
const char VERSION_STRING[] =
{
#define BUILD_HOUR_CH0 (__TIME__[0])
#define BUILD_HOUR_CH1 (__TIME__[1])
const char VERSION_STRING[] = {
BUILD_YEAR_CH0, BUILD_YEAR_CH1, BUILD_YEAR_CH2, BUILD_YEAR_CH3,
BUILD_MONTH_CH0, BUILD_MONTH_CH1,
BUILD_DAY_CH0, BUILD_DAY_CH1,
BUILD_HOUR_CH0, BUILD_HOUR_CH1,
'\0'
};
\ No newline at end of file
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment