-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqinputdbpassword.h
More file actions
175 lines (157 loc) · 4.83 KB
/
qinputdbpassword.h
File metadata and controls
175 lines (157 loc) · 4.83 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#ifndef QINPUTDBPASSWORD_H
#define QINPUTDBPASSWORD_H
#include <QDialog>
#include <QDir>
#include <QProcess>
#include <QTcpSocket>
#include <QHostAddress>
#include <windows.h>
#include <QThread>
#include <QDebug>
#include "Utility.h"
#include "WinService.h"
namespace Ui {
class QInputDBPassword;
}
class QMySQLDThread :public QThread
{
public:
QString m_strMySQLPath;
QMySQLDThread(QString strMySQLPath)
:m_strMySQLPath(strMySQLPath)
{
}
~QMySQLDThread()
{
requestInterruption();
quit();
wait();
}
void run()
{
QString strMySQLD = m_strMySQLPath;
strMySQLD += "\\bin\\mysqld.exe";
if (!QFileInfo::exists(strMySQLD))
return;
QProcess Process(0);
QString strDefaultSetting = QString("--defaults-file=\"%1\\My.ini\"").arg(m_strMySQLPath);
//QStringList strArgs;
// strArgs << strDefaultSetting << "--skip-grant-tables";// << "--explicit_defaults_for_timestamp";
//strArgs << "--skip-grant-tables";
QString strAppWorkPath = m_strMySQLPath + "\\bin";
std::string strArgs = strDefaultSetting.toStdString().c_str();
strArgs += " --skip-grant-tables";
strArgs += " --explicit_defaults_for_timestamp";
//Process.setWorkingDirectory(strAppWorkPath);
//Process.setReadChannel(QProcess::StandardOutput);
//QProcess* pProcess = &Process;
/*connect(pProcess, &QProcess::readyReadStandardOutput, [pProcess]() {
TraceMsgA("%s.\n", pProcess->readAllStandardOutput().toStdString().c_str());
});*/
int nResult = RunWinProcess(strMySQLD.toStdString().c_str(), strArgs.c_str(), strAppWorkPath.toStdString().c_str());
//Process.start(strMySQLD, strArgs);
//QProcess::ProcessState nState;
//QProcess::ExitStatus nStatus;
//QProcess::ProcessError nError;
//QByteArray Out = Process.readAll();
//if (Process.waitForStarted(-1))
//{
// QByteArray In = Process.readAll();
// nState = Process.state();
// Process.waitForFinished(-1);
// nStatus = Process.exitStatus();
// return;
//}
//else
//{
// nState = Process.state();
// nError = Process.error();
// return;
//}
return;
}
};
class QInputDBPassword : public QDialog
{
Q_OBJECT
public:
explicit QInputDBPassword(QString strMySQLPath, unsigned short nMySQLPort, QWidget* parent = nullptr);
~QInputDBPassword();
QString GetPassword();
QMySQLDThread* m_pMySQLThread = nullptr;
CWinService ServiceMgr;;
void StartMySQLWithoutAuthenticaion()
{
/*if (m_pMySQLThread)
delete m_pMySQLThread;
m_pMySQLThread = new QMySQLDThread(m_strMySQLPath);
m_pMySQLThread->start();
while (!m_pMySQLThread->isRunning())
{
QThread::sleep(50);
}*/
QString strMySQLD = m_strMySQLPath;
strMySQLD += "\\bin\\mysqld.exe";
if (!QFileInfo::exists(strMySQLD))
return;
QString strDefaultSetting = QString("--defaults-file=\"%1\\My.ini\"").arg(m_strMySQLPath);
QString strAppWorkPath = m_strMySQLPath + "\\bin";
std::string strArgs = strDefaultSetting.toStdString().c_str();
strArgs += " --skip-grant-tables";
strArgs += " --explicit_defaults_for_timestamp";
int nResult = RunWinProcess(strMySQLD.toStdString().c_str(), strArgs.c_str(), strAppWorkPath.toStdString().c_str());
}
bool ShutDownMySQL(QString strMySQLPath)
{
QTcpSocket TcpClient;
TcpClient.connectToHost("127.0.0.1", m_nMySQLPort);
if (!TcpClient.waitForConnected(100))
{// the MySql Service not start
return true;
}
QString strMySQLAdmin = strMySQLPath;
strMySQLAdmin += "\\bin\\mysqladmin.exe";
if (!QFileInfo::exists(strMySQLAdmin))
return false;
QProcess Process;
QStringList strArgs;
// -uroot -p='' shutdown
strArgs << "-uroot" << "-p=''" << "shutdown";
Process.start(strMySQLAdmin, strArgs);
Process.waitForStarted(-1);
Process.waitForFinished(-1);
if (m_pMySQLThread)
{
m_pMySQLThread->requestInterruption();
while (m_pMySQLThread->isRunning())
{
QThread::msleep(100);
}
TraceMsgA("%s %d MySQLD Thread is exit.\n", __FUNCTION__, __LINE__);
}
//do
//{
// QTcpSocket TcpClient;
// TcpClient.connectToHost("127.0.0.1", m_nMySQLPort);
// if (!TcpClient.waitForConnected(100))
// {// the MySql Service not start
// break;
// }
// QThread::sleep(500);
//} while (true);
return true;
}
private slots:
void on_pushButton_OK_clicked();
void on_pushButton_Cancel_clicked();
void on_pushButton_ResetPassword_clicked();
void on_checkBox_HidePassword_stateChanged(int arg1);
bool ResetMySQLPassword(QString strNewPassword,QString &strMessage);
private:
Ui::QInputDBPassword *ui;
QString m_strPassword;
QString m_strMySQLService;
QString m_strMySQLPath;
unsigned short m_nMySQLPort = 3306;
};
#endif // QINPUTDBPASSWORD_H