📄 jvprogramversioncheck.pas
字号:
property ProxySettings;
property UserName;
property Password;
property PasswordRequired;
property Port;
property VersionInfoLocationPathList;
property VersionInfoFileName;
end;
{$ENDIF USE_3RDPARTY_ICS}
TJvProgramVersionDatabaseLocation = class;
TJvLoadFileFromRemoteDatabaseEvent = function(AProgramVersionLocation: TJvProgramVersionDatabaseLocation;
const ARemotePath, ARemoteFileName, ALocalPath, ALocalFileName: string): string of object;
{ Simple Database location class with no http logic.
The logic must be implemented manually in the OnLoadFileFromRemote event }
TJvProgramVersionDatabaseLocation = class(TJvCustomProgramVersionLocation)
private
FServerName: string;
FUserName: string;
FPassword: string;
FSelectStatementVersion: string;
FOnLoadFileFromRemote: TJvLoadFileFromRemoteDatabaseEvent;
protected
function LoadFileFromRemoteInt(const ARemotePath, ARemoteFileName, ALocalPath, ALocalFileName: string;
ABaseThread: TJvBaseThread): string; override;
public
function LoadVersionInfoFromRemote(const ALocalDirectory, ALocalVersionInfoFileName: string;
ABaseThread: TJvBaseThread): string; override;
published
property ServerName: string read FServerName write FServerName;
property UserName: string read FUserName write FUserName;
property Password: string read FPassword write FPassword;
property SelectStatementVersion: string
read FSelectStatementVersion write FSelectStatementVersion;
property OnLoadFileFromRemote: TJvLoadFileFromRemoteDatabaseEvent
read FOnLoadFileFromRemote write FOnLoadFileFromRemote;
end;
{ Location Type for the TJvProgramVersionCheck class}
TJvProgramVersionLocationType = (pvltNetwork, pvltDatabase, pvltFTP, pvltHTTP);
{Set of TJvProgramVersionLocationTypes}
TJvProgramVersionLocationTypes = set of TJvProgramVersionLocationType;
{ Type for User Customizing options to the JvProgramVersionCheck
The settings of the Programversioncheck are stored via JvAppStorage. With
these types could be defined which settings are stored and restored and so
customisable by the end user}
TJvProgramVersionUserOption = (uoCheckFrequency, uoLocalDirectory,
uoAllowedReleaseType, uoLocationType, uoLocationNetwork,
uoLocationHTTP, uoLocationFTP, uoLocationDatabase);
{ set of TJvProgramVersionUserOption }
TJvProgramVersionUserOptions = set of TJvProgramVersionUserOption;
TJvProgramVersionCheck = class(TJvCustomPropertyStore)
private
FAllowedReleaseType: TJvProgramReleaseType;
FCheckFrequency: Integer;
FDownloadError: string;
FExecuteDownloadInstallFileName: string;
FExecuteOperation: TJvRemoteVersionOperation;
FExecuteVersionInfo: TJvProgramVersionInfo;
FLastCheck: TDateTime;
FLocalDirectory: string;
FLocalInstallerFileName: string;
FLocalVersionInfoFileName: string;
FLocationDatabase: TJvProgramVersionDatabaseLocation;
FLocationFTP: TJvProgramVersionFTPLocation;
FLocationHTTP: TJvProgramVersionHTTPLocation;
FLocationNetwork: TJvProgramVersionNetworkLocation;
FLocationType: TJvProgramVersionLocationType;
FRemoteAppStorage: TJvAppIniFileStorage;
FRemoteProgramVersionHistory: TJvProgramVersionHistory;
FThread: TJvThread;
FThreadDialog: TJvThreadAnimateDialog;
FUserOptions: TJvProgramVersionUserOptions;
protected
procedure CheckLocalDirectory;
function CurrentApplicationName: string;
function CurrentFileVersion: string;
procedure DownloadThreadOnExecute(Sender: TObject; Params: Pointer);
procedure DownloadThreadOnFinishAll(Sender: TObject);
function GetAllowedRemoteProgramVersion: string;
function GetAllowedRemoteProgramVersionReleaseType: string;
function GetLocationTypesSupported: TJvProgramVersionLocationTypes;
function IsRemoteProgramVersionNewer: Boolean;
function IsRemoteProgramVersionReleaseTypeNewer(AReleaseType: TJvProgramReleaseType): Boolean;
procedure LoadData; override;
function LoadRemoteInstallerFile(const ALocalDirectory, ALocalInstallerFileName: string;
AProgramVersionInfo: TJvProgramVersionInfo; ABaseThread: TJvBaseThread): string;
function LoadRemoteVersionInfoFile(const ALocalDirectory, ALocalVersionInfoFileName: string): string;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetThreadInfo(const Info: string);
procedure SetUserOptions(Value: TJvProgramVersionUserOptions);
procedure StoreData; override;
procedure StoreRemoteVersionInfoToFile;
procedure VersionInfoButtonClick(const ParameterList: TJvParameterList;
const Parameter: TJvBaseParameter);
property RemoteAppStorage: TJvAppIniFileStorage read FRemoteAppStorage;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DownloadInstallerFromRemote;
procedure Execute;
function GetRemoteVersionOperation(var ReleaseType: TJvProgramReleaseType): TJvRemoteVersionOperation;
function SelectedLocation: TJvCustomProgramVersionLocation;
procedure ShowProgramVersionsDescription(const AFromVersion, AToVersion: string);
property LastCheck: TDateTime read FLastCheck write FLastCheck;
property LocationTypesSupported: TJvProgramVersionLocationTypes read GetLocationTypesSupported;
property RemoteProgramVersionHistory: TJvProgramVersionHistory
read FRemoteProgramVersionHistory write FRemoteProgramVersionHistory;
published
{ Defines which release types will be shown in the update dialog }
property AllowedReleaseType: TJvProgramReleaseType
read FAllowedReleaseType write FAllowedReleaseType default prtProduction;
property AppStorage;
property AppStoragePath;
{ Defines how often the check for a new version is executed (in days) }
property CheckFrequency: Integer read FCheckFrequency write FCheckFrequency;
{ Defines the local directory where the remote files where stored }
property LocalDirectory: string read FLocalDirectory write FLocalDirectory;
{ Defines the local name of the program installer. If it is empty the name
of the remote file is used }
property LocalInstallerFileName: string
read FLocalInstallerFileName write FLocalInstallerFileName;
{ Defines the name of the local version info file. If it is empty the name
of the remote file is used }
property LocalVersionInfoFileName: string
read FLocalVersionInfoFileName write FLocalVersionInfoFileName;
{ Database Location }
property LocationDatabase: TJvProgramVersionDatabaseLocation
read FLocationDatabase write FLocationDatabase;
{ FTP Location }
property LocationFTP: TJvProgramVersionFTPLocation read FLocationFTP write FLocationFTP;
{ HTTP Location }
property LocationHTTP: TJvProgramVersionHTTPLocation read FLocationHTTP write FLocationHTTP;
{ Network Location }
property LocationNetwork: TJvProgramVersionNetworkLocation read FLocationNetwork write FLocationNetwork;
{ Defines location which is used for the version check,
only assigned locations are supported }
property LocationType: TJvProgramVersionLocationType read FLocationType write FLocationType;
{Defines which options of the component are stored/restored via AppStorage }
property UserOptions: TJvProgramVersionUserOptions read FUserOptions write SetUserOptions
default [uoCheckFrequency, uoLocalDirectory, uoAllowedReleaseType,
uoLocationType, uoLocationNetwork, uoLocationHTTP, uoLocationFTP, uoLocationDatabase];
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvProgramVersionCheck.pas,v $';
Revision: '$Revision: 1.8 $';
Date: '$Date: 2005/02/17 10:20:45 $';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
SysUtils, Dialogs, Controls, ComCtrls, StdCtrls,
{$IFDEF MSWINDOWS}
Forms,
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
QForms,
{$ENDIF UNIX}
JclBase, JclFileUtils, JclShell,
JvDSADialogs, JvParameterListParameter, JvResources;
const
SParamNameVersionButtonInfo = 'VersionButtonInfo';
SParamNameMemo = 'Memo';
SAppStorageDefaultSection = 'Version';
SParamNameNewVersionLabel = 'New Version Label';
SParamNameGroupBox = 'GroupBox';
SParamNameOperation = 'Operation';
SParamNameRadioButton = 'RadioButton';
SProgramVersion = 'Program Version ';
SLastCheck = 'LastCheck';
//=== Common Functions =======================================================
function CompareVersionNumbers(AVersion1, AVersion2: string): Integer;
var
N1, N2: Integer;
function GetNextNumber(var Version: string): Integer;
var
P: Integer;
S: string;
begin
P := Pos('.', Version);
if P > 0 then
begin
S := Copy(Version, 1, P - 1);
Version := Copy(Version, P + 1, Length(Version) - P);
end
else
begin
S := Version;
Version := '';
end;
if S = '' then
Result := -1
else
try
Result := StrToInt(S);
except
Result := -1;
end;
end;
begin
Result := 0;
repeat
N1 := GetNextNumber(AVersion1);
N2 := GetNextNumber(AVersion2);
if N2 > N1 then
begin
Result := 1;
Exit;
end
else
if N2 < N1 then
begin
Result := -1;
Exit;
end
until (AVersion1 = '') or (AVersion2 = '');
end;
//=== { TJvProgramVersionsStringList } =======================================
procedure TJvProgramVersionsStringList.Sort;
function VersionNumberSortCompare(List: TStringList; Index1, Index2: Integer): Integer;
var
S1, S2: string;
begin
S1 := TJvProgramVersionInfo(List.Objects[Index1]).ProgramVersion;
S2 := TJvProgramVersionInfo(List.Objects[Index2]).ProgramVersion;
Result := CompareVersionNumbers(S1, S2);
end;
begin
CustomSort(@VersionNumberSortCompare);
end;
//=== { TJvProgramVersionInfo } ==============================================
constructor TJvProgramVersionInfo.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FVersionDescription := TStringList.Create;
IgnoreLastLoadTime := True;
FDownloadPasswordRequired := False;
end;
destructor TJvProgramVersionInfo.Destroy;
begin
FreeAndNil(FVersionDescription);
inherited Destroy;
end;
function TJvProgramVersionInfo.GetVersionDescription: TStrings;
begin
Result := FVersionDescription;
end;
procedure TJvProgramVersionInfo.SetVersionDescription(Value: TStrings);
begin
FVersionDescription.Assign(Value);
end;
procedure TJvProgramVersionInfo.Clear;
begin
if Assigned(FVersionDescription) then
FVersionDescription.Clear;
FProgramVersion := '';
FProgramReleaseType := prtProduction;
end;
function TJvProgramVersionInfo.ProgramVersionReleaseType: string;
begin
case ProgramReleaseType of
prtBeta:
Result := Trim(ProgramVersion + ' ' + RsPVCReleaseTypeBeta);
prtAlpha:
Result := Trim(ProgramVersion + ' ' + RsPVCReleaseTypeAlpha);
else
Result := Trim(ProgramVersion + ' ' + RsPVCReleaseTypeProduction);
end;
end;
function TJvProgramVersionInfo.ProgramSizeString: string;
begin
if ProgramSize <= 0 then
Result := ''
else
if ProgramSize >= 1024 * 1024 * 1024 then
Result := Format(RsPVSiceGB, [ProgramSize / 1024 / 1024 / 1024])
else
if ProgramSize >= 1024 * 1024 then
Result := Format(RsPVSiceMB, [ProgramSize / 1024 / 1024])
else
if ProgramSize >= 1024 then
Result := Format(RsPVSiceKB, [ProgramSize / 1024])
else
Result := Format(RsPVSiceB, [ProgramSize])
end;
function TJvProgramVersionInfo.ProgramVersionInfo: string;
begin
Result := ProgramVersionReleaseType;
if ProgramSize > 0 then
Result := Result + ' (' + ProgramSizeString + ')';
end;
//=== { TJvProgramVersionHistory } ===========================================
constructor TJvProgramVersionHistory.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
DeleteBeforeStore := True;
ItemName := SProgramVersion;
IgnoreLastLoadTime := True;
IgnoreProperties.Add('Duplicates');
IgnoreProperties.Add('Sorted');
end;
procedure TJvProgramVersionHistory.RecalculateCurrentProgramVersions;
var
I: TJvProgramReleaseType;
begin
for I := Low(TJvProgramReleaseType) to High(TJvProgramReleaseType) do
FCurrentProgramVersion[I] := SearchCurrentProgramVersion(I);
end;
procedure TJvProgramVersionHistory.LoadData;
begin
inherited LoadData;
Items.Sort;
RecalculateCurrentProgramVersions;
end;
function TJvProgramVersionHistory.AllowedCurrentProgramVersion(
AAllowedReleaseType: TJvProgramReleaseType): TJvProgramVersionInfo;
var
I: TJvProgramReleaseType;
begin
Result := nil;
I := Low(TJvProgramReleaseType);
while I <= AAllowedReleaseType do
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -