-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
126 lines (103 loc) · 4.22 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
#include <QApplication>
#include <windows.h>
#include <QDebug>
#include <qapplication.h>
#include <QTranslator>
#include <QThread>
#include <QTextCodec>
#include <QDir>
#include "DbgHelp.h"
#include "tchar.h"
#include "ShlObj.h"
#include "blockchain.h"
#include "frame.h"
#include "debug_log.h"
bool checkOnly()
{
DLOG_QT_WALLET_FUNCTION_BEGIN;
// 创建互斥量
HANDLE m_hMutex = CreateMutex(NULL, FALSE, L"WALLET" WASSET_NAME);
// 检查错误代码
if (GetLastError() == ERROR_ALREADY_EXISTS) {
// 如果已有互斥量存在则释放句柄并复位互斥量
CloseHandle(m_hMutex);
m_hMutex = NULL;
// 程序退出
return false;
}
else
return true;
}
LONG WINAPI TopLevelExceptionFilter(struct _EXCEPTION_POINTERS *pExceptionInfo)
{
qDebug() << "Enter TopLevelExceptionFilter Function" ;
HANDLE hFile = CreateFile(L"project.dmp",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
MINIDUMP_EXCEPTION_INFORMATION stExceptionParam;
stExceptionParam.ThreadId = GetCurrentThreadId();
stExceptionParam.ExceptionPointers = pExceptionInfo;
stExceptionParam.ClientPointers = FALSE;
MiniDumpWriteDump(GetCurrentProcess(),GetCurrentProcessId(),hFile,MiniDumpWithFullMemory,&stExceptionParam,NULL,NULL);
CloseHandle(hFile);
qDebug() << "End TopLevelExceptionFilter Function" ;
return EXCEPTION_EXECUTE_HANDLER;
}
LPWSTR ConvertCharToLPWSTR(const char * szString)
{
int dwLen = strlen(szString) + 1;
int nwLen = MultiByteToWideChar(CP_ACP, 0, szString, dwLen, NULL, 0);//算出合适的长度
LPWSTR lpszPath = new WCHAR[dwLen];
MultiByteToWideChar(CP_ACP, 0, szString, dwLen, lpszPath, nwLen);
return lpszPath;
}
void refreshIcon()
{
// 解决windows下自动更新后图标不改变的bug
SHChangeNotify(0x8000000, 0x1000, 0, 0);
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, NULL, SMTO_ABORTIFHUNG, 100, 0);
}
void removeUpdateDeleteFile() // 删除更新时应该删除的文件
{
QDir dir;
QStringList fileList = dir.entryList();
foreach ( QString fileName, fileList)
{
if( fileName.endsWith(".delete"))
{
qDebug() << "remove delete file: " << fileName << QFile::remove(fileName);
}
}
}
int main(int argc, char *argv[])
{
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
QApplication a(argc, argv);
// refreshIcon();
// SetUnhandledExceptionFilter(TopLevelExceptionFilter);
// QTranslator translator;
// translator.load(QString(":/qm/qt_zh_cn"));
// a.installTranslator(&translator);
Blockchain::getInstance(); // 在frame创建前先创建实例,读取language
// qInstallMessageHandler(outputMessage); // 重定向qebug 到log.txt
// removeUpdateDeleteFile();
if(checkOnly()==false) return 0; // 防止程序多次启动
Frame frame;
Blockchain::getInstance()->mainFrame = &frame; // 一个全局的指向主窗口的指针
frame.show();
a.installEventFilter(&frame);
a.setStyleSheet("QScrollBar:vertical{width:13px;background:transparent;padding:19px 5px 19px 0px;}"
"QScrollBar::handle:vertical{width:8px;background:rgba(173,173,179);border-radius:4px;min-height:20;}"
"QScrollBar::handle:vertical:hover{background:rgb(130,137,143);}"
"QScrollBar::add-line:vertical{height:0px;}"
"QScrollBar::sub-line:vertical{height:0px;}"
"QScrollBar:horizontal{height:8px;background:rgb(255,255,255);padding:0px 19px 0px 19px;}"
"QScrollBar::handle:horizontal{height:8px;background:rgba(173,173,179);border-radius:4px;min-width:20;}"
"QScrollBar::handle:horizontal:hover{background:rgb(130,137,143);}"
"QScrollBar::add-line:horizontal{width:0px;}"
"QScrollBar::sub-line:horizontal{width:0px;}"
);
int result = a.exec();
Blockchain::getInstance()->quit();
DLOG_QT_WALLET_FUNCTION_END;
return result;
}