Quelltext:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls, ExtCtrls, ComCtrls, ShellApi;
type
TMainForm = class(TForm)
FileEdit1: TEdit;
FileLabel1: TLabel;
FileSpeed1: TSpeedButton;
FileEdit2: TEdit;
FileLabel2: TLabel;
FileSpeed2: TSpeedButton;
Button1: TButton;
Button2: TButton;
Bevel1: TBevel;
OpenDialog1: TOpenDialog;
GroupBox1: TGroupBox;
ParamEdit1: TEdit;
ParamEdit2: TEdit;
ParamRadio1: TRadioButton;
ParamRadio2: TRadioButton;
ParamEdit3: TEdit;
ParamEdit4: TEdit;
ParamSpeed1: TSpeedButton;
Label1: TLabel;
Label2: TLabel;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormChange(Sender: TObject);
procedure FileSpeed1Click(Sender: TObject);
procedure FileSpeed2Click(Sender: TObject);
procedure ParamSpeed1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
procedure UpdateForm;
public
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure EnableControl(Control: TControl; Enabled: Boolean);
begin
if Enabled then
begin
if Control is TLabel then
begin
TLabel(Control).Font.Color:=clWindowText;
TLabel(Control).Enabled:=Enabled;
end
else
if Control is TEdit then
begin
TEdit(Control).Color:=clWindow;
TEdit(Control).Font.Color:=clWindowText;
TEdit(Control).Enabled:=Enabled;
TEdit(Control).SelLength:=0;
end
else
if Control is TMemo then
begin
TMemo(Control).Color:=clWindow;
TMemo(Control).Font.Color:=clWindowText;
TMemo(Control).Enabled:=Enabled;
TMemo(Control).SelLength:=0;
end
else
Control.Enabled:=Enabled;
end
else
begin
if Control is TLabel then
begin
TLabel(Control).Font.Color:=clGrayText;
TLabel(Control).Enabled:=Enabled;
end
else
if Control is TEdit then
begin
TEdit(Control).Color:=clBtnFace;
TEdit(Control).Font.Color:=clGrayText;
TEdit(Control).Enabled:=Enabled;
TEdit(Control).SelLength:=0;
end
else
if Control is TMemo then
begin
TMemo(Control).Color:=clBtnFace;
TMemo(Control).Font.Color:=clGrayText;
TMemo(Control).Enabled:=Enabled;
TMemo(Control).SelLength:=0;
end
else
Control.Enabled:=Enabled;
end;
end;
//
procedure TMainForm.UpdateForm;
var s: string;
begin
EnableControl(ParamEdit1, ParamRadio1.Checked);
EnableControl(ParamEdit2, ParamRadio2.Checked);
EnableControl(ParamEdit3, ParamRadio2.Checked);
EnableControl(ParamEdit4, ParamRadio2.Checked);
EnableControl(ParamSpeed1, ParamRadio2.Checked);
//
if ParamRadio1.Checked then
begin
s:=Trim(ParamEdit1.Text);
end
else
begin
s:=Trim(Format(ParamEdit2.Text, [ParamEdit3.Text, StringOfChar('*', Length(ParamEdit4.Text))]));
end;
Memo1.Text:='"'+FileEdit1.Text+'"'+' '+s+' '+'"'+FileEdit2.Text+'"';
end;
//
procedure TMainForm.FormCreate(Sender: TObject);
begin
UpdateForm;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
//
end;
//
procedure TMainForm.FormChange(Sender: TObject);
begin
UpdateForm;
end;
//
procedure TMainForm.FileSpeed1Click(Sender: TObject);
begin
OpenDialog1.InitialDir:=ExtractFilepath(FileEdit1.Text);
OpenDialog1.FileName:=ExtractFilename(FileEdit1.Text);
if OpenDialog1.Execute then
FileEdit1.Text:=OpenDialog1.FileName;
end;
procedure TMainForm.FileSpeed2Click(Sender: TObject);
begin
OpenDialog1.InitialDir:=ExtractFilepath(FileEdit2.Text);
OpenDialog1.FileName:=ExtractFilename(FileEdit2.Text);
if OpenDialog1.Execute then
FileEdit2.Text:=OpenDialog1.FileName;
end;
//
procedure TMainForm.ParamSpeed1Click(Sender: TObject);
begin
OpenDialog1.InitialDir:=ExtractFilepath(ParamEdit3.Text);
OpenDialog1.FileName:=ExtractFilename(ParamEdit3.Text);
if OpenDialog1.Execute then
ParamEdit3.Text:=OpenDialog1.FileName;
end;
//
procedure TMainForm.Button1Click(Sender: TObject);
var s: string;
begin
if ParamRadio1.Checked then
begin
s:=Trim(ParamEdit1.Text);
end
else
begin
s:=Trim(Format(ParamEdit2.Text, [ParamEdit3.Text, ParamEdit4.Text]));
end;
ShellExecute(Handle, PChar('open'), PChar('"'+FileEdit1.Text+'"'), PChar(s+' '+'"'+FileEdit2.Text+'"'), nil, SW_SHOWNORMAL);
end;
procedure TMainForm.Button2Click(Sender: TObject);
begin
Close;
end;
end.
object MainForm: TMainForm
Left = 0
Top = 0
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = 'Code signature'
ClientHeight = 369
ClientWidth = 569
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
Position = poScreenCenter
OnCreate = FormCreate
OnDestroy = FormDestroy
TextHeight = 13
object FileLabel1: TLabel
Left = 8
Top = 10
Width = 156
Height = 13
Caption = 'Path to Microsoft "signtool.exe":'
end
object FileSpeed1: TSpeedButton
Left = 538
Top = 25
Width = 23
Height = 23
Caption = '...'
OnClick = FileSpeed1Click
end
object FileLabel2: TLabel
Left = 8
Top = 266
Width = 56
Height = 13
Caption = 'Path to file:'
end
object FileSpeed2: TSpeedButton
Left = 538
Top = 281
Width = 23
Height = 23
Caption = '...'
OnClick = FileSpeed2Click
end
object Bevel1: TBevel
Left = 8
Top = 312
Width = 553
Height = 9
Shape = bsTopLine
end
object FileEdit1: TEdit
Left = 8
Top = 26
Width = 529
Height = 21
TabOrder = 0
OnChange = FormChange
end
object FileEdit2: TEdit
Left = 8
Top = 282
Width = 529
Height = 21
TabOrder = 2
OnChange = FormChange
end
object Button1: TButton
Left = 408
Top = 334
Width = 75
Height = 25
Caption = 'Signature'
TabOrder = 3
OnClick = Button1Click
end
object Button2: TButton
Left = 486
Top = 334
Width = 75
Height = 25
Caption = 'Close'
TabOrder = 4
OnClick = Button2Click
end
object GroupBox1: TGroupBox
Left = 8
Top = 54
Width = 553
Height = 202
Caption = 'Microsoft "signtool.exe" parameters'
TabOrder = 1
object ParamSpeed1: TSpeedButton
Left = 259
Top = 161
Width = 23
Height = 23
Caption = '...'
OnClick = ParamSpeed1Click
end
object Label1: TLabel
Left = 16
Top = 146
Width = 108
Height = 13
Caption = 'Certificate file (*.pfx):'
end
object Label2: TLabel
Left = 292
Top = 146
Width = 50
Height = 13
Caption = 'Password:'
end
object ParamEdit1: TEdit
Left = 16
Top = 51
Width = 521
Height = 21
ReadOnly = True
TabOrder = 1
Text = 'sign /a'
OnChange = FormChange
end
object ParamEdit2: TEdit
Left = 16
Top = 119
Width = 521
Height = 21
ReadOnly = True
TabOrder = 3
Text = 'sign /f "%s" /p %s'
OnChange = FormChange
end
object ParamRadio1: TRadioButton
Left = 16
Top = 28
Width = 521
Height = 17
Caption = 'Auto'
Checked = True
TabOrder = 0
TabStop = True
OnClick = FormChange
end
object ParamRadio2: TRadioButton
Left = 16
Top = 96
Width = 521
Height = 17
Caption = 'File'
TabOrder = 2
OnClick = FormChange
end
object ParamEdit3: TEdit
Left = 16
Top = 162
Width = 241
Height = 21
TabOrder = 4
OnChange = FormChange
end
object ParamEdit4: TEdit
Left = 292
Top = 162
Width = 245
Height = 21
PasswordChar = '*'
TabOrder = 5
OnChange = FormChange
end
end
object Memo1: TMemo
Left = 8
Top = 323
Width = 394
Height = 40
BorderStyle = bsNone
Color = clBtnFace
TabOrder = 5
end
object OpenDialog1: TOpenDialog
Filter = 'All files (*.*)|*.*'
Left = 416
Top = 70
end
end
|