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

📄 jvuninstallcontrols.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{-----------------------------------------------------------------------------
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/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: JvUninstallControls.PAS, released on 2002-05-26.

The Initial Developer of the Original Code is Peter Th鰎nqvist [peter3 at sourceforge dot net]
Portions created by Peter Th鰎nqvist are Copyright (C) 2002 Peter Th鰎nqvist.
All Rights Reserved.

Contributor(s):

You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net

Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvUninstallControls.pas,v 1.25 2005/02/17 10:21:16 marquardt Exp $

unit JvUninstallControls;

{$I jvcl.inc}
{$I windowsonly.inc}

interface

uses
  {$IFDEF UNITVERSIONING}
  JclUnitVersioning,
  {$ENDIF UNITVERSIONING}
  Windows, SysUtils, Classes, Graphics, Controls, StdCtrls,
  JvComponent, JvTypes;

type
  TJvUCBDisplayMode = (hkCurrentUser, hkLocalMachine); // subset of TJvRegKey
  TJvUCBDisplayModes = set of TJvUCBDisplayMode;

  TJvUninstallComboBox = class(TCustomComboBox)
  private
    FDisplayMode: TJvUCBDisplayModes;
    FShowAll: Boolean;
    FShowEmptyValues: Boolean;
    function GetItems: TStrings;
    function GetDisplayName: string;
    function GetSection: string;
    function GetUninstallString: string;
    procedure SetShowAll(const Value: Boolean);
    procedure SetShowEmptyValues(const Value: Boolean);
    procedure SetDisplayMode(const Value: TJvUCBDisplayModes);
    procedure Rebuild;
    function GetProperties: TStrings;
    function GetHKey: HKEY;
    function GetHKeyName: string;
    procedure SetSorted(const Value: Boolean);
  protected
    procedure CreateHandle; override;
  public
    constructor Create(AComponent: TComponent); override;
    destructor Destroy; override;
    procedure Clear;
      {$IFDEF VCL}{$IFDEF COMPILER6_UP} override; {$ENDIF}{$ENDIF}
    procedure RefreshItem;
    property Items: TStrings read GetItems;
    property Section: string read GetSection;
    property HKey: HKEY read GetHKey;
    property HKeyName: string read GetHKeyName;
    property UninstallString: string read GetUninstallString;
    property DisplayName: string read GetDisplayName;
    property Properties: TStrings read GetProperties;
  published
    property DisplayMode: TJvUCBDisplayModes read FDisplayMode write SetDisplayMode default [hkCurrentUser, hkLocalMachine];
    property ShowAll: Boolean read FShowAll write SetShowAll default False;
    property ShowEmptyValues: Boolean read FShowEmptyValues write SetShowEmptyValues default False;
    property Color;
    {$IFDEF VCL}
    property DragCursor;
    property DragMode;
    property ImeMode;
    property ImeName;
    property BiDiMode;
    property ParentBiDiMode;
    property OnEndDock;
    property OnStartDock;
    property DragKind;
    {$ENDIF VCL}
    property DropDownCount;
    property Enabled;
    property Font;
    property ItemHeight;
    property ParentColor;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property Sorted write SetSorted;
    property Style;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnChange;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnDrawItem;
    property OnDropDown;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMeasureItem;
    property OnStartDrag;
    property Anchors;
    property Constraints;
  end;

  TJvUninstallListBox = class(TCustomListBox)
  private
    FShowAll: Boolean;
    FDisplayMode: TJvUCBDisplayModes;
    FShowEmptyValues: Boolean;
    function GetItems: TStrings;
    function GetDisplayName: string;
    function GetSection: string;
    function GetUninstallString: string;
    procedure SetShowAll(const Value: Boolean);
    procedure SetShowEmptyValues(const Value: Boolean);
    procedure SetDisplayMode(const Value: TJvUCBDisplayModes);
    function GetProperties: TStrings;
    function GetHKey: HKEY;
    function GetHKeyName: string;
    procedure SetSorted(const Value: Boolean);
  protected
    procedure CreateHandle; override;
  public
    constructor Create(AComponent: TComponent); override;
    destructor Destroy; override;
    procedure Clear;
      {$IFDEF VCL}{$IFDEF COMPILER6_UP} override; {$ENDIF}{$ENDIF}
    procedure RefreshItem;
    procedure Rebuild;
    property Items: TStrings read GetItems;
    property Section: string read GetSection;
    property UninstallString: string read GetUninstallString;
    property DisplayName: string read GetDisplayName;
    property Properties: TStrings read GetProperties;
    property HKey: HKEY read GetHKey;
    property HKeyName: string read GetHKeyName;
  published
    property Align;
    property DisplayMode: TJvUCBDisplayModes read FDisplayMode write SetDisplayMode default [hkCurrentUser, hkLocalMachine];
    property ShowAll: Boolean read FShowAll write SetShowAll default False;
    property ShowEmptyValues: Boolean read FShowEmptyValues write SetShowEmptyValues default False;
    property Color;
    {$IFDEF VCL}
    property DragCursor;
    property DragMode;
    property ImeMode;
    property ImeName;
    property BiDiMode;
    property DragKind;
    property ParentBiDiMode;
    property OnEndDock;
    property OnStartDock;
    {$ENDIF VCL}
    property Enabled;
    property Font;
    property ItemHeight;
    property ParentColor;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property Sorted write SetSorted;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnDrawItem;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMeasureItem;
    property OnStartDrag;
    property Anchors;
    property Constraints;
  end;

{$IFDEF UNITVERSIONING}
const
  UnitVersioning: TUnitVersionInfo = (
    RCSfile: '$RCSfile: JvUninstallControls.pas,v $';
    Revision: '$Revision: 1.25 $';
    Date: '$Date: 2005/02/17 10:21:16 $';
    LogPath: 'JVCL\run'
  );
{$ENDIF UNITVERSIONING}

implementation

uses
  Math, Registry;

const
  cUninstallPath = 'Software\Microsoft\Windows\CurrentVersion\Uninstall';
  cUninstallString = 'UninstallString';
  cDisplayName = 'DisplayName';

  FKey: array [TJvUCBDisplayMode] of DWORD =
    (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE);

type
  TJvUninstallInfo = class(TObject)
  private
    FSection: string;
    FHKey: HKEY;
    FProperties: TStringList;
    FHKeyName: string;
    function GetProperties: TStrings;
//    procedure SetProperties(const Value: TStrings); make Delphi 5 compiler happy // andreas
  public
    destructor Destroy; override;
    property HKey: HKEY read FHKey write FHKey;
    property HKeyName: string read FHKeyName write FHKeyName;
    property Section: string read FSection write FSection;
    property Properties: TStrings read GetProperties {write SetProperties // make Delphi 5 compiler happy // andreas};
  end;

  TSafeRegIniFile = class(TRegIniFile)
  public
    function ReadString(const Section, Ident, Default: string): string;
  end;

//=== { TJvUninstallInfo } ===================================================

destructor TJvUninstallInfo.Destroy;
begin
  FProperties.Free;
  inherited Destroy;
end;

function TJvUninstallInfo.GetProperties: TStrings;
begin
  if FProperties = nil then
    FProperties := TStringList.Create;
  Result := FProperties;
end;

{ make Delphi 5 compiler happy // andreas
procedure TJvUninstallInfo.SetProperties(const Value: TStrings);
begin
  if FProperties = nil then
    FProperties := TStringlist.Create;
  FProperties.Assign(Value);
end;}

//=== { TSafeRegIniFile } ====================================================

function TSafeRegIniFile.ReadString(const Section, Ident, Default: string): string;
var
  Key, OldKey: HKEY;
  Len: Integer;
  RegData: TRegDataType;
  Buffer: array [0..4095] of Byte;

  function BufToStr(Buffer: array of Byte; BufSize: Integer): string;
  var
    I: Integer;
  begin
    Result := '';
    for I := 0 to Min(SizeOf(Buffer), BufSize) - 1 do
      Result := Result + ' ' + IntToHex(Buffer[I], 2);
  end;

  function ExpandEnvVar(const S: string): string;
  begin
    SetLength(Result, ExpandEnvironmentStrings(PChar(S), nil, 0));
    ExpandEnvironmentStrings(PChar(S), PChar(Result), Length(Result));
  end;

begin
  Key := GetKey(Section);
  if Key <> 0 then
    try
      OldKey := CurrentKey;
      SetCurrentKey(Key);
      try
        if ValueExists(Ident) then
        begin
          RegData := GetDataType(Ident);
          case RegData of
            rdString, rdExpandString:
              begin
                Len := GetDataSize(Ident);
                if Len > 0 then
                begin
                  SetString(Result, nil, Len);
                  GetData(Ident, PChar(Result), Len, RegData);
                  SetLength(Result, StrLen(PChar(Result)));
                  if RegData = rdExpandString then
                    Result := ExpandEnvVar(Result);
                end
                else
                  Result := '';
              end;
            rdInteger:
              begin
                GetData(Ident, @Len, SizeOf(Len), RegData);
                Result := IntToStr(Len);
              end;
            rdBinary:
              begin
                Len := GetDataSize(Ident);
                if Len > 0 then
                begin
                  GetData(Ident, @Buffer, SizeOf(Buffer), RegData);
                  Result := BufToStr(Buffer, Min(Len, SizeOf(Buffer)));
                end
                else
                  Result := '';
              end;
          end;
        end
        else
          Result := Default;
      finally
        SetCurrentKey(OldKey);
      end;
    finally
      RegCloseKey(Key);
    end
  else
    Result := Default;
end;

procedure GetUninstallApps(DisplayModes: TJvUCBDisplayModes; Strings: TStrings; ShowAll, ShowEmptyValues: Boolean);
var
  I: Integer;
  FFolders, FItems: TStringList;
  Tmp: string;
  Reg: TSafeRegIniFile;
  Dm: TJvUCBDisplayMode;
  UI: TJvUninstallInfo;

  function BufToStr(Buffer: array of Byte; BufSize: Integer): string;
  var
    I: Integer;
  begin
    Result := '';
    for I := 0 to BufSize - 1 do
      Result := Result + ' ' + IntToHex(Buffer[I], 2);
  end;

  function ExpandEnvVar(const S: string): string;
  begin
    SetLength(Result, ExpandEnvironmentStrings(PChar(S), nil, 0));
    ExpandEnvironmentStrings(PChar(S), PChar(Result), Length(Result));
  end;

  procedure ReadProperties(Reg: TSafeRegIniFile; const Section: string; ShowEmptyValues: Boolean; Items, Props: TStrings);

⌨️ 快捷键说明

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