#SingleInstance force   ;   only one instance at a time
ini = %A_MyDocuments%\D3Ksettings.ini   ;   Where the ini is

;------------------------------------------------------------------------------
; Make sure the settings file exists, if not, create it
;------------------------------------------------------------------------------
If FileExist("%A_MyDocuments%\D3Ksettings.ini"){
    iniexists = True
}
Else If (iniexists = False){
FileAppend, 
(
; 0 is off, 1 is on
[USpec]
RACF=LF01234
Email=LastnameFirstname@JohnDeere.com  
[Main]
Mansol=1
Supadmin=1
MJDPaste=1
CaseFormatter=1
[Replacement]
Symbols=1
JDProductNames=1
[Language]
German=0
[Info]
Version=2.2
), %ini%
}



;------------------------------------------------------------------------------
; Read the ini
;------------------------------------------------------------------------------
;   This is the part that reads the file to see what your settings are. Variables in the ini file are in all lowercase, variables here are CamelCase for more distinction

readsettings:
;   User Specific things:
IniRead, racf, %ini%, USpec, RACF
IniRead, email, %ini%, USpec, Email

;   General Settings
IniRead, mansol, %ini%, Main, Mansol
IniRead, supadmin, %ini%, Main, Supadmin
IniRead, mjdpaste, %ini%, Main, MJDPaste
IniRead, caseformatter, %ini%, Main, CaseFormatter

;   Replacement
IniRead, symb, %ini%, Replacement, Symbols
IniRead, jdpn, %ini%, Replacement, JDProductNames

;   Language
IniRead, ger, %ini%, Language, German
return

;   Check for changes to the settings ini
#persistent
lastFileContent := ""
setTimer, checkFile, 1000  ; Checks every 10 secs, should be good enough for now, can always improve later on.
return

checkFile:
fileread newFileContent, %ini%
if(newFileContent != lastFileContent) {
    lastFileContent := newFileContent
    Goto, readsettings
}
return



;------------------------------------------------------------------------------
; Settings
;------------------------------------------------------------------------------

!+\::   ; Alt+Shift+\
    Run Settings.ahk
return



;------------------------------------------------------------------------------
; DTAC Solution Opener
;------------------------------------------------------------------------------

#If, mansol = "1"    ; checks from the variable thats set from the .ini file
    !+S::   ; Alt+Shift+S
        Run Mansol_Opener.ahk
    return

#If ; these are to make sure one "if" doesn't influence the next accidentially



;------------------------------------------------------------------------------
; Support Admin Documentation
;------------------------------------------------------------------------------

#If, supadmin = "1"
    :*:]supadmin::
        UTCTimestamp := A_NowUTC        ; Puts the date in a variable
        UTCFormatStr := "yyyy-MM-dd"    ; set that variable to only grab the date, used below, don't ask me why it only works this way
        FormatTime, DateStr, %UTCTimestamp%, %UTCFormatStr% ; The part that actually does the formatting
        UTCFormatStr := "H:mm'Z'"   ; Change the format to only grab the time
        FormatTime, TimeStr, %UTCTimestamp%, %UTCFormatStr% ; Formatting
        SendInput %DateStr%{Tab}%TimeStr%{Tab}%RACF%{Tab}    ; Type things, variables are surrounded by %. RACF is a variable read from the .ini file up there, isn't that fancy!
    return
#If



;------------------------------------------------------------------------------
; Case Formatter
;------------------------------------------------------------------------------

#If, CaseFormatter = "1"
    Pause::   ; The Pause|Break key
        Run Case_Formatter.ahk
    return
#If

;   These things below are for using in a pinch, or when there is no dealer.

SetTitleMatchMode, 2
#If (WinActive = Temp.txt) && (CaseFormatter = "1")
:*:\case::
    UTCTimestamp := A_NowUTC        ; Puts the date in a variable
    UTCFormatStr := "yyyy-MM-dd"    ; set that variable to only grab the date, used below, don't ask me why it only works this way
    FormatTime, DateStr, %UTCTimestamp%, %UTCFormatStr% ; The part that actually does the formatting
    UTCFormatStr := "H:mm'Z'"   ; Change the format to only grab the time
    FormatTime, TimeStr, %UTCTimestamp%, %UTCFormatStr% ; Formatting
    SendInput Call received on %DateStr% at %TimeStr%{Enter}Name: {Enter}Username: {Enter}Email: {Enter}{Enter}{CtrlDown}{Home}{CtrlUp}{End}{Down}
    Return
#If


;German
#If (WinActive = Temp.txt) && (CaseFormatter = "1") && (ger = "1")
:*:|case::
    UTCTimestamp := A_NowUTC        ; Puts the date in a variable
    UTCFormatStr := "yyyy-MM-dd"    ; set that variable to only grab the date, used below, don't ask me why it only works this way
    FormatTime, DateStr, %UTCTimestamp%, %UTCFormatStr% ; The part that actually does the formatting
    UTCFormatStr := "H:mm'Z'"   ; Change the format to only grab the time
    FormatTime, TimeStr, %UTCTimestamp%, %UTCFormatStr% ; Formatting
    SendInput Anruf wurde am %DateStr% um %TimeStr% entgegengenommen{Enter}Name: {Enter}Benutzername: {Enter}Email: {Enter}{Enter}{CtrlDown}{Home}{CtrlUp}{End}{Down}
    Return
#If



;-------------------------------------------------------------------------------
;  Capitalise dates
;-------------------------------------------------------------------------------

::monday::Monday
::tuesday::Tuesday
::wednesday::Wednesday
::thursday::Thursday
::friday::Friday
::saturday::Saturday
::sunday::Sunday 

::january::January
::february::February
; ::march::March  ; Commented out because it matches the common word "march".
::april::April
; ::may::May  ; Commented out because it matches the common word "may".
::june::June
::july::July
::august::August
::september::September
::october::October
::november::November
::december::December


;   German
#If, ger = "1"
    ::montag::Montag
    ::dienstag::Dienstag
    ::mittwoch::Mittwoch
    ::donnerstag::Donnerstag
    ::freitag:: Freitag
    ::samstag::Samstag
    ::sonntag::Sonntag

    ::januar::Januar
    ::februar::Februar
    ::märz::M{ASC 132}rz
    ::mai::Mai
    ::juni::Juni
    ::juli::Juli
    ::oktober::Oktober
    ::dezebmer::Dezember

; These are vital for typing in German

; scharfes s / Eszett / ß
    !s::SendInput, {ASC 225}     ;Alt+S

; ä
    !a::SendInput, {ASC 132}     ;Alt+a

; ö
    !o::SendInput, {ASC 148}     ;Alt+o

; ü
    !u::SendInput, {ASC 129}     ;Alt+u

; Ä
    +!A::SendInput, {ASC 142}    ;Alt+A

; Ö
    +!O::SendInput, {ASC 153}    ;Alt+O

; Ü
    +!U::SendInput, {ASC 154}    ;Alt+U
#If



;------------------------------------------------------------------------------
; Copypastas
;------------------------------------------------------------------------------

;   Recommending case
:*:]rec::
    SendInput Recommending Case, please contact us if there are any further questions.
    Return

;   Escalatimg Case
:*:]esc1::
    SendInput This case was unable to be resolved and has been transferred to another team. Our Tier 2 team is investigating the issue to find a short term resolution. We will update you as soon as we have a recommendation.
    Return

:*:]esc2::
    SendInput A short term resolution still has not been identified. We are requesting an immediate update on this case from our Tier 2 team. We will contact you as soon as we have a status update.
    Return

;   Requesting info
:*:]req1::
    SendInput A request has been made for additional information in this case. Please provide the information as soon as possible so that the case can be resolved.
    Return

:*:]req2::
    SendInput A follow-up request has been made for the additional information.
    Return

:*:]req3::
    SendInput The additional information required has not yet been received. This case will now be sent back to you. Please reopen the case, or contact the Global Support Center again via phone or email with the additional information and reference this case number so that it can be reopened and investigated further.
    Return

;   Defect / NCCA
:*:]ncca::
    SendInput We will be recommending this DTAC case back to you for the time being. This issue is still being investigated and worked on via an internal product corrective action ticket. We will continue to monitor the progress of that ticket and contact you when we have a solution or a short term recommendation. The case text will be updated at that time for documentation purposes.{Enter}You may choose to close this case yourself, return it to us, or keep it open until we provide you with a corrective action recommendation. If you have questions on the status of this issue, please re-open the case or contact the Global Support Center using the contact information found in DTAC solution 82793. We will provide you with any information we are able to gather from the product team.
    Return


;   German
#If, ger = "1"
;   Recommending Case
:*:[rec::
    SendInput Fall an H{ASC 132}ndler gewiesen, bitte melden Sie sich wenn sie weitere fragen haben.
    Return

;   Escalating Case
:*:[esc1::
    SendInput Der Fall konnte vom GSC nicht gel{ASC 148}st werden und wurde an die n{ASC 132}chste Supportebene weitergeleitet. Das Support Team wird das Problem weiter untersuchen und versuchen eine kurzfristige L{ASC 148}sung bereit zu stellen. Sobald wir eine Empfehlung erhalten, werden wir Sie dar{ASC 129}ber informieren.
    Return

:*:[esc2::
    SendInput Bisher steht uns keine kurzfristige L{ASC 148}sung zur Verf{ASC 129}gung. Wir fordern umgehend ein Status-Update bez{ASC 129}glich des Falls von unserem Support Team an.{Shift down}{Enter}{Shift up}Wir werden Sie erneut kontaktieren, sobald wir {ASC 129}ber den aktuellsten Stand des Falls informiert sind.
    Return

;   Requesting info
:*:[req1::
    SendInput Wir haben zus{ASC 132}tzliche Informationen von Ihnen bez{ASC 129}glich des Falls angefordert. Bitte stellen Sie uns die Informationen so bald wie m{ASC 148}glich zur Verf{ASC 129}gung, damit der Fall gel{ASC 148}st werden kann.
    Return

:*:[req2::
    SendInput Wir fordern die zus{ASC 132}tzlichen Informationen von Ihnen erneut an.
    Return

:*:[req3::
    SendInput Wir haben die ben{ASC 148}tigten zus{ASC 132}tzlichen Informationen von Ihnen noch nicht erhalten. Dieser Fall wird jetzt zu Ihnen zur{ASC 129}ckgeschickt. Bitte setzen Sie sich mit dem GSC telefonisch oder per Email mit den zus{ASC 132}tzlichen Informationen nochmal in Verbindung und referenzieren Sie die Fallnummer, damit der Fall erneut ge{ASC 148}ffnet und weiter untersucht werden kann.
    Return

;   Defect / NCCA
:*:[ncca::
    SendInput Wir werden diesen Fall vor{ASC 129}bergehend an Sie zur{ASC 129}ckweisen. Dieses Problem wird noch {ASC 129}ber ein innenseitiges Produkt Korrektur Ticket bearbeitet. Wir werden weiterhin den Fortschritt dieses Tickets verfolgen und mit Ihnen Kontakt aufnehmen, wenn wir eine L{ASC 148}sung oder eine kurzfristige Empfehlung haben.{Enter}Sie k{ASC 148}nnen diesen Fall selbst schlie{ASC 225}en, an uns zur{ASC 129}ckzugeben oder offen halten, bis wir Ihnen eine Korrekturma{ASC 225}nahme empfehlen. Wenn Sie Fragen zum Fall Status haben wenden Sie sich an das Global Support Center, indem Sie die Kontaktinformationen in der DTAC-L{ASC 148}sung 82793 abrufen. Wir werden Ihnen alle Informationen, die wir von dem Produktteam bekommen haben, zu Verf{ASC 129}gung stellen.
    Return

#If



;------------------------------------------------------------------------------
; Email
;------------------------------------------------------------------------------

;   Regular
:*:]email::
    SendInput Hello,{Enter}{Enter}   {Shift down}{Enter}{Shift up}Please contact us if you have any questions.{Up}{End}
    Return

;   DTAC Problem
:*:]97010::
    SendInput Hello,{Enter}{Enter}    As this is a hardware/compatibility related inquiry, we here at the GSC cannot assist you properly. Please contact DTAC and they will be able to assist you further.
    Return

;   2 Year old COMAR
:*:]2yc::
    SendInput Hello,{Enter}{Enter}   You are unable to activate this product as the COMAR is over 2 years old. See DTAC Solution 108357 for more information on how to get this replaced:{Shift down}{Enter}{Shift up}http://dtac.deere.com/Solutions/English/108357.htm{Enter}Please contact your TCSM if you have any questions about this process.
    Return

#If

;   German
#If, ger = "1"

;   Regular
:*:[email::
    SendInput Hallo,{Enter}{Enter}   {Shift down}{Enter}{Shift up}Bitte melden Sie sich, wenn Sie weitere Fragen haben.{Up}{End}
    Return

;   DTAC Problem
:*:[97010::
    SendInput Hallo,{Enter}{Enter}   Da dies eine Hardware/Kompatibilit{ASC 132}t-bezogene Anfrage ist, k{ASC 148}nnen wir hier im GSC leider ihre frage nicht gut beantworten. Bitte wenden Sie sich an DTAC, dort werden Sie besser f{ASC 129}r diesen typ von fragen unterst{ASC 129}tzt.
    Return

;   2 Year old COMAR
:*:[2yc::
    SendInput Hallo,{Enter}{Enter}   Sie k{ASC 148}nnen dieses Produkt nicht aktivieren weil die COMAR-Nummer {ASC 129}ber 2 Yahre alt ist. Siehe DTAC L{ASC 148}sung 108357 f{ASC 129}r mehr information {ASC 129}ber den ersetzungprozess:{Shift down}{Enter}{Shift up}http://dtac.deere.com/Solutions/German/108357.htm{Enter}Bitte melden Sie sich bei Ihrem Technischen Bezirksleiter wenn Sie Fragen {ASC 129}ber diesen Prozess haben.
    Return

#If



;------------------------------------------------------------------------------
; MyJohnDeere Profile email paste
;------------------------------------------------------------------------------
; So when editing Stellar Support Profiles, it won't let you paste in the email field. We don't like that. Make sure to let go of all keys immediatley after pressing this

#If, mjdpaste = "1"
    #v::
        sleep, 750
        sendinput %clipboard%
        sleep, 500
        send #  ; to make sure the start menu isn't open for some reason
        return
#If



;------------------------------------------------------------------------------
; Common Terms autocorrect and replacement
;------------------------------------------------------------------------------
;   Symbols, these only replace when an end character is typed afterwards

#If, symb = "1"
    ::(deg)::{ASC 248}
    ::(eq)::{ASC 247}
#If

#If, not(racf = "LF01234")  ; So that it doesn't put the fake RACF from the default ini file
    :R*:]me::
        SendInput, %racf%
        return

    :R*:[me::
        SendInput, %racf%
        return
#If

#If, not(email = "LastnameFirstname@JohnDeere.com") ; Same as above
    :R*:@me::
        SendInput, %email%
        return
#If

;   R2 Shared Inbox
#If, ger = "1"
    :R*:@amse::DealerCareCenterAMSEDCC@JohnDeere.com
#If

;   JD Names
#If, jdpn = "1"

    :R*:]xx::XXXXXXXXXXXXX  ; I'm not gonna try and find the right amount of X's to appease the CCMS demons

    :R*:]at::AutoTrac
    :R*:]sf::StarFire    
    :R*:]jdlw::JDLink Web
    :R*:]jdld::JDLink Dashboard
    :R*:]jdlc::JDLink Connect
    :R*:]jdla::JDLink Access
    :R*:]jdls::JDLink Subscription
    :R*:]jdll::JDLink
    :R*:]jdp::JDParts
    :R*:]mjd::MyJohnDeere
    :R*:]opsc::Operations Center
    :R*:]seccon::Section Control
    :R*:]gs::GreenStar
    :R*:]cc::CommandCenter
    :R*:]fc::Field Connect
    :R*:]stolen::Stolen PIN Status Change Request
    :R*:]rs::RowSense
    :R*:]sub::Subscription
    :R*:]ss::Stellar Support

    :R*:rowsense::RowSense
    :R*:comar::COMAR
    :R*:mrtk::mRTK
    :R*:rda::RDA
    :R*:rtk::RTK
    :R*:autotrac::AutoTrac
    :R*:ccms::CCMS
    :R*:dtac::DTAC
    :R*:tcsm::TCSM
    :R*:itec::iTEC Pro
    :R*:ssu::SSU
    :R*:atu::ATU
    :R*:mtg::MTG
    :R*:wdt::WDT
    :R*:itc::iTC
    :R*:vin::VIN
    :R*:gs2::GS2
    :R*:gs3::GS3
    :R*:sf2::SF2
    :R*:sf3::SF3
    :R*:xid::xID


;   German
#If, ger = "1" 
    :R*:[at::AutoTrac
    :R*:[sf::StarFire
    :R*:[jdlw::JDLink Web
    :R*:[jdld::JDLink Dashboard
    :R*:[jdlc::JDLink Connect
    :R*:[jdla::JDLink Access
    :R*:[jdls::JDLink Abonnement
    :R*:[jdll::JDLink
    :R*:[jdp::JDParts
    :R*:[mjd::MyJohnDeere
    :R*:[opsc::Einsatzzentrale
    :R*:[seccon::Teilbreitensteuerung
    :R*:[gs::GreenStar
    :R*:[cc::CommandCenter
    :R*:[fc::Field Connect
    :R*:[stolen::Stolen PIN Status Change Request
    :R*:[rs::RowSense
    :R*:[abo::Abonnement
    :R*:[ss::Stellar Support
#If