When opening my templates, I was quite shocked, it was simply E.M.P.T.Y.!
So ~100 templates gone, nice!
I read about that problem in the past (seems to happen rarely only) and always thought "pff.. guess it was the users fault, that will never happen to me".
Well.. here we are now, quite frustrated, I found a three year old backup at least, better than nothing.
Anyway, long story short, it was time for a quick backup IDE tool for the Templates:
Code: Select all
; [IDE Tool]
; Template Backup
; (c) HeX0R 2025
;
; Compile, add as PB IDE Tool, give it some name, no Arguments and let it be triggered by "Editor closing"
; at first start it will ask for a backup path
; whenever Templates.prefs size has changed, it will add a backup there.
; they will be named (keep it simple):
; Templates_001.prefs
; Templates_002.prefs
; ...
Procedure DoBackup(Template$, BackupPath$)
Protected i, Num.i = 1
While FileSize(BackupPath$ + "Templates_" + RSet(Str(Num), 3, "0") + ".prefs") > -1
Num + 1
Wend
CopyFile(Template$, BackupPath$ + "Templates_" + RSet(Str(Num), 3, "0") + ".prefs")
EndProcedure
Procedure MakeSureDirectoryExists(Dir$)
Protected Count, i, CurrDir$
If Right(Dir$, 1) <> #PS$
Dir$ + #PS$
EndIf
Count = CountString(Dir$, #PS$)
For i = 1 To Count
CurrDir$ + StringField(Dir$, i, #PS$) + #PS$
If FileSize(CurrDir$) <> -2
CreateDirectory(CurrDir$)
EndIf
Next i
EndProcedure
Procedure main()
Protected Path$, Template$, Own$
Protected Template_Size, BackupPath$
Path$ = GetPathPart(GetEnvironmentVariable("PB_TOOL_Preferences"))
Own$ = GetUserDirectory(#PB_Directory_ProgramData) + "hex0r" + #PS$ + "IDE_bk" + #PS$
MakeSureDirectoryExists(Own$)
OpenPreferences(Own$ + "bk.prefs")
Template_Size = ReadPreferenceInteger("LastSize", -1)
BackupPath$ = ReadPreferenceString("BackupPath", "")
ClosePreferences()
If BackupPath$ = ""
;first run
BackupPath$ = PathRequester("Select path to store template backups to", "")
If BackupPath$ = ""
MessageRequester("Quit", "Can't go on without knowing the backup path, closing now!")
ProcedureReturn
Else
CreatePreferences(Own$ + "bk.prefs")
WritePreferenceString("BackupPath", BackupPath$)
ClosePreferences()
EndIf
EndIf
If Path$ = ""
MessageRequester("Info", "I need to be started as PB IDE tool, closing now!")
ProcedureReturn
EndIf
Template$ = Path$ + "Templates.prefs"
If FileSize(Template$) <> Template_Size
Template_Size = FileSize(Template$)
DoBackup(Template$, BackupPath$)
OpenPreferences(Own$ + "bk.prefs")
WritePreferenceInteger("LastSize", Template_Size)
ClosePreferences()
EndIf
EndProcedure
main()