⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jclinstall.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 4 页
字号:
procedure TJclInstallation.RemoveHelpFromOpenHelp;
begin
  if Target.OpenHelp.RemoveHelpFile(Distribution.FJclHlpHelpFileName, JclHelpIndexName) then
    WriteLog(Format(LineBreak + 'Removed %s from %s Online Help', [Distribution.FJclHlpHelpFileName, Target.RADToolName]));
end;
{$ENDIF MSWINDOWS}

function TJclInstallation.Run: Boolean;
begin
  Result := True;
  if OptionSelected(ioJCL) then
  begin
    InstallationStarted;
    try
      Result := InstallSelectedOptions;
    finally
      InstallationFinished;
    end;
  end;
  SaveOptions;
end;

function TJclInstallation.Undo: Boolean;
begin
  Result := True;
  if OptionSelected(ioJCL) then
    Result := UninstallSelectedOptions;
  SaveOptions;
end;

function TJclInstallation.UninstallPackage(const Name: string): Boolean;
var
  PackageFileName: string;
begin
  PackageFileName := Distribution.Path + Format(Name, [Target.VersionNumber]);
  Result := Target.UninstallPackage(PackageFileName, StoredBPLPath, StoredDCPPath);
  { TODO : evtl. remove .HPP Files }
  if Result then
    WriteLog(Format(LineBreak + 'Removed package %s.', [PackageFileName]));
end;

function TJclInstallation.UninstallRunTimePackage(const BaseName: string): Boolean;
begin
  Result := UninstallPackage(FullPackageFileName(Target, BaseName));
end;

function TJclInstallation.UninstallSelectedOptions: Boolean;

  function BorRADToolVersionStr: string;
  begin
    Result := Format('%s Build %s ', [Target.Name, Target.IdeExeBuildNumber]);
  end;

var
  Option: TJediInstallOption;
  Success: Boolean;
begin
  Result := True;
  Tool.UpdateStatus(Format(RsUninstallMessage, [Target.Name]));
  WriteLog(StrPadRight('Starting Uninstall process', 44, '.'));
  for Option := ioJCL to ioJclLast do
    if OptionSelected(Option) then
    begin
      // Don't stop uninstall process when one step fails
      Success := UninstallOption(Option);
      Result := Result and Success;
    end;
  WriteLog('');
end;

procedure TJclInstallation.SaveOption(Option: TJediInstallOption);
var
  Value: Integer;
begin
  Value := Invalid;
  if OptionSelected(Option) then
    Value := JclBase.JclVersionBuild;
  Distribution.FIniFile.WriteInteger(Target.Name, OptionToStr(Option), Value);
end;

procedure TJclInstallation.SaveOptions;
var
  Option: TJediInstallOption;
begin
  SaveOption(ioTarget);
  for Option := ioJCL to ioJclLast do
    SaveOption(Option);
  Distribution.FIniFile.WriteString(Target.Name, 'BPL-Path', BplPath);
  Distribution.FIniFile.WriteString(Target.Name, 'DCP-Path', DcpPath);
end;

function TJclInstallation.StoredBplPath: string;
begin
  Result := Distribution.FIniFile.ReadString(Target.Name, 'BPL-Path', Target.BPLOutputPath);
end;

function TJclInstallation.StoredDcpPath: string;
begin
  Result := Distribution.FIniFile.ReadString(Target.Name, 'DCP-Path', Target.DCPOutputPath);
end;

function TJclInstallation.StoredOption(Option: TJediInstallOption; Default: Boolean = True): Boolean;
begin
  case Distribution.FIniFile.ReadInteger(Target.Name, OptionToStr(Option), 0) of
    Invalid:
      Result := False;
    0:
      Result := Default;
  else
    Result := True;
  end;
end;

function TJclInstallation.TotalUnitCount: Integer;
var
  I: Integer;
begin
  Result := 0;
  for I := Low(JclSourceDirs) to High(JclSourceDirs) do
  begin
    {$IFDEF MSWINDOWS}
    if (JclSourceDirs[I] = 'visclx') and
      not (OptionSelected(ioJclMakeReleaseVClx) or OptionSelected(ioJclMakeDebugVClx)) then
      Continue;
    {$ENDIF MSWINDOWS}
    with Units[JclSourceDirs[I]] do
      Inc(Result, Count);
  end;
end;

procedure TJclInstallation.WriteLog(const Msg: string);
begin
  if Assigned(FOnWriteLog) then
    FOnWriteLog(Msg);
end;

{ TJclDistribution }

constructor TJclDistribution.Create;
begin
  inherited;
  FTargetInstalls := TObjectList.Create;
  FTargetInstalls.OwnsObjects := True;
  FIniFile := TMemIniFile.Create(ExtractFilePath(ParamStr(0)) + RsIniFileName);
end;

destructor TJclDistribution.Destroy;
begin
  FTargetInstalls.Free;
  if Assigned(FIniFile) then
  begin
    FIniFile.UpdateFile;
    FreeAndNil(FIniFile);
  end;
  inherited;
end;

function TJclDistribution.CreateInstall(Target: TJclBorRADToolInstallation): Boolean;
var
  Inst: TJclInstallation;
begin
  if Supports(Target) then
  begin
    Inst := TJclInstallation.Create(Self, Target);
    FTargetInstalls.Add(Inst);
    Inst.InitOptions;
  end;
  Result := True;
end;

function TJclDistribution.DocFileName(const BaseFileName: string): string;
const
  SDocFileMask = '%sdocs' + PathSeparator + '%s';
begin
  Result := Format(SDocFileMask, [FJclPath, BaseFileName]);
end;

function TJclDistribution.FeatureInfoFileName(FeatureID: Cardinal): string;
begin
  Result := DocFileName(Format('%.7x.info', [FeatureID]));
end;

function TJclDistribution.GetTargetInstall(Installation: TJclBorRADToolInstallation): TJclInstallation;
var
  I: Integer;
begin
  for I := 0 to FTargetInstalls.Count - 1 do
  begin
    Result := TJclInstallation(FTargetInstalls[I]);
    if Result.Target = Installation then
      Exit;
  end;
  Result := nil;
end;

procedure TJclDistribution.InitInstallationTargets;
begin
  if not Tool.GetBorRADToolInstallations.Iterate(CreateInstall) then
    raise EJediInstallInitFailure.CreateRes(@RsNoInstall);
end;

function TJclDistribution.InitInformation(const ApplicationFileName: string): Boolean;
var
  I: Integer;
begin
  FJclPath := PathAddSeparator(ExpandFileName(PathExtractFileDirFixed(ApplicationFileName) + '..'));
  FLibDirMask := Format('%slib' + VersionDirExp, [FJclPath]);
  FLibDebugDirMask := FLibDirMask + PathSeparator + 'debug';
  FLibObjDirMask := FLibDirMask + PathSeparator + 'obj';
  FJclSourceDir := FJclPath + 'source';

  FJclSourcePath := '';
  for I := Low(JclSourceDirs) to High(JclSourceDirs) do
    FJclSourcePath := FJclSourcePath +
      Format('%s' + PathSeparator + '%s' + PathSep, [FJclSourceDir, JclSourceDirs[I]]);

  {$IFDEF MSWINDOWS}
  FClxDialogFileName := AnsiUpperCase(FJclPath + DialogsPath + ClxDialogFileName);
  {$ENDIF MSWINDOWS}
  {$IFDEF UNIX}
  FClxDialogFileName := FJclPath + DialogsPath + ClxDialogFileName;
  {$ENDIF UNIX}
  FClxDialogIconFileName := ChangeFileExt(FClxDialogFileName, '.ico');
  {$IFDEF MSWINDOWS}
  FVclDialogFileName := AnsiUpperCase(FJclPath + DialogsPath + VclDialogFileName);
  FVclDialogSendFileName := AnsiUpperCase(FJclPath + DialogsPath + VclDlgSndFileName);
  FVclDialogIconFileName := ChangeFileExt(FVclDialogFileName, '.ico');
  FVclDialogSendIconFileName := ChangeFileExt(FVclDialogSendFileName, '.ico');
  {$ENDIF MSWINDOWS}
  FJclChmHelpFileName := FJclPath + JclChmHelpFile;
  FJclHlpHelpFileName := FJclPath + JclHlpHelpFile;
  if not FileExists(FJclChmHelpFileName) then
    FJclChmHelpFileName := '';
  if not FileExists(FJclHlpHelpFileName) then
    FJclHlpHelpFileName := '';
  {$IFDEF MSWINDOWS}
  // Reset ReadOnly flag for dialog forms
  FileSetAttr(FClxDialogFileName, faArchive);
  FileSetAttr(ChangeFileExt(FClxDialogFileName, '.xfm'), faArchive);
  FileSetAttr(FVclDialogFileName, faArchive);
  FileSetAttr(ChangeFileExt(FVclDialogFileName, '.dfm'), faArchive);
  FileSetAttr(FVclDialogSendFileName, faArchive);
  FileSetAttr(ChangeFileExt(FVclDialogSendFileName, '.dfm'), faArchive);
  Result := FileExists(FClxDialogFileName) and FileExists(FClxDialogIconFileName)
    and FileExists(FVclDialogFileName)  and FileExists(FVclDialogIconFileName)
  {$ELSE ~MSWINDOWS}
  Result := True;
  {$ENDIF ~MSWINDOWS};
  FJclReadmeFileName := DocFileName(RsReadmeFileName);
  if FileExists(FJclReadmeFileName) then
    Tool.Readme := FJclReadmeFileName;
  if not Result then
    raise EJediInstallInitFailure.CreateRes(@RsCantFindFiles);
end;

procedure TJclDistribution.InitProgress;
var
  I: Integer;
begin
  FProgress := 0;
  FProgressTotal := 0;
  for I := 0 to FTargetInstalls.Count - 1 do
    Inc(FProgressTotal, TJclInstallation(FTargetInstalls[I]).ProgressTotal);
end;

function TJclDistribution.Install: Boolean;
var
  I: Integer;
begin
  Result := True;
  try
    InitProgress;
    for I := 0 to FTargetInstalls.Count - 1 do
      Result := Result and TJclInstallation(FTargetInstalls[I]).Run;
  finally
    Tool.UpdateStatus('');
  end;
end;

function TJclDistribution.Uninstall: Boolean;
var
  I: Integer;
  Success: Boolean;
begin
  Result := True;
  try
    InitProgress;
    for I := 0 to FTargetInstalls.Count - 1 do
    begin
      Success := TJclInstallation(FTargetInstalls[I]).Undo;
      Result := Result and Success;
    end;
  finally
    Tool.UpdateStatus('');
  end;
end;

procedure TJclDistribution.InstallProgress(Steps: Integer);
begin
  if Steps > 0 then
  begin
    Inc(FProgress, Steps);
    ShowProgress;
  end;
end;

function TJclDistribution.ReadmeFileName: string;
begin
  Result := FJclReadmeFileName;
end;

procedure TJclDistribution.SetOnWriteLog(Installation: TJclBorRADToolInstallation; Value: TTextHandler);
begin
  TargetInstall[Installation].OnWriteLog := Value;
end;

procedure TJclDistribution.SetOnEnding(Value: TInstallationEvent);
begin
  FOnEnding := Value;
end;

procedure TJclDistribution.SetOnProgress(Value: TInstallationProgressEvent);
begin
  FOnProgress := Value;
end;

procedure TJclDistribution.SetOnStarting(Value: TInstallationEvent);
begin
  FOnStarting := Value;
end;

procedure TJclDistribution.SetTool(const Value: IJediInstallTool);
begin
  FTool := Value;
  InitInformation(ParamStr(0));
  InitInstallationTargets;
end;

procedure TJclDistribution.ShowProgress;
var
  Percent: Integer;
begin
  if (FProgressTotal > 0) and Assigned(FOnProgress) then
  begin
    Percent := (FProgress * 100) div FProgressTotal;
    if Percent <> FProgressPercent then
    begin
      FProgressPercent := Percent;
      FOnProgress(Percent);
    end;
  end;
end;

function TJclDistribution.Supports(Target: TJclBorRADToolInstallation): Boolean;
begin
  {$IFDEF KYLIX}
  Result := Target.VersionNumber = 3;
  {$ELSE ~KYLIX}
  if Target.RADToolKind = brCppBuilder then
    Result := Target.VersionNumber in [5..6]
  else
    Result := Target.VersionNumber in [5..7, 9];
  {$ENDIF ~KYLIX}
end;

// History:

// $Log: JclInstall.pas,v $
// Revision 1.53  2005/03/05 06:33:17  rrossmair
// - support for some conditional defines added.
//
// Revision 1.52  2005/02/28 20:19:05  uschuster
// changes for Uses wizard
//
// Revision 1.51  2005/02/23 08:32:30  rrossmair
// - TJclInstallation: replaced Target.DCC.Options.Clear by Target.DCC.SetDefaultOptions.
//   Some cleanup.
//
// Revision 1.50  2005/02/05 05:16:18  rrossmair
// - check-in for release 1.94.1.1802
//
// Revision 1.49  2005/02/04 05:19:41  rrossmair
// - some uninstall support finally functional
//
// Revision 1.48  2005/02/03 06:15:41  rrossmair
// - fixed for Kylix
//
// Revision 1.47  2005/02/03 05:22:17  rrossmair
// - more uninstall support (still unfinished)
//
// Revision 1.46  2004/12/23 05:32:28  rrossmair
// - fixed for Kylix
//
// Revision 1.45  2004/12/23 05:09:26  rrossmair
// - except dialog and help integration disabled for D 2005
//
// Revision 1.44  2004/12/15 21:49:35  rrossmair
// - denotes D2005 as supported now
//
// Revision 1.43  2004/12/08 18:25:07  rrossmair
// - fixed TJclInstallation.StoredOption so that Default parameter gets evaluated
//
// Revision 1.42  2004/12/08 18:14:49  rrossmair
// - all install options now selected by default
// - minor fixes
//
// Revision 1.41  2004/11/18 10:14:54  rrossmair
// - changes for release 1.93
//
// Revision 1.40  2004/11/17 06:34:01  marquardt
// suppress warning about unused UninstallOption
//
// Revision 1.39  2004/11/14 12:08:05  rrossmair
// - some precautions & minor fixes
//
// Revision 1.38  2004/11/14 05:55:55  rrossmair
// - installer refactoring (continued)
//
// Revision 1.37  2004/11/10 05:18:11  rrossmair
// - fixed for Kylix
//
// Revision 1.36  2004/11/09 07:51:37  rrossmair
// - installer refactoring (incomplete)
//

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -