Contrib/ExperienceUI/Utils/Source/PatchGen.nsi
changeset 0 d5ce4c64ef88
equal deleted inserted replaced
-1:000000000000 0:d5ce4c64ef88
       
     1 Name "ExperienceUI Patch Generator"
       
     2 Caption "$(^Name)"
       
     3 OutFile ..\PatchGen.exe
       
     4 InstallDir $DESKTOP\PatchFiles
       
     5 
       
     6 Var NAME
       
     7 Var TYPE
       
     8 Var START
       
     9 Var SOURCE
       
    10 Var TARGET
       
    11 Var SALT
       
    12 Var SIG
       
    13 Var CN
       
    14 Var CE
       
    15 Var APPEND
       
    16 Var IL
       
    17 Var AP
       
    18 Var FN
       
    19 
       
    20 !include XPUI.nsh
       
    21 
       
    22 !include RecFind.nsh
       
    23 
       
    24 Page custom io iofin " "
       
    25 !define XPUI_PAGE_CUSTOMFUNCTION_LEAVE DirWarn
       
    26 !insertmacro XPUI_PAGE_DIRECTORY
       
    27 !insertmacro XPUI_PAGE_INSTFILES
       
    28 
       
    29 Section
       
    30   RMDir /r "$INSTDIR" ; don't worry, you're warned first
       
    31   StrCpy $3 0 ; NumFields count
       
    32   SetOutPath $INSTDIR
       
    33   WriteINIStr $INSTDIR\Content.dat "EUI-$TYPE" Name "$NAME"
       
    34   StrLen $IL $SOURCE
       
    35   IntOp $IL $IL + 1
       
    36   ${RecFindOpen} "$SOURCE" $0 $1
       
    37     StrCpy $4 $0
       
    38     StrCpy $2 $TARGET$0
       
    39     ${RecFindFirst}
       
    40     IntOp $3 $3 + 1
       
    41       SetDetailsPrint both
       
    42       StrCpy $AP $SOURCE$0 "" $IL
       
    43       DetailPrint "  $$AP: $AP"
       
    44       Push $AP
       
    45       Push "\"
       
    46       Push "_"
       
    47       Call StrReplace
       
    48       Pop $FN
       
    49       StrCpy $FN "$FN_$1"
       
    50       DetailPrint "  $$FN: $FN"
       
    51     WriteINIStr $INSTDIR\Content.dat "EUI-$TYPE" NumFiles $3
       
    52     WriteINIStr $INSTDIR\Content.dat "EUI-$TYPE" "File$START" $1
       
    53     WriteINIStr $INSTDIR\Content.dat "EUI-$TYPE" "File$START Path" $2
       
    54     WriteINIStr $INSTDIR\Content.dat "EUI-$TYPE" "File$START SName" $FN
       
    55     StrCmp $SIG 1 "" NoSig
       
    56       SetDetailsPrint none
       
    57       GetTempFileName $R0
       
    58       CopyFiles $SOURCE$0\$1 $R0
       
    59       FileOpen $R1 $R0 a
       
    60         FileSeek $R1 0 END
       
    61         FileWrite $R1 $SALT$APPEND
       
    62       FileClose $R1
       
    63       DCryptDll::MD5Hash "FS" $R0 "--End--"
       
    64       Delete $R0 ; Let's not leave 300 temporary files sitting on your computer...
       
    65       Pop $R2
       
    66         StrCmp $R2 OK GoodMD5
       
    67           DetailPrint "WARNING: An error ocurred while trying to get the signature hash"
       
    68           DetailPrint "DCryptDll returned: $R2"
       
    69           DetailPrint "The patch/skin will NOT be signed."
       
    70           StrCpy $SIG 0
       
    71           Goto NoSig
       
    72         GoodMD5:
       
    73       Pop $R2
       
    74       WriteINIStr $INSTDIR\Content.dat "EUI-$TYPE" "File$START Sig" $R2
       
    75       SetDetailsPrint Both
       
    76     NoSig:
       
    77     IntOp $START $START + 1
       
    78     SetDetailsPrint none ;TEMPORARY
       
    79     CopyFiles $SOURCE$0\$1 $INSTDIR\$FN
       
    80     ${RecFindNext}
       
    81   ${RecFindClose}
       
    82   ; Sign the content file
       
    83   StrCmp $SIG 1 "" NoSignScript
       
    84     StrCmp $CN "" NoCN
       
    85       WriteINIStr $INSTDIR\Content.dat SigInfo PN "Dan Fuhry"
       
    86       WriteINIStr $INSTDIR\Content.dat SigInfo PE "dandaman32@users.sourceforge.net"
       
    87       WriteINIStr $INSTDIR\Content.dat SigInfo CN "$CN"
       
    88       WriteINIStr $INSTDIR\Content.dat SigInfo CE "$CE"
       
    89     NoCN:
       
    90     GetTempFileName $R0
       
    91       CopyFiles $INSTDIR\Content.dat $R0
       
    92       FileOpen $R1 $R0 a
       
    93         FileSeek $R1 0 END
       
    94         FileWrite $R1 $SALT
       
    95       FileClose $R1
       
    96       DCryptDll::MD5Hash "FS" $R0 "--End--"
       
    97       Delete $R0
       
    98       Pop $R2
       
    99         StrCmp $R2 OK GoodMD5b
       
   100           DetailPrint "WARNING: An error ocurred while trying to get the signature hash"
       
   101           DetailPrint "DCryptDll returned: $R2"
       
   102           DetailPrint "The patch/skin will NOT be signed."
       
   103           StrCpy $SIG 0
       
   104           Goto NoSignScript
       
   105         GoodMD5b:
       
   106       Pop $R2
       
   107       FileOpen $R0 "$INSTDIR\content.sig" w
       
   108       FileWrite $R0 $R2
       
   109       FileClose $R0
       
   110   NoSignScript:
       
   111   SetAutoClose false
       
   112   SetDetailsPrint both
       
   113 SectionEnd
       
   114 
       
   115 Function io
       
   116   SetOutPath $PLUGINSDIR
       
   117   File patchgen.ini
       
   118   !insertmacro XPUI_INSTALLOPTIONS_INITDIALOG "patchgen.ini"
       
   119   !insertmacro XPUI_HEADER_TEXT "Patch Generator" "This program generates a recursive list of files and adds writes it to an ExperienceUI-compatible Content.dat."
       
   120     GetDlgItem $0 $XPUI_HWND 1214
       
   121     ShowWindow $0 0
       
   122     GetDlgItem $0 $XPUI_HWND 1215
       
   123     ShowWindow $0 0
       
   124     GetDlgItem $0 $XPUI_HWND 1216
       
   125     ShowWindow $0 0
       
   126     GetDlgItem $0 $XPUI_HWND 1217
       
   127     ShowWindow $0 0
       
   128     GetDlgItem $0 $XPUI_HWND 1218
       
   129     ShowWindow $0 0
       
   130     GetDlgItem $0 $XPUI_HWND 1219
       
   131     ShowWindow $0 0
       
   132   InstallOptions::show
       
   133 FunctionEnd
       
   134 
       
   135 Function iofin
       
   136   ReadINIStr $0 $PLUGINSDIR\patchgen.ini "Settings" State
       
   137   StrCmp $0 13 b
       
   138   ReadINIStr $0 $PLUGINSDIR\patchgen.ini "Field 1" State
       
   139   StrCmp $0 1 p
       
   140   StrCpy $TYPE skin
       
   141   goto c
       
   142   b:
       
   143     ReadINIStr $0 $PLUGINSDIR\patchgen.ini "Field 13" State
       
   144     StrCmp $0 1 Show
       
   145     GetDlgItem $0 $XPUI_HWND 1214
       
   146     ShowWindow $0 0
       
   147     GetDlgItem $0 $XPUI_HWND 1215
       
   148     ShowWindow $0 0
       
   149     GetDlgItem $0 $XPUI_HWND 1216
       
   150     ShowWindow $0 0
       
   151     GetDlgItem $0 $XPUI_HWND 1217
       
   152     ShowWindow $0 0
       
   153     GetDlgItem $0 $XPUI_HWND 1218
       
   154     ShowWindow $0 0
       
   155     GetDlgItem $0 $XPUI_HWND 1219
       
   156     ShowWindow $0 0
       
   157     Abort
       
   158     Show:
       
   159     GetDlgItem $0 $XPUI_HWND 1214
       
   160     ShowWindow $0 5
       
   161     GetDlgItem $0 $XPUI_HWND 1215
       
   162     ShowWindow $0 5
       
   163     GetDlgItem $0 $XPUI_HWND 1216
       
   164     ShowWindow $0 5
       
   165     GetDlgItem $0 $XPUI_HWND 1217
       
   166     ShowWindow $0 5
       
   167     GetDlgItem $0 $XPUI_HWND 1218
       
   168     ShowWindow $0 5
       
   169     GetDlgItem $0 $XPUI_HWND 1219
       
   170     ShowWindow $0 5
       
   171     Abort
       
   172   p:
       
   173   StrCpy $TYPE patch
       
   174   c:
       
   175   ReadINIStr $NAME $PLUGINSDIR\patchgen.ini "Field 3" State
       
   176   ReadINIStr $START $PLUGINSDIR\patchgen.ini "Field 10" State
       
   177   ReadINIStr $TARGET $PLUGINSDIR\patchgen.ini "Field 7" State
       
   178   ReadINIStr $SOURCE $PLUGINSDIR\patchgen.ini "Field 11" State
       
   179   ReadINIStr $SIG $PLUGINSDIR\patchgen.ini "Field 13" State
       
   180   ReadINIStr $SALT $PLUGINSDIR\patchgen.ini "Field 14" State
       
   181   ReadINIStr $CN $PLUGINSDIR\patchgen.ini "Field 17" State
       
   182   ReadINIStr $CE $PLUGINSDIR\patchgen.ini "Field 18" State
       
   183   StrCpy $APPEND ""
       
   184   StrCmp $CN "" +2
       
   185     StrCpy $APPEND ";PN=Dan Fuhry;PE=dandaman32@users.sourceforge.net;CN=$CN;CE=$CE"
       
   186 FunctionEnd
       
   187 
       
   188 Function DirWarn
       
   189   IfFileExists $INSTDIR 0 NoID
       
   190   MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Caution: the selected target folder already exists.  The entire target folder will be erased, recursively.  Do you REALLY want to continue?" IDYES +3
       
   191   LockWindow off
       
   192   Abort
       
   193   NoID:
       
   194 FunctionEnd
       
   195 
       
   196 Function GetParentPath
       
   197   Exch $0
       
   198   Push $1
       
   199   Push $2
       
   200     StrLen $1 $0
       
   201     loop:
       
   202       IntOp $1 $1 - 1
       
   203       StrCpy $2 $0 1 $1
       
   204       StrCmp $2 "" error
       
   205       StrCmp $2 "\" "" Loop
       
   206     StrCpy $0 $0 $1
       
   207     Goto good
       
   208     error:
       
   209     StrCpy $0 $0
       
   210     good:
       
   211   Pop $2
       
   212   Pop $1
       
   213   Exch $0
       
   214 FunctionEnd
       
   215 
       
   216 Var STR_REPLACE_VAR_0
       
   217 Var STR_REPLACE_VAR_1
       
   218 Var STR_REPLACE_VAR_2
       
   219 Var STR_REPLACE_VAR_3
       
   220 Var STR_REPLACE_VAR_4
       
   221 Var STR_REPLACE_VAR_5
       
   222 Var STR_REPLACE_VAR_6
       
   223 Var STR_REPLACE_VAR_7
       
   224 Var STR_REPLACE_VAR_8
       
   225 
       
   226 Function StrReplace
       
   227   Exch $STR_REPLACE_VAR_2
       
   228   Exch 1
       
   229   Exch $STR_REPLACE_VAR_1
       
   230   Exch 2
       
   231   Exch $STR_REPLACE_VAR_0
       
   232     StrCpy $STR_REPLACE_VAR_3 -1
       
   233     StrLen $STR_REPLACE_VAR_4 $STR_REPLACE_VAR_1
       
   234     StrLen $STR_REPLACE_VAR_6 $STR_REPLACE_VAR_0
       
   235     loop:
       
   236       IntOp $STR_REPLACE_VAR_3 $STR_REPLACE_VAR_3 + 1
       
   237       StrCpy $STR_REPLACE_VAR_5 $STR_REPLACE_VAR_0 $STR_REPLACE_VAR_4 $STR_REPLACE_VAR_3
       
   238       StrCmp $STR_REPLACE_VAR_5 $STR_REPLACE_VAR_1 found
       
   239       StrCmp $STR_REPLACE_VAR_3 $STR_REPLACE_VAR_6 done
       
   240       Goto loop
       
   241     found:
       
   242       StrCpy $STR_REPLACE_VAR_5 $STR_REPLACE_VAR_0 $STR_REPLACE_VAR_3
       
   243       IntOp $STR_REPLACE_VAR_8 $STR_REPLACE_VAR_3 + $STR_REPLACE_VAR_4
       
   244       StrCpy $STR_REPLACE_VAR_7 $STR_REPLACE_VAR_0 "" $STR_REPLACE_VAR_8
       
   245       StrCpy $STR_REPLACE_VAR_0 $STR_REPLACE_VAR_5$STR_REPLACE_VAR_2$STR_REPLACE_VAR_7
       
   246       StrLen $STR_REPLACE_VAR_6 $STR_REPLACE_VAR_0
       
   247       Goto loop
       
   248     done:
       
   249   Pop $STR_REPLACE_VAR_1
       
   250   Pop $STR_REPLACE_VAR_1
       
   251   Exch $STR_REPLACE_VAR_0
       
   252 FunctionEnd
       
   253 
       
   254 !insertmacro XPUI_LANGUAGE English