-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbackup-indicator.ahk
executable file
·118 lines (98 loc) · 3.09 KB
/
backup-indicator.ahk
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
; Version: 27 februari 2013
; AutoHotkey script to check if the backup is running.
#NoTrayIcon ; Initially hide the icon.
script_dir = %A_ScriptDir%
; backups are placed in a subfolder name $identifier, the identifier is also used as a lockfile
; Note, %A_ComputerName% isn't used because it returns the name as uppercase.
RegRead, identifier
, HKEY_LOCAL_MACHINE
, SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
, NV Hostname
; Determine lockfile, the identifier is used as a name for the lockfile
lockfile = %script_dir%\%identifier%.lck
; == START of PID check ==
is_pid_running(pid)
{
; The following line can be used if the process PID is shown in the Windows process list.
; Process, Exist, %pid% ; check to see if the backup is running
; The following return can only be used with the function 'Process, Exist'.
; return (%ErrorLevel% = %pid%)
; Since the backup expects the backup to be running in cygwin, another approach must be made.
; The ps and grep executables from cygwin will be run
RunWait "c:\cygwin\bin\ps.exe" -p %pid% | "c:\cygwin\bin\grep.exe" %pid%, , Hide
; For cygwin, the %ErrorLevel% equals 0 if the process is running.
return (%ErrorLevel% = 0)
}
; == END of PID check ==
show_start_notification := true
show_stop_notification := true
; show a notification for 3 seconds
show_notification(message)
{
TrayTip, Backup, %message%, 3
return
}
show_start_notification()
{
global show_start_notification
global show_stop_notification
if (show_start_notification = true)
{
show_notification("Backup started")
show_start_notification := false
show_stop_notification := true
}
return
}
show_stop_notification()
{
global show_start_notification
global show_stop_notification
if (show_stop_notification = true)
{
show_notification("Backup stopped")
show_start_notification := true
show_stop_notification := false
sleep 3500 ; Give the message time to be displayed, it is hidden when the icon is.
}
return
}
set_status()
{
global lockfile
IfExist, %lockfile%
{
; File is found, get the pid from it and see if the process is really running.
; If it's not, it probably belongs to a ghost backup process (probably crashed).
FileReadLine, pid, %lockfile%, 1
pid := pid ; Convert string to integer.
if (ErrorLevel = 0 and is_pid_running(pid))
{
Menu, Tray, Icon ; Display the icon.
show_start_notification()
}
else
{
show_stop_notification()
Menu, Tray, NoIcon ; Hide the icon.
}
}
else
{
show_stop_notification()
Menu, Tray, NoIcon ; Hide the icon.
}
}
; Create the status indicator
icon = %script_dir%/backup-windows7_20x20.ico
Menu, Tray, Icon, %icon%
Menu, Tray, NoStandard ; remove standard Menu items
Menu, Tray, Tip, Backup running ; remove standard Menu items
set_status() ; set initial status
; Start a loop which keeps checking the backup status.
#Persistent
SetTimer, SetStatus, 1000
return
SetStatus:
set_status()
return