-
Notifications
You must be signed in to change notification settings - Fork 0
/
Common.bas
394 lines (228 loc) · 9.75 KB
/
Common.bas
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
Attribute VB_Name = "Common"
Option Explicit
Public Const Const_Website = "Our website is ( www.mama520.cn )....\"
Public Const Const_UserDBFile = "PrivateUser.DB"
Public Const Const_CustomerFile = "Private.ini"
Public Const Const_SkinFile = "Private.dat"
Public Const Const_DefaultURL = "http://www.mama520.cn/Software_AD/PrivateMaMa/index.htm"
Public IsFirstRun As Boolean
Public g_UserPwd As String
Public g_URL As String
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
'for top most window
Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Const SWP_SHOWWINDOW = &H40
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Function SetTopMostWindow(ByVal thwnd As Long, ByVal b As Boolean) As Boolean
If b Then
If SetWindowPos(thwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE) <> 0 Then SetTopMostWindow = True Else SetTopMostWindow = False
Else
If SetWindowPos(thwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE) <> 0 Then SetTopMostWindow = True Else SetTopMostWindow = False
End If
End Function
Public Function AppPath() As String
Dim sPath As String
sPath = App.Path
If Right(App.Path, 1) <> "\" Then
sPath = sPath + "\"
End If
AppPath = LCase(sPath)
End Function
Public Function GetDriveTypeOfString(ByVal sDrvName As String) As String
Select Case GetDriveType(sDrvName)
Case 0
GetDriveTypeOfString = "不明"
Case 2
GetDriveTypeOfString = "移动盘" '包括软盘与U盘
Case 3
GetDriveTypeOfString = "硬盘"
Case 4
GetDriveTypeOfString = "网络盘"
Case 5
GetDriveTypeOfString = "光驱"
Case 6
GetDriveTypeOfString = "RamDisk"
Case Else
GetDriveTypeOfString = "不明"
End Select
End Function
Public Function GetSystemDrive() As String
GetSystemDrive = Environ("SystemDrive") + "\"
End Function
Public Function AppPrePath() As String
'当使用FilePacker压缩时,解压后,读取上级目录的功能。
'此处得到应用程序上级目录,以方便读取个性化配置文档
'Const_CustomerFile 常量所对应的文件。
Dim sPath As String
Dim FileName As String
Dim FilePrePath As String
Dim sTmp As String
Dim iPos As Integer
sPath = App.Path
If Right(App.Path, 1) <> "\" Then
sTmp = StrReverse(sPath)
iPos = InStr(sTmp, "\")
FilePrePath = Mid(sTmp, iPos)
FilePrePath = StrReverse(FilePrePath)
sPath = FilePrePath
End If
AppPrePath = LCase(sPath)
End Function
Public Function HasPassword() As Boolean
On Error GoTo err
'MkDir GetAppLocalDisk & Const_Website
'RmDir GetAppLocalDisk & Const_Website
HasPassword = False
Exit Function
err:
HasPassword = True
End Function
Public Sub InIt()
On Error Resume Next
Dim FileNum As Integer
Dim sBatFile As String
Kill AppPath() & Const_UserDBFile
sBatFile = GetSystemDrive() & "HappyQQ__5_5abc5_Pwd520.bat"
g_URL = Const_DefaultURL
FileNum = FreeFile
Open sBatFile For Output As #FileNum
Print #FileNum, "Copy/y """ & GetAppLocalDisk & Const_Website & Const_UserDBFile; """ """ & AppPath() + Const_UserDBFile; """"
Print #FileNum, "del %0"
Close #FileNum
Shell sBatFile, vbHide
' Dim bHasPwd As Boolean
'
' ' bHasPwd = HasPassword()
'
'
' If bHasPwd Then
'
'' While Dir(AppPath() + Const_UserDBFile) = ""
'' Wend
' Sleep (2000)
'
' End If
Sleep (2000)
Dim sAppTitle, sAppBoldTitle, sAppMessage, sPrivateURL, sRegisterCode As String
Dim sUserName, sPwd As String
frmMain.txtMachineCode.Text = GetDriveSerialNumber()
sRegisterCode = GetIniParam(AppPath() & Const_UserDBFile, "Config", "RegisterCode")
frmMain.txtRegisterCode.Text = IIf(sRegisterCode = "", frmMain.txtRegisterCode.Text, sRegisterCode)
'这一部分保存在User.DB里面
sUserName = GetIniParam(AppPath() & Const_UserDBFile, "Config", "UserID")
sPwd = GetIniParam(AppPath() & Const_UserDBFile, "Config", "UserPwd")
If sRegisterCode = CalculateMD5("www.mama520.cn" & frmMain.txtMachineCode.Text & "HappyQQ520") Then
sAppTitle = GetIniParam(AppPath() & Const_CustomerFile, "Config", "AppTitle")
sAppBoldTitle = GetIniParam(AppPath() & Const_CustomerFile, "Config", "AppBoldTitle")
sAppMessage = GetIniParam(AppPath() & Const_CustomerFile, "Config", "AppMessage")
sPrivateURL = GetIniParam(AppPath() & Const_CustomerFile, "Config", "PrivateURL")
g_URL = IIf(sPrivateURL = "", Const_DefaultURL, sPrivateURL)
End If
frmMain.Caption = IIf(sAppTitle = "", frmMain.Caption, sAppTitle)
frmMain.lblBoldTitle = IIf(sAppBoldTitle = "", frmMain.lblBoldTitle.Caption, Left(sAppBoldTitle, 9))
frmMain.lblMessage = IIf(sAppMessage = "", frmMain.lblMessage.Caption, sAppMessage)
frmMain.txtUserID.Text = IIf(sUserName = "", frmMain.txtUserID.Text, sUserName)
' frmMain.txtPwd.Text = IIf(sPwd = "", frmMain.txtPwd.Text, sPwd)
If Dir(AppPath() + Const_UserDBFile) = "" Then
IsFirstRun = True
frmMain.txtPwd.Text = "888888"
g_UserPwd = CalculateMD5(frmMain.txtPwd.Text)
MkDir GetAppLocalDisk & Const_Website
' frmMain.Hide
' frmSetting.Show
' frmSetting.SetFocus
Else
frmMain.txtPwd.Text = ""
g_UserPwd = sPwd
IsFirstRun = False
End If
'MkDir AppPath() & Const_Website
' MsgBox """" & AppPath() & Const_Website & Const_UserDBFile & """"
' FileCopy """" & AppPath() & Const_Website & Const_UserDBFile & """", AppPath() + Const_UserDBFile
End Sub
Public Sub SaveUserDB()
On Error Resume Next
Dim FileNum As Integer
Dim sBatFile As String
WriteWinIniParam AppPath() & Const_UserDBFile, "Config", "UserID", frmSetting.txtUserID.Text
WriteWinIniParam AppPath() & Const_UserDBFile, "Config", "UserPwd", CalculateMD5(frmSetting.txtNewPwd1.Text)
WriteWinIniParam AppPath() & Const_UserDBFile, "Config", "RegisterCode", frmMain.txtRegisterCode.Text
g_UserPwd = CalculateMD5(frmSetting.txtNewPwd1.Text)
sBatFile = GetSystemDrive() & "HappyQQ__Save_5abcSave_Pwd520.bat"
FileNum = FreeFile
Open sBatFile For Output As #FileNum
Print #FileNum, "Copy/y """ & AppPath() & Const_UserDBFile & """ """ & GetAppLocalDisk & Const_Website & """"
Print #FileNum, "del """ & AppPath() & Const_UserDBFile & """"
Print #FileNum, "del %0"
Close #FileNum
Shell sBatFile, vbHide
frmMain.txtPwd.Text = frmSetting.txtNewPwd1.Text
End Sub
Public Function GetAppLocalDisk() As String
GetAppLocalDisk = Left(App.Path, 3)
End Function
Public Function CheckPassword(ByVal sPwd As String) As Boolean
CheckPassword = (CalculateMD5(sPwd) = g_UserPwd)
End Function
Public Function CheckProtectFile(ByVal sFilePath As String) As Boolean
Dim sProtectFilePath(4) As String
Dim i As Integer
sProtectFilePath(0) = GetSystemDrive() & "RECYCLER"
sProtectFilePath(1) = GetSystemDrive() & "WINDOWS"
sProtectFilePath(2) = GetSystemDrive() & "Program Files"
sProtectFilePath(3) = GetSystemDrive() & "Documents and Settings"
For i = 0 To 3
If InStr(1, sFilePath, sProtectFilePath(i)) <> 0 Then
Exit For
End If
Next i
If i > 3 Then
CheckProtectFile = False
Else
CheckProtectFile = True
End If
End Function
Public Sub EncryptFilePath(ByVal sFilePath As String)
On Error Resume Next
Dim FileNum As Integer
Dim sBatFile As String
sBatFile = GetSystemDrive() & "HappyQQ__0_0abc0_1314520.bat"
FileNum = FreeFile
Open sBatFile For Output As #FileNum
Print #FileNum, "md """ & sFilePath; "..\"""
Print #FileNum, "md """ & sFilePath; "...\"""
Print #FileNum, "move """ & sFilePath; """ """ & sFilePath; "...\"""
Print #FileNum, "rd """ & sFilePath; "...\"""
Print #FileNum, "del %0"
Close #FileNum
Shell sBatFile, vbHide
End Sub
Public Sub DecryptFilePath(ByVal sFilePath As String)
On Error Resume Next
Dim FileNum As Integer
Dim FileName As String
Dim FilePrePath As String
Dim sTmp As String
Dim iPos As Integer
Dim sBatFile As String
sBatFile = GetSystemDrive() & "HappyQQ__1_1cab1_1314520.bat"
sTmp = StrReverse(sFilePath)
iPos = InStr(sTmp, "\")
FileName = Left(sTmp, iPos - 1)
FileName = StrReverse(FileName)
FilePrePath = Mid(sTmp, iPos)
FilePrePath = StrReverse(FilePrePath)
FileNum = FreeFile
Open sBatFile For Output As #FileNum
Print #FileNum, "md """ & sFilePath; "...\"""
Print #FileNum, "move """ & sFilePath; "...\\" & FileName & """ """ & FilePrePath & """"
Print #FileNum, "rd """ & sFilePath; "...\"""
Print #FileNum, "rd """ & sFilePath; "..\"""
Print #FileNum, "del %0"
Close #FileNum
Shell sBatFile, vbHide
End Sub