明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2069|回复: 1

发个Delphi版的安装源码(arx随cad自动启动,可动态设定)

[复制链接]
发表于 2012-3-11 23:51:15 | 显示全部楼层 |阅读模式


首先感谢各位前辈的付出。我整合了一下。
使用方法:
1.将Setup.exe和Setup.ini放到你的arx目录.
2.修改[Applications]下的内容,如果您有多个dll,则加入多条
[Applications]
xx=xx.dll
yy=yy.dll
3.如果您有更新版本的cad,则修改[Version]下的内容.请自行参数已设定的参数

pas
-----
unit fFrmMain;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, CheckLst, IniFiles, ExtCtrls, Registry;
type
  TFrmMain = class(TForm)
    lstVersion: TCheckListBox;
    Panel1: TPanel;
    btnInstall: TButton;
    btnUnInstall: TButton;
    btnExit: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btnExitClick(Sender: TObject);
    procedure btnInstallClick(Sender: TObject);
    procedure btnUnInstallClick(Sender: TObject);
  private
    { Private declarations }
    FIni: TIniFile;
    FReg: TRegistry;
    function AcadExists(VerCode: String): Boolean;
    function Install(VerCode, Name, Path: String): Boolean;
    function UnInstall(VerCode, Name, Path: String): Boolean;   
  public
    { Public declarations }
  end;
var
  FrmMain: TFrmMain;
const
  AutoCADKey = 'Software\Autodesk\AutoCAD\';
  HKLM = HKEY_LOCAL_MACHINE;
  HKCU = HKEY_CURRENT_USER;
implementation
{$R *.dfm}
function TFrmMain.AcadExists(VerCode: String): Boolean;
begin
  FReg.RootKey := HKCU;
  Result := FReg.OpenKey(AutoCADKey + VerCode, False);
  FReg.CloseKey;
end;
procedure TFrmMain.FormCreate(Sender: TObject);
var
  i: Integer;
  VerCode: String;
  list: TStringList;
begin
  if not FileExists(ExtractFilePath(Application.ExeName)+'Setup.ini') then begin
    Application.MessageBox('Can`t find Setup.ini File!', 'Error', MB_OK+MB_ICONERROR);
    Application.Terminate;
    Abort;
  end;
  FIni := TIniFile.Create(ExtractFilePath(Application.ExeName)+'Setup.ini');
  //
  FReg := TRegistry.Create;  
  //
  list := TStringList.Create;
  try
    FIni.ReadSection('Version', list);
    for i:=0 to list.Count-1 do begin
      lstVersion.Items.Add(list);
      VerCode := FIni.ReadString('Version', list, '');
      lstVersion.ItemEnabled := AcadExists(VerCode);
    end;
  finally
    list.Free;
  end;
end;
procedure TFrmMain.FormDestroy(Sender: TObject);
begin
  FReg.Free;
  FIni.Free;
end;
procedure TFrmMain.btnExitClick(Sender: TObject);
begin
  Close;
end;
function TFrmMain.Install(VerCode, Name, Path: String): Boolean;
var
  CurVer: String;
begin
  Result := False;
  FReg.RootKey := HKCU;
  if not FReg.OpenKey(AutoCADKey + VerCode, False) then exit;
  CurVer := FReg.ReadString('CurVer');
  FReg.CloseKey;
  CurVer := AutoCADKey + VerCode + '\' + CurVer + '\Applications';
  if FReg.KeyExists(CurVer) then
    FReg.OpenKey(CurVer + '\' + Name, True);
  FReg.WriteInteger('LOADCTRLS', 2);  //LOADCTRLS
  FReg.WriteString('LOADER', Path);  //LOADER
  FReg.WriteInteger('MANAGED', 1);  //MANAGED
  FReg.CloseKey;
end;

function TFrmMain.UnInstall(VerCode, Name, Path: String): Boolean;
var
  CurVer: String;
begin
  Result := False;
  FReg.RootKey := HKCU;
  if not FReg.OpenKey(AutoCADKey + VerCode, False) then exit;
  CurVer := FReg.ReadString('CurVer');
  FReg.CloseKey;
  CurVer := AutoCADKey + VerCode + '\' + CurVer + '\Applications';
  if FReg.KeyExists(CurVer) then
    FReg.DeleteKey(CurVer + '\' + Name);
  FReg.CloseKey;
end;

procedure TFrmMain.btnInstallClick(Sender: TObject);
var
  i, j: Integer;
  VerCode, Name, Path: String;
  list: TStringList;
begin
  list := TStringList.Create;
  try
    FIni.ReadSection('Applications', list);
    for i:=0 to list.Count-1 do begin
      Name := list;
      Path := FIni.ReadString('Applications', Name, '');
      Path := ExtractFilePath(Application.ExeName) + Path;
      for j:=0 to lstVersion.Count-1 do begin
        if lstVersion.Checked[j] then begin
          VerCode := FIni.ReadString('Version', lstVersion.Items[j], '');
          Install(VerCode, Name, Path);
        end;
      end;
    end;
    Application.MessageBox('Install success!', 'Install', MB_OK+MB_ICONINFORMATION);
  finally
    list.Free;
  end;
end;
procedure TFrmMain.btnUnInstallClick(Sender: TObject);
var
  i, j: Integer;
  VerCode, Name, Path: String;
  list: TStringList;
begin
  list := TStringList.Create;
  try
    FIni.ReadSection('Applications', list);
    for i:=0 to list.Count-1 do begin
      Name := list;
      Path := FIni.ReadString('Applications', Name, '');
      Path := ExtractFilePath(Application.ExeName) + Path;
      for j:=0 to lstVersion.Count-1 do begin
        if lstVersion.Checked[j] then begin
          VerCode := FIni.ReadString('Version', lstVersion.Items[j], '');
          UnInstall(VerCode, Name, Path);
        end;
      end;
    end;
    Application.MessageBox('UnInstall success!', 'UnInstall', MB_OK+MB_ICONINFORMATION);
  finally
    list.Free;
  end;
end;
end.

ini
-----
[Version]
AutoCAD 2000=R15.0
AutoCAD 2002=R15.0
AutoCAD 2004=R16.0
AutoCAD 2005=R16.1
AutoCAD 2006=R16.2
AutoCAD 2007=R17.0
AutoCAD 2008=R17.1
AutoCAD 2009=R17.2
[Applications]
mcad=mcad.dll




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2012-3-12 08:48:52 | 显示全部楼层
这个很强大,学习一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 19:55 , Processed in 0.165161 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表