| 1 |
Parse Arg innsi nsifiles outnsi |
| 2 |
trace o |
| 3 |
If Stream( innsi, 'C', 'QUERY EXISTS' ) = '' Then Call Abort innsi 'does not exist. Cannot continue!' |
| 4 |
If Stream( nsifiles, 'C', 'QUERY EXISTS' ) = '' Then Call Abort nsifiles 'does not exist. Cannot continue!' |
| 5 |
|
| 6 |
Call Stream outnsi, 'C', 'OPEN WRITE REPLACE' |
| 7 |
|
| 8 |
Do While Lines( innsi ) > 0 |
| 9 |
line = Linein( innsi ) |
| 10 |
If Countstr( '[', line ) = 1 & Countstr( ']', line ) = 1 Then |
| 11 |
Do |
| 12 |
Parse Var line '[' section ']' . |
| 13 |
If Lower( section ) = 'uninstall' Then Call UninstallFiles nsifiles, outnsi |
| 14 |
Else Call InstallFiles nsifiles, outnsi, section |
| 15 |
End |
| 16 |
Else |
| 17 |
Call Lineout outnsi, line |
| 18 |
End |
| 19 |
Call Stream outnsi, 'C', 'CLOSE' |
| 20 |
Return 0 |
| 21 |
|
| 22 |
/* |
| 23 |
* Read the nsifiles file and write all lines for the supplied section to the outnsi file |
| 24 |
*/ |
| 25 |
InstallFiles: Procedure |
| 26 |
Parse Arg nsifiles, outnsi, section |
| 27 |
Call Stream nsifiles, 'C','OPEN READ' |
| 28 |
state = 'start' |
| 29 |
Do While Lines( nsifiles ) > 0 |
| 30 |
line = Linein( nsifiles ) |
| 31 |
If Strip( line ) = '' | Left( line, 1 ) = '#' Then Iterate |
| 32 |
Select |
| 33 |
When state = 'start' Then |
| 34 |
Do |
| 35 |
Parse Var line '[' sec ']' . |
| 36 |
If sec = section Then state = 'in' |
| 37 |
End |
| 38 |
When state = 'in' Then |
| 39 |
Do |
| 40 |
If Countstr( '[', line ) = 1 & Countstr( ']', line ) = 1 Then Leave |
| 41 |
Call Lineout outnsi, line |
| 42 |
End |
| 43 |
Otherwise Nop |
| 44 |
End |
| 45 |
End |
| 46 |
Call Stream nsifiles, 'C', 'CLOSE' |
| 47 |
Return |
| 48 |
|
| 49 |
UninstallFiles: Procedure |
| 50 |
Parse Arg nsifiles, outnsi, section |
| 51 |
curdir = '' |
| 52 |
Call Stream nsifiles, 'C','OPEN READ' |
| 53 |
Do While Lines( nsifiles ) > 0 |
| 54 |
line = Linein( nsifiles ) |
| 55 |
If Strip( line ) = '' | Left( line, 1 ) = '#' | (Countstr( '[', line ) = 1 & Countstr( ']', line ) = 1) Then Iterate |
| 56 |
Select |
| 57 |
When Word( line, 1 ) = 'File' Then |
| 58 |
Do |
| 59 |
If Countstr( '/oname=', line ) = 1 Then |
| 60 |
Do |
| 61 |
Parse Var line . '/oname=' fn . |
| 62 |
End |
| 63 |
Else Parse Var line . fn |
| 64 |
pos = Lastpos( '\', fn ) |
| 65 |
If pos \= 0 Then fn = Substr( fn, pos+1 ) |
| 66 |
Call Lineout outnsi, 'Delete' curdir'\'fn |
| 67 |
End |
| 68 |
When Word( line, 1 ) = 'SetOutPath' Then |
| 69 |
Do |
| 70 |
-- remove previous directory before setting a new one |
| 71 |
If curdir \= '' Then Call Lineout outnsi, 'RMDir' curdir |
| 72 |
Parse Var line . curdir |
| 73 |
End |
| 74 |
Otherwise Nop |
| 75 |
End |
| 76 |
End |
| 77 |
Call Lineout outnsi, 'Delete $INSTDIR\uninstall.exe' |
| 78 |
If curdir \= '' Then Call Lineout outnsi, 'RMDir' curdir |
| 79 |
Call Stream nsifiles, 'C', 'CLOSE' |
| 80 |
Return |
| 81 |
|
| 82 |
Abort: Procedure |
| 83 |
Parse Arg msg |
| 84 |
Say msg |
| 85 |
Exit 1 |