Menu

[r375]: / trunk / Src / Install / DataLocations.ps  Maximize  Restore  History

Download this file

203 lines (181 with data), 7.1 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
{
* DataLocations.ps
*
* Pascal script for use in [Code] Section of CodeSnip's Install.iss.
*
* Gets information about location of application data folder and any existing
* config files and databaseon on the system where CodeSnip is being installed.
* Sets global variables storing folder paths that indicate where config files
* and database can be found.
*
* $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 DataLocations.ps.
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2008-2009 Peter
* Johnson. All Rights Reserved.
*
* Contributors:
* NONE
*
* ***** END LICENSE BLOCK *****
}
{
File locations in CodeSnip versions:
+ Versions up to v1.8.11:
- Config file is CodeSnip.ini and is stored in DelphiDabbler\CodeSnip sub-
directory of the per-user application data folder.
- Main database is in DelphiDabbler\CodeSnip\Data sub-directory of the
per-user application data folder.
- No user defined database.
+ From v1.9 to v1.9.4:
- Two config files:
o Common.ini in DelphiDabbler\CodeSnip sub-directory of common application
data foler.
o User.ini in DelphiDabbler\CodeSnip sub-directory of per user application
data foler.
- Main database moved to the DelphiDabbler\CodeSnip\Data sub-directory of
the common application data folder.
- No user defined database.
+ All v2 versions:
- Two config files:
o Common.ini in DelphiDabbler\CodeSnip sub-directory of common application
data foler.
o User.ini in DelphiDabbler\CodeSnip sub-directory of per user application
data foler.
- Main database moved to the DelphiDabbler\CodeSnip\Data sub-directory of
the common application data folder.
- User defined database in the DelphiDabbler\CodeSnip\UserData sub-directory
of the per user application data folder.
+ From v3.0:
- Two config files:
o Common.ini in DelphiDabbler\CodeSnip sub-directory of common application
data foler.
o User.3.ini in DelphiDabbler\CodeSnip sub-directory of per user
application data foler.
- Main database remains in the DelphiDabbler\CodeSnip\Data sub-directory of
the common application data folder.
- User defined database moves to the DelphiDabbler\CodeSnip\UserData.3 sub-
directory of the per user application data folder.
}
type
// Different editions of program with different file locations
TFileLocations = (
flNone, // CodeSnip not installed
flOriginal, // original locations
flV1_9, // v1.9 to v1.9.4
flV2, // all v2 versions
flV3 // v3.0 and later
);
var
// Name of original user's CodeSnip data folder
gUserAppDataDir: string;
// Name of CodeSnip's common data folder
gCommonAppDataDir: string;
// Information about location of config file(s)
gFileLocation: TFileLocations;
function MainDatabaseExists: Boolean;
{Checks if database is installed in "new" location, i.e. under common app data
folder.
@return True if database is installed in new location, False if not.
}
begin
Result := FileExists(
AddBackslash(gCommonAppDataDir) + 'Data\categories.ini'
);
end;
function DataConversionRequired: Boolean;
{Checks if database and config files need to be converted and copied to new
location in order for installed application to use them.
@return True if data conversion required, False if not.
}
begin
Result := (gFileLocation = flOriginal) or (gFileLocation = flV1_9) or
(gFileLocation = flV2);
end;
procedure InitAppDataFolders;
{Records the application data folders: both common and user. The user folder
relates to the original user. This is not necessarily the user who is
installing the application on Vista.
}
var
HelperApp: string; // name of setup helper app
TmpDir: string; // temp dir where helper app writes required info
TmpFile: string; // temp file that received helper app's info
Res: Integer; // return code from helper app: ignored
UserAppDir: string; // user's application data directory
begin
// Create name of a temporary directory in which helper app can store data
TmpDir := ExpandConstant('{commonappdata}\DelphiDabbler\~Tmp');
TmpFile := TmpDir + '\data';
ForceDirectories(TmpDir);
// Copy helper app into temp directory
HelperApp := ExpandConstant('{#SetupHelper}');
ExtractTemporaryFile(HelperApp);
// Run helper app as original user. Helper app writes information relating to
// original user to a ini file in temp directory created above.
ExecAsOriginalUser(
ExpandConstant('{tmp}\' + HelperApp),
'"' + TmpFile + '"',
'',
SW_HIDE,
ewWaitUntilTerminated,
Res
);
// Get original user's application data directory from temp file
UserAppDir := GetIniString('SpecialFolders', 'CSIDL_APPDATA', '', TmpFile);
// Delete temporary directory
DelTree(TmpDir, True, True, True);
// Record per-user and common application data directories used by CodeSnip
// per-user directory relates to original user.
gUserAppDataDir := AddBackslash(UserAppDir) + 'DelphiDabbler\CodeSnip';
gCommonAppDataDir := ExpandConstant('{commonappdata}\DelphiDabbler\CodeSnip');
end;
procedure InitDataLocations;
{Initialises global variables that store information about location of config
files and database.
}
begin
InitAppDataFolders;
if FileExists(AddBackslash(gCommonAppDataDir) + 'Common.ini') then
begin
// We have CodeSnip v1.9 or later
if FileExists(AddBackslash(gUserAppDataDir) + 'User.3.ini') then
// We have CodeSnip v3 or later
gFileLocation := flV3
else
begin
// We have CodeSnip v1.9 to v2.4.1
if FileExists(
AddBackslash(gUserAppDataDir) + 'UserData\database.xml'
) then
// We have CodeSnip v2.x
gFileLocation := flV2
else
// We have CodeSnip v1.9 to v1.9.4 (or v2.x with no user database)
gFileLocation := flV1_9;
end;
end
else if FileExists(AddBackslash(gUserAppDataDir) + 'CodeSnip.ini') then
// We have up to v1.8.11
gFileLocation := flOriginal
else
// We have no installation
gFileLocation := flNone;
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.