unit uMAMu_MaintenanceSettings;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ImgList, ComCtrls, IniFiles, ToolWin,
  ExtCtrls, GR32_Image;

type
  TFormMAMu_MaintenanceSettings = class(TForm)
    IL_Settings: TImageList;
    SettingsList: TListView;
    ButtonDefault: TButton;
    ButtonStart: TButton;
    ButtonCancel: TButton;
    LabelDescription: TLabel;
    TopImage: TImage32;
    procedure ButtonCancelClick(Sender: TObject);
    procedure ButtonStartClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure ButtonDefaultClick(Sender: TObject);
  private
    { Private declarations }
    procedure VerifyMAMu_MaintenanceSettings(IO_Mode: ShortInt);
  public
    { Public declarations }
  end;

var
  FormMAMu_MaintenanceSettings: TFormMAMu_MaintenanceSettings;

implementation

{$R *.dfm}

uses uMain, uCommon;

procedure TFormMAMu_MaintenanceSettings.VerifyMAMu_MaintenanceSettings(IO_Mode: ShortInt);
var
  elFile: TMemIniFile;
  Loop: ShortInt;
begin
  case IO_Mode of
    0: // read
      begin
        case FileExists(FormMain.FrontendPath+'ini_files\el_extras.ini') of
          True:
            begin
              elFile:= TMemIniFile.Create(FormMain.FrontendPath+'ini_files\el_extras.ini');
              SettingsList.Items.BeginUpdate;
              SettingsList.Items[0].Checked:= elFile.ReadBool('MAMu_', 'SearchCloneIcons', True);
              SettingsList.Items[1].Checked:= elFile.ReadBool('MAMu_', 'ScanZippedIcons', True);
              SettingsList.Items[2].Checked:= elFile.ReadBool('MAMu_', 'ScanUnzippedIcons', True);
              SettingsList.Items[3].Checked:= elFile.ReadBool('MAMu_', 'ScanMAMEIcons', True);
              SettingsList.Items[4].Checked:= elFile.ReadBool('MAMu_', 'ScanZiNcIcons', True);
              SettingsList.Items[5].Checked:= elFile.ReadBool('MAMu_', 'ScanDaphneIcons', True);
              SettingsList.Items[6].Checked:= elFile.ReadBool('MAMu_', 'ScanAGEMAMEIcons', True);
              SettingsList.Items[7].Checked:= elFile.ReadBool('MAMu_', 'ScanPinMAMEIcons', True);
              SettingsList.Items[8].Checked:= elFile.ReadBool('MAMu_', 'ScanHazeMDIcons', True);
              SettingsList.Items.EndUpdate;
              FreeAndNil(elFile);
            end;
          False:
            begin
              SettingsList.Items.BeginUpdate;
              for Loop:=0 to SettingsList.Items.Count-1 do
                  SettingsList.Items[Loop].Checked:= True;
              SettingsList.Items.EndUpdate;
            end;
        end;
      end;
    1: // write
      begin
        if FormMain.CheckReadOnly(FormMain.FrontendPath+'ini_files\el_extras.ini') then
           Exit;
        elFile:= TMemIniFile.Create(FormMain.FrontendPath+'ini_files\el_extras.ini');
        elFile.WriteBool('MAMu_', 'SearchCloneIcons', SettingsList.Items[0].Checked);
        elFile.WriteBool('MAMu_', 'ScanZippedIcons', SettingsList.Items[1].Checked);
        elFile.WriteBool('MAMu_', 'ScanUnzippedIcons', SettingsList.Items[2].Checked);
        elFile.WriteBool('MAMu_', 'ScanMAMEIcons', SettingsList.Items[3].Checked);
        elFile.WriteBool('MAMu_', 'ScanZiNcIcons', SettingsList.Items[4].Checked);
        elFile.WriteBool('MAMu_', 'ScanDaphneIcons', SettingsList.Items[5].Checked);
        elFile.WriteBool('MAMu_', 'ScanAGEMAMEIcons', SettingsList.Items[6].Checked);
        elFile.WriteBool('MAMu_', 'ScanPinMAMEIcons', SettingsList.Items[7].Checked);
        elFile.WriteBool('MAMu_', 'ScanHazeMDIcons', SettingsList.Items[8].Checked);
        elFile.UpdateFile;
        FreeAndNil(elFile);
      end;
  end;
end;

procedure TFormMAMu_MaintenanceSettings.ButtonCancelClick(Sender: TObject);
begin
  FormMAMu_MaintenanceSettings.Tag:= 1;
  Close;
end;

procedure TFormMAMu_MaintenanceSettings.ButtonStartClick(Sender: TObject);
begin
  if (not SettingsList.Items[1].Checked) and (not SettingsList.Items[2].Checked) then
     GenerateMessage('Warning', 'You need to select one type of files for scanning, either zipped or unzipped!', 2)
  else
     Close;
end;

procedure TFormMAMu_MaintenanceSettings.FormShow(Sender: TObject);
begin
  VerifyMAMu_MaintenanceSettings(0);
  FormMain.LoadTopBar(TopImage, 'mamu.png');
end;

procedure TFormMAMu_MaintenanceSettings.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  VerifyMAMu_MaintenanceSettings(1);
end;

procedure TFormMAMu_MaintenanceSettings.ButtonDefaultClick(
  Sender: TObject);
var
  Loop: ShortInt;
begin
  SettingsList.Items.BeginUpdate;
  for Loop:=0 to SettingsList.Items.Count-1 do
      SettingsList.Items[Loop].Checked:= True;
  SettingsList.Items.EndUpdate;
end;

end.
