Menu

[r1205]: / branches / v4-dev / Src / Install / UpdateIni.ps  Maximize  Restore  History

Download this file

276 lines (259 with data), 9.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
{
* UpdateIni.ps
*
* Pascal script for use in [Code] Section of CodeSnip's Install.iss.
*
* Creates per-user and application-wide ini files in correct data folders. Can
* also create the ini files from the information stored in the single ini file
* used in versions of CodeSnip prior to version 1.9.
*
* $Rev$
* $Date$
*
* ***** BEGIN LICENSE BLOCK *****
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is UpdateIni.ps.
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2007-2010 Peter
* Johnson. All Rights Reserved.
*
* Contributors:
* NONE
*
* ***** END LICENSE BLOCK *****
}
function OriginalIniFileName: string;
{Gets fully specified file name of original style, solitary, config file.
@return Ini file name.
}
begin
Result := AddBackslash(gUserAppDataDir) + 'CodeSnip.ini';
end;
function CommonIniFileName: string;
{Gets fully specified file name of current application wide config file.
@return Ini file name.
}
begin
Result := AddBackslash(gCommonAppDataDir) + 'Common.ini';
end;
function OldUserIniFileName: string;
{Gets fully specified file name of original per user config file.
@return Ini file name.
}
begin
Result := AddBackslash(gUserAppDataDir) + 'User.ini';
end;
function V3UserIniFileName: string;
{Gets fully specified file name of version 3's per user config file.
@return Ini file name.
}
begin
Result := AddBackslash(gUserAppDataDir) + 'User.3.ini';
end;
function UserIniFileName: string;
{Gets fully specified file name of current per user config file.
@return Ini file name.
}
begin
Result := AddBackslash(gUserAppDataDir) + 'User.4.ini';
end;
procedure CopyAnsiToUnicodeIniFile(OldFileName, NewFileName: string);
{Reads an ANSI .ini file, coverts content to Unicode and writes that to a
UTF-16LE encoded Unicode .ini file. Requires Unicode Inno Setup.
@param OldFileName [in] Name of ANSI .ini file.
@param NewFileName [in] Name of Unicode .ini file.
}
var
Lines: TArrayOfString; // lines of text read from ANSI .ini file
begin
// reads an ANSI file and converts contents to Unicode, using system default
// encoding
LoadStringsFromFile(OldFileName, Lines);
// writes string array to UTF-16LE file
WriteStringsToUnicodeFile(NewFileName, Lines);
end;
procedure CreateUnicodeIniFile(FileName: string);
{Create a new empty UTF-16LE encoding .ini file. Used to ensure the ini file
writing routines write in Unicode. This works because built in Inno Setup
ini function call Windows API WritePrivateProfileString which only writes
Unicode if the file it is writing to is detected as Unicode. If not it writes
ANSI text.
@param FileName [in] Name of new .ini file.
}
var
NulLines: TArrayOfString; // dummy empty string array
begin
SetLength(NulLines, 0);
WriteStringsToUnicodeFile(FileName, NulLines);
end;
procedure StampIniFiles;
{Updates both config files with correct version information. This records ini
file versions and version number of program being installed.
}
begin
// Flag ini file versions
if not FileExists(UserIniFileName) then
CreateUnicodeIniFile(UserIniFileName);
SetIniInt('IniFile', 'Version', 7, UserIniFileName);
if not FileExists(CommonIniFileName) then
CreateUnicodeIniFile(CommonIniFileName);
SetIniInt('IniFile', 'Version', 5, CommonIniFileName);
// Record application version in common ini file
SetIniString(
'Application',
'Version',
ExpandConstant('{#AppVersion}'),
CommonIniFileName
);
end;
procedure CreateIniFilesFromOldStyle;
{Creates new style per user and common config files from content of single,
old style config file used before CodeSnip v1.9.
}
var
I: Integer; // loops thru all highlight elements
begin
// Create per-user settings file:
// Copy file
CopyAnsiToUnicodeIniFile(OriginalIniFileName, UserIniFileName);
// Delete unwanted sections:
// - Application section now in common ini file
// - Source code output format: format lost when updating from CodeSnip pre
// 1.7 since section was SourceOutput, but format preserved from v1.7 since
// current Prefs:SourceCode section used
// - Highlighting style is deliberately lost since CodeSnip v3 has new default
// style and main display uses style, therefore sections HiliteOutput
// (pre v1.7.5) and Prefs:Hiliter (v1.7 and later) deleted
DeleteIniSection('Application', UserIniFileName);
DeleteIniSection('SourceOutput', UserIniFileName);
DeleteIniSection('HiliteOutput', UserIniFileName);
for I := 0 to 11 do
DeleteIniSection('HiliteOutput:Elem' + IntToStr(I), UserIniFileName);
DeleteIniSection('Prefs:Hiliter', UserIniFileName);
// Main window's overview tabs have changed in v3: so we reset to 0 (default)
SetIniInt('MainWindow', 'OverviewTab', 0, UserIniFileName);
// Create common (application specific) settings file
// Copy file
CopyAnsiToUnicodeIniFile(OriginalIniFileName, CommonIniFileName);
// Delete unwanted sections
// following sections belong in per-user file
DeleteIniSection('Cmp:D2', CommonIniFileName);
DeleteIniSection('Cmp:D3', CommonIniFileName);
DeleteIniSection('Cmp:D4', CommonIniFileName);
DeleteIniSection('Cmp:D5', CommonIniFileName);
DeleteIniSection('Cmp:D6', CommonIniFileName);
DeleteIniSection('Cmp:D7', CommonIniFileName);
DeleteIniSection('Cmp:D2005w32', CommonIniFileName);
DeleteIniSection('Cmp:D2006w32', CommonIniFileName);
DeleteIniSection('Cmp:D2007', CommonIniFileName);
DeleteIniSection('Cmp:FPC', CommonIniFileName);
DeleteIniSection('FindCompiler', CommonIniFileName);
DeleteIniSection('FindText', CommonIniFileName);
DeleteIniSection('FindXRefs', CommonIniFileName);
DeleteIniSection('MainWindow', CommonIniFileName);
DeleteIniSection('Prefs:General', CommonIniFileName);
DeleteIniSection('Prefs:Printing', CommonIniFileName);
DeleteIniSection('Prefs:SourceCode', CommonIniFileName);
DeleteIniSection('Prefs:Hiliter', CommonIniFileName);
// following sections may occur when updating from CodeSnip v1.7.5 or earlier
DeleteIniSection('SourceOutput', CommonIniFileName);
DeleteIniSection('HiliteOutput', CommonIniFileName);
for I := 0 to 11 do
DeleteIniSection('HiliteOutput:Elem' + IntToStr(I), CommonIniFileName);
end;
procedure CopyOldUserIniFile;
{Copies original per user config file to current location.
}
begin
// Copy the file
CopyAnsiToUnicodeIniFile(OldUserIniFileName, UserIniFileName);
// Delete highlighter preferences: not to be brought forward from old versions
DeleteIniSection('Prefs:Hiliter', UserIniFileName);
// Main window's overview tabs have changed in v3: so we reset to 0 (default)
SetIniInt('MainWindow', 'OverviewTab', 0, UserIniFileName);
end;
procedure CopyV3UserIniFile;
{Copies version 3's per user config file to current location.
}
begin
// Copy the file
CopyAnsiToUnicodeIniFile(V3UserIniFileName, UserIniFileName);
end;
procedure CreateDefaultCodeGenEntries;
{Adds Prefs:CodeGen section along with default data.
}
begin
if not FileExists(UserIniFileName) then
CreateUnicodeIniFile(UserIniFileName);
SetIniInt('Prefs:CodeGen', 'SwitchOffWarnings', 0, UserIniFileName);
SetIniInt('Prefs:CodeGen', 'WarningCount', 8, UserIniFileName);
SetIniString(
'Prefs:CodeGen', 'Warning0.Symbol', 'UNSAFE_TYPE', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning0.MinCompiler', '15.00', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning1.Symbol', 'UNSAFE_CAST', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning1.MinCompiler', '15.00', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning2.Symbol', 'UNSAFE_CODE', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning2.MinCompiler', '15.00', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning3.Symbol', 'SYMBOL_PLATFORM', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning3.MinCompiler', '14.00', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning4.Symbol', 'SYMBOL_DEPRECATED', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning4.MinCompiler', '14.00', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning5.Symbol', 'SYMBOL_LIBRARY', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning5.MinCompiler', '14.00', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning6.Symbol', 'IMPLICIT_STRING_CAST', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning6.MinCompiler', '20.00', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning7.Symbol', 'EXPLICIT_STRING_CAST', UserIniFileName
);
SetIniString(
'Prefs:CodeGen', 'Warning7.MinCompiler', '20.00', UserIniFileName
);
end;
procedure DeleteProxyPassword;
{Deletes proxy password entry.
}
begin
if not FileExists(UserIniFileName) then
CreateUnicodeIniFile(UserIniFileName);
SetIniString('ProxyServer', 'Password', '', UserIniFileName);
end;
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.