-
Notifications
You must be signed in to change notification settings - Fork 2
/
RCProcessor.pas
96 lines (86 loc) · 3.01 KB
/
RCProcessor.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
unit RCProcessor;
interface
uses
System.SysUtils, System.Classes, BuildVersion;
type
TRCProcessor = class
private
FFileName: String;
FFileContents: TStringList;
function GetVersion: TBuildVersion;
public
constructor Create(AFileName: String);
destructor Destroy; override;
procedure SetVersion(AVersion: TBuildVersion);
procedure Save;
property Version: TBuildVersion read GetVersion;
end;
implementation
constructor TRCProcessor.Create(AFileName: String);
begin
FFileName := AFileName;
FFileContents := TStringList.Create;
FFileContents.LoadFromFile(FFileName);
end;
destructor TRCProcessor.Destroy;
begin
FFileContents.Free;
inherited Destroy;
end;
function TRCProcessor.GetVersion: TBuildVersion;
var
i: Integer;
LTemp: String;
LVerStr: TArray<String>;
begin
for i := 0 to (FFileContents.Count - 1) do
begin
if -1 <> FFileContents[i].IndexOf('FILEVERSION') then
begin
LVerStr := FFileContents[i].Replace('FILEVERSION', '').Trim.Split([',']);
BREAK;
end;
if -1 <> FFileContents[i].IndexOf('PRODUCTVERSION') then
begin
LVerStr := FFileContents[i].Replace('PRODUCTVERSION', '').Trim.Split([',']);
BREAK;
end;
if -1 <> FFileContents[i].IndexOf('VALUE "ProductVersion",') then
begin
LTemp := FFileContents[i].Replace('VALUE "ProductVersion", "', '').Trim;
LVerStr := LTemp.Replace('\0"', '').Trim.Split([',']);
BREAK;
end;
if -1 <> FFileContents[i].IndexOf('VALUE "FileVersion",') then
begin
LTemp := FFileContents[i].Replace('VALUE "FileVersion", "', '').Trim;
LVerStr := LTemp.Replace('\0"', '').Trim.Split([',']);
BREAK;
end;
end;
Result.Major := StrToInt(LVerStr[0]);
Result.Minor := StrToInt(LVerStr[1]);
Result.Release := StrToInt(LVerStr[2]);
Result.Build := StrToInt(LVerStr[3]);
end;
procedure TRCProcessor.SetVersion(AVersion: TBuildVersion);
var
i: Integer;
begin
for i := 0 to (FFileContents.Count - 1) do
begin
if -1 <> FFileContents[i].IndexOf('FILEVERSION') then
FFileContents[i] := String.Format('FILEVERSION %d,%d,%d,%d', [AVersion.Major, AVersion.Minor, AVersion.Release, AVersion.Build]);
if -1 <> FFileContents[i].IndexOf('PRODUCTVERSION') then
FFileContents[i] := String.Format('PRODUCTVERSION %d,%d,%d,%d', [AVersion.Major, AVersion.Minor, AVersion.Release, AVersion.Build]);
if -1 <> FFileContents[i].IndexOf('VALUE "ProductVersion",') then
FFileContents[i] := String.Format(' VALUE "ProductVersion", "%d,%d,%d,%d\0"', [AVersion.Major, AVersion.Minor, AVersion.Release, AVersion.Build]);
if -1 <> FFileContents[i].IndexOf('VALUE "FileVersion",') then
FFileContents[i] := String.Format(' VALUE "FileVersion", "%d,%d,%d,%d\0"', [AVersion.Major, AVersion.Minor, AVersion.Release, AVersion.Build]);
end;
end;
procedure TRCProcessor.Save;
begin
FFileContents.SaveToFile(FFileName);
end;
end.