Menu

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

Download this file

124 lines (116 with data), 4.5 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
{
* UpdateIni.ps
*
* Pascal script for use in [Code] Section of CodeSnip's Install.iss.
*
* Creates application-wide config files in correct data folder. Brings forward
* information from versions including and after v1.9.
*
* Config files of version 1.8.11 and earlier are ignored. This means
* application will get a new key and registration info may be lost.
*
* $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-2012 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 using system default encoding and converts contents to
// Unicode array where each element is one line of text file
LoadStringsFromFile(OldFileName, Lines);
// writes Unicode string array to file using UTF-16LE encoding
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 <= piV2V3;
end;
// Creates a new empty UTF-16LE encoded 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 common config file of a previous installation to new installation,
// updating to Unicode format if necessary.
procedure CopyCommonConfigFile(InstallID: Integer);
var
OldCommonConfigFile: string;
begin
OldCommonConfigFile := gCommonConfigFiles[InstallID];
if OldCommonConfigFile <> '' then
begin
if IsAnsiConfigFile(InstallID) then
CopyAnsiToUnicodeConfigFile(OldCommonConfigFile, gCurrentCommonConfigFile)
else
CopyUnicodeConfigFiles(OldCommonConfigFile, gCurrentCommonConfigFile);
end;
end;
// Updates common config file with correct version information. This records
// both config file version and version number of program being installed. If
// no config file exists, it is created.
procedure StampCommonConfigFile;
begin
// Set ini file version
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;
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.