Advertisement
variksoo21

SAMPLogManager V2 Source code

Sep 13th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;——————————————————————————————————————————————————————
  2. ;————————      Notify() 0.4991 by gwarble       ————————
  3. ;—————                                            —————
  4. ;———      easy multiple tray area notifications     ———
  5. ;——    http://www.autohotkey.net/~gwarble/Notify/    ——
  6. ;——————————————————————————————————————————————————————
  7. ;
  8. ; Notify([Title,Message,Duration,Options])
  9. ;
  10. ; Duration  seconds to show notification [Default: 30]
  11. ;             0  for permanent/remain until clicked (flashing)
  12. ;            -3  negative value to ExitApp on click/timeout
  13. ;           "-0" for permanent and ExitApp when clicked (needs "")
  14. ;
  15. ; Options   string of options, single-space seperated, ie:
  16. ;           "TS=16 TM=8 TF=Times New Roman GC_=Blue SI_=1000"
  17. ;           most options are remembered (static), some not (local)
  18. ;           Option_= can be used for non-static call, ie:
  19. ;           "GC=Blue" makes all future blue, "GC_=Blue" only takes effect once
  20. ;           "Wait=ID"   to wait for a notification
  21. ;           "Update=ID" to change Title, Message, and Progress Bar (with 'Duration')
  22. ;
  23. ; Return   ID (Gui Number used)
  24. ;          0 if failed (too many open most likely)
  25. ;          VarValue if Options includes: Return=VarName
  26. ;——————————————————————————————————————————————————————
  27.  
  28. Notify(Title="Notify()",Message="",Duration="",Options="")
  29. {
  30.  static GNList, ACList, ATList, AXList, Exit, _Wallpaper_, _Title_, _Message_, _Progress_, _Image_, Saved
  31.  static GF := 50            ; Gui First Number
  32.  static GL := 74            ; Gui Last  Number (which defines range and allowed count)
  33.  static GC,GR,GT,BC,BK,BW,BR,BT,BF      ; static options, remembered between calls
  34.  static TS,TW,TC,TF,MS,MW,MC,MF
  35.  static SI,SC,ST,IW,IH,IN,XC,XS,XW,PC,PB
  36.  
  37.  If (Options)           ; skip parsing steps if Options param isn't used
  38.  {
  39.   If (A_AutoTrim = "Off")
  40.   {
  41.    AutoTrim, On
  42.    _AutoTrim = 1
  43.   } ; ¶
  44.   Options = %Options%
  45.   Options.=" "          ; poor whitespace handling for next parsing step (ensures last option is parsed)
  46.   Loop,Parse,Options,=      ; parse options string at "="s, needs better whitespace handling
  47.   {
  48.       If A_Index = 1        ; first option handling
  49.         Option := A_LoopField       ; sets options VarName
  50.       Else          ; for the rest after the first,
  51.       {         ; split at the last space, apply the first chunk to the VarValue for the last Option
  52.         %Option% := SubStr(A_LoopField, 1, (pos := InStr(A_LoopField, A_Space, false, 0))-1)
  53.         %Option% = % %Option%
  54.         Option   := SubStr(A_LoopField, pos+1)  ; and set the next option to the last chunk (from the last space to the "=")
  55.       }
  56.   }
  57.   If _AutoTrim
  58.    AutoTrim, Off
  59.   If Wait <>            ; option Wait=ID used, normal Notify window not being created
  60.   {
  61.       If Wait Is Number     ; waits for a specific notify
  62.       {
  63.         Gui %Wait%:+LastFound       ; i'd like to remove this to not affect calling script...
  64.         If NotifyGuiID := WinExist()    ; but think i have to use hWnd's for reference instead of gui numbers which will
  65.         {           ; probably happen in my AHK_L transition since gui numbers won't matter anymore
  66.           WinWaitClose, , , % Abs(Duration) ; wait to close for duration
  67.           If (ErrorLevel && Duration < 1)   ; destroys window when done waiting if duration is negative
  68.           {         ; otherwise lets the calling script procede after waiting the duration (without destroying)
  69.             Gui, % Wait + GL - GF + 1 ":Destroy"    ; destroys border gui
  70.             If ST
  71.               DllCall("AnimateWindow","UInt",NotifyGuiID,"Int",ST,"UInt","0x00050001") ; slides window out to the right if ST or SC are used
  72.             Gui, %Wait%:Destroy     ; and destroys it
  73.           }
  74.         }
  75.       }
  76.       Else          ; wait for all notify's if "Wait=All" is used in the options string
  77.       {         ; loops through all existing notify's and performs the same wait logic
  78.         Loop, % GL-GF       ; (with or without destroying if negative or not)
  79.         {
  80.           Wait := A_Index + GF - 1
  81.           Gui %Wait%:+LastFound
  82.           If NotifyGuiID := WinExist()
  83.           {
  84.             WinWaitClose, , , % Abs(Duration)
  85.             If (ErrorLevel && Duration < 1)
  86.             {
  87.               Gui, % Wait + GL - GF + 1 ":Destroy"  ; destroys border gui
  88.               If ST
  89.                 DllCall("AnimateWindow","UInt",NotifyGuiID,"Int",ST,"UInt","0x00050001") ; slides window out to the right if ST or SC are used
  90.               Gui, %Wait%:Destroy       ; and destroys it
  91.             }
  92.           }
  93.         }
  94.         GNList := ACList := ATList := AXList := ""  ; clears internal variables since they're all destroyed now
  95.       }
  96.       Return
  97.   }
  98.   If Update <>          ; option "Update=ID" being used, Notify window will not be created
  99.   {         ; title, message, image and progress position can be updated
  100.       If Title <>
  101.        GuiControl, %Update%:,_Title_,%Title%
  102.       If Message <>
  103.        GuiControl, %Update%:,_Message_,%Message%
  104.       If Duration <>
  105.        GuiControl, %Update%:,_Progress_,%Duration%
  106.       If Image <>
  107.        GuiControl, %Update%:,_Image_,%Image%
  108.       If Wallpaper <>
  109.        GuiControl, %Update%:,_Wallpaper_,%Image%
  110.       Return
  111.   }
  112.   If Style = Save           ; option "Style=Save" is used to save the existing window style
  113.   {         ; and call it back later with "Style=Load"
  114.    Saved := Options " GC=" GC " GR=" GR " GT=" GT " BC=" BC " BK=" BK " BW=" BW " BR=" BR " BT=" BT " BF=" BF
  115.    Saved .= " TS=" TS " TW=" TW " TC=" TC " TF=" TF " MS=" MS " MW=" MW " MC=" MC " MF=" MF
  116.    Saved .= " IW=" IW " IH=" IH " IN=" IN " PW=" PW " PH=" PH " PC=" PC " PB=" PB " XC=" XC " XS=" MS " XW=" XW
  117.    Saved .= " SI=" SI " SC=" SC " ST=" ST " WF=" Image " IF=" IF
  118.   }         ; this needs some major improvement to have multiple saved instead of just one, otherwise pointless
  119.   If Return <>
  120.    Return, % (%Return%)
  121.   If Style <>           ; option "Style=Default will reset all variables back to defaults... except options also specified
  122.   {         ; so "Style=Default GC=Blue" is allowed, which will reset all defaults and then set GC=Blue
  123.    If Style = Default
  124.     Return % Notify(Title,Message,Duration, ; maybe handled poorly by calling itself, but it saves having to have the defaults set in two areas... thoughts?
  125. (
  126. "GC= GR= GT= BC= BK= BW= BR= BT= BF= TS= TW= TC= TF=
  127. MS= MW= MC= MF= SI= ST= SC= IW=
  128. IH= IN= XC= XS= XW= PC= PB= " Options "Style=")
  129. )           ; below are more internally saved styles, which may move to an auxiliary function at some point, but could use some improvement
  130.    Else If Style = ToolTip
  131.     Return % Notify(Title,Message,Duration,"SI=50 GC=FFFFAA BC=00000 GR=0 BR=0 BW=1 BT=255 TS=8 MS=8 " Options "Style=")
  132.    Else If Style = BalloonTip
  133.     Return % Notify(Title,Message,Duration,"SI=350 GC=FFFFAA BC=00000 GR=13 BR=15 BW=1 BT=255 TS=10 MS=8 AX=1 XC=999922 IN=8 Image=" A_WinDir "\explorer.exe " Options "Style=")
  134.    Else If Style = Error
  135.     Return % Notify(Title,Message,Duration,"SI=250 GC=Default BC=00000 GR=0 BR=0 BW=1 BT=255 TS=12 MS=12 AX=1 XC=666666 IN=10 IW=32 IH=32 Image=" A_WinDir "\explorer.exe " Options "Style=")
  136.    Else If Style = Warning
  137.     Return % Notify(Title,Message,Duration,"SI=250 GC=Default BC=00000 GR=0 BR=0 BW=1 BT=255 TS=12 MS=12 AX=1 XC=666666 IN=9 IW=32 IH=32 Image=" A_WinDir "\explorer.exe " Options "Style=")
  138.    Else If Style = Info
  139.     Return % Notify(Title,Message,Duration,"SI=250 GC=Default BC=00000 GR=0 BR=0 BW=1 BT=255 TS=12 MS=12 AX=1 XC=666666 IN=8 IW=32 IH=32 Image=" A_WinDir "\explorer.exe " Options "Style=")
  140.    Else If Style = Question
  141.     Return % Notify(Title,Message,Duration,"SI=250 GC=Default BC=00000 GR=0 BR=0 BW=1 BT=255 TS=12 MS=12 AX=1 XC=666666 Image=24 IW=32 IH=32 " Options "Style=")
  142.    Else If Style = Progress
  143.     Return % Notify(Title,Message,Duration,"SI=100 GC=Default BC=00000 GR=9 BR=13 BW=2 BT=105 TS=10 MS=10 PG=100 PH=10 GW=300 " Options "Style=")
  144.    Else If Style = Huge
  145.     Return % Notify(Title,Message,Duration,"SI=100 ST=200 SC=200 GC=FFFFAA BC=00000 GR=27 BR=39 BW=6 BT=105 TS=24 MS=22 " Options "Style=")
  146.    Else If Style = Load
  147.     Return % Notify(Title,Message,Duration,Saved)
  148.   }
  149.  }
  150. ;—————— end if options ————————————————————————————————————————————————————————————————————————————
  151.  
  152.   GC_ := GC_<>"" ? GC_ : GC := GC<>"" ? GC : "FFFFAA"       ; defaults are set here, and static overrides are used and saved
  153.   GR_ := GR_<>"" ? GR_ : GR := GR<>"" ? GR : 9      ; and non static options (with OP_=) are used but not saved
  154.   GT_ := GT_<>"" ? GT_ : GT := GT<>"" ? GT : "Off"
  155.   BC_ := BC_<>"" ? BC_ : BC := BC<>"" ? BC : "000000"
  156.   BK_ := BK_<>"" ? BK_ : BK := BK<>"" ? BK : "Silver"
  157.   BW_ := BW_<>"" ? BW_ : BW := BW<>"" ? BW : 2
  158.   BR_ := BR_<>"" ? BR_ : BR := BR<>"" ? BR : 13
  159.   BT_ := BT_<>"" ? BT_ : BT := BT<>"" ? BT : 105
  160.   BF_ := BF_<>"" ? BF_ : BF := BF<>"" ? BF : 350
  161.   TS_ := TS_<>"" ? TS_ : TS := TS<>"" ? TS : 10
  162.   TW_ := TW_<>"" ? TW_ : TW := TW<>"" ? TW : 625
  163.   TC_ := TC_<>"" ? TC_ : TC := TC<>"" ? TC : "Default"
  164.   TF_ := TF_<>"" ? TF_ : TF := TF<>"" ? TF : "Default"
  165.   MS_ := MS_<>"" ? MS_ : MS := MS<>"" ? MS : 10
  166.   MW_ := MW_<>"" ? MW_ : MW := MW<>"" ? MW : "Default"
  167.   MC_ := MC_<>"" ? MC_ : MC := MC<>"" ? MC : "Default"
  168.   MF_ := MF_<>"" ? MF_ : MF := MF<>"" ? MF : "Default"
  169.   SI_ := SI_<>"" ? SI_ : SI := SI<>"" ? SI : 0
  170.   SC_ := SC_<>"" ? SC_ : SC := SC<>"" ? SC : 0
  171.   ST_ := ST_<>"" ? ST_ : ST := ST<>"" ? ST : 0
  172.   IW_ := IW_<>"" ? IW_ : IW := IW<>"" ? IW : 32
  173.   IH_ := IH_<>"" ? IH_ : IH := IH<>"" ? IH : 32
  174.   IN_ := IN_<>"" ? IN_ : IN := IN<>"" ? IN : 0
  175.   XF_ := XF_<>"" ? XF_ : XF := XF<>"" ? XF : "Arial Black"
  176.   XC_ := XC_<>"" ? XC_ : XC := XC<>"" ? XC : "Default"
  177.   XS_ := XS_<>"" ? XS_ : XS := XS<>"" ? XS : 12
  178.   XW_ := XW_<>"" ? XW_ : XW := XW<>"" ? XW : 800
  179.   PC_ := PC_<>"" ? PC_ : PC := PC<>"" ? PC : "Default"
  180.   PB_ := PB_<>"" ? PB_ : PB := PB<>"" ? PB : "Default"
  181.  
  182.   wPW := ((PW<>"") ? ("w" PW) : (""))       ; needs improvement, poor handling of explicit sizes and progress widths
  183.   hPH := ((PH<>"") ? ("h" PH) : (""))
  184.   If GW <>
  185.   {
  186.    wGW = w%GW%
  187.    wPW := "w" GW - 20
  188.   }
  189.   hGH := ((GH<>"") ? ("h" GH) : (""))
  190.   wGW_ := ((GW<>"") ? ("w" GW - 20) : (""))
  191.   hGH_ := ((GH<>"") ? ("h" GH - 20) : (""))
  192. ;————————————————————————————————————————————————————————————————————————
  193.  If Duration =              ; default if duration is not used or set to ""
  194.   Duration = 30
  195.  GN := GF               ; find the next available gui number to use, starting from GF (default 50)
  196.  Loop               ; within the defined range GF to GL
  197.   IfNotInString, GNList, % "|" GN
  198.    Break
  199.   Else
  200.    If (++GN > GL)               ;=== too many notifications open, returns 0, handle this error in the calling script
  201.     Return 0                        ; this is uncommon as the screen is too cluttered by this point anyway
  202.  GNList .= "|" GN
  203.  GN2 := GN + GL - GF + 1
  204.  
  205.  If AC <>               ; saves the action to be used when clicked or timeout (or x-button is clicked)
  206.   ACList .= "|" GN "=" AC           ; need to add different clicks for Title, Message, Image as well
  207.  If AT <>               ; saved internally in a list, then parsed by the timer or click routine
  208.   ATList .= "|" GN "=" AT           ; to run the script-side subroutine/label "AC=LabelName"
  209.  If AX <>
  210.   AXList .= "|" GN "=" AX
  211.  
  212.  
  213.  P_DHW := A_DetectHiddenWindows         ; start finding location based on what other Notify() windows are on the screen
  214.  P_TMM := A_TitleMatchMode          ; saved to restore these settings after changing them, so the calling script won't know
  215.  DetectHiddenWindows On         ; as they are needed to find all as they are being made as well... or hidden for some reason...
  216.  SetTitleMatchMode 1            ; and specific window title match is a little more failsafe
  217.  If (WinExist("_Notify()_GUI_"))            ;=== find all Notifications from ALL scripts, for placement
  218.   WinGetPos, OtherX, OtherY                 ;=== change this to a loop for all open notifications and find the highest?
  219.  DetectHiddenWindows %P_DHW%            ;=== using the last Notify() made at this point, which may be better
  220.  SetTitleMatchMode %P_TMM%          ; and the global settings are restored for the calling thread
  221.  
  222.  Gui, %GN%:-Caption +ToolWindow +AlwaysOnTop -Border        ; here begins the creation of the window
  223.  Gui, %GN%:Color, %GC_%         ; with the logic to add or not add certain controls, Wallpaper, Image, Title, Progress, Message
  224.  If FileExist(WP)               ; and some placement logic depending if they are used or not... could definitely be improved
  225.  {
  226.   Gui, %GN%:Add, Picture, x0 y0 w0 h0 v_Wallpaper_, % WP    ; wallpaper added first, stretched to size later
  227.   ImageOptions = x+8 y+4
  228.  }
  229.  If Image <>                ; icon image added next, sized, and spacing added for whats next
  230.  {
  231.   If FileExist(Image)
  232.    Gui, %GN%:Add, Picture, w%IW_% h%IH_% Icon%IN_% v_Image_ %ImageOptions%, % Image
  233.   Else
  234.    Gui, %GN%:Add, Picture, w%IW_% h%IH_% Icon%Image% v_Image_ %ImageOptions%, %A_WinDir%\system32\shell32.dll
  235.   ImageOptions = x+10
  236.  }
  237.  If Title <>                ; title text control added next, if used
  238.  {
  239.   Gui, %GN%:Font, w%TW_% s%TS_% c%TC_%, %TF_%
  240.   Gui, %GN%:Add, Text, %ImageOptions% BackgroundTrans v_Title_, % Title
  241.  }
  242.  If PG              ; then the progress bar, if called for
  243.   Gui, %GN%:Add, Progress, Range0-%PG% %wPW% %hPH% c%PC_% Background%PB_% v_Progress_
  244.  Else
  245.   If ((Title) && (Message))         ; some spacing tweaks if both used
  246.    Gui, %GN%:Margin, , -5
  247.  If Message <>              ; and finally the message text control if used
  248.  {
  249.   Gui, %GN%:Font, w%MW_% s%MS_% c%MC_%, %MF_%
  250.   Gui, %GN%:Add, Text, BackgroundTrans v_Message_, % Message
  251.  }
  252.  If ((Title) && (Message))          ; final spacing
  253.   Gui, %GN%:Margin, , 8        
  254.  Gui, %GN%:Show, Hide %wGW% %hGH%, _Notify()_GUI_       ; final sizing
  255.  Gui  %GN%:+LastFound           ; would like to get rid of this to prevent calling script being affected
  256.  WinGetPos, GX, GY, GW, GH          ; final positioning
  257.  GuiControl, %GN%:, _Wallpaper_, % "*w" GW " *h" GH " " WP  ; stretch that wallpaper to size
  258.  GuiControl, %GN%:MoveDraw, _Title_,    % "w" GW-20 " h" GH-10  ; poor handling of text wrapping when gui has explicit size called
  259.  GuiControl, %GN%:MoveDraw, _Message_,  % "w" GW-20 " h" GH-10  ; needs improvement (and if image is used or not)
  260.  If AX <>               ; add the corner "X" for closing with a different action than otherwise clicked
  261.  {
  262.   GW += 10
  263.   Gui, %GN%:Font, w%XW_% s%XS_% c%XC_%, Arial Black         ; × (multiply) is the character used for the X-Button
  264.   Gui, %GN%:Add, Text, % "x" GW-15 " y-2 Center w12 h20 g_Notify_Kill_" GN - GF + 1, % chr(0x00D7) ;××
  265.  }
  266.  Gui, %GN%:Add, Text, x0 y0 w%GW% h%GH% BackgroundTrans g_Notify_Action_Clicked_    ; to catch clicks anywhere on the gui
  267.  If (GR_)                   ; may have to be removed for seperate title/message/etc actions
  268.   WinSet, Region, % "0-0 w" GW " h" GH " R" GR_ "-" GR_
  269.  If (GT_)                   ; non-functioning GT option, since the border gui gets in the way
  270.   WinSet, Transparent, % GT_                ; will be addressed someday, leaving it in
  271.  
  272.  SysGet, Workspace, MonitorWorkArea             ; positioning
  273.  NewX := WorkSpaceRight-GW-5
  274.  If (OtherY)
  275.   NewY := OtherY-GH-2-BW_*2
  276.  Else
  277.   NewY := WorkspaceBottom-GH-5
  278.  If NewY < % WorkspaceTop
  279.   NewY := WorkspaceBottom-GH-5
  280.  
  281.  Gui, %GN2%:-Caption +ToolWindow +AlwaysOnTop -Border +E0x20        ; border gui
  282.  Gui, %GN2%:Color, %BC_%
  283.  Gui  %GN2%:+LastFound
  284.  If (BR_)
  285.   WinSet, Region, % "0-0 w" GW+(BW_*2) " h" GH+(BW_*2) " R" BR_ "-" BR_
  286.  If (BT_)
  287.   WinSet, Transparent, % BT_
  288.  
  289.  Gui, %GN2%:Show, % "Hide x" NewX-BW_ " y" NewY-BW_ " w" GW+(BW_*2) " h" GH+(BW_*2), _Notify()_BGGUI_   ; actual creation of border gui! but still not shown
  290.  Gui, %GN%:Show,  % "Hide x" NewX " y" NewY " w" GW, _Notify()_GUI_         ; actual creation of Notify() gui! but still not shown
  291.  Gui  %GN%:+LastFound                   ; need to get rid of this so calling script isn't affected
  292.  If SI_
  293.   DllCall("AnimateWindow","UInt",WinExist(),"Int",SI_,"UInt","0x00040008")      ; animated in, if SI is used
  294.  Else
  295.   Gui, %GN%:Show, NA, _Notify()_GUI_                ; otherwise, just shown
  296.  Gui, %GN2%:Show, NA, _Notify()_BGGUI_              ; and the border shown
  297.  WinSet, AlwaysOnTop, On                    ; and set to Always on Top
  298.  
  299.  If ((Duration < 0) OR (Duration = "-0"))               ; saves internally that ExitApp should happen when this
  300.   Exit := GN                        ; notify dissappears
  301.  If (Duration) 
  302.   SetTimer, % "_Notify_Kill_" GN - GF + 1, % - Abs(Duration) * 1000         ; timer set depending on Duration parameter
  303.  Else
  304.   SetTimer, % "_Notify_Flash_" GN - GF + 1, % BF_               ; timer set to flash border if the Notify has 0 (infinite) duration
  305.  
  306. Return %GN%                 ; end of Notify(), returns Gui ID number used
  307.  
  308. ;==========================================================================
  309. ;========================================== when a notification is clicked:
  310. _Notify_Action_Clicked_:                ; option AC=Label means Label: subroutine will be called here when clicked
  311.  ; Critical
  312.  SetTimer, % "_Notify_Kill_" A_Gui - GF + 1, Off
  313.  Gui, % A_Gui + GL - GF + 1 ":Destroy"
  314.  If SC
  315.  {
  316.   Gui, %A_Gui%:+LastFound
  317.   DllCall("AnimateWindow","UInt",WinExist(),"Int",SC,"UInt", "0x00050001")
  318.  }
  319.  Gui, %A_Gui%:Destroy
  320.  If (ACList)
  321.   Loop,Parse,ACList,|
  322.    If ((Action := SubStr(A_LoopField,1,2)) = A_Gui)
  323.    {
  324.     Temp_Notify_Action:= SubStr(A_LoopField,4)
  325.     StringReplace, ACList, ACList, % "|" A_Gui "=" Temp_Notify_Action, , All
  326.     If IsLabel(_Notify_Action := Temp_Notify_Action)
  327.      Gosub, %_Notify_Action%
  328.     _Notify_Action =
  329.     Break
  330.    }
  331.  StringReplace, GNList, GNList, % "|" A_Gui, , All
  332.  SetTimer, % "_Notify_Flash_" A_Gui - GF + 1, Off
  333.  If (Exit = A_Gui)
  334.   ExitApp
  335. Return
  336.  
  337. ;==========================================================================
  338. ;=========================================== when a notification times out:
  339. _Notify_Kill_1:
  340. _Notify_Kill_2:     ; this needs a different method, too many labels
  341. _Notify_Kill_3:     ; they are used for Timers, different for each Notify() based on duration...
  342. _Notify_Kill_4:
  343. _Notify_Kill_5:
  344. _Notify_Kill_6:
  345. _Notify_Kill_7:
  346. _Notify_Kill_8:
  347. _Notify_Kill_9:
  348. _Notify_Kill_10:
  349. _Notify_Kill_11:
  350. _Notify_Kill_12:
  351. _Notify_Kill_13:
  352. _Notify_Kill_14:
  353. _Notify_Kill_15:
  354. _Notify_Kill_16:
  355. _Notify_Kill_17:
  356. _Notify_Kill_18:
  357. _Notify_Kill_19:
  358. _Notify_Kill_20:
  359. _Notify_Kill_21:
  360. _Notify_Kill_22:
  361. _Notify_Kill_23:
  362. _Notify_Kill_24:
  363. _Notify_Kill_25:
  364. Critical
  365.  StringReplace, GK, A_ThisLabel, _Notify_Kill_
  366.  SetTimer, _Notify_Flash_%GK%, Off
  367.  GK := GK + GF - 1
  368.  Gui, % GK + GL - GF + 1 ":Destroy"
  369.  If ST
  370.  {
  371.   Gui, %GK%:+LastFound
  372.   DllCall("AnimateWindow","UInt",WinExist(),"Int",ST,"UInt", "0x00050001")
  373.  }
  374.  Gui, %GK%:Destroy
  375.  StringReplace, GNList, GNList, % "|" GK, , All
  376.  If (Exit = GK)
  377.   ExitApp
  378. Return 1
  379.  
  380. ;==========================================================================
  381. ;======================================== flashes a permanent notification:
  382. _Notify_Flash_1:
  383. _Notify_Flash_2:
  384. _Notify_Flash_3:
  385. _Notify_Flash_4:        ; this needs a different method, too many labels
  386. _Notify_Flash_5:        ; they are used for Timers, different for each Notify() based on flash speed...
  387. _Notify_Flash_6:        ; when duration is 0 (infinite)
  388. _Notify_Flash_7:        ; this may feature may be removed completely, Update given the ability to affect GC and BC
  389. _Notify_Flash_8:        ; and then the flashing could be handled script-side via returned gui number and a script-side timer
  390. _Notify_Flash_9:
  391. _Notify_Flash_10:
  392. _Notify_Flash_11:
  393. _Notify_Flash_12:
  394. _Notify_Flash_13:
  395. _Notify_Flash_14:
  396. _Notify_Flash_15:
  397. _Notify_Flash_16:
  398. _Notify_Flash_17:
  399. _Notify_Flash_18:
  400. _Notify_Flash_19:
  401. _Notify_Flash_20:
  402. _Notify_Flash_21:
  403. _Notify_Flash_22:
  404. _Notify_Flash_23:
  405. _Notify_Flash_24:
  406. _Notify_Flash_25:
  407. StringReplace, FlashGN, A_ThisLabel, _Notify_Flash_
  408.  FlashGN += GF - 1
  409.  FlashGN2 := FlashGN + GL - GF + 1
  410.  If Flashed%FlashGN2% := !Flashed%FlashGN2%
  411.   Gui, %FlashGN2%:Color, %BK%
  412.  Else
  413.   Gui, %FlashGN2%:Color, %BC%
  414. Return
  415. }
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447. #SingleInstance force
  448. #Persistent
  449.  
  450. Version = 2
  451.  
  452. FileInstall, Banner.png, Banner.png, 1
  453. FileInstall, success.png, success.png, 1
  454. FileInstall, fail.png, fail.png, 1
  455. FileInstall, Icon.ico, Icon.ico
  456.  
  457. SplitGetIndex(InputVal, Delimeter, N)
  458. {
  459.     InputVal = %Delimeter%%InputVal%%Delimeter%
  460.     N += 1
  461.     StringLen, InputLen, InputVal
  462.     StringGetPos, ValStartN, InputVal, %Delimeter%, L%N%
  463.     ValStartN += 1
  464.     N += 1
  465.     StringGetPos, ValEndN, InputVal, %Delimeter%, L%N%
  466.     StringTrimLeft, Output, InputVal, %ValStartN%
  467.     TrimRight := InputLen - ValEndN
  468.     StringTrimRight, Output, Output, %TrimRight%
  469.     return Output
  470. }
  471.  
  472. ;http://www.autohotkey.com/board/topic/2486-code-to-convert-fromto-unix-timestamp/page-2
  473.  
  474. Time_unix2Human(unixTimestamp) {
  475.     returnDate = 19700101000000
  476.     returnDate += unixTimestamp, s
  477.     return returnDate
  478. }
  479.  
  480.  
  481. Time_human2Unix(humanTime) {
  482.     humanTime -= 1970, s
  483.     return humanTime
  484. }
  485.  
  486. Time_unix2hhmmss(time)
  487. {
  488.     Hours := Floor(time/3600)
  489.     if (Hours > 0) {
  490.         time -= Hours * 3600
  491.     }
  492.     Minutes := Floor(time/60)
  493.     if (Minutes > 0) {
  494.         time -= Minutes * 60
  495.     }
  496.     Seconds := time
  497.    
  498.     ifLess, Hours, 10
  499.         Hours := "0" . Hours
  500.     ifLess, Minutes, 10
  501.         Minutes := "0" . Minutes
  502.     ifLess, Seconds, 10
  503.         Seconds := "0" . Seconds
  504.    
  505.     return Hours . ":" . Minutes . ":" . Seconds
  506. }
  507.  
  508. IniLocation = %A_ScriptDir%\settings.ini
  509.  
  510. IfNotExist, %A_ScriptDir%\Logs
  511.     FileCreateDir, %A_ScriptDir%\Logs
  512. IfNotExist, %A_ScriptDir%\settings.ini
  513. {
  514.     MsgBox, 36, SAMPLogManager, SAMPLogManager can add itself into your computers startup folder so it will automatically start when you log into windows. This way you won't have to worry about forgetting to launch it and losing some log files.`n`nWould you like to add SAMPLogManager to system startup?
  515.     IfMsgBox, Yes
  516.         FileCreateShortcut, %A_ScriptFullPath%, %A_Startup%\SAMPLogManager.lnk
  517.     FileSelectFile, LogLocation,, %A_MyDocuments%\GTA San Andreas User Files\SAMP\chatlog.txt, Select SAMP logfile, .txt
  518.     IniWrite, %LogLocation%, %IniLocation%, Main, LogLocation
  519.     IniWrite, UNDEFINED_SERVER_NAME, %IniLocation%, Main, NoServerName
  520.     IniWrite, %A_ScriptDir%\Logs, %IniLocation%, Main, BackupLocation
  521.     IniWrite, 1, %IniLocation%, Main, ShowNotification
  522. }
  523.  
  524. IniRead, LogLocation, %IniLocation%, Main, LogLocation
  525. IniRead, Server, %IniLocation%, Main, NoServerName
  526. IniRead, BackupLocation, %IniLocation%, Main, BackupLocation
  527. IniRead, ShowNotification, %IniLocation%, Main, ShowNotification
  528.  
  529. Menu, Tray, NoStandard
  530. Menu, Tray, Icon, Icon.ico
  531. Menu, Tray, Tip, SAMPLogManager
  532.  
  533. Menu, Tray, Add, SAMPLogManager, TrayMenuLogo
  534. Menu, Tray, Disable, SAMPLogManager
  535.  
  536. Menu, Tray, Add
  537.  
  538. Menu, Tray, Add, Show notifications, notifytoggle
  539.  
  540. if (ShowNotification == 0) {
  541.     Menu, Tray, UnCheck, Show notifications
  542. } else {
  543.     Menu, Tray, Check, Show notifications
  544. }
  545. Menu, Tray, Add, Change chatlog location, updatechatlocation
  546.  
  547. Menu, Tray, Add
  548.  
  549. Menu, Tray, Add, View logs, viewlogs
  550. Menu, Tray, Add, Info, info
  551. Menu, Tray, Add, Quit, quit
  552.  
  553. Menu, Tray, Default, View logs
  554.  
  555. ;Call home
  556. URLDownloadToFile, http://pastebin.com/raw.php?i=81Vx9pZc, Temp.txt
  557. FileRead, CurrentVersion, Temp.txt
  558. FileDelete, Temp.txt
  559.  
  560. URLDownloadToFile, http://pastebin.com/raw.php?i=BwKsgABa, Temp.txt
  561. FileRead, HomePage, Temp.txt
  562. FileDelete, Temp.txt
  563.  
  564. ifLess, CurrentVersion, %Version%
  565. {
  566.     MsgBox, 52, SAMPLogManager - Out of date, Your installation of SAMPLogManager may be out of date.`n`nWould you like to visit the homepage to find out more?
  567.     ifMsgBox, Yes
  568.     {
  569.         Run, %HomePage%
  570.     }
  571. }
  572.  
  573. Loop
  574. {
  575.     IfExist, %LogLocation%
  576.     {
  577.         IfWinNotExist, GTA:SA:MP
  578.         {
  579.             Loop, Read, %LogLocation%
  580.             {
  581.                 ifInString, A_LoopReadLine, Connecting to
  582.                 {
  583.                     StringTrimLeft, IP, A_LoopReadLine, 26
  584.                     StringTrimRight, IP, IP, 8
  585.                 }
  586.                 ifInString, A_LoopReadLine,  Connected to
  587.                 {
  588.                     StringTrimLeft, Server, A_LoopReadLine, 32
  589.                     break
  590.                 }
  591.             }
  592.             FileGetTime, StartTime, %LogLocation%, C
  593.             StartTime := Time_human2Unix(StartTime)
  594.             FileGetTime, LeaveTime, %LogLocation%, M
  595.             LeaveTime := Time_human2Unix(LeaveTime)
  596.            
  597.             RegRead, Nickname, HKEY_CURRENT_USER, Software\SAMP, PlayerName
  598.            
  599.             StringReplace, Server, Server, _, [(--UNDERSCORE--)], All
  600.             StringReplace, IP, IP, _, [(--UNDERSCORE--)], All
  601.             StringReplace, Nickname, Nickname, _, [(--UNDERSCORE--)], All
  602.            
  603.             FileName = %A_YYYY%-%A_MM%-%A_DD%_%A_Hour%-%A_Min%_%Server%_%StartTime%_%LeaveTime%_%IP%_%Nickname%.txt
  604.             FileCopy, %LogLocation%, %BackupLocation%\%FileName%
  605.             Sleep, 2500
  606.             ifExist, %BackupLocation%\%FileName%
  607.             {
  608.                 ifEqual, ShowNotification, 1
  609.                 {
  610.                     Notify("Success!","We have sucessfully backed up your chatlog.",5,"GC=94104C BC=630432 BT=255 BK=Black TC=White MC=White Image=success.png")
  611.                 }
  612.             }
  613.             IfNotExist, %BackupLocation%\%FileName%
  614.             {
  615.               RunWait, cmd /c copy /Y `"%LogLocation%`" `"%BackupLocation%\%FileName%`",, Hide
  616.               Sleep, 2500
  617.               ifExist, %BackupLocation%\%FileName%
  618.               {
  619.                 ifEqual, ShowNotification, 1
  620.                 {
  621.                     Notify("Success!","We have sucessfully backed up your chatlog.",5,"GC=94104C BC=630432 BT=255 BK=Black TC=White MC=White Image=success.png")
  622.                     FileDelete, %LogLocation%
  623.                     ifExist, %LogLocation%
  624.                     {
  625.                      RunWait, cmd /c DEL `"%LogLocation%`",, Hide
  626.                      Sleep, 2500
  627.                      ifExist, %LogLocation%
  628.                      {
  629.                       Notify("Fail!","We have unfortunately not been able to delete your original chatlog file.",5,"GC=94104C BC=630432 BT=255 BK=Black TC=White MC=White Image=fail.png")
  630.                      }
  631.                     }
  632.                 }
  633.               }
  634.               ifNotExist, %BackupLocation%\%FileName%
  635.               {
  636.                 Notify("Fail!","We have unfortunately not been able to back up your chatlog.",5,"GC=94104C BC=630432 BT=255 BK=Black TC=White MC=White Image=fail.png")
  637.                 FileAppend, FileName - %FileName%,`nLogLocation - %LogLocation%,`nIP - %IP%,`nServer - %Server%,`nNickname - %Nickname%,`nStartTime - %StartTime%,`nLeaveTime - %LeaveTime%, ERROR-%A_YYYY%-%A_MM%-%A_DD%_%A_Hour%-%A_Min%.txt
  638.                }
  639.             }
  640.         }
  641.     }
  642.     Sleep, 2500
  643. }
  644.  
  645. TrayMenuLogo:
  646. Run, %Homepage%
  647. return
  648.  
  649. viewlogs:
  650. Gui, Destroy
  651. Gui, Add, ListView, x16 y11 w1010 h380 gDaListView, Filename|Time|Server|Join time|Leave time|Playtime|IP|Nickname
  652. Loop, %BackupLocation%\*.txt
  653. {
  654.     StringTrimRight, FileName, A_LoopFileName, 4
  655.    
  656.     RowTime := SplitGetIndex(FileName, "_", 0) . " " . SplitGetIndex(FileName, "_", 1)
  657.     ServerName := SplitGetIndex(FileName, "_", 2)
  658.     StartTime := SplitGetIndex(FileName, "_", 3)
  659.     LeaveTime := SplitGetIndex(FileName, "_", 4)
  660.     IP := SplitGetIndex(FileName, "_", 5)
  661.     Nickname := SplitGetIndex(FileName, "_", 6)
  662.    
  663.     Duration := Time_unix2hhmmss(LeaveTime - StartTime)
  664.    
  665.     StartTime := Time_unix2Human(StartTime)
  666.     LeaveTime := Time_unix2Human(LeaveTime)
  667.    
  668.     StringReplace, ServerName, ServerName, [(--UNDERSCORE--)], _, All
  669.     StringReplace, IP, IP, [(--UNDERSCORE--)], _, All
  670.     StringReplace, Nickname, Nickname, [(--UNDERSCORE--)], _, All
  671.    
  672.     FormatTime, StartTime, %StartTime%, dd.MM.yyyy HH:mm
  673.     FormatTime, LeaveTime, %LeaveTime%, dd.MM.yyyy HH:mm
  674.    
  675.     LV_Add("", A_LoopFileName, RowTime, ServerName, StartTime, LeaveTime, Duration, IP, Nickname)
  676. }
  677. LV_ModifyCol()
  678. LV_ModifyCol(1, 0)
  679. LV_ModifyCol(6, 55)
  680. ; Generated using SmartGUI Creator for SciTE
  681. Gui, Show, w1043 h404, SAMPLogManager - View logs
  682. return
  683.  
  684. DaListView:
  685. ifEqual, A_GuiEvent, DoubleClick
  686. {
  687.     LV_GetText(Title1, A_EventInfo, 1)
  688.     ifNotEqual, Title1, Filename
  689.     {
  690.         Run, %BackupLocation%\%Title1%
  691.     }
  692. }
  693. return
  694.  
  695. GuiClose:
  696. Gui, Destroy
  697. return
  698.  
  699. info:
  700. Gui, 2: Destroy
  701. Gui, 2: Add, Picture, x46 y11 w500 h150 gBanner, Banner.png
  702. Gui, 2: Add, Button, x246 y371 w100 h30 gGuiClose, Okay
  703. Gui, 2: Add, Link, x46 y171 w500 h190 , <a href=`"%Homepage%`">SAMPLogManager</a> was created by <a href="https://about.me/kristjanvariksoo">EstonianHacker</a>.`n`n<a href="http://www.pelfusion.com/">Icon "Log Icon" By PelFusion from Iconset "Flat File Type Icons"</a>`n<a href="http://www.iconarchive.com/show/flatastic-2-icons-by-custom-icon-design/success-icon.html">Icon "Success Icon" by Custom Icon Design from Iconset "Flatastic 2 Icons"</a>`n<a href="http://awicons.com/">Icon "Delete Icon" by Lokas Software from Iconset "Vista Artistic Icons"</a>`n`n<a href="http://ahkscript.org/">Coded in AutoHotkey</a>`n<a href="http://fincs.ahk4.net/scite4ahk">Coded using SciTE4AutoHotkey</a>`n<a href="http://www.autohotkey.com/board/topic/44870-notify-multiple-easy-tray-area-notifications-v04991/">AutoHotkey Notify() library by gwarble</a>`n<a href="http://www.autohotkey.com/board/topic/2486-code-to-convert-fromto-unix-timestamp/page-2">Timestamp to/from Epoch using functions by [VxE] and Laszlo</a>`n<a href="http://ahkscript.org/boards/viewtopic.php?f=6&t=303">Gui created using SmartGUI Creator for SciTE4AutoHotkey v3</a>
  704.  
  705. ; Generated using SmartGUI Creator for SciTE
  706. Gui, 2: Show, w594 h419, SAMPLogManager - About
  707. return
  708.  
  709. Banner:
  710. Run, %Homepage%
  711. return
  712.  
  713. notifytoggle:
  714. Menu, Tray, ToggleCheck, Show notifications
  715. if (ShowNotification == 0) {
  716.     ShowNotification = 1
  717. } else {
  718.     ShowNotification = 0
  719. }
  720. IniWrite, %ShowNotification%, %A_MyDocuments%\SAMPLogManager\settings.ini, Main, ShowNotification
  721. return
  722.  
  723. updatechatlocation:
  724. FileSelectFile, LogLocation,, %A_MyDocuments%\GTA San Andreas User Files\SAMP\chatlog.txt, Select SAMP logfile, .txt
  725. IniWrite, %LogLocation%, %IniLocation%, Main, LogLocation
  726. IniRead, LogLocation, %IniLocation%, Main, LogLocation
  727. return
  728.  
  729. quit:
  730. ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement