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

📄 liveupdate.dpr

📁 一个基于Socket的在线更新程序
💻 DPR
字号:
library LiveUpdate;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  Windows,
  SysUtils,
  Dialogs,
  Classes,
  hxClasses in '..\Common Files\hxClasses.pas',
  hxFileRes in '..\Common Files\hxFileRes.pas',
  hxSysUtils in '..\Common Files\hxSysUtils.pas',
  hxUpdate in '..\Common Files\hxUpdate.pas',
  hxVersion in '..\Common Files\hxVersion.pas',
  hxDllClient in 'hxDllClient.pas';

{$R *.res}

var
  DllClient: ThxDllClient;

procedure DllEntryPoint(dwReason: DWORD);
begin
  case dwReason of
    DLL_PROCESS_ATTACH:
    begin
      DllClient:= ThxDllClient.Create;
    end;
    DLL_PROCESS_DETACH:
    begin
      DllClient.Free;
    end;
    DLL_THREAD_ATTACH:
    begin
    end;
    DLL_THREAD_DETACH:
    begin
    end;
  end;
end;

function Init(AProjectName: PChar; AHost: PChar; APort: Integer;
  ASocksInfo: PSocksInfo = nil): Boolean; stdcall;
begin
  try
    with DllClient do
    begin
      ProjectName:= AProjectName;
      Host:= AHost;
      Port:= APort;
      with ProxyInfo do
      begin
        if ASocksInfo <> nil then
        begin
          Enabled:= True;
          IP:= ASocksInfo.ProxyIP;
          Port:= ASocksInfo.ProxyPort;
          Username:= ASocksInfo.ProxyUser;
          Password:= ASocksInfo.ProxyPass;
        end
        else
          Enabled:= False;
      end;
    end;
    Result:= True;
  except
    on E: Exception do
    begin
      MessageBox(0, PChar(E.Message), '提示', MB_OK + MB_ICONERROR);
      Result:= False;
    end;
  end;
end;

function CheckNewVersion: Boolean; stdcall;
begin
  try
    Result:= DllClient.CheckNewVersion;
  except
    on E: Exception do
    begin
      MessageBox(0, PChar(E.Message), '提示', MB_OK + MB_ICONERROR);
      Result:= False;
    end;
  end;
end;

function UpdateProduct(DownloadProgress: TDownloadProgress): Boolean; stdcall;
begin
  try
    DllClient.UpdateProduct(DownloadProgress);
    Result:= True;
  except
    on E: Exception do
    begin
      MessageBox(0, PChar(E.Message), '提示', MB_OK + MB_ICONERROR);
      Result:= False;
    end;
  end;
end;

//获取旧版本号
function GetOldVersions(VerInfo: PVerInfo; Index: Integer): Integer; stdcall;
begin
  if VerInfo = nil then
  begin
    //获取文件数量
    Result:= DllClient.OldVersions.Count;
  end
  else
  begin
    with DllClient.OldVersions.Items[Index]^ do
    begin
      //Todo:这里为什么不能赋值?
      StrPCopy(VerInfo^.FileName, FileName);
      StrPCopy(VerInfo^.Version, Version);
    end;
  end;
end;

//获取新版本号
function GetNewVersions(VerInfo: PVerInfo; Index: Integer): Integer; stdcall;
begin
  if VerInfo = nil then
  begin
    Result:= DllClient.NewVersions.Count;
  end
  else
  begin
    with DllClient.NewVersions.Items[Index]^ do
    begin
      StrPCopy(VerInfo.FileName, FileName);
      StrPCopy(VerInfo.Version, Version);
    end;
  end;
end;

exports
  Init,
  UpdateProduct,
  CheckNewVersion,
  GetOldVersions,
  GetNewVersions;

begin
  DllProc:= @DllEntryPoint;
  DllEntryPoint(DLL_PROCESS_ATTACH);
end.

⌨️ 快捷键说明

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