-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
111 lines (104 loc) · 3.65 KB
/
main.cpp
File metadata and controls
111 lines (104 loc) · 3.65 KB
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
#include "Log4Qt/LogManager"
#include "Log4Qt/propertyconfigurator.h"
#include "Log4Qt/helpers/properties.h"
#include "mymainwindow.h"
#include <QApplication>
#include <QTextCodec>
#include <QDebug>
#include <QFile>
#include "AppSetting.h"
#include "AntiCrack.h"
#include <QtSingleApplication>
using namespace std;
#include "moyea_log.h"
using namespace MoyeaBased;
namespace Internal
{
enum{
emAppConfigError = 200, ///< AppConfig Error
emGUIDSame, ///< GUID is same
emInstallInnoMutex, ///< Inno pkg is Installing
emOther ///< other error
};
}
int main(int argc, char *argv[])
{
int returnValue = -1;
try
{
QtSingleApplication a(argc, argv);
if (a.isRunning()) {
a.sendMessage("Wake up!");
return 0;
}
#ifdef Q_OS_MAC
QDir dir(a.applicationDirPath());
dir.cdUp();
dir.cd("PlugIns");
a.setLibraryPaths(QStringList(dir.absolutePath()));
#else //Q_OS_WIN
QString strPluginPath = a.applicationDirPath() + QString("/plugins");
a.addLibraryPath(strPluginPath);
#endif
//定义编码格式
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
//QTextCodec *codec = QTextCodec::codecForName("GB2312");
//设置和对本地文件系统读写时候的编码格式
QTextCodec::setCodecForLocale(codec);
//设置传给tr函数时的默认字符串编码
QTextCodec::setCodecForTr(codec);
//用在字符常量或者QByteArray构造QString对象时使用的一种编码方式
QTextCodec::setCodecForCStrings(codec);
//产品UI日志
Log4Qt::Properties qtlogProper;
qtlogProper.setProperty("log4j.rootLogger", "DEBUG, A1");
qtlogProper.setProperty("log4j.appender.A1", "org.apache.log4j.FileAppender");
qtlogProper.setProperty("log4j.appender.A1.file", CAppSetting::instance().getUILogFilePath());
qtlogProper.setProperty("log4j.appender.A1.layout", "org.apache.log4j.TTCCLayout");
qtlogProper.setProperty("log4j.appender.A1.layout.DateFormat", "{yyyy-MM-dd HH:mm:ss}");
Log4Qt::PropertyConfigurator::configure(qtlogProper);
Log4Qt::LogManager::setHandleQtMessages(true);
//底层日志
QFileInfo logFileInfo(CAppSetting::instance().getLogFilePath());
if (logFileInfo.size() > 10*1024*1024) { //10M
QFile::remove(CAppSetting::instance().getLogFilePath());
}
#ifdef QT_NO_DEBUG
LOG_SETTING_RELEASE(CAppSetting::instance().getLogFilePath().toUtf8().data());
#else
LOG_SETTING_DEBUG(CAppSetting::instance().getLogFilePath().toUtf8().data());
#endif
LOG_INFO("==================================================================");
QString skinPath = CAppSetting::instance().getSkinPath();
#ifdef Q_OS_WIN
QString winMainCss = skinPath + "skin.css";
QFile file(winMainCss);
#else
QString macMainCss = skinPath + "skin_mac.css";
QFile file(macMainCss);
#endif
if (!file.open(QIODevice::ReadOnly)) {
Q_ASSERT(false);
}
QString styleSheet = file.readAll();
QString absoluteCssPath = QDir(skinPath).absolutePath();
styleSheet.replace("%skinpath%",absoluteCssPath,Qt::CaseInsensitive);
a.setStyleSheet(styleSheet);
file.close();
#ifdef Q_OS_WIN
AntiCrack_DecryptEXE();
#endif
MyMainWindow mainWindow;
mainWindow.showMainwindow();
a.setActivationWindow(&mainWindow);
returnValue = a.exec();
}
catch (int e)
{
returnValue = e;
}
catch (...)
{
}
return returnValue;
}