Skip to content

Commit 7545e36

Browse files
committed
initial commit
0 parents  commit 7545e36

14 files changed

+5390
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__history
2+
Win32
3+
*.local

MSXML2_TLB.pas

+4,751
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Sample Code for Video "online updates with delphi"
2+
3+
This repro contains the source code of the video series "online updates with delphi"
4+
5+
This code requires the jedi api lib.
6+
7+
## Part 1 - Intro and best practices
8+
https://www.youtube.com/watch?v=MjRVpPztbMU
9+
10+
## Part 2 - all about the version number
11+
https://www.youtube.com/watch?v=PbLoxL7WNpc&t=22s
12+
13+
## Part 3 - check for updates and downloading them
14+
-- todo --

Version.rc

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "windows.h"
2+
3+
#define VER_FILEVERSION 3,10,349,0
4+
#define VER_FILEVERSION_STR "3.10.349.0\0"
5+
6+
#define VER_PRODUCTVERSION 3,10,0,0
7+
#define VER_PRODUCTVERSION_STR "3.10\0"
8+
9+
#define VER_PRIVATEBUILD 0
10+
#define VER_PRERELEASE 0
11+
#define VER_DEBUG 0
12+
13+
VS_VERSION_INFO VERSIONINFO
14+
FILEVERSION VER_FILEVERSION
15+
PRODUCTVERSION VER_PRODUCTVERSION
16+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
17+
FILEFLAGS (VER_PRIVATEBUILD|VER_PRERELEASE|VER_DEBUG)
18+
FILEOS VOS__WINDOWS32
19+
FILETYPE VFT_DLL
20+
FILESUBTYPE VFT2_UNKNOWN
21+
BEGIN
22+
BLOCK "StringFileInfo"
23+
BEGIN
24+
BLOCK "040904E4"
25+
BEGIN
26+
/* VALUE "CompanyName", VER_COMPANYNAME_STR
27+
VALUE "FileDescription", VER_FILEDESCRIPTION_STR
28+
*/ VALUE "FileVersion", VER_FILEVERSION_STR
29+
/* VALUE "InternalName", VER_INTERNALNAME_STR
30+
VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR
31+
VALUE "LegalTrademarks1", VER_LEGALTRADEMARKS1_STR
32+
VALUE "LegalTrademarks2", VER_LEGALTRADEMARKS2_STR
33+
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
34+
VALUE "ProductName", VER_PRODUCTNAME_STR
35+
*/ VALUE "ProductVersion", VER_PRODUCTVERSION_STR
36+
END
37+
END
38+
39+
BLOCK "VarFileInfo"
40+
BEGIN
41+
/* The following line should only be modified for localized versions. */
42+
/* It consists of any number of WORD,WORD pairs, with each pair */
43+
/* describing a language,codepage combination supported by the file. */
44+
/* */
45+
/* For example, a file might have values "0x409,1252" indicating that it */
46+
/* supports English language (0x409) in the Windows ANSI codepage (1252). */
47+
48+
VALUE "Translation", 0x409, 1252
49+
50+
END
51+
END

Version.res

388 Bytes
Binary file not shown.

VersionHelpher.pas

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
unit VersionHelpher;
2+
3+
interface
4+
5+
uses
6+
Classes, Windows;
7+
8+
type
9+
tVersionsInformation = record
10+
case boolean of
11+
true:
12+
(minor,
13+
major,
14+
build,
15+
patch: Word);
16+
false:
17+
(dwFileVersionMS,
18+
dwFileVersionLS: DWord);
19+
end;
20+
21+
TVersionHelpher = class
22+
public
23+
class function gibVersion(filename: string): tVersionsInformation;
24+
class function vergleicheVersion(a,b: tVersionsInformation): integer;
25+
class function stringZuVersion(str_version:string): tVersionsInformation;
26+
class function versionZuString(version: tVersionsInformation): string;
27+
end;
28+
29+
implementation
30+
31+
uses
32+
SysUtils, Math;
33+
34+
{ tVersionsErmittlung }
35+
36+
class function TVersionHelpher.gibVersion(filename: string): tVersionsInformation;
37+
var
38+
versionHandle, versionSize: DWord;
39+
pVersionInfo: pointer;
40+
itemLen: UInt;
41+
FixedFileInfo: PVSFixedFileInfo;
42+
bol_versiongefunden: boolean;
43+
begin
44+
bol_versiongefunden:=false;
45+
versionSize:=GetFileVersionInfoSize(PChar(filename), versionHandle);
46+
pVersionInfo:=AllocMem(versionSize);
47+
try
48+
if versionSize>0 then
49+
begin
50+
if GetFileVersionInfo(PChar(filename), versionHandle, versionSize, pVersionInfo) then
51+
begin
52+
if VerQueryValue(pVersionInfo, '', pointer(FixedFileInfo), itemLen) then
53+
begin
54+
result.dwFileVersionMS:=FixedFileInfo.dwFileVersionMS;
55+
result.dwFileVersionLS:=FixedFileInfo.dwFileVersionLS;
56+
bol_versiongefunden:=true;
57+
end;
58+
end;
59+
end;
60+
if not bol_versiongefunden then
61+
raise Exception.Create('keine Versionsinformation gefunden');
62+
finally
63+
freemem(pVersionInfo);
64+
end;
65+
end;
66+
67+
class function TVersionHelpher.stringZuVersion(
68+
str_version:string): tVersionsInformation;
69+
var
70+
sl: TStringlist;
71+
begin
72+
Result.dwFileVersionMS:=0;
73+
Result.dwFileVersionLS:=0;
74+
75+
sl:=TStringList.Create;
76+
try
77+
sl.Delimiter:='.';
78+
sl.DelimitedText:=str_version;
79+
80+
result.major:=strtoint(sl[0]);
81+
if sl.Count>1 then
82+
result.minor:=strtoint(sl[1]);
83+
if sl.Count>2 then
84+
result.patch:=strtoint(sl[2]);
85+
if sl.Count>3 then
86+
result.build:=strtoint(sl[3]);
87+
finally
88+
sl.Free;
89+
end;
90+
91+
end;
92+
93+
class function TVersionHelpher.vergleicheVersion(a,
94+
b: tVersionsInformation): integer;
95+
begin
96+
result:=CompareValue(a.major, b.major);
97+
if result=0 then
98+
result:=CompareValue(a.minor, b.minor);
99+
if result=0 then
100+
result:=CompareValue(a.patch, b.patch);
101+
if result=0 then
102+
result:=CompareValue(a.build, b.build);
103+
end;
104+
105+
class function TVersionHelpher.versionZuString(
106+
version: tVersionsInformation): string;
107+
begin
108+
result:=Format('%d.%d.%d.%d', [version.major, version.minor, version.patch, version.build]);
109+
end;
110+
111+
initialization
112+
113+
end.

demo.dpr

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
program demo;
2+
3+
{$APPTYPE CONSOLE}
4+
5+
{$R *.res}
6+
7+
{$R 'Version.res' 'Version.rc'}
8+
9+
uses
10+
System.SysUtils,
11+
VersionHelpher in 'VersionHelpher.pas',
12+
MSXML2_TLB in 'MSXML2_TLB.pas',
13+
uc_downloadactionloadurl in 'uc_downloadactionloadurl.pas',
14+
uc_DownloadBits in 'uc_DownloadBits.pas',
15+
uc_updatecheck in 'uc_updatecheck.pas';
16+
17+
var
18+
version: tVersionsInformation;
19+
begin
20+
try
21+
version:=TVersionHelpher.gibVersion( ParamStr(0) );
22+
writeln(
23+
TVersionHelpher.versionZuString(version)
24+
);
25+
26+
case TVersionHelpher.vergleicheVersion(version, TVersionHelpher.stringZuVersion('3.11.12')) of
27+
1: Writeln('Größer');
28+
0: Writeln('gleich');
29+
-1: Writeln('kleiner');
30+
end;
31+
32+
Readln;
33+
except
34+
on E: Exception do
35+
Writeln(E.ClassName, ': ', E.Message);
36+
end;
37+
end.

0 commit comments

Comments
 (0)