Delphi XE8 利用HttpClient实现的一个App自动更新组件

第一个版本,分享了。
unit AutoUpdate;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants, System.IOUtils, System.JSON, System.Net.HttpClient

{$IFDEF MSWINDOWS}
    , Winapi.Windows,
{$ENDIF}
{$IFDEF IOS}
, FMX.Platform.iOS,
  iOSapi.Foundation,
  Macapi.ObjectiveC,
{$ELSE}
{$IFDEF MACOS}
, FMX.Platform.Mac,
  Macapi.Foundation,
  Macapi.ObjectiveC,
{$ELSE}
{$IFDEF ANDROID}
, Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.JavaTypes,
  FMX.Helpers.Android, Androidapi.Helpers,
  Androidapi.JNI.Net,
{$ENDIF ANDROID}
{$ENDIF MACOS}
{$ENDIF IOS}
  FMX.Dialogs;

type
  TAutoUpdate = class(TComponent)
  private
    FServerVersion, FInstallFileUrl, FDescription: String;
    FInstallFileName: string;
    FCheckURL: String;
    procedure SetCheckURL(const Value: String);
  public
    constructor Create(AOwner: TComponent); override;
    function Check: Boolean;
    procedure DownLoad;
    procedure Install;
    property CheckURL: String read FCheckURL write SetCheckURL;
    property ServerVersion: string read FServerVersion;
    property Description: String read FDescription;
  end;

function GetAppVersion: String;

implementation

function GetAppVersion: String;
{$IFDEF MSWINDOWS}
  function GetBuildInfoAsString: string;
  var
    V1, V2, V3, V4: word;
    procedure GetBuildInfo(var V1, V2, V3, V4: word);
    var
      VerInfoSize, VerValueSize, Dummy: DWORD;
      VerInfo: Pointer;
      VerValue: PVSFixedFileInfo;
    begin
      VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
      if VerInfoSize > 0 then
      begin
        GetMem(VerInfo, VerInfoSize);
        try
          if GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo)
          then
          begin
            VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
            with VerValue^ do
            begin
              V1 := dwFileVersionMS shr 16;
              V2 := dwFileVersionMS and $FFFF;
              V3 := dwFileVersionLS shr 16;
              V4 := dwFileVersionLS and $FFFF;
            end;
          end;
        finally
        

你可能感兴趣的:(delphi)