📄 compwizard.pas
字号:
end;
end;
until not SkipCurPage;
CurPageChanged;
end;
procedure TWizardForm.BackButtonClick(Sender: TObject);
begin
if CurPage = Low(TWizardPage) then Exit;
{ Go to the previous page }
Dec(CurPage);
while SkipCurPage do
Dec(CurPage);
CurPageChanged;
end;
{---}
procedure TWizardForm.AddWizardFile(const Source: String; const RecurseSubdirs: Boolean);
var
WizardFile: PWizardFile;
begin
New(WizardFile);
WizardFile.Source := Source;
WizardFile.RecurseSubdirs := RecurseSubdirs;
WizardFile.DestRootDirIsConstant := True;
if not NotCreateAppDirCheck.Checked then
WizardFile.DestRootDir := '{app}'
else
WizardFile.DestRootDir := '{win}';
WizardFile.DestSubDir := '';
FWizardFiles.Add(WizardFile);
end;
procedure TWizardForm.UpdateWizardFiles;
var
WizardFile: PWizardFile;
I: Integer;
begin
AppFilesListBox.Items.BeginUpdate;
AppFilesListBox.Items.Clear;
for I := 0 to FWizardFiles.Count-1 do begin
WizardFile := FWizardFiles[i];
AppFilesListBox.Items.Add(WizardFile.Source);
end;
AppFilesListBox.Items.EndUpdate;
UpdateHorizontalExtent(AppFilesListBox);
end;
procedure TWizardForm.UpdateWizardFilesButtons;
var
Enabled: Boolean;
begin
Enabled := AppFilesListBox.ItemIndex >= 0;
AppFilesEditButton.Enabled := Enabled;
AppFilesRemoveButton.Enabled := Enabled;
end;
{---}
procedure TWizardForm.AppRootDirComboBoxChange(Sender: TObject);
begin
if AppRootDirComboBox.ItemIndex = AppRootDirComboBox.Items.Count-1 then begin
AppRootDirEdit.Enabled := True;
AppRootDirEdit.Color := clWindow;
ActiveControl := AppRootDirEdit;
end else begin
AppRootDirEdit.Enabled := False;
AppRootDirEdit.Color := clBtnFace;
end;
end;
procedure TWizardForm.NotCreateAppDirCheckClick(Sender: TObject);
const
EnabledColors: array[Boolean] of TColor = (clBtnFace, clWindow);
var
Enabled: Boolean;
begin
Enabled := not NotCreateAppDirCheck.Checked;
{ AppDir }
AppRootDirLabel.Enabled := Enabled;
AppRootDirComboBox.Enabled := Enabled;
AppRootDirComboBox.Color := EnabledColors[Enabled];
AppRootDirEdit.Enabled := Enabled and (AppRootDirComboBox.ItemIndex = AppRootDirComboBox.Items.Count-1);
AppRootDirEdit.Color := EnabledColors[AppRootDirEdit.Enabled];
AppDirNameLabel.Enabled := Enabled;
AppDirNameEdit.Enabled := Enabled;
AppDirNameEdit.Color := EnabledColors[Enabled];
NotDisableDirPageCheck.Enabled := Enabled;
{ AppFiles }
AppExeLabel.Enabled := Enabled;
AppExeEdit.Enabled := Enabled;
AppExeEdit.Color := EnabledColors[Enabled];
AppExeButton.Enabled := Enabled;
AppExeRunCheck.Enabled := Enabled;
if Enabled then begin
AppRootDirLabel.Font.Style := AppRootDirLabel.Font.Style + [fsBold];
AppDirNameLabel.Font.Style := AppRootDirLabel.Font.Style + [fsBold];
AppExeLabel.Font.Style := AppExeLabel.Font.Style + [fsBold];
end else begin
AppRootDirLabel.Font.Style := AppRootDirLabel.Font.Style - [fsBold];
AppDirNameLabel.Font.Style := AppRootDirLabel.Font.Style - [fsBold];
AppExeLabel.Font.Style := AppExeLabel.Font.Style - [fsBold];
end;
end;
procedure TWizardForm.AppExeButtonClick(Sender: TObject);
begin
OpenDialog.InitialDir := '';
OpenDialog.Filter := SWizardAppExeFilter;
OpenDialog.DefaultExt := SWizardAppExeDefaultExt;
if OpenDialog.Execute then
AppExeEdit.Text := OpenDialog.FileName;
end;
procedure TWizardForm.AppFilesListBoxClick(Sender: TObject);
begin
UpdateWizardFilesButtons;
end;
procedure TWizardForm.AppFilesListBoxDblClick(Sender: TObject);
begin
if AppFilesEditButton.Enabled then
AppFilesEditButton.Click;
end;
procedure TWizardForm.AppFilesAddButtonClick(Sender: TObject);
var
I: Integer;
OldOptions: TOpenOptions;
begin
OpenDialog.InitialDir := '';
OpenDialog.Filter := SWizardAllFilesFilter;
OldOptions := OpenDialog.Options;
OpenDialog.Options := OpenDialog.Options + [ofAllowMultiSelect];
try
if OpenDialog.Execute then begin
for I := 0 to OpenDialog.Files.Count-1 do begin
AddWizardFile(OpenDialog.Files[I], False);
UpdateWizardFiles;
end;
end;
finally
OpenDialog.Options := OldOptions;
end;
end;
procedure TWizardForm.AppFilesAddDirButtonClick(Sender: TObject);
var
Malloc: IMalloc;
BrowseInfo: TBrowseInfo;
DisplayName, Path: array[0..MAX_PATH-1] of Char;
IDList: PItemIDList;
Recurse: Boolean;
begin
if FAILED(SHGetMalloc(Malloc)) then
Malloc := nil;
FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);
with BrowseInfo do begin
hwndOwner := Handle;
pszDisplayName := @DisplayName;
lpszTitle := PChar(SWizardAppFiles3);
ulFlags := BIF_RETURNONLYFSDIRS;
end;
IDList := SHBrowseForFolder(BrowseInfo);
try
if (IDList = nil) or not SHGetPathFromIDList(IDList, Path) then
Exit;
case MsgBox(Format(SWizardAppFilesSubdirsMessage, [Path]), '', mbConfirmation, MB_YESNOCANCEL) of
ID_YES: Recurse := True;
ID_NO: Recurse := False;
else
Exit;
end;
AddWizardFile(AddBackslash(Path) + '*', Recurse);
UpdateWizardFiles;
finally
if Assigned(Malloc) then
Malloc.Free(IDList);
end;
end;
procedure TWizardForm.AppFilesListBoxDropFile(Sender: TDropListBox;
const FileName: String);
begin
if DirExists(FileName) then
AddWizardFile(AddBackslash(FileName) + '*', True)
else
AddWizardFile(FileName, False);
UpdateWizardFiles;
UpdateWizardFilesButtons;
end;
procedure TWizardForm.AppFilesEditButtonClick(Sender: TObject);
var
WizardFileForm: TWizardFileForm;
Index: Integer;
begin
WizardFileForm := TWizardFileForm.Create(Application);
try
Index := AppFilesListBox.ItemIndex;
WizardFileForm.AllowAppDestRootDir := not NotCreateAppDirCheck.Checked;
WizardFileForm.WizardFile := FWizardFiles[Index];
if WizardFileForm.ShowModal = mrOK then begin
UpdateWizardFiles;
AppFilesListBox.ItemIndex := Index;
AppFilesListBox.TopIndex := Index;
UpdateWizardFilesButtons;
end;
finally
WizardFileForm.Free;
end;
end;
procedure TWizardForm.AppFilesRemoveButtonClick(Sender: TObject);
var
I: Integer;
begin
I := AppFilesListBox.ItemIndex;
Dispose(FWizardFiles[I]);
FWizardFiles.Delete(I);
UpdateWizardFiles;
UpdateWizardFilesButtons;
end;
procedure TWizardForm.NotDisableProgramGroupPageCheckClick(
Sender: TObject);
begin
AllowNoIconsCheck.Enabled := NotDisableProgramGroupPageCheck.Checked;
end;
procedure TWizardForm.AppDocsFileButtonClick(Sender: TObject);
begin
OpenDialog.InitialDir := '';
OpenDialog.Filter := SWizardAppDocsFilter;
OpenDialog.DefaultExt := SWizardAppDocsDefaultExt;
if OpenDialog.Execute then begin
if Sender = AppLicenseFileButton then
AppLicenseFileEdit.Text := OpenDialog.FileName
else if Sender = AppInfoBeforeFileButton then
AppInfoBeforeFileEdit.Text := OpenDialog.FileName
else if Sender = AppInfoAfterFileButton then
AppInfoAfterFileEdit.Text := OpenDialog.FileName;
end;
end;
{ --- }
procedure TWizardForm.GenerateScript;
var
Script, Setup, Tasks, Files, INI, Icons, Run, UninstallDelete: String;
WizardFile: PWizardFile;
I: Integer;
begin
Script := '';
Setup := '[Setup]' + SNewLine;
Tasks := '[Tasks]' + SNewLine;
Files := '[Files]' + SNewLine;
INI := '[INI]' + SNewLine;
Icons := '[Icons]' + SNewLine;
Run := '[Run]' + SNewLine;
UninstallDelete := '[UninstallDelete]' + SNewLine;
if not EmptyCheck.Checked then begin
{ AppInfo }
Setup := Setup + 'AppName=' + AppNameEdit.Text + SNewLine;
Setup := Setup + 'AppVerName=' + AppVerNameEdit.Text + SNewLine;
if AppPublisherEdit.Text <> '' then
Setup := Setup + 'AppPublisher=' + AppPublisherEdit.Text + SNewLine;
if AppURLEdit.Text <> '' then begin
Setup := Setup + 'AppPublisherURL=' + AppURLEdit.Text + SNewLine;
Setup := Setup + 'AppSupportURL=' + AppURLEdit.Text + SNewLine;
Setup := Setup + 'AppUpdatesURL=' + AppURLEdit.Text + SNewLine;
end;
{ AppDir }
if not NotCreateAppDirCheck.Checked then begin
if AppRootDirComboBox.ItemIndex = AppRootDirComboBox.Items.Count-1 then
Setup := Setup + 'DefaultDirName=' + AddBackslash(AppRootDirEdit.Text) + AppDirNameEdit.Text + SNewLine
else
Setup := Setup + 'DefaultDirName=' + AddBackslash(AppRootDirs[AppRootDirComboBox.ItemIndex].Constant) + AppDirNameEdit.Text + SNewLine;
if not NotDisableDirPageCheck.Checked then
Setup := Setup + 'DisableDirPage=yes' + SNewLine;
end else begin
Setup := Setup + 'CreateAppDir=no' + SNewLine;
end;
{ AppFiles }
if not NotCreateAppDirCheck.Checked then begin
Files := Files + 'Source: "' + AppExeEdit.Text + '"; DestDir: "{app}"; Flags: ignoreversion' + SNewLine;
if AppExeRunCheck.Checked then begin
if CompareText(PathExtractExt(AppExeEdit.Text), '.exe') = 0 then
Run := Run + 'Filename: "{app}\' + PathExtractName(AppExeEdit.Text) + '"; Description: "{cm:LaunchProgram,' + AppNameEdit.Text + '}"; Flags: nowait postinstall skipifsilent' + SNewLine
else
Run := Run + 'Filename: "{app}\' + PathExtractName(AppExeEdit.Text) + '"; Description: "{cm:LaunchProgram,' + AppNameEdit.Text + '}"; Flags: shellexec postinstall skipifsilent' + SNewLine;
end;
end;
for I := 0 to FWizardFiles.Count-1 do begin
WizardFile := FWizardFiles[I];
Files := Files + 'Source: "' + WizardFile.Source + '"; DestDir: "' + RemoveBackSlash(AddBackSlash(WizardFile.DestRootDir) + WizardFile.DestSubDir) + '"; Flags: ignoreversion';
if WizardFile.RecurseSubdirs then
Files := Files + ' recursesubdirs';
Files := Files + SNewLine;
end;
{ AppGroup }
if not NotCreateAppDirCheck.Checked then begin
Setup := Setup + 'DefaultGroupName=' + AppGroupNameEdit.Text + SNewLine;
Icons := Icons + 'Name: "{group}\' + AppNameEdit.Text + '"; Filename: "{app}\' + PathExtractName(AppExeEdit.Text) + '"' + SNewLine;
if not NotDisableProgramGroupPageCheck.Checked then
Setup := Setup + 'DisableProgramGroupPage=yes' + SNewLine;
if AllowNoIconsCheck.Checked and NotDisableProgramGroupPageCheck.Checked then
Setup := Setup + 'AllowNoIcons=yes' + SNewLine;
if CreateURLIconCheck.Checked and (AppURLEdit.Text <> '') then begin
Icons := Icons + 'Name: "{group}\{cm:ProgramOnTheWeb,' + AppNameEdit.Text + '}"; Filename: "{app}\' + PathChangeExt(PathExtractName(AppExeEdit.Text), '.url') + '"' + SNewLine;
INI := INI + 'Filename: "{app}\' + PathChangeExt(PathExtractName(AppExeEdit.Text), '.url') + '"; Section: "InternetShortcut"; Key: "URL"; String: "' + AppURLEdit.Text + '"' + SNewLine;
UninstallDelete := UninstallDelete + 'Type: files; Name: "{app}\' + PathChangeExt(PathExtractName(AppExeEdit.Text), '.url') + '"' + SNewLine;
end;
if CreateUninstallIconCheck.Checked then
Icons := Icons + 'Name: "{group}\{cm:UninstallProgram,' + AppNameEdit.Text + '}"; Filename: "{uninstallexe}"' + SNewLine;
if DesktopIconCheck.Checked then begin
Tasks := Tasks + 'Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked' + SNewLine;
Icons := Icons + 'Name: "{userdesktop}\' + AppNameEdit.Text + '"; Filename: "{app}\' + PathExtractName(AppExeEdit.Text) + '"; Tasks: desktopicon' + SNewLine;
end;
if QuickLaunchIconCheck.Checked then begin
Tasks := Tasks + 'Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked' + SNewLine;
Icons := Icons + 'Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\' + AppNameEdit.Text + '"; Filename: "{app}\' + PathExtractName(AppExeEdit.Text) + '"; Tasks: quicklaunchicon' + SNewLine;
end;
end;
{ AppDocs }
if AppLicenseFileEdit.Text <> '' then
Setup := Setup + 'LicenseFile=' + AppLicenseFileEdit.Text + SNewLine;
if AppInfoBeforeFileEdit.Text <> '' then
Setup := Setup + 'InfoBeforeFile=' + AppInfoBeforeFileEdit.Text + SNewLine;
if AppInfoAfterFileEdit.Text <> '' then
Setup := Setup + 'InfoAfterFile=' + AppInfoAfterFileEdit.Text + SNewLine;
{ Other }
Setup := Setup + 'Compression=lzma' + SNewLine;
Setup := Setup + 'SolidCompression=yes' + SNewLine;
{ Build script }
Script := Script + Setup + SNewLine;
if Length(Tasks) > Length('[Tasks]')+2 then
Script := Script + Tasks + SNewLine;
if Length(Files) > Length('[Files]')+2 then
Script := Script + Files +
'; NOTE: Don''t use "Flags: ignoreversion" on any shared system files' +
SNewLine2;
if Length(INI) > Length('[INI]')+2 then
Script := Script + INI + SNewLine;
if Length(Icons) > Length('[Icons]')+2 then
Script := Script + Icons + SNewLine;
if Length(Run) > Length('[Run]')+2 then
Script := Script + Run + SNewLine;
if Length(UninstallDelete) > Length('[UninstallDelete]')+2 then
Script := Script + UninstallDelete + SNewLine;
FResult := wrComplete;
end else begin
Script := Script + Setup + SNewLine;
FResult := wrEmpty;
end;
FResultScript := FixLabel(SWizardScriptHeader) + SNewLine2 + Script;
end;
{ --- }
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -