|
| 1 | +#include <MsgBoxConstants.au3> |
| 2 | +#include <WinAPIFiles.au3> |
| 3 | + |
| 4 | +;Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase |
| 5 | + |
| 6 | +$INI="JoplinWinBackup.ini" |
| 7 | +$JOPLINEXE = IniRead($INI, "General", "joplin", "C:\Program Files\Joplin\Joplin.exe") |
| 8 | + |
| 9 | +; Ask for backup start |
| 10 | +if(IniRead($INI, "General", "ask_for_start", 1) = 1) Then |
| 11 | + if(MsgBox($MB_OKCANCEL + $MB_ICONQUESTION, "Joplin Backup", "Start Joplin Backup?") <> $IDOK) Then |
| 12 | + exit |
| 13 | + EndIf |
| 14 | +EndIf |
| 15 | + |
| 16 | +; Create backup directory |
| 17 | +$BACKUPFOLDER = IniRead($INI, "General", "backup_folder", @ScriptDir & "\joplinbackup") |
| 18 | +DirCreate ( $BACKUPFOLDER ) |
| 19 | +if(FileExists ($BACKUPFOLDER) = False) Then |
| 20 | + MsgBox($MB_OK + $MB_ICONERROR, "Joplin Backup", "Access Error on Backup directory '" & $BACKUPFOLDER & "'") |
| 21 | + exit |
| 22 | +EndIf |
| 23 | + |
| 24 | +; Activate Joplin window or start joplin |
| 25 | +if (WinActivate("[REGEXPTITLE:^Joplin$; CLASS:Chrome_WidgetWin_1]","") = 0) Then |
| 26 | + run($JOPLINEXE) |
| 27 | +EndIf |
| 28 | +$hJOPLIN = WinWaitActive("[REGEXPTITLE:^Joplin$; CLASS:Chrome_WidgetWin_1]","", 10) |
| 29 | + |
| 30 | +if( WinWaitActive("[REGEXPTITLE:^Joplin$; CLASS:Chrome_WidgetWin_1]","", 10) = 0) Then |
| 31 | + MsgBox($MB_OK + $MB_ICONERROR, "Joplin Backup", "Failed to start Joplin") |
| 32 | + exit |
| 33 | +EndIf |
| 34 | + |
| 35 | +; Send keys for export menue |
| 36 | +$keyCombo = IniRead($INI, "General", "key_combo", "fej") |
| 37 | +Send ("!" & StringMid($keyCombo,1,1)) |
| 38 | +Sleep(100) |
| 39 | +For $i = 2 To StringLen($keyCombo) Step +1 |
| 40 | + Send (StringMid($keyCombo,$i,1)) |
| 41 | + Sleep(100) |
| 42 | +Next |
| 43 | + |
| 44 | +; Wait wor save dialog |
| 45 | +$save_dialog = IniRead($INI, "General", "save_dialog", "Speichern unter") |
| 46 | +$hSAVE = WinWaitActive("[TITLE:" & $save_dialog & "]","", 2) |
| 47 | +if($hSAVE = 0) Then |
| 48 | + MsgBox($MB_OK + $MB_ICONERROR, "Joplin Backup", "Failed to open export") |
| 49 | + exit |
| 50 | +EndIf |
| 51 | + |
| 52 | +; Generate backupfile name |
| 53 | +$BACKUPFILE = IniRead($INI, "General", "backup_file_name", "joplin_backup.jex") |
| 54 | +$BACKUPFILE = StringReplace($BACKUPFILE, ".jex", "") |
| 55 | + |
| 56 | +if(IniRead($INI, "General", "backup_file_add_date", 1) = 1) Then |
| 57 | + if($BACKUPFILE <> "") Then |
| 58 | + $BACKUPFILE = $BACKUPFILE & "_" |
| 59 | + EndIf |
| 60 | + $BACKUPFILE = $BACKUPFILE & @YEAR & @MON & @MDAY |
| 61 | +EndIf |
| 62 | + |
| 63 | +if(IniRead($INI, "General", "backup_file_add_time", 1) = 1) Then |
| 64 | + if($BACKUPFILE <> "") Then |
| 65 | + $BACKUPFILE = $BACKUPFILE & "_" |
| 66 | + EndIf |
| 67 | + $BACKUPFILE = $BACKUPFILE & @HOUR & @MIN |
| 68 | +EndIf |
| 69 | + |
| 70 | +$BACKUPFILE = $BACKUPFILE & ".jex" |
| 71 | + |
| 72 | +; Send filename and save |
| 73 | +ControlSetText($hSAVE, "", "[CLASS:Edit]", $BACKUPFOLDER & "\" & $BACKUPFILE) |
| 74 | +Sleep(50) |
| 75 | +ControlClick($hSAVE, "", "[Class:Button;Instance:2]") |
| 76 | +Sleep(50) |
| 77 | + |
| 78 | +; Check for confirmation dialog |
| 79 | +$hCONFIRM = WinGetHandle ( "[ACTIVE]", "" ) |
| 80 | +if(StringInStr(WinGetTitle($hCONFIRM,""), $save_dialog) = 0) Then |
| 81 | + $hCONFIRM = 0 |
| 82 | +EndIf |
| 83 | + |
| 84 | +if ($hCONFIRM <> 0) Then |
| 85 | + if(IniRead($INI, "General", "overwrite_file", 0) = 1) Then |
| 86 | + ControlClick($hCONFIRM, "", "[Class:Button;Instance:1]") |
| 87 | + Else |
| 88 | + ControlClick($hCONFIRM, "", "[Class:Button;Instance:2]") |
| 89 | + Sleep(100) |
| 90 | + ControlClick($hSAVE, "", "[Class:Button;Instance:3]") |
| 91 | + |
| 92 | + MsgBox($MB_OK + $MB_ICONERROR, "Joplin Backup", "Backup file already exists!" ) |
| 93 | + EndIf |
| 94 | +EndIf |
0 commit comments