-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.au3
326 lines (273 loc) · 13.1 KB
/
main.au3
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
#NoTrayIcon
#Region
#AutoIt3Wrapper_Icon=pakar.ico
;#AutoIt3Wrapper_Run_After="EXE Signer.exe"
#AutoIt3Wrapper_Outfile=התרעות צבע אדום.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Comment=Yehuda Eisenberg - יהודה אייזנברג
#AutoIt3Wrapper_Res_Description=תוכנה לעדכון על התרעות צבע אדום
#AutoIt3Wrapper_Res_Fileversion=1.0.8
#AutoIt3Wrapper_Res_ProductName=תוכנה לעדכון על התרעות צבע אדום
#AutoIt3Wrapper_Res_ProductVersion=1.0.8
#AutoIt3Wrapper_Res_CompanyName=Yehuda Software
#AutoIt3Wrapper_Res_LegalCopyright=Yehuda Eisenberg - יהודה אייזנברג
#AutoIt3Wrapper_Res_Language=1037
#AutoIt3Wrapper_Res_Field=ProductName|תוכנה לעדכון על התרעות צבע אדום
#AutoIt3Wrapper_Res_Field=ProductVersion|1.0.8
#AutoIt3Wrapper_Res_Field=CompanyName|Yehuda Eisenberg - יהודה אייזנברג
#EndRegion
#include <Inet.au3>
#include <Misc.au3>
#include <Date.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <ListviewConstants.au3>
#include "json/json.au3"
#include "notify/notify.au3"
#include "locations.au3"
Global $sProvider = "inn"
Global $sPakarAlertLinkInn = "https://www.inn.co.il/Generic/PakarAlerts/all"
Global $sPakarAlertLinkOref = "https://www.oref.org.il/WarningMessages/History/AlertsHistory.json"
Global $sPakarAlertLinkOref2 = "https://www.oref.org.il/Shared/Ajax/GetAlarmsHistory.aspx"
Global $aLastAlertsInn[0]
Global $aLastAlertsOref[0]
Global $sConfigPath = @AppDataDir & "\RedAlert.config"
If Not FileExists($sConfigPath) Then
IniWrite($sConfigPath, "General", "Sound", "Work")
IniWrite($sConfigPath, "General", "Mode", "Work")
IniWrite($sConfigPath, "General", "Locations", "All")
EndIf
Func _ReduceMemory()
Local $aReturn = DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1)
If @error = 1 Then
Return SetError(1, 0, 0)
EndIf
Return $aReturn[0]
EndFunc ;==>_ReduceMemory
Func _CheckAlertsInn()
If Ping("inn.co.il", 100) Then
HttpSetUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36")
Local $sData = BinaryToString(InetRead($sPakarAlertLinkInn), 4)
Local $aAlerts = Json_Decode($sData)
Local $i = 0
While (StringLen(Json_Get($aAlerts, '["list"][' & $i & ']["RedWebNo"]')) > 0)
Local $RedWebNo = Json_Get($aAlerts, '["list"][' & $i & ']["RedWebNo"]')
Local $alertId = Json_Get($aAlerts, '["list"][' & $i & ']["TtlUniversalTime"]') & Json_Get($aAlerts, '["list"][' & $i & ']["AlertTime"]') & Json_Get($aAlerts, '["list"][' & $i & ']["Header"]') & Json_Get($aAlerts, '["list"][' & $i & ']["RedWebNo"]')
If $RedWebNo <> "998" And $RedWebNo <> "999" And $RedWebNo <> "0" And $RedWebNo <> "1" And $RedWebNo <> "3002" And $RedWebNo <> "3004" And $RedWebNo <> "3005" And $RedWebNo <> "3006" And $RedWebNo <> "3007" And $RedWebNo <> "3000" Then
Local $iArrayId = _ArraySearch($aLastAlertsInn, $alertId)
If $iArrayId = -1 And (@error = 6 Or @error = 3) Then
ReDim $aLastAlertsInn[UBound($aLastAlertsInn) + 1]
$aLastAlertsInn[UBound($aLastAlertsInn) - 1] = $alertId
_ShowAlert(Json_Get($aAlerts, '["list"][' & $i & ']["Header"]'))
EndIf
EndIf
$i = $i + 1
WEnd
If $i = 0 Then
Local $aTmp[0]
$aLastAlertsInn = $aTmp
EndIf
EndIf
EndFunc
Func _CheckAlertsOref()
HttpSetUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36")
Local $sData = BinaryToString(InetRead($sPakarAlertLinkOref), 4)
Local $aAlerts = Json_Decode($sData)
Local $i = 0
While _DateDiff("s", StringReplace(Json_Get($aAlerts, '[' & $i & ']["alertDate"]'), "-", "/"), _NowCalc()) < 30
Local $alertId = Json_Get($aAlerts, '[' & $i & ']["alertDate"]') & "|" & Json_Get($aAlerts, '[' & $i & ']["data"]')
Local $iArrayId = _ArraySearch($aLastAlertsOref, $alertId)
If $iArrayId = -1 And (@error = 6 Or @error = 3) Then
ReDim $aLastAlertsOref[UBound($aLastAlertsOref) + 1]
$aLastAlertsOref[UBound($aLastAlertsOref) - 1] = $alertId
_ShowAlert(Json_Get($aAlerts, '[' & $i & ']["data"]'))
EndIf
$i = $i + 1
WEnd
If $i = 0 Then
Local $aTmp[0]
$aLastAlertsOref = $aTmp
EndIf
EndFunc
Func _CheckZone($sZone)
If $sZone = "***בדיקה***" Then Return True
Local $aCurrentLocations = IniRead($sConfigPath, "General", "Locations", "All")
If $aCurrentLocations = "All" Then Return True
Local $iIndex = _ArraySearch($aLocations, $sZone, 0, 0, 0, 0, 1, 3)
If @error Then
Return False
EndIf
If StringInStr($aCurrentLocations, "," & $iIndex & ",") Then
Return True
Else
Return False
EndIf
EndFunc
Func _ShowAlert($sZone)
If Not _CheckZone($sZone) Then Return
FileInstall("pakar.ico", @TempDir & "\PAKAR-Icon.ico", 1)
FileInstall("alarm.mp3", @TempDir & "\PAKAR-Alarm.mp3", 1)
If IniRead($sConfigPath, "General", "Sound", "Work") = "Work" Then
SoundPlay(@TempDir & "\PAKAR-Alarm.mp3", 0)
EndIf
_Notify_Set(0, 0xFF0000, 0xFFFF00, "Arial", False, 250)
_Notify_Show(@TempDir & "\PAKAR-Icon.ico", "התרעת צבע אדום!", "התרעת צבע אדום בישוב " & $sZone & ".", 5)
EndFunc
If $cmdLine[0] > 0 Then
If $cmdLine[1] = "ChooseLocations" Then
If _Singleton("Pakar-YE-Single-ChooseLocations", 1) = 0 Then Exit
Local $w = 650, $h = 350, $minW = 15
Local $hGUI = GUICreate("התרעות צבע אדום - בחירת אזורים", $w, $h, -1, -1, -1, 0x400000)
Local $idList = GUICtrlCreateListView("מקום התרעה|אזור התרעה", $minW, 40, $w - 30, 260, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES))
Local $idButton_Done = GUICtrlCreateButton("סיום", $w - 64, $h - 40, 50, 25)
Local $idButton_All = GUICtrlCreateButton("בחר הכל", 15, $h - 40, 70, 25)
GUICtrlCreateLabel("בחר את המקומות עבורן תרצה שתופעל התרעה", $minW, 15)
GUICtrlSendMsg($idList, $LVM_SETCOLUMNWIDTH, 0, $w - 210)
GUICtrlSendMsg($idList, $LVM_SETCOLUMNWIDTH, 1, $w - 500)
GUISetState(@SW_SHOW, $idList)
GUISetState(@SW_SHOW, $hGUI)
Local $sOldLocations = IniRead($sConfigPath, "General", "Locations", "")
Local $ApplicationFrameHost = False
For $i = 0 To UBound($aLocations) - 1
GUICtrlCreateListViewItem($aLocations[$i][3] & "|" & $aLocations[$i][2], $idList)
If StringInStr($sOldLocations, "," & $i & ",") Then _GUICtrlListView_SetItemChecked($idList, $i)
Next
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $idButton_Done
ExitLoop
Case $idButton_All
GUIDelete($hGUI)
IniWrite($sConfigPath, "General", "Locations", "All")
MsgBox(BitOR(0x40, 0x100000), "התרעות צבע אדום", "אזורי ההתרעה עודכנו בהצלחה.", 10)
Exit
EndSwitch
WEnd
GUISetState(@SW_HIDE, $hGUI)
IniWrite($sConfigPath, "General", "Locations", ",")
For $i = 0 To UBound($aLocations) - 1
If _GUICtrlListView_GetItemChecked($idList, $i) = True Then
$tmpIni = IniRead($sConfigPath, "General", "Locations", "")
IniWrite($sConfigPath, "General", "Locations", $tmpIni & $i & ",")
EndIf
Next
GUIDelete($hGUI)
MsgBox(BitOR(0x40, 0x100000), "התרעות צבע אדום", "אזורי ההתרעה עודכנו בהצלחה.", 10)
Exit
EndIf
If $cmdLine[1] = "Core" Then
If _Singleton("Pakar-YE-Single-Core", 1) = 0 Then Exit
While True
If IniRead($sConfigPath, "General", "Mode", "Work") = "Work" Then
If $sProvider = "inn" Then
_CheckAlertsInn()
Else
_CheckAlertsOref()
EndIf
If IniRead($sConfigPath, "General", "Close", "Nop") = "Yup" Then
IniDelete($sConfigPath, "General", "Close")
Exit
EndIf
EndIf
WEnd
EndIf
EndIf
If _Singleton("Pakar-YE-Single", 1) = 0 Then
MsgBox(BitOR(0x30, 0x100000), "התרעות צבע אדום", "התוכנה כבר פועלת...", 5)
Exit
EndIf
HttpSetUserAgent("AU3-Pakar-UA")
Local $sCheckVer = BinaryToString(InetRead("https://test.yehudae.net/pakar-i.php?version=" & FileGetVersion(@ScriptFullPath)), 4)
If $sCheckVer = "abc" Then
MsgBox(BitOR(0x10, 0x100000), "התרעות צבע אדום", "קיימת גרסה מעודכנת יותר. אנא הורד אותה מהקישור:" & @CRLF & "https://files.yehudae.net/redAlarm", 10)
ShellExecute("https://l.yehudae.net/redAlarm")
Exit
EndIf
If Not Ping("inn.co.il", 250) Then
MsgBox(BitOR(0x30, 0x100000), "התרעות צבע אדום", "התוכנה זיהתה בעיה באינטרנט, התוכנה לא תדווח על התרעות עד אשר תתחבר לאינטרנט.")
EndIf
FileDelete(@AppDataDir & "\Microsoft\Windows\Start Menu\Programs\StartUp\התראות צבע אדום.exe")
FileDelete(@AppDataDir & "\Microsoft\Windows\Start Menu\Programs\StartUp\התראות צבע התרעות.exe")
If @ScriptDir <> @AppDataDir & "\Microsoft\Windows\Start Menu\Programs\StartUp" Then
FileCopy(@ScriptFullPath, @AppDataDir & "\Microsoft\Windows\Start Menu\Programs\StartUp\התרעות צבע אדום.exe", 1)
EndIf
_Notify_RegMsg()
_Notify_Locate(3)
Opt("TrayIconHide", 0)
Opt("TrayMenuMode", 3)
TraySetToolTip("התרעות צבע אדום (v" & FileGetVersion(@ScriptFullPath) & ") - ספק: ערוץ 7")
;Local $idTrayProvider = TrayCreateItem("החלף ספק לפיקוד העורף (פחות מהימן)")
Local $idTrayChoose = TrayCreateItem("בחר את האזורים עבורם תופעל התרעה")
Local $idTrayPause = TrayCreateItem("השהה את פעילות המערכת")
Local $idTraySound = TrayCreateItem("כבה התרעות קוליות")
Local $idTrayDemo = TrayCreateItem("התרעה לבדיקה")
Local $idTrayMail = TrayCreateItem("לשליחת הודעה למתכנת")
Local $idTraySite = TrayCreateItem("אתר התוכנה")
Local $idTraySource = TrayCreateItem("קוד מקור התוכנה")
Local $idTrayExit = TrayCreateItem("סגירת התוכנה")
If IniRead($sConfigPath, "General", "Mode", "Work") = "Work" Then
MsgBox(BitOR(0x40, 0x100000), "התרעות צבע אדום", "התוכנה התחילה לרוץ.", 5)
Else
TrayItemSetText($idTrayPause, "הפעל את פעילות המערכת")
MsgBox(BitOR(0x40, 0x100000), "התרעות צבע אדום", "התוכנה התחילה לרוץ (אך היא מושהית).", 5)
EndIf
Run(@ScriptFullPath & " Core")
While True
_ReduceMemory()
Switch TrayGetMsg()
#cs
Case $idTrayProvider
If $sProvider = "inn" Then
MsgBox(BitOR(0x40, 0x100000), "התרעות צבע אדום", "הספק הוחלף לפיקוד העורף. לתשומך ליבך, ספק זה הינו פחות מיהמן.", 5)
TrayItemSetText($idTrayProvider, "החלף ספק לערוץ 7 (יותר מהימן)")
TraySetToolTip("התרעות צבע אדום (v" & FileGetVersion(@ScriptFullPath) & ") - ספק: פיקוד העורף")
$sProvider = "oref"
Else
MsgBox(BitOR(0x40, 0x100000), "התרעות צבע אדום", "הספק הוחלף לערוץ 7.", 5)
TrayItemSetText($idTrayProvider, "החלף ספק לפיקוד העורף (פחות מהימן)")
TraySetToolTip("התרעות צבע אדום (v" & FileGetVersion(@ScriptFullPath) & ") - ספק: ערוץ 7")
$sProvider = "inn"
EndIf
#ce
Case $idTrayChoose
Run(@ScriptFullPath & " ChooseLocations")
Case $idTrayPause
If IniRead($sConfigPath, "General", "Mode", "Work") = "Work" Then
IniWrite($sConfigPath, "General", "Mode", "Work")
MsgBox(BitOR(0x40, 0x100000), "התרעות צבע אדום", "התוכנה המשיכה את פעולתה.", 5)
TrayItemSetText($idTrayPause, "השהה את פעילות המערכת")
Else
IniWrite($sConfigPath, "General", "Mode", "Pause")
MsgBox(BitOR(0x40, 0x100000), "התרעות צבע אדום", "התוכנה השהתה את פעולתה.", 5)
TrayItemSetText($idTrayPause, "הפעל את פעילות המערכת")
EndIf
Case $idTraySound
If IniRead($sConfigPath, "General", "Sound", "Work") = "Work" Then
IniWrite($sConfigPath, "General", "Sound", "Pause")
MsgBox(BitOR(0x40, 0x100000), "התרעות צבע אדום", "ההתרעות הקוליות כבויות.", 5)
TrayItemSetText($idTraySound, "הפעל התרעות קוליות")
Else
IniWrite($sConfigPath, "General", "Sound", "Work")
MsgBox(BitOR(0x40, 0x100000), "התרעות צבע אדום", "ההתרעות הקוליות דלוקות.", 5)
TrayItemSetText($idTraySound, "כבה התרעות קוליות")
EndIf
Case $idTrayDemo
_ShowAlert("***בדיקה***")
Case $idTrayMail
ShellExecute("mailto:[email protected]")
Case $idTraySite
ShellExecute("https://l.yehudae.net/redAlarm")
Case $idTraySource
ShellExecute("https://l.yehudae.net/RedAlarmSource")
Case $idTrayExit
MsgBox(BitOR(0x40, 0x100000), "התרעות צבע אדום", "להתראות.", 3)
IniWrite($sConfigPath, "General", "Close", "Yup")
ProcessClose(@ScriptName)
Exit
EndSwitch
WEnd