Skip to content

Commit

Permalink
Comment updater. Not needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
raininforest committed Oct 7, 2019
1 parent 2362472 commit f49a451
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 196 deletions.
30 changes: 0 additions & 30 deletions config/gerber_translator.ini

This file was deleted.

30 changes: 15 additions & 15 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "controller.h"
#include "updater.h"
//#include "updater.h"
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
Expand All @@ -8,20 +8,20 @@

int main(int argc, char *argv[])
{
// запуск апдейта
int was_update_succesfull = 0;
was_update_succesfull = update();
switch (was_update_succesfull) {
case -1:{
qDebug()<< "Failed to update the current version of the program! The old version will be launched...";
} break;
case 1:{
qDebug()<< "Current version will be updated!";
} return 1;
case 2:{
qDebug()<< "No update required!";
} break;
}

// int was_update_succesfull = 0;
// was_update_succesfull = update();
// switch (was_update_succesfull) {
// case -1:{
// qDebug()<< "Failed to update the current version of the program! The old version will be launched...";
// } break;
// case 1:{
// qDebug()<< "Current version will be updated!";
// } return 1;
// case 2:{
// qDebug()<< "No update required!";
// } break;
// }

QApplication a(argc, argv);

Expand Down
282 changes: 141 additions & 141 deletions updater.cpp
Original file line number Diff line number Diff line change
@@ -1,151 +1,151 @@
#include "updater.h"
//#include "updater.h"

int update(){
//int update(){

int local_version=0;
int actual_version=0;
QString platform="windows";
QString bit="64";
QString extension="";
// int local_version=0;
// int actual_version=0;
// QString platform="windows";
// QString bit="64";
// QString extension="";

QString local_ver_file_name; //(not full path)
QString local_version_text=""; //
QString local_app_name; //local application path (not full path)
QFileInfo local_app; //
QString updater_name; //updater path (not full path)
QFileInfo updater; //
QString actual_path; //path to actual versions
QString actual_ver_file_name; //absolute path for actual version file
QString actual_version_text=""; //
QString actual_app_path; //absolute path for actual version of application
// QString local_ver_file_name; //(not full path)
// QString local_version_text=""; //
// QString local_app_name; //local application path (not full path)
// QFileInfo local_app; //
// QString updater_name; //updater path (not full path)
// QFileInfo updater; //
// QString actual_path; //path to actual versions
// QString actual_ver_file_name; //absolute path for actual version file
// QString actual_version_text=""; //
// QString actual_app_path; //absolute path for actual version of application

qDebug()<<"Checking updates...";
local_ver_file_name = "gt_version";
QFile loc_version_file(local_ver_file_name);
if(!loc_version_file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can not open local version file!";
return -1;
}
while (!loc_version_file.atEnd()){
QByteArray str = loc_version_file.readLine().trimmed();
// read local version
if (str.contains("version")){
local_version_text = str.right(str.size()-(str.indexOf('=')+1));
bool ok;
QString lvt_without_point = local_version_text;
lvt_without_point.remove('.');
local_version = lvt_without_point.toInt(&ok);
if ((local_version == 0)||(!ok)) {
qDebug()<<"Can not read [version] from local version file!";
loc_version_file.close();
return -1;
}
}
// read platform
if (str.contains("platform")){
platform = str.right(str.size()-(str.indexOf('=')+1));
if (platform=="windows"){
extension = ".exe";
}
else if (platform=="linux") {
extension.clear();
}
else {
qDebug()<<"Can not read [platform] from local version file!";
loc_version_file.close();
return -1;
}
}
// read bit
if (str.contains("bit")){
bit = str.right(str.size()-(str.indexOf('=')+1));
if (bit.isEmpty()){
qDebug()<<"Can not read [bit] from local version file!";
loc_version_file.close();
return -1;
}
}
}
loc_version_file.close();
// qDebug()<<"Checking updates...";
// local_ver_file_name = "gt_version";
// QFile loc_version_file(local_ver_file_name);
// if(!loc_version_file.open(QIODevice::ReadOnly | QIODevice::Text)){
// qDebug()<<"Can not open local version file!";
// return -1;
// }
// while (!loc_version_file.atEnd()){
// QByteArray str = loc_version_file.readLine().trimmed();
// // read local version
// if (str.contains("version")){
// local_version_text = str.right(str.size()-(str.indexOf('=')+1));
// bool ok;
// QString lvt_without_point = local_version_text;
// lvt_without_point.remove('.');
// local_version = lvt_without_point.toInt(&ok);
// if ((local_version == 0)||(!ok)) {
// qDebug()<<"Can not read [version] from local version file!";
// loc_version_file.close();
// return -1;
// }
// }
// // read platform
// if (str.contains("platform")){
// platform = str.right(str.size()-(str.indexOf('=')+1));
// if (platform=="windows"){
// extension = ".exe";
// }
// else if (platform=="linux") {
// extension.clear();
// }
// else {
// qDebug()<<"Can not read [platform] from local version file!";
// loc_version_file.close();
// return -1;
// }
// }
// // read bit
// if (str.contains("bit")){
// bit = str.right(str.size()-(str.indexOf('=')+1));
// if (bit.isEmpty()){
// qDebug()<<"Can not read [bit] from local version file!";
// loc_version_file.close();
// return -1;
// }
// }
// }
// loc_version_file.close();

local_app_name = "gerber_translator" + extension;
updater_name = "gt_u" + extension;
updater.setFile(updater_name);
if (!updater.exists()){
qDebug()<<"Updater gt_u not found!";
return -1;
}
// local_app_name = "gerber_translator" + extension;
// updater_name = "gt_u" + extension;
// updater.setFile(updater_name);
// if (!updater.exists()){
// qDebug()<<"Updater gt_u not found!";
// return -1;
// }

// reading path with acual versions
QFile path_file("path");
if(!path_file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can not open path file!";
return -1;
}
while (!path_file.atEnd()){
actual_path = path_file.readLine().trimmed();
}
if (actual_path.isEmpty()){
path_file.close();
qDebug()<<"Failed to determine the path to the actual version!";
return -1;
}
// // reading path with acual versions
// QFile path_file("path");
// if(!path_file.open(QIODevice::ReadOnly | QIODevice::Text)){
// qDebug()<<"Can not open path file!";
// return -1;
// }
// while (!path_file.atEnd()){
// actual_path = path_file.readLine().trimmed();
// }
// if (actual_path.isEmpty()){
// path_file.close();
// qDebug()<<"Failed to determine the path to the actual version!";
// return -1;
// }

// creating actual paths
QString platform_folder_name;
QString bit_folder_name;
platform_folder_name = "/" + platform;
bit_folder_name = "/gerber_translator_" + bit;
actual_path.append(platform_folder_name);
actual_path.append(bit_folder_name);
actual_ver_file_name = actual_path + "/gt_version";
actual_app_path = actual_path + "/gerber_translator" + extension;
path_file.close();
// // creating actual paths
// QString platform_folder_name;
// QString bit_folder_name;
// platform_folder_name = "/" + platform;
// bit_folder_name = "/gerber_translator_" + bit;
// actual_path.append(platform_folder_name);
// actual_path.append(bit_folder_name);
// actual_ver_file_name = actual_path + "/gt_version";
// actual_app_path = actual_path + "/gerber_translator" + extension;
// path_file.close();

QFile act_version_file(actual_ver_file_name);
// QFile act_version_file(actual_ver_file_name);

if(!act_version_file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can not open actual version file!";
return -1;
}
while (!act_version_file.atEnd()){
QByteArray str = act_version_file.readLine().trimmed();
// read version
if (str.contains("version")){
actual_version_text = str.right(str.size()-(str.indexOf('=')+1));
bool ok;
QString avt_without_point = actual_version_text;
avt_without_point.remove('.');
actual_version = avt_without_point.toInt(&ok);
if ((actual_version == 0)||(!ok)) {
qDebug()<<"Can not read acual version from actual version file!";
act_version_file.close();
return -1;
}
}
}
act_version_file.close();
// if(!act_version_file.open(QIODevice::ReadOnly | QIODevice::Text)){
// qDebug()<<"Can not open actual version file!";
// return -1;
// }
// while (!act_version_file.atEnd()){
// QByteArray str = act_version_file.readLine().trimmed();
// // read version
// if (str.contains("version")){
// actual_version_text = str.right(str.size()-(str.indexOf('=')+1));
// bool ok;
// QString avt_without_point = actual_version_text;
// avt_without_point.remove('.');
// actual_version = avt_without_point.toInt(&ok);
// if ((actual_version == 0)||(!ok)) {
// qDebug()<<"Can not read acual version from actual version file!";
// act_version_file.close();
// return -1;
// }
// }
// }
// act_version_file.close();

// compare versions
if (actual_version>local_version){
//argv[1] - local version path
//argv[2] - actual version string
//argv[3] - local application path
//argv[4] - actual application path
QStringList arguments;
arguments.append(local_ver_file_name); //
arguments.append(actual_version_text); //
arguments.append(local_app_name); //
arguments.append(actual_app_path); //absolute path
// run updater
QProcess updater_process(nullptr);
updater_process.startDetached(updater.absoluteFilePath(), arguments);
// exit
return 1;
}
else if (actual_version==local_version){
return 2; //app is up to date
}
qDebug()<<"Error! Local version > Actual version!";
return -1;
}
// // compare versions
// if (actual_version>local_version){
// //argv[1] - local version path
// //argv[2] - actual version string
// //argv[3] - local application path
// //argv[4] - actual application path
// QStringList arguments;
// arguments.append(local_ver_file_name); //
// arguments.append(actual_version_text); //
// arguments.append(local_app_name); //
// arguments.append(actual_app_path); //absolute path
// // run updater
// QProcess updater_process(nullptr);
// updater_process.startDetached(updater.absoluteFilePath(), arguments);
// // exit
// return 1;
// }
// else if (actual_version==local_version){
// return 2; //app is up to date
// }
// qDebug()<<"Error! Local version > Actual version!";
// return -1;
//}
20 changes: 10 additions & 10 deletions updater.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef UPDATER_H
#define UPDATER_H
//#ifndef UPDATER_H
//#define UPDATER_H

#include <QFile>
#include <QFileInfo>
#include <QString>
#include <QDebug>
#include <QProcess>
//#include <QFile>
//#include <QFileInfo>
//#include <QString>
//#include <QDebug>
//#include <QProcess>

//main function
int update();
////main function
//int update();

#endif // UPDATER_H
//#endif // UPDATER_H

0 comments on commit f49a451

Please sign in to comment.