root / LicensesMercure / UFUSB.pas @ 5
Historique | Voir | Annoter | Télécharger (6,683 ko)
1 | 1 | avalancogn | unit UFUSB;
|
---|---|---|---|
2 | |||
3 | interface
|
||
4 | |||
5 | uses
|
||
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
||
7 | Dialogs, StdCtrls, Buttons, JvBaseDlg, JvSelectDirectory, ComCtrls; |
||
8 | |||
9 | type
|
||
10 | TFUSB = class(TForm)
|
||
11 | LAjinomoto: TLabel; |
||
12 | CBAjinomoto: TComboBox; |
||
13 | LCourse: TLabel; |
||
14 | ECourse: TEdit; |
||
15 | LUser: TLabel; |
||
16 | CBUser: TComboBox; |
||
17 | LFormationDate: TLabel; |
||
18 | LFormationPlace: TLabel; |
||
19 | EFormationDate: TEdit; |
||
20 | EFormationPlace: TEdit; |
||
21 | LFirstName: TLabel; |
||
22 | LLastName: TLabel; |
||
23 | LCompany: TLabel; |
||
24 | EFirstName: TEdit; |
||
25 | ELastName: TEdit; |
||
26 | ECompany: TEdit; |
||
27 | GBAjinomoto: TGroupBox; |
||
28 | GBUser: TGroupBox; |
||
29 | JvSelectDirectory: TJvSelectDirectory; |
||
30 | BBNext: TBitBtn; |
||
31 | EDirectory: TEdit; |
||
32 | BBDirectory: TBitBtn; |
||
33 | LFinalDate: TLabel; |
||
34 | DTPFinalDate: TDateTimePicker; |
||
35 | LDirectory: TLabel; |
||
36 | procedure FormCreate(Sender: TObject);
|
||
37 | procedure FormShow(Sender: TObject);
|
||
38 | procedure CBAjinomotoChange(Sender: TObject);
|
||
39 | procedure CBUserChange(Sender: TObject);
|
||
40 | procedure BBDirectoryClick(Sender: TObject);
|
||
41 | procedure BBNextClick(Sender: TObject);
|
||
42 | private
|
||
43 | { D?clarations priv?es }
|
||
44 | public
|
||
45 | { D?clarations publiques }
|
||
46 | end;
|
||
47 | |||
48 | var
|
||
49 | FUSB: TFUSB; |
||
50 | |||
51 | implementation
|
||
52 | |||
53 | uses
|
||
54 | IniFiles, UFMenu; |
||
55 | |||
56 | {$R *.dfm}
|
||
57 | |||
58 | procedure TFUSB.FormCreate(Sender: TObject);
|
||
59 | begin
|
||
60 | Top := 0;
|
||
61 | Left := 0;
|
||
62 | DTPFinalDate.DateTime := Now; |
||
63 | end;
|
||
64 | |||
65 | procedure TFUSB.FormShow(Sender: TObject);
|
||
66 | begin
|
||
67 | CBAjinomoto.Clear; |
||
68 | with FMenu.TAjinomoto do |
||
69 | begin
|
||
70 | First; |
||
71 | while not Eof do |
||
72 | begin
|
||
73 | CBAjinomoto.Items.Insert(0, FieldByName('Key').AsString); |
||
74 | Next; |
||
75 | end;
|
||
76 | end;
|
||
77 | CBAjinomotoChange(nil);
|
||
78 | end;
|
||
79 | |||
80 | procedure TFUSB.CBAjinomotoChange(Sender: TObject);
|
||
81 | var
|
||
82 | i: Integer; |
||
83 | begin
|
||
84 | EFormationDate.Clear; |
||
85 | EFormationPlace.Clear; |
||
86 | ECourse.Clear; |
||
87 | CBUser.Clear; |
||
88 | CBUserChange(nil);
|
||
89 | if CBAjinomoto.ItemIndex = -1 then Exit; |
||
90 | with FMenu.TAjinomoto do |
||
91 | if Locate('Key', CBAjinomoto.Text, []) |
||
92 | then
|
||
93 | begin
|
||
94 | EFormationDate.Text := FieldByName('FormationDate').AsString;
|
||
95 | EFormationPlace.Text := FieldByName('FormationPlace').AsString;
|
||
96 | ECourse.Text := Format('Formation du %s ? %s', [EFormationDate.Text, EFormationPlace.Text]);
|
||
97 | for i := 1 to FieldByName('Licenses').AsInteger do |
||
98 | CBUser.Items.Add(Format('%s %s (%s)', [FieldByName(Format('FirstName%d', [i])).AsString, FieldByName(Format('LastName%d', [i])).AsString, FieldByName(Format('Company%d', [i])).AsString])); |
||
99 | end;
|
||
100 | end;
|
||
101 | |||
102 | procedure TFUSB.CBUserChange(Sender: TObject);
|
||
103 | begin
|
||
104 | EFirstName.Clear; |
||
105 | ELastName.Clear; |
||
106 | ECompany.Clear; |
||
107 | BBNext.Enabled := (CBUser.ItemIndex <> -1) and (Length(EDirectory.Text) > 0); |
||
108 | if CBUser.ItemIndex = -1 then Exit; |
||
109 | with FMenu.TAjinomoto do |
||
110 | begin
|
||
111 | EFirstName.Text := FieldByName(Format('FirstName%d', [CBUser.ItemIndex + 1])).AsString; |
||
112 | ELastName.Text := FieldByName(Format('LastName%d', [CBUser.ItemIndex + 1])).AsString; |
||
113 | ECompany.Text := FieldByName(Format('Company%d', [CBUser.ItemIndex + 1])).AsString; |
||
114 | end;
|
||
115 | end;
|
||
116 | |||
117 | procedure TFUSB.BBDirectoryClick(Sender: TObject);
|
||
118 | begin
|
||
119 | if JvSelectDirectory.Execute
|
||
120 | then
|
||
121 | EDirectory.Text := JvSelectDirectory.Directory; |
||
122 | BBNext.Enabled := (CBUser.ItemIndex <> -1) and (Length(EDirectory.Text) > 0); |
||
123 | end;
|
||
124 | |||
125 | procedure TFUSB.BBNextClick(Sender: TObject);
|
||
126 | var
|
||
127 | Lic : TIniFile; |
||
128 | MajorVersion, MinorVersion, ReleaseVersion, BuildVersion : integer ; |
||
129 | FileName, VersionString, Drive, Volume, SoftwareEnableKey : string ;
|
||
130 | Buffer : Pointer ; |
||
131 | Version : PVSFixedFileInfo ; |
||
132 | BufferSize, VersionSize : DWORD ; |
||
133 | VolumeSerialNumber, MaximumComponentLength, FileSystemFlags : DWORD ; |
||
134 | begin
|
||
135 | if not DirectoryExists(EDirectory.Text) |
||
136 | then
|
||
137 | begin
|
||
138 | MessageDlg('Le dossier d''installation n''existe pas !' + sLineBreak + 'V?rifier que la cl? USB a bien ?t? ins?r?e.', mtError, [mbOK], 0);; |
||
139 | Exit; |
||
140 | end;
|
||
141 | FileName := IncludeTrailingPathDelimiter(JvSelectDirectory.Directory) + 'InraPorc.exe';
|
||
142 | if not FileExists(FileName) |
||
143 | then
|
||
144 | begin
|
||
145 | MessageDlg('Le programme InraPorc.exe ne se trouve pas dans ce dossier !', mtError, [mbOK], 0); |
||
146 | Exit; |
||
147 | end;
|
||
148 | // Version du programme
|
||
149 | BufferSize := GetFileVersionInfoSize(PChar(FileName), BufferSize); |
||
150 | if BufferSize > 0 |
||
151 | then
|
||
152 | begin
|
||
153 | GetMem(Buffer, BufferSize); |
||
154 | GetFileVersionInfo(PChar(FileName), 0, BufferSize, Buffer);
|
||
155 | VerQueryValue(Buffer, '\', Pointer(Version), VersionSize);
|
||
156 | MajorVersion := Version.dwFileVersionMS shr 16; |
||
157 | MinorVersion := Version.dwFileVersionMS and $FFFF; |
||
158 | ReleaseVersion := Version.dwFileVersionLS shr 16; |
||
159 | BuildVersion := Version.dwFileVersionLS and $FFFF; |
||
160 | FreeMem(Buffer, BufferSize); |
||
161 | VersionString := Format ('%d.%d.%d.%d', [MajorVersion, MinorVersion, ReleaseVersion, BuildVersion]);
|
||
162 | end ;
|
||
163 | // Num?ro de s?rie du volume
|
||
164 | Drive := IncludeTrailingPathDelimiter(ExtractFileDrive(FileName)); |
||
165 | GetVolumeInformation(PChar(Drive), nil, 0, @VolumeSerialNumber, MaximumComponentLength, FileSystemFlags, nil, 0); |
||
166 | Volume := IntToHex(HiWord(VolumeSerialNumber), 4) + '-' + IntToHex(LoWord(VolumeSerialNumber), 4); |
||
167 | // Cl? d'activation
|
||
168 | SoftwareEnableKey := FMenu.EducationKey(VersionString, EFirstName.Text, ELastName.Text, ECompany.Text, Volume, DateToStr(DTPFinalDate.Date)); |
||
169 | // Enregistrement dans la base
|
||
170 | FMenu.MLog.Lines.Add('Recording education...');
|
||
171 | with FMenu.TEducation do |
||
172 | begin
|
||
173 | Append; |
||
174 | FieldByName('Date').AsDateTime := Now;
|
||
175 | FieldByName('Version').AsString := VersionString;
|
||
176 | FieldByName('FirstName').AsString := EFirstName.Text;
|
||
177 | FieldByName('LastName').AsString := ELastName.Text;
|
||
178 | FieldByName('Company').AsString := ECompany.Text;
|
||
179 | FieldByName('Course').AsString := ECourse.Text;
|
||
180 | FieldByName('VolumeSerialNumber').AsString := Volume;
|
||
181 | FieldByName('FinalDate').AsString := DateToStr(DTPFinalDate.Date);
|
||
182 | FieldByName('SoftwareEnableKey').AsString := SoftwareEnableKey;
|
||
183 | Post; |
||
184 | end;
|
||
185 | // Cr?ation du fichier de licence
|
||
186 | FMenu.MLog.Lines.Add('Writing license file...');
|
||
187 | Lic := TIniFile.Create(ChangeFileExt(FileName, '.lic'));
|
||
188 | Lic.WriteInteger('License', 'LicenseType', 1); |
||
189 | Lic.WriteString('License', 'Version', VersionString); |
||
190 | Lic.WriteString('License', 'FirstName', EFirstName.Text); |
||
191 | Lic.WriteString('License', 'LastName', ELastName.Text); |
||
192 | Lic.WriteString('License', 'Company', ECompany.Text); |
||
193 | Lic.WriteString('License', 'Course', ECourse.Text); |
||
194 | Lic.WriteString('License', 'VolumeSerialNumber', Volume); |
||
195 | Lic.WriteString('License', 'FinalDate', DateToStr(DTPFinalDate.Date)); |
||
196 | Lic.WriteString('License', 'SoftwareEnableKey', SoftwareEnableKey); |
||
197 | Lic.Free; |
||
198 | CBUser.ItemIndex := -1;
|
||
199 | CBUserChange(nil);
|
||
200 | end;
|
||
201 | |||
202 | end. |