inst-resources/applist.nsh
changeset 0 67e1cc6cd929
equal deleted inserted replaced
-1:000000000000 0:67e1cc6cd929
       
     1 /**
       
     2  * Inserts an HTML file at the necessary point in applications.html.
       
     3  * @param string HTML file
       
     4  */
       
     5 
       
     6 Function BNRegisterApplicationToList
       
     7   ClearErrors
       
     8 
       
     9   ; Make sure it's not already in there
       
    10   FileOpen $0 "$stack_instdir\apache2\htdocs\applications.html" "r"
       
    11   IfErrors 0 +3
       
    12     SetErrors
       
    13     Return
       
    14     
       
    15   loop:
       
    16     FileRead $0 $1
       
    17     IfErrors EOF
       
    18     Push $1
       
    19     Push "Module ${PRODUCT_SHORTNAME}"
       
    20     Call StrStr
       
    21     Pop $1
       
    22     StrCmp $1 "" +3
       
    23       ; found it, skip write
       
    24       FileClose $0
       
    25       Return
       
    26     Goto loop
       
    27   EOF:
       
    28   FileClose $0
       
    29   
       
    30   Pop $0
       
    31   Push "$stack_instdir\apache2\htdocs\applications.html"
       
    32   Push $0
       
    33   Push "<!-- @@BITNAMI_MODULE_PLACEHOLDER@@ -->"
       
    34   Call AppendBeforeSubstring
       
    35 FunctionEnd
       
    36 
       
    37 Function AppendBeforeSubstring
       
    38   Pop $R2 ; marker
       
    39   Pop $R1 ; file to insert
       
    40   Pop $R0 ; file to modify
       
    41   
       
    42   StrCpy $R7 0 ; $R7 = current offset
       
    43   
       
    44   ClearErrors
       
    45   FileOpen $R3 $R0 "a" ; $R3 = handle
       
    46   FileSeek $R3 0
       
    47   IfErrors 0 +3
       
    48     SetErrors
       
    49     Return
       
    50     
       
    51   loop:
       
    52     FileRead $R3 $R4 ${NSIS_MAX_STRLEN} ; $R4 = line
       
    53     IfErrors 0 +3
       
    54       DetailPrint "EOF"
       
    55       Goto EOF
       
    56     StrLen $R8 $R4 ; $R8 = length of line
       
    57     IntOp $R7 $R7 + $R8
       
    58     
       
    59     Push $R4
       
    60     Push $R2
       
    61     Call StrStr
       
    62     Pop $R5 ; $R5 = substring test
       
    63     StrCmp $R5 "" /* no match */ loop
       
    64     
       
    65     ; got a match!
       
    66     StrLen $R6 $R5 ; Length of found substring
       
    67     ; rewind a little bit, to right before the substring
       
    68     IntOp $R8 $R7 - $R6
       
    69     FileSeek $R3 -$R6 CUR $R5
       
    70     
       
    71     ; store the rest of the file
       
    72     StrCpy $R9 ""
       
    73     remainderloop:
       
    74       ClearErrors
       
    75       FileRead $R3 $R7
       
    76       StrCpy $R9 "$R9$R7"
       
    77       IfErrors 0 remainderloop
       
    78     ; now jump back to our point
       
    79     FileSeek $R3 $R5
       
    80     
       
    81     ; Now, write it all in
       
    82     FileOpen $R4 $R1 "r"
       
    83     IfErrors 0 +3
       
    84       SetErrors
       
    85       Return
       
    86     loop2:
       
    87       FileRead $R4 $R5 ${NSIS_MAX_STRLEN}
       
    88       IfErrors EOF2
       
    89       FileWrite $R3 $R5
       
    90       Goto loop2
       
    91       EOF2:
       
    92         FileClose $R5
       
    93       
       
    94     FileWrite $R3 $R9
       
    95   EOF:
       
    96   FileClose $R3
       
    97 FunctionEnd
       
    98 
       
    99 Function enano_add_to_applist
       
   100   StrCmp $PLUGINSDIR "" 0 +2
       
   101     InitPluginsDir
       
   102     
       
   103   SetOutPath "$stack_instdir\apache2\htdocs\img"
       
   104   File "gfx\enanocms-module.png"
       
   105   SetOutPath "$PLUGINSDIR"
       
   106   File "gfx\application.html"
       
   107   Push "$PLUGINSDIR\application.html"
       
   108   Call BNRegisterApplicationToList
       
   109   IfErrors 0 +2
       
   110     MessageBox MB_OK|MB_ICONEXCLAMATION "There was an error adding the application to the list."
       
   111 FunctionEnd
       
   112