To configure, compile program with whatever name you wish then click Tools > Configure Tools > Click New
Now edit to something similar:
Commandline: C:\Tools\MyToolsName.exe
Arguments: %FILE
Name: Whatever you want
Event to trigger the tool:
Sourcecode saved
To prevent an annoying console from popping up every save, I have Run Hidden checked
Code modifications have been created in below posts. Check them out if you use this tool!
Code: Select all
; ---------------------------------------------------------------------------------------------
; author: nituvious
; notes:
; This program will try to modify your source code by adding the date
; upon saving the file. If it finds a date recorded already, it will attempt
; to overwrite it with the current date and time.
; Otherwise it will automatically add the date at the beginning of the file.
; This program includes fully changable date/time functions as well.
;
; Please let me know of any bugs!
;
; ---------------------------------------------------------------------------------------------
; last modified: February 27th, 2011 @ 3:24:05 AM
; ---------------------------------------------------------------------------------------------
#C12HOUR = 12 ; silly constants, trying to pretend to be a clock!
#C24HOUR = 24
Procedure.s GetDate()
gMonth.b = Month(Date()) : gDay.b = Day(Date()) : gYear.i = Year(Date())
Dim monthName.s(12) ; set each month by it's english name into an array
; I am not aware of any native PB function that formats the date with a string
monthName.s(0) = "none" ; <-- the array should only have 11 elements, but for sake of simplicity(my favorite thing in the world) it will have 12 elements instead
monthName.s(1) = "January"
monthName.s(2) = "February"
monthName.s(3) = "March"
monthName.s(4) = "April"
monthName.s(5) = "May"
monthName.s(6) = "June"
monthName.s(7) = "July"
monthName.s(8) = "August"
monthName.s(9) = "September"
monthName.s(10) = "October"
monthName.s(11) = "November"
monthName.s(12) = "December" ; <-- my favorite month
; give each day ending with 1, 2, 3, 4... 23,24 etc their proper ordinal suffix
If (Val(Mid(Str(gDay.b),Len(Str(gDay.b)))) = 1) : ordSuffix.s = "st"
ElseIf (Val(Mid(Str(gDay.b),Len(Str(gDay.b)))) = 2) : ordSuffix.s = "nd"
ElseIf (Val(Mid(Str(gDay.b),Len(Str(gDay.b)))) = 3) : ordSuffix.s = "rd"
Else : ordSuffix.s = "th" : EndIf
gDate.s = monthName.s(gMonth.b) + " " + Str(gDay.b)+ ordSuffix.s + ", " + Str(gYear.i)
ProcedureReturn gDate.s
EndProcedure
Procedure.S GetTime(const)
; depending on user settings, should this date be displayed as a 24 hour clock, or 12 hour?
; format 12 hour clock...
gHour.i = Hour(Date())
If const = #C12HOUR ; this is my crappy time conversion function which will add meridiem if the 12 hour clock is used
If gHour.i >= 13
gHour_n.i = gHour.i - 12
gMeridiem.s = "PM"
Else
If gHour.i = 0
gHour_n = 12
EndIf
gHour_n.i = gHour.i
gMeridiem.s = "AM"
EndIf
gTime.s = Str(gHour_n.i) + ":" + FormatDate("%ii:%ss",Date()) + " " + gMeridiem.s
ProcedureReturn gTime.s
ElseIf const = #C24HOUR
gTime.s = FormatDate("%hh:%ii:%ss",Date())
ProcedureReturn gTime.s
EndIf
EndProcedure
Procedure AddDateToSource(modString.s)
source.s = ProgramParameter(0)
file = OpenFile(#PB_Any,source.s)
If file <> 0
While Eof(file) = 0
string$ = ReadString(file)
bufferSize = Lof(file) - Loc(file)
If FindString(string$, "; last modified: ",1) ; all i am doing here is looking for the "last modified" string, if it's found then I add date in it's location
*bufferFile = AllocateMemory(bufferSize)
location = Loc(file) - Len(string$) - 2 ; -- Why does it require len - 2?? beginning/ending of line maybe?
ReadData(file, *bufferFile,bufferSize)
FileSeek(file, location)
TruncateFile(file)
WriteStringN(file, modString.s)
WriteData(file, *bufferFile, bufferSize)
CloseFile(file)
ProcedureReturn 1 ; done, exit loop and return
EndIf
Wend
; I can't seem to think of any other way to reset location to the beginning of the file after reaching the EoF
; no entry found, so add one at the beginning of the file
bufferSize = Lof(file)
FileSeek(file,0) ; <-- go back to beginning of the file
*bufferFile = AllocateMemory(bufferSize)
ReadData(file, *bufferFile, bufferSize)
FileSeek(file,0) ; <-- go back again after copying everything
TruncateFile(file)
WriteStringN(file,modString.s)
WriteData(file,*bufferFile,bufferSize)
CloseFile(file)
; all done :-(
EndIf
EndProcedure
AddDateToSource("; last modified: " + GetDate() + " @ " + GetTime(#C12HOUR))