1 |
!include "LogicLib.nsh" |
!include "LogicLib.nsh" |
2 |
|
|
3 |
; from: http://nsis.sourceforge.net/StrRep |
; from: http://nsis.sourceforge.net/StrRep |
4 |
!define StrRep "!insertmacro StrRep" |
!define StrRep "!insertmacro StrRep" |
5 |
|
|
6 |
!macro StrRep ResultVar String SubString RepString |
!macro StrRep ResultVar String SubString RepString |
7 |
Push "${String}" |
Push "${String}" |
8 |
Push "${SubString}" |
Push "${SubString}" |
9 |
Push "${RepString}" |
Push "${RepString}" |
10 |
Call StrRep |
Call StrRep |
11 |
Pop "${ResultVar}" |
Pop "${ResultVar}" |
12 |
!macroend |
!macroend |
13 |
|
|
14 |
Function StrRep |
Function StrRep |
15 |
/*After this point: |
/*After this point: |
16 |
------------------------------------------ |
------------------------------------------ |
17 |
$R0 = RepString (input) |
$R0 = RepString (input) |
18 |
$R1 = SubString (input) |
$R1 = SubString (input) |
19 |
$R2 = String (input) |
$R2 = String (input) |
20 |
$R3 = RepStrLen (temp) |
$R3 = RepStrLen (temp) |
21 |
$R4 = SubStrLen (temp) |
$R4 = SubStrLen (temp) |
22 |
$R5 = StrLen (temp) |
$R5 = StrLen (temp) |
23 |
$R6 = StartCharPos (temp) |
$R6 = StartCharPos (temp) |
24 |
$R7 = TempStrL (temp) |
$R7 = TempStrL (temp) |
25 |
$R8 = TempStrR (temp)*/ |
$R8 = TempStrR (temp)*/ |
26 |
|
|
27 |
;Get input from user |
;Get input from user |
28 |
Exch $R0 |
Exch $R0 |
29 |
Exch |
Exch |
30 |
Exch $R1 |
Exch $R1 |
31 |
Exch |
Exch |
32 |
Exch 2 |
Exch 2 |
33 |
Exch $R2 |
Exch $R2 |
34 |
Push $R3 |
Push $R3 |
35 |
Push $R4 |
Push $R4 |
36 |
Push $R5 |
Push $R5 |
37 |
Push $R6 |
Push $R6 |
38 |
Push $R7 |
Push $R7 |
39 |
Push $R8 |
Push $R8 |
40 |
|
|
41 |
;Return "String" if "SubString" is "" |
;Return "String" if "SubString" is "" |
42 |
${IfThen} $R1 == "" ${|} Goto Done ${|} |
${IfThen} $R1 == "" ${|} Goto Done ${|} |
43 |
|
|
44 |
;Get "RepString", "String" and "SubString" length |
;Get "RepString", "String" and "SubString" length |
45 |
StrLen $R3 $R0 |
StrLen $R3 $R0 |
46 |
StrLen $R4 $R1 |
StrLen $R4 $R1 |
47 |
StrLen $R5 $R2 |
StrLen $R5 $R2 |
48 |
;Start "StartCharPos" counter |
;Start "StartCharPos" counter |
49 |
StrCpy $R6 0 |
StrCpy $R6 0 |
50 |
|
|
51 |
;Loop until "SubString" is found or "String" reaches its end |
;Loop until "SubString" is found or "String" reaches its end |
52 |
${Do} |
${Do} |
53 |
;Remove everything before and after the searched part ("TempStrL") |
;Remove everything before and after the searched part ("TempStrL") |
54 |
StrCpy $R7 $R2 $R4 $R6 |
StrCpy $R7 $R2 $R4 $R6 |
55 |
|
|
56 |
;Compare "TempStrL" with "SubString" |
;Compare "TempStrL" with "SubString" |
57 |
${If} $R7 == $R1 |
${If} $R7 == $R1 |
58 |
;Split "String" to replace the string wanted |
;Split "String" to replace the string wanted |
59 |
StrCpy $R7 $R2 $R6 ;TempStrL |
StrCpy $R7 $R2 $R6 ;TempStrL |
60 |
|
|
61 |
;Calc: "StartCharPos" + "SubStrLen" = EndCharPos |
;Calc: "StartCharPos" + "SubStrLen" = EndCharPos |
62 |
IntOp $R8 $R6 + $R4 |
IntOp $R8 $R6 + $R4 |
63 |
|
|
64 |
StrCpy $R8 $R2 "" $R8 ;TempStrR |
StrCpy $R8 $R2 "" $R8 ;TempStrR |
65 |
|
|
66 |
;Insert the new string between the two separated parts of "String" |
;Insert the new string between the two separated parts of "String" |
67 |
StrCpy $R2 $R7$R0$R8 |
StrCpy $R2 $R7$R0$R8 |
68 |
;Now calculate the new "StrLen" and "StartCharPos" |
;Now calculate the new "StrLen" and "StartCharPos" |
69 |
StrLen $R5 $R2 |
StrLen $R5 $R2 |
70 |
IntOp $R6 $R6 + $R3 |
IntOp $R6 $R6 + $R3 |
71 |
${Continue} |
${Continue} |
72 |
${EndIf} |
${EndIf} |
73 |
|
|
74 |
;If not "SubString", this could be "String" end |
;If not "SubString", this could be "String" end |
75 |
${IfThen} $R6 >= $R5 ${|} ${ExitDo} ${|} |
${IfThen} $R6 >= $R5 ${|} ${ExitDo} ${|} |
76 |
;If not, continue the loop |
;If not, continue the loop |
77 |
IntOp $R6 $R6 + 1 |
IntOp $R6 $R6 + 1 |
78 |
${Loop} |
${Loop} |
79 |
|
|
80 |
Done: |
Done: |
81 |
|
|
82 |
;Return output to user |
;Return output to user |
83 |
StrCpy $R0 $R2 |
StrCpy $R0 $R2 |
84 |
|
|
85 |
/*After this point: |
/*After this point: |
86 |
------------------------------------------ |
------------------------------------------ |
87 |
$R0 = ResultVar (output)*/ |
$R0 = ResultVar (output)*/ |
88 |
|
|
89 |
Pop $R8 |
Pop $R8 |
90 |
Pop $R7 |
Pop $R7 |
91 |
Pop $R6 |
Pop $R6 |
92 |
Pop $R5 |
Pop $R5 |
93 |
Pop $R4 |
Pop $R4 |
94 |
Pop $R3 |
Pop $R3 |
95 |
Pop $R2 |
Pop $R2 |
96 |
Pop $R1 |
Pop $R1 |
97 |
Exch $R0 |
Exch $R0 |
98 |
FunctionEnd |
FunctionEnd |