Menu

[327ada]: / Source / Tools / Packman / Installers.pas  Maximize  Restore  History

Download this file

164 lines (135 with data), 4.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
unit Installers;
interface
uses
{$IFDEF WIN32}
SysUtils, Classes, InstallFiles, Forms, Windows, Dialogs;
{$ENDIF}
{$IFDEF LINUX}
SysUtils, Classes, InstallFiles, QForms, QDialogs;
{$ENDIF}
type
TProgressEvent = procedure(Sender: TObject; CurrentFile: TInstallFile;
Progress, Max: Integer) of Object;
TInstaller = Class
private
FAbort, FInstalling: Boolean;
FInfo: TInstallInfo;
FOnAbort: TNotifyEvent;
FOnProgress: TProgressEvent;
public
constructor Create(Info: TInstallInfo);
procedure Abort;
function Install: Boolean;
property OnAbort: TNotifyEvent read FOnAbort write FOnAbort;
property OnProgress: TProgressEvent read FOnProgress write FOnProgress;
end;
implementation
uses
RemoveForms, PackmanUtils;
constructor TInstaller.Create(Info: TInstallInfo);
begin
inherited Create;
FAbort := False;
FInstalling := False;
FInfo := Info;
end;
procedure TInstaller.Abort;
begin
if FInstalling then
FAbort := True;
end;
procedure Mkdir(const DirName: AnsiString);
begin
if not ForceDirectories(DirName) then
raise Exception.Create('error creating folder "'+ DirName + '"');
end;
function TInstaller.Install: Boolean;
var
i: Integer;
Files: TInstallFiles;
TheFile: TInstallFile;
EntryName: AnsiString;
F: TextFile;
IMod: Integer;
strDevRoot: AnsiString;
begin
Result := True;
FInstalling := True;
Files := FInfo.Files(ExtractFileDir(ParamStr(0)));
EntryName := ChangeFileExt(ExtractFileName(Files.InfoFile), '.entry');
EntryName := Files.AppDir + '\Packages\' + EntryName;
{ First uninstall old package, if it exists }
if FileExists(EntryName) then
begin
RemoveForm := TRemoveForm.Create(Application);
with RemoveForm do
try
Entry := EntryName;
CloseWhenDone := True;
ShowModal;
finally
Free;
end;
end;
{ Copy the files }
IMod := CalcMod(Files.Count);
for i := 0 to Files.Count - 1 do
begin
if FAbort then
Break;
TheFile := Files.Files[i];
if (IMod = 0) or (i mod IMod = 0) then
if Assigned(FOnProgress) then
FOnProgress(Self, TheFile, i + 1, Files.Count);
if not DirectoryExists(ExtractFileDir(TheFile.Dest)) then
Mkdir(ExtractFileDir(TheFile.Dest));
CopyFile(PChar(String(TheFile.Source)), PChar(String(TheFile.Dest)), False);
if (IMod = 0) or (i mod IMod = 0) then
Application.ProcessMessages;
end;
{ Create icons }
for i := 0 to Files.IconCount - 1 do
begin
if not DirectoryExists(ExtractFileDir(Files.Icons[i].FileName)) then
MkDir(ExtractFileDir(Files.Icons[i].FileName));
CreateShortcut(Files.Icons[i].FileName, Files.Icons[i].Target,
Files.Icons[i].Icon);
end;
{ Create a package entry and write basic information }
Mkdir(Files.AppDir + '\Packages');
AssignFile(F, EntryName);
Rewrite(F);
Writeln(F, '[Setup]');
Writeln(F, 'AppName=' + FInfo.AppName);
Writeln(F, 'AppVersion=' + FInfo.AppVersion);
Writeln(F, 'Description=' + FInfo.Description);
Writeln(F, 'Url=' + FInfo.URL);
strDevRoot := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
{ Write the file logs }
Writeln(F, '');
Writeln(F, '[Files]');
with Files do
begin
for i := 0 to Count - 1 do
if Pos(strDevRoot, Files[i].Dest) = 1 then
//if in root of dev-c++, write just relative path to the root
Writeln(F, Copy(Files[i].Dest, Length(strDevRoot) + 1,
Length(Files[i].Dest) - Length(strDevRoot)))
else
Writeln(F, Files[i].Dest);
for i := 0 to IconCount - 1 do
Writeln(F, Icons[i].FileName);
end;
Flush(F);
CloseFile(F);
{ Finish }
FInstalling := False;
if FAbort then
begin
FAbort := False;
if Assigned(FOnAbort) then
FOnAbort(Self);
Result := False;
end;
end;
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.