/
functions.au3
236 lines (180 loc) · 5.94 KB
/
functions.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
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=jotter.ico
#AutoIt3Wrapper_Outfile_x64=jotter_64.exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
# Changelog v0.2.2
# Removed logging option
# Dark mode
# Change in dropdown list
# Bugfixes with the INI file
# Do not store empty files
# Save to single file
# UX is now a separate file (ux.au3)
# Added transparancy option via .ini
# Changelog v0.2.1
# Sort dropdown selectbox by date (last modified)
# New config for versioning
# Added scrollbar to dropdown list
# Show limited items in dropdown (10)
# Changelog v0.2
# Added reminders to the text
# Changelog v0.1.1
# Changed filenames to %DD-%MM-%YYY.txt
# Changelog v0.1
# First release
# File: functions.au3
Func _CheckFileExist($FileToCheck)
# Controleer of het bestand voor vandaag al bestaat. Zo niet, maak het aan.
If Not FileExists($FileToCheck) Then
$hFileOpen = FileOpen($FileToCheck, 2)
If @error > 0 then
MsgBox($MB_SYSTEMMODAL, "Error while writing", "Error writing " & $FileToCheck & " in " & $SavePath & ". Exiting...")
Exit
EndIf
If FileExists("default.txt") Then
$hdefaultOpen = FileOpen("default.txt", 0)
$defaultTXT = FileRead("default.txt")
Else
$defaultTXT = ""
EndIf
FileWriteLine($hFileOpen, $defaultTXT)
FileClose($hFileOpen)
Endif
EndFunc
Func _CheckForReminders($RemStart, $txtfile)
AdlibUnRegister("TimerSaveFile")
$CheckForReminders = FileOpen($txtfile, $FO_READ)
$NewTxt = ""
$Reminded = "false"
For $i = 1 to _FileCountLines($CheckForReminders)
$line = FileReadLine($CheckForReminders, $i)
if StringLeft($line, StringLen($RemStart)) = $RemStart Then
if StringMid($line, StringLen($RemStart)+2, 5) = _NowTime(4) Then
AdLibUnRegister("TimerReminderCheck")
$Message = stringRight($line, StringLen($line) - stringLen($RemStart) - 7)
Traytip($ReminderTitle, _NowTime(4) & " | " & $Message, 30, 1)
ConsoleWrite(_NowTime(4) & " | " & $Message & @CRLF)
# _WinAPI_MessageBeep(2)
$line = StringReplace($line, $RemStart, "[Reminded!]")
$Reminded = "true"
EndIf
EndIf
if $i = 1 then
$NewTxt = $line
Else
$NewTxt = $NewTxt & @crlf & $line
EndIf
Next
FileClose($txtfile)
if $Reminded = "true" Then
GUICtrlSetData($Notitie, $NewTxt)
EndIf
AdlibRegister("TimerSaveFile", 45)
AdLibRegister("TimerReminderCheck", 490)
EndFunc
Func _ConvertFileName($Pattern)
# Bepaal de bestandsnaam voor vandaag op basis van het %Pattern% uit de INI-file
Local $dag, $tijd
Local $datum = _DateTimeSplit(_DateTimeFormat(_NowCalc(), 2), $dag, $tijd)
if stringlen($dag[1]) = 2 Then
$Filename = StringReplace($Pattern, "%DD", $dag[1])
Else
$Filename = StringReplace($Pattern, "%DD", "0" & $dag[1])
EndIf
if stringlen($dag[2]) = 2 Then
$FileName = StringReplace($Filename, "%MM", $dag[2])
Else
$FileName = StringReplace($Filename, "%MM", "0" & $dag[2])
EndIf
$FileName = StringReplace($Filename, "%YYYY", $dag[3])
Return $Filename
EndFunc
Func _FileCheckOnExit($Content, $TodayFileVar)
If $Content = "" Then
FileDelete($TodayFileVar)
EndIf
EndFunc
Func _GetFileLastModifiedDate($sFilename)
Return Number(FileGetTime($SavePath & "\" & $sFilename, 0, 1))
EndFunc
Func _OpenFile($FileToOpen)
# Open het bestand en toon de inhoud in de Editbox
$hFileOpen = FileOpen($FileToOpen,0)
If @error > 0 then
MsgBox($MB_SYSTEMMODAL, "Error while opening ", "Error opening " & $FileToOpen & " in " & $SavePath & ". Exiting...")
Exit
EndIf
$txtNote = FileRead($hFileOpen)
If @error > 0 then
MsgBox($MB_SYSTEMMODAL, "Error while reading", "Error reading " & $FileToOpen & " in " & $SavePath & ". Exiting...")
Exit
EndIf
FileClose($hFileOpen)
GUICtrlSetData($Notitie, $txtNote)
EndFunc
Func _PopulateListBox($PathToLook)
Local $aFileList = _FileListToArray($PathToLook, "*.txt",0,0)
If @error = 1 Then
Msgbox($MB_SYSTEMMODAL, "Error while reading", "Path (" & $PathToLook & ") is invalid. Exiting...")
Exit
EndIf
If @error = 4 Then
MsgBox($MB_SYSTEMMODAL, "Error while reading", "No file(s) were found in " & $PathToLook & ". Exiting...")
Exit
EndIf
_ArrayDelete($aFileList, 0)
_Sort($aFileList)
For $File in $aFileList
if StringUpper($File) = $SaveFile then
GUICtrlSetData($NotesList, $File, $File)
Else
GUICtrlSetData($NotesList, $File)
Endif
Next
EndFunc
Func _Sort(ByRef $aArray)
For $i = UBound($aArray) - 1 To 1 Step -1
For $j = 1 To $i
If _GetFileLastModifiedDate($aArray[$j - 1]) >_GetFileLastModifiedDate($aArray[$j]) Then
$temp = $aArray[$j - 1]
$aArray[$j - 1] = $aArray[$j]
$aArray[$j] = $temp
EndIf
Next
Next
Return $aArray
EndFunc
Func _SaveFile($FileToSave)
# Sla het bestand op in het aangegeven bestand
$NoteToSave = GUICtrlRead($Notitie)
$hFileOpen = FileOpen($FileToSave, 2)
If @error > 0 then
MsgBox($MB_SYSTEMMODAL, "Error while saving", "Error saving " & $FileToSave & " in " & $SavePath & ". Exiting...")
Exit
EndIf
FileWrite($hFileOpen, $NoteToSave)
If @error > 0 then
MsgBox($MB_SYSTEMMODAL, "Error while saving", "Error saving " & $FileToSave & " in " & $SavePath & ". Exiting...")
Exit
EndIf
FileClose($hFileOpen)
EndFunc
Func _SetFormTitle($Edit, $AutoSave, $Reminders)
$formTitle = $Title & " " & $Version & " | " & $SaveFile
if $Singlefile = "false" Then
$formTitle = $formTitle & " | Edit " & $Edit & " | Autosave " & $AutoSave & " | Reminders " & $Reminders
Else
$formTitle = $formTitle & " | Mode: Single File" & " | Reminders " & $Reminders
EndIf
Return $formTitle
EndFunc
Func TimerSaveFile()
# Kapstokfunctie voor het automatisch saven van de notitie met AdlibRegister
_SaveFile($SavePath & "\" & $SaveFile)
EndFunc
Func TimerReminderCheck()
# Kapstopfunctie voor het automatisch starten van de Check op reminders
_CheckForReminders($ReminderStart, $SavePath & "\" & $SaveFile)
EndFunc