-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
147 lines (108 loc) · 3.62 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "mainwindow.h"
#include <iostream>
#include <QDebug>
#include <QApplication>
#include <QTextCodec>
#include <QProcess>
#include <QFileInfo>
#include <QMessageBox>
#include <QDateTime>
#include "version.h"
#include "installwizard.h"
#include "launchframe.h"
extern QString WORKDIR;
#include "datathread.h"
#include "qrcode/QrCode.hpp"
#define VERSION "0.1"
extern QString REDISSERVER; // "127.0.0.1"
extern int REDISPORT; // 6379
extern QString REDISAUTH; //
extern int gRID;
extern QString LOCALWEBSERVER; // "https://cnshop.aiwaiter.net:443"
extern QApplication* gApp;
int launchMainWnd(int argc, char *argv[]) {
QApplication app(argc, argv);
gApp = &app;
// int ret = app.exec();
static LaunchFrame lf;
lf.setMinimumSize(800, 600);
lf.show();
return app.exec();
}
int main(int argc, char *argv[])
{
if(argc > 1) {
if("--version" == QString(argv[1])) {
std::cout << AMPVersion.toStdString().c_str() << "."
<< AMPBuild.toStdString().c_str()
<< std::endl;
return 0;
}
}
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
WORKDIR = "/opt/pos";
#ifdef MPOS_CLOUD
#ifdef Q_OS_ANDROID
WORKDIR = "/sdcard";
#elif defined(Q_OS_WIN32)
WORKDIR = "c:/pos";
#else
WORKDIR = "/opt/pos";
#endif
#endif
QDir dir(QString("%1/plugins").arg(WORKDIR));
if(dir.exists() == false) {
dir.mkdir(QString("%1/plugins").arg(WORKDIR));
}
char* env = (char*)QString("QT_QPA_PLATFORM_PLUGIN_PATH=%1/plugins/platforms").arg(WORKDIR).toStdString().c_str();
::putenv(env);
#ifdef Q_OS_WIN32
QApplication::addLibraryPath( QString("%1").arg(WORKDIR) ); //"/opt/bin/plugins");
#else
QApplication::addLibraryPath( QString("%1/plugins").arg(WORKDIR) ); //"/opt/bin/plugins");
#endif
QString installflag = QString("%1/%2").arg(WORKDIR).arg(".installed");
qDebug() << "install path: " << installflag;
QFileInfo fi( installflag );
if(! fi.isFile() ) {
QApplication app(argc, argv);
InstallWizard w;
w.setMinimumSize(400, 300);
w.setMaximumSize(1024, 768);
w.showFullScreen();
int ret = app.exec();
if(ret != 0) {
QMessageBox::warning(nullptr, QObject::tr("出错"), QObject::tr("安装过程中已被用户取消"));
return ret;
}
#ifndef MPOS_CLOUD
QFile file(installflag);
file.open(QIODevice::WriteOnly);
file.write( QDateTime::currentDateTime().toString().toLocal8Bit());
file.close();
#endif
}
QFile file(installflag);
file.open(QIODevice::ReadOnly);
QTextStream stream(&file);
while(!stream.atEnd()) {
QString line = stream.readLine();
line = line.trimmed();
if(line.startsWith("redis-server=")) {
REDISSERVER = line.mid( QString("redis-server=").length() );
} else if(line.startsWith("redis-port=")) {
REDISPORT = line.mid( QString("redis-port=").length() ).toInt();
} else if(line.startsWith("redis-auth=")) {
REDISAUTH = line.mid( QString("redis-auth=").length() );
} else if(line.startsWith("local-web-server=")) {
LOCALWEBSERVER = line.mid( QString("local-web-server=").length() );
} else if(line.startsWith("shop-id=")) {
gRID = line.mid( QString("shop-id=").length() ).toInt();
}
}
qDebug() << "redis-server: " << REDISSERVER
<< "redis-port: " << REDISPORT
<< "redis-auth: " << REDISAUTH
<< "local-web-server: " << LOCALWEBSERVER;
return launchMainWnd(argc, argv);
}