Menu

[r1786]: / trunk / Src / Install / UpdateIni.ps  Maximize  Restore  History

Download this file

337 lines (323 with data), 10.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
{
* 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 *****
}
// Reads an ANSI config file, converts content to Unicode and writes that to a
// UTF-16LE encoded Unicode config file with BOM. Does nothing if old and new
// file names are the same.
// *** Requires Unicode Inno Setup. ***
procedure CopyAnsiToUnicodeConfigFile(OldFileName, NewFileName: string);
var
Lines: TArrayOfString; // lines of text read from ANSI .ini file
begin
if CompareText(OldFileName, NewFileName) = 0 then
Exit;
// reads an ANSI file and converts contents to Unicode, using system default
// encoding
LoadStringsFromFile(OldFileName, Lines);
// writes string array to UTF-16LE file
ForceDirectories(ExtractFileDir(NewFileName));
WriteStringsToUnicodeFile(NewFileName, Lines);
end;
// Makes a copy of a Unicode config file with a different name. Does nothing if
// old and new file names are the same.
procedure CopyUnicodeConfigFiles(OldFileName, NewFileName: string);
begin
if CompareText(OldFileName, NewFileName) = 0 then
Exit;
ForceDirectories(ExtractFileDir(NewFileName));
FileCopy(OldFileName, NewFileName, False);
end;
// Checks if a config file is ANSI. If False is returned the file is assumed to
// be Unicode.
function IsAnsiConfigFile(InstallID: Integer): Boolean;
begin
Result := InstallID <= piV3;
end;
// Gets version number of new installation's user config file.
function UserConfigFileVer: Integer;
begin
Result := GetIniInt('IniFile', 'Version', 1, 0, 0, gCurrentUserConfigFile);
end;
// Create a new empty UTF-16LE encoding config file. Used to ensure the config
// file writing routines write in Unicode. This works because built in Inno
// Setup ini functions 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.
procedure CreateUnicodeConfigFile(FileName: string);
var
NulLines: TArrayOfString; // dummy empty string array
begin
ForceDirectories(ExtractFileDir(FileName));
SetLength(NulLines, 0);
WriteStringsToUnicodeFile(FileName, NulLines);
end;
// Copies config files of a previous installation to new installation, updating
// to Unicode format if necessary.
procedure CopyConfigFiles(InstallID: Integer);
var
OldCommonConfigFile: string;
OldUserConfigFile: string;
begin
OldCommonConfigFile := gCommonConfigFiles[InstallID];
OldUserConfigFile := gUserConfigFiles[InstallID];
if OldCommonConfigFile <> '' then
begin
if IsAnsiConfigFile(InstallID) then
CopyAnsiToUnicodeConfigFile(OldCommonConfigFile, gCurrentCommonConfigFile)
else
CopyUnicodeConfigFiles(OldCommonConfigFile, gCurrentCommonConfigFile);
end;
if OldUserConfigFile <> '' then
begin
if IsAnsiConfigFile(InstallID) then
CopyAnsiToUnicodeConfigFile(OldUserConfigFile, gCurrentUserConfigFile)
else
CopyUnicodeConfigFiles(OldUserConfigFile, gCurrentUserConfigFile);
end;
end;
// Updates both common and user config files with correct version information.
// This records both config file versions and (common config file only) version
// number of program being installed.
procedure StampConfigFiles;
begin
// Flag ini file versions
if not FileExists(gCurrentUserConfigFile) then
CreateUnicodeConfigFile(gCurrentUserConfigFile);
SetIniInt('IniFile', 'Version', 8, gCurrentUserConfigFile);
if not FileExists(gCurrentCommonConfigFile) then
CreateUnicodeConfigFile(gCurrentCommonConfigFile);
SetIniInt('IniFile', 'Version', 6, gCurrentCommonConfigFile);
// Record application version in common ini file
SetIniString(
'Application',
'Version',
ExpandConstant('{#AppVersion}'),
gCurrentCommonConfigFile
);
end;
// Deletes any highlighter preferences from new installation's user config file.
procedure DeleteHighligherPrefs;
begin
DeleteIniSection('Prefs:Hiliter', gCurrentUserConfigFile);
end;
// Creates new style per user and common config files from content of single,
// old style config file used before CodeSnip v1.9.
procedure CreateIniFilesFromOldStyle;
var
I: Integer; // loops thru all highlight elements
begin
// Create per-user settings file:
// Copy file
CopyAnsiToUnicodeConfigFile(
gUserConfigFiles[piOriginal], gCurrentUserConfigFile
);
// Delete unwanted sections:
// - Application section now in common config 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', gCurrentUserConfigFile);
DeleteIniSection('SourceOutput', gCurrentUserConfigFile);
DeleteIniSection('HiliteOutput', gCurrentUserConfigFile);
for I := 0 to 11 do
DeleteIniSection('HiliteOutput:Elem' + IntToStr(I), gCurrentUserConfigFile);
DeleteHighligherPrefs;
// Main window's overview tabs have changed in v3: so we reset to 0 (default)
SetIniInt('MainWindow', 'OverviewTab', 0, gCurrentUserConfigFile);
// Create common (application specific) settings file
// Copy file
CopyAnsiToUnicodeConfigFile(
gUserConfigFiles[piOriginal], gCurrentCommonConfigFile
);
// Delete unwanted sections
// following sections belong in per-user file
DeleteIniSection('Cmp:D2', gCurrentCommonConfigFile);
DeleteIniSection('Cmp:D3', gCurrentCommonConfigFile);
DeleteIniSection('Cmp:D4', gCurrentCommonConfigFile);
DeleteIniSection('Cmp:D5', gCurrentCommonConfigFile);
DeleteIniSection('Cmp:D6', gCurrentCommonConfigFile);
DeleteIniSection('Cmp:D7', gCurrentCommonConfigFile);
DeleteIniSection('Cmp:D2005w32', gCurrentCommonConfigFile);
DeleteIniSection('Cmp:D2006w32', gCurrentCommonConfigFile);
DeleteIniSection('Cmp:D2007', gCurrentCommonConfigFile);
DeleteIniSection('Cmp:FPC', gCurrentCommonConfigFile);
DeleteIniSection('FindCompiler', gCurrentCommonConfigFile);
DeleteIniSection('FindText', gCurrentCommonConfigFile);
DeleteIniSection('FindXRefs', gCurrentCommonConfigFile);
DeleteIniSection('MainWindow', gCurrentCommonConfigFile);
DeleteIniSection('Prefs:General', gCurrentCommonConfigFile);
DeleteIniSection('Prefs:Printing', gCurrentCommonConfigFile);
DeleteIniSection('Prefs:SourceCode', gCurrentCommonConfigFile);
DeleteIniSection('Prefs:Hiliter', gCurrentCommonConfigFile);
// following sections may occur when updating from CodeSnip v1.7.5 or earlier
DeleteIniSection('SourceOutput', gCurrentCommonConfigFile);
DeleteIniSection('HiliteOutput', gCurrentCommonConfigFile);
for I := 0 to 11 do
DeleteIniSection(
'HiliteOutput:Elem' + IntToStr(I), gCurrentCommonConfigFile
);
end;
// Adds Prefs:CodeGen section along with default data to new installation's user
// config file.
procedure CreateDefaultCodeGenEntries;
begin
if not FileExists(gCurrentUserConfigFile) then
CreateUnicodeConfigFile(gCurrentUserConfigFile);
SetIniInt(
'Prefs:CodeGen',
'SwitchOffWarnings',
0,
gCurrentUserConfigFile
);
SetIniInt(
'Prefs:CodeGen',
'WarningCount',
8,
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning0.Symbol',
'UNSAFE_TYPE',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning0.MinCompiler',
'15.00',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning1.Symbol',
'UNSAFE_CAST',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning1.MinCompiler',
'15.00',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning2.Symbol',
'UNSAFE_CODE',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning2.MinCompiler',
'15.00',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning3.Symbol',
'SYMBOL_PLATFORM',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning3.MinCompiler',
'14.00',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning4.Symbol',
'SYMBOL_DEPRECATED',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning4.MinCompiler',
'14.00',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning5.Symbol',
'SYMBOL_LIBRARY',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning5.MinCompiler',
'14.00',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning6.Symbol',
'IMPLICIT_STRING_CAST',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning6.MinCompiler',
'20.00',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning7.Symbol',
'EXPLICIT_STRING_CAST',
gCurrentUserConfigFile
);
SetIniString(
'Prefs:CodeGen',
'Warning7.MinCompiler',
'20.00',
gCurrentUserConfigFile
);
end;
// Deletes proxt password entry from new installation's user config file.
procedure DeleteProxyPassword;
begin
if not FileExists(gCurrentUserConfigFile) then
CreateUnicodeConfigFile(gCurrentUserConfigFile);
SetIniString(
'ProxyServer',
'Password',
'',
gCurrentUserConfigFile
);
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.