2017-01-23 08:46:43 +00:00
|
|
|
unit uconfigform;
|
2017-01-25 09:33:15 +00:00
|
|
|
{ LazAutoUpdater Tray Updater
|
2017-01-23 08:46:43 +00:00
|
|
|
|
2017-01-25 09:33:15 +00:00
|
|
|
Copyright (C)2014 Gordon Bamber minesadorada@charcodelvalle.com
|
|
|
|
|
|
|
|
An example of using LazAutoUpdate as a silent updater
|
|
|
|
|
|
|
|
This source is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free
|
|
|
|
Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This code is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
|
|
|
|
|
|
|
A copy of the GNU General Public License is available on the World Wide Web
|
|
|
|
at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
|
|
|
|
to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
|
|
|
MA 02111-1307, USA.
|
|
|
|
}
|
2017-01-23 08:46:43 +00:00
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-01-25 09:33:15 +00:00
|
|
|
SysUtils, Forms, Controls, Dialogs, Buttons,
|
|
|
|
StdCtrls, EditBtn;
|
2017-01-23 08:46:43 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
2017-01-25 09:33:15 +00:00
|
|
|
{ Tconfigform }
|
|
|
|
|
|
|
|
Tconfigform = class(TForm)
|
|
|
|
cmd_DeleteAppProfile: TButton;
|
|
|
|
cmd_SaveChanges: TBitBtn;
|
|
|
|
chk_Update: TCheckBox;
|
|
|
|
cmb_IntervalDate: TComboBox;
|
|
|
|
cmb_IntervalHour: TComboBox;
|
|
|
|
cmb_IntervalDay: TComboBox;
|
|
|
|
cmd_Close: TBitBtn;
|
|
|
|
cmd_NewAppProfile: TButton;
|
|
|
|
cmb_AppProfile: TComboBox;
|
|
|
|
cmb_IntervalType: TComboBox;
|
|
|
|
edt_INIPath: TEdit;
|
|
|
|
edt_AppPath: TFileNameEdit;
|
|
|
|
edt_AppVersion: TEdit;
|
|
|
|
edt_SFUpdatesDirectory: TEdit;
|
|
|
|
edt_ZipPath: TEdit;
|
|
|
|
edt_SFProjectName: TEdit;
|
|
|
|
grp_updateinterval: TGroupBox;
|
|
|
|
grp_configapp: TGroupBox;
|
|
|
|
lbl_LastUpdated: TLabel;
|
|
|
|
lbl_AppVersion: TLabel;
|
|
|
|
lbl_AppProfile: TLabel;
|
|
|
|
lbl_AppPath: TLabel;
|
|
|
|
lbl_INIPath: TLabel;
|
|
|
|
lbl_IntervalDate: TLabel;
|
|
|
|
lbl_SFUpdatesDirectory: TLabel;
|
|
|
|
lbl_IntervalType: TLabel;
|
|
|
|
lbl_SFUpdatesDirectory2: TLabel;
|
|
|
|
lbl_IntervalDay: TLabel;
|
|
|
|
lbl_ZipPath: TLabel;
|
|
|
|
lbl_SFProjectName: TLabel;
|
|
|
|
procedure chk_UpdateClick(Sender: TObject);
|
|
|
|
procedure cmb_AppProfileClick(Sender: TObject);
|
|
|
|
procedure cmb_AppProfileCloseUp(Sender: TObject);
|
|
|
|
procedure cmd_CloseClick(Sender: TObject);
|
|
|
|
procedure cmd_DeleteAppProfileClick(Sender: TObject);
|
|
|
|
procedure cmd_NewAppProfileClick(Sender: TObject);
|
|
|
|
procedure cmd_SaveChangesClick(Sender: TObject);
|
|
|
|
procedure cmb_IntervalTypeChange(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure FormShow(Sender: TObject);
|
|
|
|
private
|
|
|
|
{ private declarations }
|
|
|
|
procedure DoInitialiseCombobox;
|
|
|
|
procedure DoDisplayProfile(AIndex: integer);
|
|
|
|
procedure DoSaveAllChanges;
|
|
|
|
procedure DoEnableDisableIntervalCombos;
|
|
|
|
public
|
|
|
|
{ public declarations }
|
|
|
|
bDetailsChanged: boolean;
|
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
configform: Tconfigform;
|
2017-01-23 08:46:43 +00:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2017-01-25 09:33:15 +00:00
|
|
|
umainform;
|
2017-01-23 08:46:43 +00:00
|
|
|
|
|
|
|
{$R *.lfm}
|
|
|
|
|
|
|
|
{ Tconfigform }
|
|
|
|
|
|
|
|
procedure Tconfigform.FormCreate(Sender: TObject);
|
|
|
|
begin
|
2017-01-25 09:33:15 +00:00
|
|
|
Icon := Application.Icon;
|
2017-01-23 08:46:43 +00:00
|
|
|
Caption := 'Configure ' + Application.Title;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.DoSaveAllChanges;
|
|
|
|
begin
|
|
|
|
with mainform.AppRecArray[cmb_AppProfile.ItemIndex] do
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
AppPath := edt_AppPath.Text;
|
|
|
|
AppVersion := edt_AppVersion.Text;
|
|
|
|
INIPath := edt_INIPath.Text;
|
|
|
|
ZipPath := edt_ZipPath.Text;
|
|
|
|
SFProjectName := edt_SFProjectName.Text;
|
|
|
|
SFUpdatesDirectory := edt_SFUpdatesDirectory.Text;
|
|
|
|
IntervalType := cmb_IntervalType.ItemIndex;
|
|
|
|
IntervalDay := cmb_IntervalDay.ItemIndex;
|
|
|
|
IntervalDate := cmb_IntervalDate.ItemIndex;
|
|
|
|
IntervalHour := cmb_IntervalHour.ItemIndex;
|
|
|
|
Update := chk_Update.Checked;
|
|
|
|
bDetailsChanged := True;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.DoDisplayProfile(AIndex: integer);
|
|
|
|
begin
|
|
|
|
with mainform.AppRecArray[AIndex] do
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
|
|
|
edt_AppPath.Text := AppPath;
|
2017-01-23 08:46:43 +00:00
|
|
|
edt_AppVersion.Text := AppVersion;
|
2017-01-25 09:33:15 +00:00
|
|
|
edt_INIPath.Text := INIPath;
|
|
|
|
edt_ZipPath.Text := ZipPath;
|
2017-01-23 08:46:43 +00:00
|
|
|
edt_SFProjectName.Text := SFProjectName;
|
|
|
|
edt_SFUpdatesDirectory.Text := SFUpdatesDirectory;
|
|
|
|
cmb_IntervalType.ItemIndex := IntervalType;
|
|
|
|
cmb_IntervalDay.ItemIndex := IntervalDay;
|
|
|
|
cmb_IntervalDate.ItemIndex := IntervalDate;
|
|
|
|
cmb_IntervalHour.ItemIndex := IntervalHour;
|
2017-01-25 09:33:15 +00:00
|
|
|
chk_Update.Checked := Update;
|
2017-01-23 08:46:43 +00:00
|
|
|
lbl_LastUpdated.Caption :=
|
|
|
|
Format('Last successful update was %s',
|
|
|
|
[FormatDateTime('c', LastCheckDateTime)]);
|
|
|
|
DoEnableDisableIntervalCombos;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.DoEnableDisableIntervalCombos;
|
|
|
|
begin
|
|
|
|
case cmb_IntervalType.ItemIndex of
|
|
|
|
0:
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
|
|
|
cmb_IntervalDay.Enabled := False;
|
2017-01-23 08:46:43 +00:00
|
|
|
cmb_IntervalDate.Enabled := False;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
1:
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
|
|
|
cmb_IntervalDay.Enabled := True;
|
2017-01-23 08:46:43 +00:00
|
|
|
cmb_IntervalDate.Enabled := False;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
2:
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
|
|
|
cmb_IntervalDay.Enabled := False;
|
2017-01-23 08:46:43 +00:00
|
|
|
cmb_IntervalDate.Enabled := True;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.cmd_SaveChangesClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
DoSaveAllChanges;
|
|
|
|
if (MessageDlg(Application.Title, 'Changes saved OK. Close window now?',
|
|
|
|
mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
|
|
|
|
cmd_Close.Click;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.cmd_CloseClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
mainform.iCurrentRecIndex := cmb_AppProfile.ItemIndex;
|
|
|
|
mainform.INI.WriteInteger('ProgramInfo', 'CurrentProfileIndex',
|
|
|
|
mainform.iCurrentRecIndex);
|
|
|
|
mainform.INI.UpdateFile;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.chk_UpdateClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
mainform.AppRecArray[cmb_AppProfile.ItemIndex].Update := chk_Update.Checked;
|
2017-01-25 09:33:15 +00:00
|
|
|
// mainform.LongTimerArray[cmb_AppProfile.ItemIndex].Enabled := chk_Update.Checked;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.cmb_AppProfileClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
DoSaveAllChanges;
|
|
|
|
DoDisplayProfile(cmb_AppProfile.ItemIndex);
|
|
|
|
mainform.iCurrentRecIndex := cmb_AppProfile.ItemIndex;
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.cmb_AppProfileCloseUp(Sender: TObject);
|
|
|
|
begin
|
|
|
|
DoDisplayProfile(cmb_AppProfile.ItemIndex);
|
|
|
|
mainform.iCurrentRecIndex := cmb_AppProfile.ItemIndex;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.cmd_DeleteAppProfileClick(Sender: TObject);
|
|
|
|
// Make a temp copy of AppRecArray
|
|
|
|
// Copy over all but the deleted profile into the temp copy
|
|
|
|
// Copy the temp copy back to AppRecArray
|
|
|
|
// Delete the INIFile section
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
TempAppRecArray: array of TAppRec;
|
|
|
|
i, iLastIndex: integer;
|
2017-01-23 08:46:43 +00:00
|
|
|
begin
|
|
|
|
if High(mainform.AppRecArray) = 0 then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
MessageDlg(Application.Title,
|
|
|
|
'You cannot delete the only profile left',
|
|
|
|
mtError, [mbOK], 0);
|
|
|
|
exit;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
|
|
|
|
// Delete INI section
|
|
|
|
mainform.INI.EraseSection(
|
|
|
|
mainform.AppRecArray[cmb_AppProfile.ItemIndex].AppPrettyName);
|
|
|
|
|
|
|
|
SetLength(TempAppRecArray, High(mainform.AppRecArray)); // one less
|
|
|
|
iLastIndex := -1;
|
|
|
|
for i := Low(mainform.AppRecArray) to High(mainform.AppRecArray) do
|
|
|
|
if (i <> cmb_AppProfile.ItemIndex) then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
Inc(iLastIndex);
|
|
|
|
TempAppRecArray[iLastIndex] := mainform.AppRecArray[i];
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
SetLength(mainform.AppRecArray, High(TempAppRecArray) + 1);
|
|
|
|
mainform.AppRecArray := TempAppRecArray;
|
|
|
|
|
|
|
|
DoInitialiseCombobox;
|
2017-01-25 09:33:15 +00:00
|
|
|
cmb_AppProfile.ItemIndex := 0;
|
2017-01-23 08:46:43 +00:00
|
|
|
mainform.iCurrentRecIndex := 0;
|
|
|
|
mainform.INI.WriteInteger('ProgramInfo', 'CurrentProfileIndex',
|
|
|
|
mainform.iCurrentRecIndex);
|
|
|
|
mainform.INI.UpdateFile;
|
|
|
|
bDetailsChanged := True;
|
|
|
|
mainform.DoWriteAppRecArrayIntoINI;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.cmd_NewAppProfileClick(Sender: TObject);
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
szProfileName: string;
|
|
|
|
iLastIndex: integer;
|
2017-01-23 08:46:43 +00:00
|
|
|
begin
|
|
|
|
if InputQuery('New Profile', 'New Profile', False, szProfileName) then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
iLastIndex := High(mainform.AppRecArray);
|
|
|
|
SetLength(mainform.AppRecArray, iLastIndex + 2);
|
|
|
|
iLastIndex := High(mainform.AppRecArray);
|
|
|
|
mainform.AppRecArray[iLastIndex] := mainform.AppRecArray[iLastIndex - 1];
|
|
|
|
mainform.AppRecArray[iLastIndex].AppPrettyName := szProfileName;
|
|
|
|
DoInitialiseCombobox;
|
2017-01-25 09:33:15 +00:00
|
|
|
cmb_AppProfile.ItemIndex := iLastIndex;
|
2017-01-23 08:46:43 +00:00
|
|
|
mainform.iCurrentRecIndex := iLastIndex;
|
|
|
|
mainform.INI.WriteInteger('ProgramInfo', 'CurrentProfileIndex',
|
|
|
|
mainform.iCurrentRecIndex);
|
|
|
|
mainform.INI.UpdateFile;
|
|
|
|
bDetailsChanged := True;
|
|
|
|
mainform.DoWriteAppRecArrayIntoINI;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.cmb_IntervalTypeChange(Sender: TObject);
|
|
|
|
begin
|
|
|
|
DoEnableDisableIntervalCombos;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.DoInitialiseCombobox;
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
i: integer;
|
2017-01-23 08:46:43 +00:00
|
|
|
begin
|
|
|
|
if (Length(mainform.AppRecArray) = 0) then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
ShowMessage('There are no profiles to configure!');
|
|
|
|
ModalResult := mrOk;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
cmb_AppProfile.Clear;
|
|
|
|
with mainform do
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
for i := Low(AppRecArray) to High(AppRecArray) do
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
cmb_AppProfile.Items.Add(AppRecArray[i].AppPrettyName);
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
mainform.iCurrentRecIndex :=
|
|
|
|
mainform.INI.ReadInteger('ProgramInfo', 'CurrentProfileIndex', 0);
|
2017-01-25 09:33:15 +00:00
|
|
|
cmb_AppProfile.ItemIndex := mainform.iCurrentRecIndex;
|
2017-01-23 08:46:43 +00:00
|
|
|
DoDisplayProfile(mainform.iCurrentRecIndex);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tconfigform.FormShow(Sender: TObject);
|
|
|
|
begin
|
|
|
|
DoInitialiseCombobox;
|
|
|
|
bDetailsChanged := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|