?? fnsis.pas
字號:
unit fNSIS;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons, fEditEntry;
type
PSectionData = ^TSectionData;
TSectionData = record
Description: String;
SectionsIn:TStringList;
SectionFiles: TStringList;
FileDirectories: TStringList;
OverWrite: TStringList;
end;
type
TfrmNSIS = class(TForm)
pnlTop: TPanel;
lblInfo: TLabel;
Image1: TImage;
bvlSplitter: TBevel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Panel3: TPanel;
ntNSIS: TNotebook;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
edtAppName: TEdit;
edtAppVer: TEdit;
edtAppPub: TEdit;
edtAppWebsite: TEdit;
Label5: TLabel;
Label6: TLabel;
Label8: TLabel;
Label9: TLabel;
edtIcon: TEdit;
edtSetup: TEdit;
Panel1: TPanel;
Panel2: TPanel;
rdModern: TRadioButton;
rdClassic: TRadioButton;
rdNone: TRadioButton;
btnIcon: TButton;
btnFile: TButton;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
GroupBox1: TGroupBox;
cmbDefaultDir: TComboBox;
chkAllowChange: TCheckBox;
GroupBox2: TGroupBox;
edtLicense: TEdit;
btnLicense: TButton;
chCreateLicense: TCheckBox;
memLicense: TMemo;
dlgOpen: TOpenDialog;
dlgSave: TSaveDialog;
edtSection: TEdit;
Label7: TLabel;
Button4: TButton;
lstSection: TListBox;
Button5: TButton;
Button6: TButton;
Panel4: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
lstFiles: TListView;
lstSections: TListBox;
memDesc: TMemo;
Label10: TLabel;
Label11: TLabel;
lstIncludeIn: TListView;
lblTitle: TLabel;
Image2: TImage;
Panel5: TPanel;
Label12: TLabel;
Label13: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure chCreateLicenseClick(Sender: TObject);
procedure btnLicenseClick(Sender: TObject);
procedure btnIconClick(Sender: TObject);
procedure btnFileClick(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure lstIncludeInClick(Sender: TObject);
procedure lstSectionsClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure memDescChange(Sender: TObject);
private
{ Private declarations }
public
procedure AddSection(strSection: STring);
procedure UpdateFiles();
{ Public declarations }
end;
var
frmNSIS: TfrmNSIS;
implementation
{$R *.dfm}
procedure TfrmNSIS.Button1Click(Sender: TObject);
begin
ntNSIS.PageIndex := ntNSIS.PageIndex + 1;
lblTitle.Caption := ntNsis.Pages[ntNsis.PageIndex];
end;
procedure TfrmNSIS.Button2Click(Sender: TObject);
begin
ntNSIS.PageIndex := ntNSIS.PageIndex - 1;
lblTitle.Caption := ntNsis.Pages[ntNsis.PageIndex];
end;
procedure TfrmNSIS.Button3Click(Sender: TObject);
begin
close;
end;
procedure TfrmNSIS.chCreateLicenseClick(Sender: TObject);
begin
memLicense.ReadOnly := chCreateLicense.Checked;
end;
procedure TfrmNSIS.btnLicenseClick(Sender: TObject);
begin
with dlgOpen do begin
Filter := 'Text Files (*.txt)|*.txt';
if Execute then begin
edtLicense.Text := Filename;
memLicense.Lines.LoadFromFile(Filename);
end;
end;
end;
procedure TfrmNSIS.btnIconClick(Sender: TObject);
begin
With dlgOpen do begin
Filter := 'Icon Files (*.ico)|*.ico';
if Execute then begin
edtIcon.Text := filename;
end;
end;
end;
procedure TfrmNSIS.btnFileClick(Sender: TObject);
var
s: String;
begin
With dlgSave do begin
Filter := 'Executable Files (*.exe)|*.exe';
if Execute then begin
if FileExists(Filename) then begin
if MessageBox(Handle, 'This file already exists.#10#32Do you wish to overwrite?', 'Overwrite', MB_YESNO) = mrno then
exit;
end;
s := Filename;
if ExtractFileExt(s) <> '.exe' then
s := s + '.exe';
edtSetup.Text := s;
end;
end;
end;
procedure TfrmNSIS.Button4Click(Sender: TObject);
var i: integer;
begin
lstSection.Items.Add(edtSection.Text);
lstIncludeIn.Items.Clear;
for i := 0 to lstSection.Items.Count - 1 do begin
with lstIncludeIn.Items.Add do
Caption := lstSection.Items[i];
end;
end;
procedure TfrmNSIS.Button5Click(Sender: TObject);
begin
lstSection.Items.Delete(lstSection.ItemIndex);
end;
procedure TfrmNSIS.Button6Click(Sender: TObject);
begin
lstSection.Items.Clear;
end;
procedure TfrmNsis.AddSection(strSection: String);
var
s: String;
d: PSectionData;
begin
new(d);
d.SectionsIn := TStringList.Create;
d.FileDirectories := TStringList.Create;
d.SectionFiles := TStringList.Create;
d.OverWrite := TStringList.Create;
if strSection <> '' then
lstSections.Items.InsertObject(lstSections.Items.Count,strSection, TObject(d));
end;
procedure TfrmNSIS.SpeedButton1Click(Sender: TObject);
var
s: String;
begin
s := InputBox('New Section', 'Enter the name of the new section.', '');
AddSection(s);
end;
procedure TfrmNSIS.SpeedButton2Click(Sender: TObject);
var
s: String;
begin
s := InputBox('New Section', 'Enter the name of the new section.', lstSections.Items[lstSections.ItemIndex]);
if (s <> '') and (s <> lstSections.Items[lstSections.ItemIndex]) then
lstSections.Items[lstSections.ItemIndex] := s;
end;
procedure TfrmNSIS.SpeedButton3Click(Sender: TObject);
begin
lstSections.Items.Delete(lstSections.ItemIndex);
end;
procedure TfrmNSIS.lstIncludeInClick(Sender: TObject);
var
d: PSectionData;
i: Integer;
begin
if lstSections.ItemIndex = -1 then exit;
PSectionData(lstSections.Items.Objects[lstSections.ItemIndex]).SectionsIn := TStringList.Create;
PSectionData(lstSections.Items.Objects[lstSections.ItemIndex]).SectionsIn.Clear;
for i:=0 to lstIncludeIn.Items.Count - 1 do begin
if lstIncludeIn.ITems[i].Checked then
PSectionData(lstSections.Items.Objects[lstSections.ItemIndex]).SectionsIn.Add(IntToStr(i));
end;
end;
procedure TfrmNSIS.lstSectionsClick(Sender: TObject);
var
d: PSectionData;
i: Integer;
begin
if lstIncludeIn.Items.Count > 0 then begin
for i := 0 to lstSections.Items.Count-1 do begin
lstIncludeIn.Items[i].Checked := false;
end;
end;
lstFiles.Items.Clear;
if PSectionData(lstSections.Items.Objects[lstSections.ItemIndex]).FileDirectories.Count <> 0 then begin
for i := 0 to PSectionData(lstSections.Items.Objects[lstSections.ItemIndex]).FileDirectories.Count - 1 do begin
With lstFiles.Items.Add do begin
Caption := PSectionData(lstSections.Items.Objects[lstSections.ItemIndex]).SectionFiles[i];
SubItems.Add(PSectionData(lstSections.Items.Objects[lstSections.ItemIndex]).FileDirectories[i]);
SubItems.Add(PSectionData(lstSections.Items.Objects[lstSections.ItemIndex]).OverWrite[i]);
end;
end;
end;
memDesc.Text := '';
memDesc.Text := PSectionData(lstSections.Items.Objects[lstSections.ItemIndex]).Description;
if lstIncludeIn.Items.Count = 0 then exit;
for i:=0 to PSectionData(lstSections.Items.Objects[lstSections.ItemIndex]).SectionsIn.Count - 1 do begin
lstIncludeIn.Items[StrToInt(PSectionData(lstSections.Items.Objects[lstSections.ItemIndex]).SectionsIn[i])].Checked := True
end;
end;
procedure TfrmNSIS.FormCreate(Sender: TObject);
var str: String;
begin
str := 'This wizard will guide you through the process of creating a new NSIS script file. ';
str := str + 'The results will be used to generate a new script file which can be compiled ';
str := str + 'directly or saved on disk for later use.' + chr(10) + chr(10) + 'Not all features of Nullsoft ';
str := str + 'lInstall System are covered by this wizard. See the documentation for details ';
str := str + 'on creating Nullsoft Install System script files!' + chr(10) + chr(10) + 'Click next to continue, or cancel to exit this wizard.';
AddSection('MainSection');
label13.caption := str;
end;
procedure TfrmNSIS.SpeedButton4Click(Sender: TObject);
var
i: Integer;
strOverWrite: String;
begin
if lstSections.ItemIndex = -1 then exit;
with TfrmEditEntry.Create(nil) do begin
if SHowModal = mrOK then begin
if rb1.Checked then
strOverWrite := 'on';
if rb2.checked then
strOverWrite := 'off';
if rb3.checked then
strOverWrite := 'try';
if rb4.Checked then
strOverWrite := 'ifnewer';
for i := 0 to dlgOpen.Files.Count - 1 do begin
With lstFiles.Items.Add do begin
Caption := dlgOpen.Files[i];
SubItems.Add(cmbDir.Text);
SubItems.Add(strOverwrite);
end;
end;
UpdateFiles;
end;
end;
end;
procedure TfrmNSIS.SpeedButton5Click(Sender: TObject);
begin
if lstFiles.Selected = nil then exit;
end;
procedure TfrmNSIS.UpdateFiles();
var i: Integer;
d: PSectionData;
begin
if lstSections.ItemIndex = -1 then exit;
PSectionData((lstSections.Items.Objects[lstSections.ItemIndex])).SectionFiles := TStringList.Create;
PSectionData((lstSections.Items.Objects[lstSections.ItemIndex])).FileDirectories := TStringList.Create;
PSectionData((lstSections.Items.Objects[lstSections.ItemIndex])).OverWrite := TStringList.Create;
for i := 0 to lstFiles.Items.Count - 1 do begin
PSectionData((lstSections.Items.Objects[lstSections.ItemIndex])).SectionFiles.Add(lstFiles.Items[i].Caption);
PSectionData((lstSections.Items.Objects[lstSections.ItemIndex])).FileDirectories.Add(lstFiles.Items[i].SubItems[0]);
PSectionData((lstSections.Items.Objects[lstSections.ItemIndex])).OverWrite.Add(lstFiles.Items[i].SubItems[1]);
end;
end;
procedure TfrmNSIS.SpeedButton6Click(Sender: TObject);
begin
if lstFIles.Selected = nil then exit;
end;
procedure TfrmNSIS.memDescChange(Sender: TObject);
begin
if lstSections.ItemIndex = -1 then exit;
PSectionData((lstSections.Items.Objects[lstSections.ItemIndex])).Description := memDesc.Text;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -