2017-01-23 08:46:43 +00:00
|
|
|
unit umainform;
|
|
|
|
|
|
|
|
{ LazAutoUpdater Tray Updater
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
SUMMARY
|
|
|
|
=======
|
|
|
|
TrayUpdater is a companion to LazAutoUpdate and UpdatePack
|
|
|
|
It sits in the system tray, and automatically checks for updates
|
|
|
|
and optionally auto-updates any apps for which it has a profile
|
|
|
|
It uses an array of custom component LongTimers in order to
|
|
|
|
update a number of different apps on different schedules
|
|
|
|
It uses a config file LAUTray.ini to keep track. This file
|
2017-01-25 08:46:02 +00:00
|
|
|
is automatically generated by UpdatePack and imported by this app when first run.
|
2017-01-23 08:46:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
VERSION HISTORY
|
|
|
|
===============
|
|
|
|
0.1.12: Updated to Laz 1.7 fpc 3.1.1
|
|
|
|
0.1.12: Updated lpr to correctly hide the mainform on startup
|
|
|
|
0.1.12: Commit to svn
|
2017-01-25 08:46:02 +00:00
|
|
|
0.1.13: Updated January 2017
|
|
|
|
Ini filename uses C_PFX
|
2017-01-25 09:33:15 +00:00
|
|
|
0.1.14: Memory leaks fixed
|
|
|
|
0.1.15: ??
|
2017-01-23 08:46:43 +00:00
|
|
|
}
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-01-25 09:33:15 +00:00
|
|
|
Classes, SysUtils, FileUtil, LazFileUtils, Forms, Dialogs, ExtCtrls,
|
|
|
|
Menus, uLongTimer, ulazautoupdate, inifiles, eventlog, strUtils, uconfigform
|
2017-01-23 08:46:43 +00:00
|
|
|
{$IFDEF WINDOWS}, registry{$ENDIF};
|
|
|
|
|
|
|
|
type
|
2017-01-25 09:33:15 +00:00
|
|
|
{ TAppRec - in-memory storage for all settings }
|
|
|
|
TAppRec = record
|
|
|
|
AppPrettyName: string;
|
|
|
|
AppPath: string;
|
|
|
|
INIPath: string;
|
|
|
|
ZipPath: string;
|
|
|
|
AppVersion: string;
|
|
|
|
SFProjectName: string;
|
|
|
|
SFUpdatesDirectory: string;
|
|
|
|
Location: string;
|
|
|
|
IntervalType: word;
|
|
|
|
IntervalDay: word;
|
|
|
|
IntervalDate: word;
|
|
|
|
IntervalHour: word;
|
|
|
|
Update: boolean;
|
|
|
|
LastCheckDateTime: TDateTime;
|
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
|
2017-01-25 09:33:15 +00:00
|
|
|
{ Tmainform }
|
|
|
|
Tmainform = class(TForm)
|
|
|
|
Logger: TEventLog;
|
|
|
|
idleReminder: TIdleTimer;
|
|
|
|
LazAutoUpdate1: TLazAutoUpdate;
|
|
|
|
mnu_About: TMenuItem;
|
|
|
|
mnu_SelfCheck: TMenuItem;
|
|
|
|
mnu_startAtOSStartUp: TMenuItem;
|
|
|
|
mnu_configure: TMenuItem;
|
|
|
|
mnu_fileExit: TMenuItem;
|
|
|
|
PopupMenu1: TPopupMenu;
|
|
|
|
TrayIcon1: TTrayIcon;
|
|
|
|
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure FormWindowStateChange(Sender: TObject);
|
|
|
|
procedure idleReminderTimer(Sender: TObject);
|
|
|
|
procedure LazAutoUpdate1DebugEvent(Sender: TObject; WhereAt, Message: string);
|
|
|
|
procedure mnu_AboutClick(Sender: TObject);
|
|
|
|
procedure mnu_configureClick(Sender: TObject);
|
|
|
|
procedure mnu_fileExitClick(Sender: TObject);
|
|
|
|
procedure mnu_startAtOSStartUpClick(Sender: TObject);
|
|
|
|
procedure mnu_SelfCheckClick(Sender: TObject);
|
|
|
|
procedure TrayIcon1Click(Sender: TObject);
|
|
|
|
function UT_DateTimeToStr(TheDate: TDateTime): string;
|
|
|
|
function UT_StrToDate(str: string): TDateTime;
|
|
|
|
|
|
|
|
private
|
|
|
|
{ private declarations }
|
|
|
|
szImportINIPath: string;
|
|
|
|
DebugMode: boolean;
|
|
|
|
procedure DoAlert(aAppname, aVersion: string);
|
|
|
|
// Transfers info from lauimport.ini to local ini
|
|
|
|
function ImportINIFile: boolean;
|
|
|
|
// When first run, Populates INI and AppRecArray with default entry
|
|
|
|
procedure PopulateOwnProfile;
|
|
|
|
// Transfers info from local INI to AppRecArray
|
|
|
|
procedure DoReadINIIntoAppRecArray;
|
|
|
|
// Re-initialises a LongTimer array from AppRecArray info
|
|
|
|
procedure DoSetupLongTimerArray;
|
|
|
|
// All LongTimers use this for their OnTimer event
|
|
|
|
procedure DoLongTimerEvent(Sender: TObject);
|
|
|
|
// Do a silent check/install for this AppRecArray member
|
|
|
|
procedure CheckAndUpdate(ARecIndex: integer);
|
|
|
|
public
|
|
|
|
{ public declarations }
|
|
|
|
INI: TIniFile;
|
|
|
|
AppRecArray: array of TAppRec; // Dynamic array
|
|
|
|
LongTimerArray: array of TLongTimer; // Dynamic array
|
|
|
|
iCurrentRecIndex: integer;
|
|
|
|
// Transfers info from AppRecArray to local INI
|
|
|
|
procedure DoWriteAppRecArrayIntoINI;
|
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
mainform: Tmainform;
|
2017-01-23 08:46:43 +00:00
|
|
|
|
2017-01-25 09:33:15 +00:00
|
|
|
const
|
2017-01-23 08:46:43 +00:00
|
|
|
{$IFDEF WINDOWS}
|
|
|
|
C_OS = 'win';
|
|
|
|
{$ELSE}
|
|
|
|
C_OS = 'linux';
|
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF CPU32}
|
|
|
|
C_BITNESS = '32';
|
|
|
|
{$ELSE}
|
|
|
|
C_BITNESS = '64';
|
|
|
|
{$ENDIF}
|
|
|
|
C_PFX = C_OS + C_BITNESS;
|
2017-01-25 09:33:15 +00:00
|
|
|
C_LAUTRayINI = 'lauimport.ini';
|
|
|
|
C_INIFilename = 'trayupdater' + C_PFX + '.ini';
|
2017-01-23 08:46:43 +00:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
resourcestring
|
2017-01-25 09:33:15 +00:00
|
|
|
rs_balloontitle = '%s service';
|
|
|
|
rs_trayloaded = '%s Loaded';
|
|
|
|
rs_newversionavailable = 'A new version of %s (v%s) is available';
|
2017-01-23 08:46:43 +00:00
|
|
|
// TODO: Put all the other strings here
|
|
|
|
{$R *.lfm}
|
|
|
|
|
|
|
|
{ Tmainform }
|
|
|
|
procedure Tmainform.DoWriteAppRecArrayIntoINI;
|
|
|
|
// AppRecArray is an in-memory copy of the INI file
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
i: integer;
|
|
|
|
szSection: string;
|
2017-01-23 08:46:43 +00:00
|
|
|
begin
|
|
|
|
if High(AppRecArray) = 0 then
|
|
|
|
Exit;
|
|
|
|
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
|
|
|
szSection := AppRecArray[i].AppPrettyName;
|
2017-01-25 09:33:15 +00:00
|
|
|
try
|
2017-01-23 08:46:43 +00:00
|
|
|
INI.WriteString(szSection, 'AppPrettyName', AppRecArray[i].AppPrettyName);
|
|
|
|
INI.WriteString(szSection, 'AppPath', AppRecArray[i].AppPath);
|
|
|
|
INI.WriteString(szSection, 'INIPath', AppRecArray[i].INIPath);
|
|
|
|
INI.WriteString(szSection, 'ZipPath', AppRecArray[i].ZipPath);
|
|
|
|
INI.WriteString(szSection, 'AppVersion', AppRecArray[i].AppVersion);
|
|
|
|
INI.WriteString(szSection, 'SFProjectName', AppRecArray[i].SFProjectName);
|
|
|
|
INI.WriteString(szSection, 'SFUpdatesDirectory',
|
|
|
|
AppRecArray[i].SFUpdatesDirectory);
|
|
|
|
INI.WriteString(szSection, 'Location', AppRecArray[i].Location);
|
|
|
|
INI.WriteInteger(szSection, 'IntervalType', AppRecArray[i].IntervalType);
|
|
|
|
INI.WriteInteger(szSection, 'IntervalDate', AppRecArray[i].IntervalDate);
|
|
|
|
INI.WriteInteger(szSection, 'IntervalDay', AppRecArray[i].IntervalDay);
|
|
|
|
INI.WriteInteger(szSection, 'IntervalHour', AppRecArray[i].IntervalHour);
|
|
|
|
INI.WriteInteger(szSection, 'IntervalHour', AppRecArray[i].IntervalHour);
|
|
|
|
INI.WriteBool(szSection, 'Update', AppRecArray[i].Update);
|
|
|
|
INI.WriteString(szSection, 'LastCheckDateTime',
|
|
|
|
UT_DateTimeToStr(AppRecArray[i].LastCheckDateTime));
|
|
|
|
INI.UpdateFile;
|
2017-01-25 09:33:15 +00:00
|
|
|
except
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Error('Failed to write AppRecArray to %s', [INI.Filename])
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.DoLongTimerEvent(Sender: TObject);
|
|
|
|
// All LongTimerArray.OnTimer events go here
|
|
|
|
// The Tag property is the same as the AppRecArray entry it relates to
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
iTag: integer;
|
2017-01-23 08:46:43 +00:00
|
|
|
begin
|
|
|
|
iTag := 0;
|
|
|
|
// Assertion check
|
|
|
|
if Sender is TLongTimer then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
iTag := TLongTimer(Sender).Tag;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Log('Timer for %s fired', [AppRecArray[iTag].AppPrettyName]);
|
2017-01-23 08:46:43 +00:00
|
|
|
TrayIcon1.BalloonHint :=
|
|
|
|
Format('Checking %s for updates', [AppRecArray[iTag].AppPrettyName]);
|
|
|
|
TrayIcon1.ShowBalloonHint;
|
|
|
|
CheckAndUpdate(iTag);
|
|
|
|
// AppRecArray[iTag].LastCheckDateTime := Now();
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.DoSetupLongTimerArray;
|
|
|
|
// This is called every time the AppRecArray is changed
|
|
|
|
// Each profile has a LongTimer associated with it in LongTimerArray()
|
|
|
|
// If the AppRecArray.Update=TRUE then the associated LongTimer is enabled
|
|
|
|
// 1. Destroy and clear all the LongTimers aready allocated
|
|
|
|
// 2. Iterate through the AppRecArray, setting up a new LongTimer for each element
|
|
|
|
// 3. Enable the LongTimers for which AppArray.Update=TRUE
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
i, iArrayElement: integer;
|
2017-01-23 08:46:43 +00:00
|
|
|
begin
|
|
|
|
// Start with an empty array
|
|
|
|
for i := Low(LongTimerArray) to High(LongTimerArray) do
|
|
|
|
if LongTimerArray[i] <> nil then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
LongTimerArray[i].Enabled := False;
|
|
|
|
FreeAndNil(LongTimerArray[i]);
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
SetLength(LongTimerArray, 0); // Zeros the array
|
|
|
|
iArrayElement := -1;
|
|
|
|
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
|
|
|
Inc(iArrayElement); // initially to zero
|
|
|
|
SetLength(LongTimerArray, iArrayElement + 1);
|
|
|
|
LongTimerArray[iArrayElement] := TLongTimer.Create(nil);
|
|
|
|
with AppRecArray[i] do
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
case IntervalType of
|
|
|
|
0: LongTimerArray[iArrayElement].IntervalType := lt1Daily;
|
|
|
|
1: LongTimerArray[iArrayElement].IntervalType := lt2Weekly;
|
|
|
|
2: LongTimerArray[iArrayElement].IntervalType := lt3Monthly;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
case IntervalDay of
|
|
|
|
0: LongTimerArray[iArrayElement].WeeklyDay := lt1Monday;
|
|
|
|
1: LongTimerArray[iArrayElement].WeeklyDay := lt2Tuesday;
|
|
|
|
2: LongTimerArray[iArrayElement].WeeklyDay := lt3Wednesday;
|
|
|
|
3: LongTimerArray[iArrayElement].WeeklyDay := lt4Thursday;
|
|
|
|
4: LongTimerArray[iArrayElement].WeeklyDay := lt5Friday;
|
|
|
|
5: LongTimerArray[iArrayElement].WeeklyDay := lt6Saturday;
|
|
|
|
6: LongTimerArray[iArrayElement].WeeklyDay := lt7Sunday;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
LongTimerArray[iArrayElement].MonthlyDate := IntervalDate;
|
|
|
|
LongTimerArray[iArrayElement].Daily24Hour := IntervalHour;
|
2017-01-25 09:33:15 +00:00
|
|
|
LongTimerArray[iArrayElement].Tag := i;
|
2017-01-23 08:46:43 +00:00
|
|
|
LongTimerArray[iArrayElement].OnTimer := @DoLongTimerEvent;
|
|
|
|
// Make sure timer doesn't fire right after a self-update
|
|
|
|
LongTimerArray[iArrayElement].SampleInterval := lt5Every45Minutes;
|
|
|
|
LongTimerArray[iArrayElement].Enabled := Update;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function Tmainform.UT_DateTimeToStr(TheDate: TDateTime): string;
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
frmstg: TFormatSettings;
|
2017-01-23 08:46:43 +00:00
|
|
|
// Ensures consitent String dates across platforms
|
|
|
|
begin
|
|
|
|
//GetLocaleFormatSettings(0, frmstg);
|
|
|
|
frmstg.DateSeparator := '-';
|
|
|
|
frmstg.ShortDateFormat := 'yyyy-mm-dd';
|
|
|
|
frmstg.TimeSeparator := '-';
|
|
|
|
frmstg.LongTimeFormat := 'hh-nn';
|
|
|
|
Result := DateTimeToStr(TheDate, frmstg);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function Tmainform.UT_StrToDate(str: string): TDateTime;
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
frmstg: TFormatSettings;
|
2017-01-23 08:46:43 +00:00
|
|
|
// Ensures consitent String dates across platforms
|
|
|
|
begin
|
|
|
|
//GetLocaleFormatSettings(0, frmstg);
|
2017-01-25 09:33:15 +00:00
|
|
|
frmstg.DateSeparator := '-';
|
2017-01-23 08:46:43 +00:00
|
|
|
frmstg.ShortDateFormat := 'yyyy-mm-dd';
|
2017-01-25 09:33:15 +00:00
|
|
|
frmstg.TimeSeparator := '-';
|
|
|
|
frmstg.LongTimeFormat := 'hh-nn';
|
2017-01-23 08:46:43 +00:00
|
|
|
if not TryStrToDateTime(str, Result, frmstg) then
|
|
|
|
Result := Now();
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.DoReadINIIntoAppRecArray;
|
|
|
|
// AppRecArray is an in-memory copy of the INI file
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
SectionStringList: TStringList;
|
|
|
|
szSection: string;
|
|
|
|
i, iArrayElement: integer;
|
2017-01-23 08:46:43 +00:00
|
|
|
begin
|
|
|
|
SetLength(AppRecArray, 0); // Zeros the array
|
|
|
|
SectionStringList := TStringList.Create;
|
2017-01-25 09:33:15 +00:00
|
|
|
try
|
|
|
|
try
|
2017-01-23 08:46:43 +00:00
|
|
|
// Fetch all the section names
|
|
|
|
INI.ReadSections(SectionStringList);
|
|
|
|
iArrayElement := -1;
|
|
|
|
if SectionStringList.Count > 0 then
|
|
|
|
for i := 0 to SectionStringList.Count - 1 do
|
2017-01-25 09:33:15 +00:00
|
|
|
begin // Loop through all the INI file sections
|
2017-01-23 08:46:43 +00:00
|
|
|
szSection := SectionStringList[i];
|
|
|
|
// Skip over the ProgramInfo section
|
|
|
|
if (szSection <> 'ProgramInfo') then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
Inc(iArrayElement); // initially to zero
|
|
|
|
SetLength(AppRecArray, iArrayElement + 1);
|
|
|
|
AppRecArray[iArrayElement].AppPrettyName :=
|
|
|
|
INI.ReadString(szSection, 'AppPrettyName', '');
|
|
|
|
AppRecArray[iArrayElement].AppPath :=
|
|
|
|
INI.ReadString(szSection, 'AppPath', '');
|
|
|
|
AppRecArray[iArrayElement].INIPath :=
|
|
|
|
INI.ReadString(szSection, 'INIPath', '');
|
|
|
|
AppRecArray[iArrayElement].ZipPath :=
|
|
|
|
INI.ReadString(szSection, 'ZipPath', '');
|
|
|
|
AppRecArray[iArrayElement].AppVersion :=
|
|
|
|
INI.ReadString(szSection, 'AppVersion', '');
|
|
|
|
AppRecArray[iArrayElement].SFProjectName :=
|
|
|
|
INI.ReadString(szSection, 'SFProjectName', '');
|
|
|
|
AppRecArray[iArrayElement].SFUpdatesDirectory :=
|
|
|
|
INI.ReadString(szSection, 'SFUpdatesDirectory', '');
|
|
|
|
AppRecArray[iArrayElement].Location :=
|
|
|
|
INI.ReadString(szSection, 'Location', '');
|
|
|
|
AppRecArray[iArrayElement].IntervalType :=
|
|
|
|
INI.ReadInteger(szSection, 'IntervalType', 0);
|
|
|
|
AppRecArray[iArrayElement].IntervalDate :=
|
|
|
|
INI.ReadInteger(szSection, 'IntervalDate', 1);
|
|
|
|
AppRecArray[iArrayElement].IntervalDay :=
|
|
|
|
INI.ReadInteger(szSection, 'IntervalDay', 0);
|
|
|
|
AppRecArray[iArrayElement].IntervalHour :=
|
|
|
|
INI.ReadInteger(szSection, 'IntervalHour', 9);
|
|
|
|
AppRecArray[iArrayElement].Update :=
|
|
|
|
INI.ReadBool(szSection, 'Update', False);
|
|
|
|
AppRecArray[iArrayElement].LastCheckDateTime :=
|
|
|
|
UT_StrToDate(INI.ReadString(szSection, 'LastCheckDateTime',
|
|
|
|
UT_DateTimeToStr(Now)));
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
except
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Error('Failed to read AppRecArray from %s', [INI.Filename])
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
|
|
|
finally
|
2017-01-23 08:46:43 +00:00
|
|
|
FreeAndNil(SectionStringList);
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
// Low(AppRecArray) to High(AppRecArray) iterates the whole array
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.PopulateOwnProfile;
|
|
|
|
// Only called when app is first run
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
szSection, szOSsuffix: string;
|
2017-01-23 08:46:43 +00:00
|
|
|
begin
|
2017-01-25 09:33:15 +00:00
|
|
|
szSection := Application.Title;
|
2017-01-23 08:46:43 +00:00
|
|
|
szOSsuffix := LowerCase(
|
|
|
|
{$I %FPCTARGETOS%}
|
|
|
|
);
|
2017-01-25 09:33:15 +00:00
|
|
|
szSection += szOSsuffix;
|
2017-01-23 08:46:43 +00:00
|
|
|
with INI do
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
WriteString(szSection, 'AppPrettyName', szSection);
|
|
|
|
WriteString(szSection, 'AppPath', ParamStr(0));
|
|
|
|
WriteString(szSection, 'Location', ProgramDirectory);
|
|
|
|
WriteString(szSection, 'INIPath', 'lautraynotify' + szOSsuffix + '.ini');
|
|
|
|
WriteString(szSection, 'ZipPath', 'lautraynotify' + szOSsuffix + '.zip');
|
|
|
|
WriteString(szSection, 'AppVersion', LazAutoUpdate1.AppVersion);
|
|
|
|
WriteString(szSection, 'SFProjectName', 'lazautoupdate');
|
|
|
|
WriteString(szSection, 'SFUpdatesDirectory', 'updates');
|
|
|
|
WriteInteger(szSection, 'IntervalType', 0); // lt1Daily
|
|
|
|
WriteInteger(szSection, 'IntervalDay', 0); // lt1Monday (dummy)
|
|
|
|
WriteInteger(szSection, 'IntervalDate', 1); // 1st Month (dummy)
|
|
|
|
WriteInteger(szSection, 'IntervalHour', 9); // 9am
|
|
|
|
WriteBool(szSection, 'Update', False); // Dont autoupdate the default profile!
|
|
|
|
WriteString(szSection, 'LastCheckDateTime', UT_DateTimeToStr(Now));
|
|
|
|
WriteBool('ProgramInfo', 'IsVirgin', False);
|
|
|
|
UpdateFile;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
with LazAutoUpdate1 do
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
VersionsININame := 'lautraynotify' + szOSsuffix + '.ini';
|
2017-01-25 09:33:15 +00:00
|
|
|
ZipFileName := 'lautraynotify' + szOSsuffix + '.zip';
|
|
|
|
UpdatesFolder := 'updates';
|
|
|
|
SFProjectName := 'lazautoupdate';
|
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
DoReadINIIntoAppRecArray;
|
|
|
|
if not FileExistsUTF8(C_LAUTRayINI) then
|
|
|
|
LazAutoUpdate1.CreateLocalLauImportFile;
|
|
|
|
LazAutoUpdate1.RelocateLauImportFile;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function Tmainform.ImportINIFile: boolean;
|
|
|
|
// Copies ini info from shared AppData directory
|
|
|
|
// Appends Location info to the AppPath entry
|
|
|
|
// Sets Update=TRUE
|
|
|
|
// into C_INIFilename then deletes source ini
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
ImportINI: TIniFile;
|
|
|
|
SectionStringList, SectionContents: TStringList;
|
|
|
|
i: integer;
|
|
|
|
szSection, szKey, szLocation, szAppPath: string;
|
2017-01-23 08:46:43 +00:00
|
|
|
begin
|
|
|
|
{TODO: Preserve user Logtimer settings?}
|
|
|
|
Result := False;
|
|
|
|
if not FileExists(szImportINIPath) then
|
|
|
|
Exit;
|
|
|
|
ImportINI := TIniFile.Create(szImportINIPath);
|
|
|
|
SectionStringList := TStringList.Create;
|
|
|
|
SectionContents := TStringList.Create;
|
2017-01-25 09:33:15 +00:00
|
|
|
try
|
2017-01-23 08:46:43 +00:00
|
|
|
ImportINI.ReadSections(SectionStringList);
|
|
|
|
if SectionStringList.Count > 0 then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
szSection := SectionStringList[0];
|
|
|
|
ImportINI.ReadSection(szSection, SectionContents);
|
|
|
|
for i := 0 to SectionContents.Count - 1 do
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
szKey := SectionContents[i];
|
|
|
|
if szKey = 'Location' then
|
|
|
|
szLocation := ImportINI.ReadString(szSection, szKey, '');
|
|
|
|
if szKey = 'AppPath' then
|
|
|
|
szAppPath := ImportINI.ReadString(szSection, szKey, '');
|
|
|
|
INI.WriteString(szSection, szKey, ImportINI.ReadString(
|
|
|
|
szSection, szKey, ''));
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
// Append Location to AppPath
|
|
|
|
if ((szAppPath <> '') and (szLocation <> '')) then
|
|
|
|
INI.WriteString(szSection, 'AppPath', AppendPathDelim(szLocation) +
|
|
|
|
ExtractFilename(szAppPath));
|
|
|
|
INI.WriteBool(szSection, 'Update', True);
|
|
|
|
INI.WriteString(szSection, 'LastCheckDateTime',
|
|
|
|
UT_DateTimeToStr(Now));
|
|
|
|
INI.UpdateFile;
|
|
|
|
Result := True;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
|
|
|
finally
|
2017-01-23 08:46:43 +00:00
|
|
|
FreeAndNil(SectionContents);
|
|
|
|
FreeAndNil(SectionStringList);
|
|
|
|
FreeAndNil(ImportINI);
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
if (Result = True) then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Log('%s: Imported %s into %s',
|
2017-01-23 08:46:43 +00:00
|
|
|
[Application.Title, szImportINIPath, INI.Filename]);
|
|
|
|
DoReadINIIntoAppRecArray;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.DoAlert(aAppname, aVersion: string);
|
|
|
|
begin
|
|
|
|
TrayIcon1.BalloonHint := Format(rs_newversionavailable, [aAppname, aVersion]);
|
|
|
|
TrayIcon1.ShowBalloonHint;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure Tmainform.FormWindowStateChange(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if mainform.WindowState = wsMinimized then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
// 2 lines below are ineffective at hiding the main form
|
|
|
|
// Replaced with Application.ShowMainForm := false; in the lpr
|
|
|
|
// mainform.WindowState := wsNormal;
|
|
|
|
// mainform.Hide;
|
|
|
|
mainform.ShowInTaskBar := stNever;
|
|
|
|
// Log a successful startup
|
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Active := True;
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Log('%s version %s started OK',
|
2017-01-23 08:46:43 +00:00
|
|
|
[Application.Title, LazAutoUpdate1.AppVersion]);
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.idleReminderTimer(Sender: TObject);
|
|
|
|
// IdleTimer checks for any new C_LAUTRayINI in the AppData folder
|
|
|
|
// If found, it is imported then deleted.
|
|
|
|
begin
|
|
|
|
if LazAutoUpdate1.DownloadInprogress then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
TrayIcon1.BalloonHint := 'Download in progress';
|
|
|
|
TrayIcon1.ShowBalloonHint;
|
|
|
|
Exit;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
if FileExists(szImportINIPath) then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Log('%s: Import file %s discovered',
|
2017-01-23 08:46:43 +00:00
|
|
|
[Application.Title, szImportINIPath]);
|
|
|
|
if ImportINIFile then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Log('%s: Import file %s successfully imported',
|
2017-01-23 08:46:43 +00:00
|
|
|
[Application.Title, szImportINIPath]);
|
|
|
|
DeleteFileUTF8(szImportINIPath);
|
2017-01-25 09:33:15 +00:00
|
|
|
end
|
2017-01-23 08:46:43 +00:00
|
|
|
else
|
2017-01-25 09:33:15 +00:00
|
|
|
if DebugMode then
|
|
|
|
Logger.Error('%s: Failed to import file %s',
|
|
|
|
[Application.Title, szImportINIPath]);
|
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.LazAutoUpdate1DebugEvent(Sender: TObject; WhereAt, Message: string);
|
|
|
|
begin
|
2017-01-25 08:46:02 +00:00
|
|
|
if ((Logger.Active) and (DebugMode = True)) then
|
|
|
|
Logger.Log('LazAutoUpdate:%s Message:%s', [WhereAt, Message]);
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.mnu_AboutClick(Sender: TObject);
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
sz: string;
|
2017-01-23 08:46:43 +00:00
|
|
|
begin
|
|
|
|
LazAutoUpdate1.ResetAppVersion;
|
|
|
|
sz := Application.Title + ' system tray application' + LineEnding;
|
|
|
|
sz += Format('Version %s', [LazAutoUpdate1.AppVersion]) + LineEnding;
|
|
|
|
sz += 'License: LGPLv2' + LineEnding + LineEnding;
|
|
|
|
sz += Format('Using LazAutoUpdate v%s', [LazAutoUpdate1.AutoUpdateVersion]) +
|
|
|
|
LineEnding;
|
|
|
|
sz += Format('%s %s', [LazAutoUpdate1.LCLVersion, LazAutoUpdate1.FPCVersion]) +
|
|
|
|
LineEnding;
|
|
|
|
sz += Format('Compiled %s', [LazAutoUpdate1.LastCompiled]) + LineEnding;
|
|
|
|
MessageDlg('About ' + Application.Title,
|
|
|
|
sz, mtInformation, [mbOK], 0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.mnu_configureClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
DoReadINIIntoAppRecArray;
|
|
|
|
LazAutoUpdate1.ShowWhatsNewIfAvailable;
|
|
|
|
configform.ShowModal;
|
|
|
|
// may alter AppRecArray
|
|
|
|
DoSetupLongTimerArray;
|
|
|
|
DoWriteAppRecArrayIntoINI;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.mnu_fileExitClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
DoWriteAppRecArrayIntoINI;
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.mnu_startAtOSStartUpClick(Sender: TObject);
|
|
|
|
{$IFDEF WINDOWS}
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
Reg: TRegistry;
|
2017-01-23 08:46:43 +00:00
|
|
|
{$ENDIF}
|
|
|
|
begin
|
|
|
|
{$IFDEF WINDOWS}
|
|
|
|
Reg := TRegistry.Create(KEY_ALL_ACCESS);
|
2017-01-25 09:33:15 +00:00
|
|
|
try
|
2017-01-23 08:46:43 +00:00
|
|
|
Reg.RootKey := HKEY_CURRENT_USER;
|
|
|
|
Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', False);
|
|
|
|
if mnu_startAtOSStartUp.Checked then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
Reg.WriteString(Application.Title, ParamStr(0));
|
|
|
|
INI.WriteBool('ProgramInfo', 'RunAtStartUp', True);
|
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Log('Run at OS startup Activated');
|
2017-01-23 08:46:43 +00:00
|
|
|
MessageDlg(Application.Title,
|
|
|
|
'Run at OS startup activated OK', mtInformation, [mbOK], 0);
|
2017-01-25 09:33:15 +00:00
|
|
|
end
|
2017-01-23 08:46:43 +00:00
|
|
|
else
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
Reg.DeleteValue(Application.Title);
|
|
|
|
INI.WriteBool('ProgramInfo', 'RunAtStartUp', False);
|
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Log('Run at OS startup Deactivated');
|
2017-01-23 08:46:43 +00:00
|
|
|
MessageDlg(Application.Title,
|
|
|
|
'Run at OS startup deactivated OK', mtInformation, [mbOK], 0);
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
Reg.CloseKey;
|
2017-01-25 09:33:15 +00:00
|
|
|
finally
|
2017-01-23 08:46:43 +00:00
|
|
|
FreeAndNil(Reg);
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
{$ELSE}
|
|
|
|
if mnu_startAtOSStartUp.Checked then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
ShowMessage('Sorry - not implemented in Linux in this version');
|
|
|
|
mnu_startAtOSStartUp.Checked := False;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TmainForm.CheckAndUpdate(ARecIndex: integer);
|
|
|
|
begin
|
|
|
|
if LazAutoUpdate1.DownloadInprogress then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Error(
|
2017-01-23 08:46:43 +00:00
|
|
|
'Tried to update whilst download in progress. Exiting CheckAndUpdate routine');
|
|
|
|
Exit;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
with AppRecArray[ARecIndex] do
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
LazAutoUpdate1.AppFileWithPath := AppPath;
|
|
|
|
LazAutoUpdate1.AppVersion := AppVersion;
|
|
|
|
LazAutoUpdate1.ZipfileName := ZipPath;
|
|
|
|
LazAutoUpdate1.SFProjectName := SFProjectName;
|
|
|
|
LazAutoUpdate1.UpdatesFolder := SFUpdatesDirectory;
|
|
|
|
LazAutoUpdate1.VersionsININame := INIPath;
|
|
|
|
LazAutoUpdate1.CopyTree := True;
|
2017-01-25 09:33:15 +00:00
|
|
|
TrayIcon1.BalloonHint :=
|
2017-01-23 08:46:43 +00:00
|
|
|
Format('Checking %s for updates', [AppPrettyName]);
|
|
|
|
TrayIcon1.ShowBalloonHint;
|
|
|
|
// Debugging line
|
|
|
|
LazAutoUpdate1.DebugMode := True; // Logs everyting
|
|
|
|
if LazAutoUpdate1.NewVersionAvailable then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
TrayIcon1.BalloonHint :=
|
|
|
|
Format('Found newer version %s. Downloading...',
|
|
|
|
[LazAutoUpdate1.GUIOnlineVersion]);
|
|
|
|
TrayIcon1.ShowBalloonHint;
|
|
|
|
if LazAutoUpdate1.DownloadNewVersion then
|
|
|
|
if LazAutoUpdate1.SilentUpdate then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
TrayIcon1.BalloonHint :=
|
|
|
|
Format('Successfully updated %s to version %s',
|
|
|
|
[AppPrettyName, LazAutoUpdate1.GUIOnlineVersion]);
|
2017-01-25 09:33:15 +00:00
|
|
|
LastCheckDateTime := Now;
|
|
|
|
end
|
2017-01-23 08:46:43 +00:00
|
|
|
else
|
|
|
|
TrayIcon1.BalloonHint := Format('Failed to update %s', [AppPrettyName]);
|
2017-01-25 09:33:15 +00:00
|
|
|
end
|
2017-01-23 08:46:43 +00:00
|
|
|
else
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
TrayIcon1.BalloonHint := AppPrettyName + ' is up-to-date';
|
|
|
|
TrayIcon1.ShowBalloonHint;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
LazAutoUpdate1.ResetAppVersion;
|
|
|
|
TrayIcon1.ShowBalloonHint;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.mnu_SelfCheckClick(Sender: TObject);
|
|
|
|
// iCurrentRecIndex is the selected profile
|
|
|
|
begin
|
|
|
|
// Production line
|
|
|
|
//CheckAndUpdate(0); // Default profile (self)
|
|
|
|
|
|
|
|
//Debugging line
|
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Active := True;
|
2017-01-23 08:46:43 +00:00
|
|
|
|
|
|
|
ShowMessageFmt('Update %s', [AppRecArray[iCurrentRecIndex].AppPrettyName]);
|
|
|
|
CheckAndUpdate(iCurrentRecIndex);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.TrayIcon1Click(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if LazAutoUpdate1.DownloadInprogress then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
TrayIcon1.BalloonHint := 'Currently downloading...';
|
|
|
|
TrayIcon1.ShowBalloonHint;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if LowerCase(ParamStr(1)) = 'debug' then
|
|
|
|
DebugMode := True
|
|
|
|
else
|
|
|
|
DebugMode := False;
|
2017-01-25 09:33:15 +00:00
|
|
|
{$IFDEF DEBUGMODE}
|
|
|
|
DebugMode := True;
|
|
|
|
{$ENDIF}
|
2017-01-23 08:46:43 +00:00
|
|
|
// Initialise the App's main INI file
|
2017-01-25 09:33:15 +00:00
|
|
|
try
|
|
|
|
INI := TIniFile.Create(GetAppConfigDirUTF8(False) + C_INIFilename);
|
|
|
|
except
|
|
|
|
sleep(4000);
|
|
|
|
if (INI = nil) then
|
2017-01-23 13:26:04 +00:00
|
|
|
INI := TIniFile.Create(GetAppConfigDirUTF8(False) + C_INIFilename);
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
INI.CacheUpdates := False;
|
|
|
|
INI.WriteString('ProgramInfo', 'AppName', Application.Title);
|
|
|
|
INI.WriteString('ProgramInfo', 'Location', LazAutoUpdate1.AppFileWithPath);
|
|
|
|
INI.WriteString('ProgramInfo', 'Version', LazAutoUpdate1.AppVersion);
|
|
|
|
INI.WriteString('ProgramInfo', 'LastStarted',
|
|
|
|
FormatDateTime(shortdateformat, Now));
|
|
|
|
mnu_startAtOSStartUp.Checked := INI.ReadBool('ProgramInfo', 'RunAtStartUp', False);
|
|
|
|
// Is this a first-time run?
|
|
|
|
if INI.ReadBool('ProgramInfo', 'IsVirgin', True) then
|
|
|
|
PopulateOwnProfile;
|
|
|
|
// Start up a system Event Log
|
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.LogType := ltFile;
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Filename := ExtractFileNameWithoutExt(ParamStr(0)) + '.log';
|
2017-01-23 08:46:43 +00:00
|
|
|
// New logfile every time
|
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
if FileExistsUTF8(Logger.Filename) then
|
|
|
|
DeleteFile(Logger.Filename);
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.AppendContent := True;
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.DefaultEventType := etInfo;
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.RaiseExceptionOnError := False;
|
|
|
|
// Logger.Identification := Application.Title;
|
2017-01-23 08:46:43 +00:00
|
|
|
// Fetch the location of any trayicon INI on the users system
|
|
|
|
szImportINIPath := GetAppConfigDirUTF8(False, True);
|
2017-01-25 09:33:15 +00:00
|
|
|
szImportINIPath := AnsiReplaceText(szImportINIPath, Application.Title,
|
|
|
|
'updatehm' + C_PFX);
|
2017-01-23 08:46:43 +00:00
|
|
|
szImportINIPath := AppendPathDelim(szImportINIPath) + C_LAUTRayINI;
|
2017-01-25 08:46:02 +00:00
|
|
|
if DebugMode then
|
2017-01-25 09:33:15 +00:00
|
|
|
Logger.Debug('szImportINIPath=' + szImportINIPath);
|
2017-01-23 08:46:43 +00:00
|
|
|
// Initialise the AppRecArray
|
|
|
|
DoReadINIIntoAppRecArray;
|
|
|
|
// Use last saved Profile at startup
|
|
|
|
iCurrentRecIndex := mainform.INI.ReadInteger('ProgramInfo',
|
|
|
|
'CurrentProfileIndex', 0);
|
|
|
|
DoSetupLongTimerArray;
|
|
|
|
// Sort out the TrayIcon stuff
|
2017-01-25 09:33:15 +00:00
|
|
|
TrayIcon1.Icon := Application.Icon;
|
2017-01-23 08:46:43 +00:00
|
|
|
TrayIcon1.BalloonTitle := Format(rs_balloontitle, [Application.Title]);
|
2017-01-25 09:33:15 +00:00
|
|
|
TrayIcon1.Hint := Application.Title;
|
2017-01-23 08:46:43 +00:00
|
|
|
TrayIcon1.ShowIcon := True;
|
|
|
|
TrayIcon1.Show;
|
|
|
|
TrayIcon1.BalloonHint := Format(rs_trayloaded, [Application.Title]);
|
|
|
|
TrayIcon1.ShowBalloonHint;
|
|
|
|
LazAutoUpdate1.DebugMode := DebugMode;
|
2017-01-25 09:33:15 +00:00
|
|
|
mnu_SelfCheck.Visible := DebugMode;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tmainform.FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
|
|
|
var
|
2017-01-25 09:33:15 +00:00
|
|
|
i: integer;
|
2017-01-23 08:46:43 +00:00
|
|
|
begin
|
|
|
|
if LazAutoUpdate1.DownloadInprogress then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
ShowMessage('Please wait. Update in progress');
|
|
|
|
CanClose := False;
|
2017-01-25 09:33:15 +00:00
|
|
|
end
|
2017-01-23 08:46:43 +00:00
|
|
|
else
|
2017-01-25 09:33:15 +00:00
|
|
|
// Clean up memory No leaks (V0.1.14)
|
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
if DebugMode then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-25 08:46:02 +00:00
|
|
|
Logger.Log('User closed application');
|
|
|
|
Logger.Active := False;
|
2017-01-25 09:33:15 +00:00
|
|
|
FreeAndNil(Logger);
|
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
CanClose := True;
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
if CanClose then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
// Clean up any LongTimers
|
|
|
|
for i := Low(LongTimerArray) to High(LongTimerArray) do
|
|
|
|
if LongTimerArray[i] <> nil then
|
2017-01-25 09:33:15 +00:00
|
|
|
begin
|
2017-01-23 08:46:43 +00:00
|
|
|
LongTimerArray[i].Enabled := False;
|
|
|
|
FreeAndNil(LongTimerArray[i]);
|
2017-01-25 09:33:15 +00:00
|
|
|
end;
|
|
|
|
SetLength(AppRecArray, 0);
|
|
|
|
FreeAndNil(AppRecArray);
|
|
|
|
FreeAndNil(INI);
|
|
|
|
end;
|
2017-01-23 08:46:43 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|