#region - RainLendar install script - (Nullsoft)
#include <Common_Functions.au3>
Opt('TrayIconDebug', 1)
Break(False)

; Installer.
$executable = 'RainLendar 0.22.exe'
; Default group folder in startmenu.
$group = 'Rainlendar'
; Installation folder in Program Files.
$directory = 'Rainlendar'

; Check if ini exist
$file_ini = @AppDataDir & '\Rainlendar\Rainlendar.ini'
If FileExists($file_ini) Then
    $ini_existed = True
Else
    $ini_existed = False
EndIf

; Run the installer.
$pid = _Nullsoft()
ProcessWaitClose($pid)

; Remove shortcuts.
If _Programs('Rainlendar.lnk') Then
    FileMove($group & '\Rainlendar.lnk', 'General\', 9)
    DirRemove($group, 1)
EndIf
_Desktop('Rainlendar.lnk')

; Setup startup position (not working right, maybe start program 1st?)
;~ _Rainlendar()

Exit
#endregion

Func _Rainlendar()
    Local $x, $width = @DesktopWidth
    Dim $file_ini; = @AppDataDir & '\Rainlendar\Rainlendar.ini'
    Local $file_exe = @ProgramFilesDir & '\Rainlendar\Rainlendar.exe'
    If Not $ini_existed Then
        Select
            Case $width = 640
                $x = 469
            Case $width = 800
                $x = 619
            Case $width = 1024
                $x = 840
            Case $width = 1280
                $x = 1084
            Case $width = 1600
                $x = 1429
            Case Else
                Return
        EndSelect
        IniWrite($file_ini, 'Rainlendar', 'X', $x)
        IniWrite($file_ini, 'Rainlendar', 'Y', 15)
        IniWrite($file_ini, 'Rainlendar', 'TodoX', $x+10)
        IniWrite($file_ini, 'Rainlendar', 'TodoY', 184)
        IniWrite($file_ini, 'Rainlendar', 'EventListX', $x+10)
        IniWrite($file_ini, 'Rainlendar', 'EventListY', 242)
        ; Hide extra windows
        IniWrite($file_ini, 'Rainlendar', 'TodoEnable', 0)
        IniWrite($file_ini, 'Rainlendar', 'TodoLocked', 0)
        IniWrite($file_ini, 'Rainlendar', 'EventListEnable', 0)
        IniWrite($file_ini, 'Rainlendar', 'EventListLocked', 0)
        ; Hide TrayIcon
        IniWrite($file_ini, 'Rainlendar', 'ShowTrayIcon', 0)
    EndIf
EndFunc