{******************************************************************************* Unit: fSelectfpccfg.pas contains Form_Select *******************************************************************************} {******************************************************************************* LazUpdater runs SVN Update/Checkout, Make and Strip for FPC and Lazarus. Copyright (C) 2010 Ingo Steiniger This program 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 3 of the License, or (at your option) any later version. This program 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. You should have received a copy of the GNU General Public License along with this program; if not, see . *******************************************************************************} unit fselect_fpccfg; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, INIFiles; type { TForm_Select } TForm_Select = class(TForm) Btn_Open: TButton; Btn_Create: TButton; Btn_Close: TButton; Btn_Delete: TButton; LiBo_Select: TListBox; Panel1: TPanel; procedure Btn_DeleteClick(Sender: TObject); procedure Btn_OpenClick(Sender: TObject); procedure Btn_CreateClick(Sender: TObject); procedure Btn_CloseClick(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); procedure FormShow(Sender: TObject); procedure LiBo_SelectDblClick(Sender: TObject); private { private declarations } procedure SearchConfigFiles(); public { public declarations } end; var Form_Select: TForm_Select; implementation uses fpccfg, helper, gvars; var myINI:TIniFile; { TForm_Select } procedure TForm_Select.Btn_OpenClick(Sender: TObject); var sFpcCfg:String; begin if LiBo_Select.Count>0 then begin if LiBo_Select.ItemIndex>=0 then begin sFpcCfg:=LiBo_Select.Items.Strings[LiBo_Select.ItemIndex]; if FileExists(sFpcCfg) then begin //load fpc.cfg Form_FpcCfg.Memo_FpcCfg.Lines.LoadFromFile(sFpcCfg); Form_FpcCfg.Memo_FpcCfg.Modified:=False; //prepare form fpccfg.FpcCfgPath:=sFpcCfg; Form_FpcCfg.Caption:='Edit '+sFpcCfg; //show form Form_FpcCfg.ShowModal; end else begin MessageDlg(Format(rsTheFileCould, [sFpcCfg]), mtError, [mbOK], 0); end; end else begin MessageDlg(rsNoConfigFile, mtWarning, [mbOK], 0); end; end else begin MessageDlg(rsNoConfigFile2, mtWarning, [mbOK], 0); end; end; //delete procedure TForm_Select.Btn_DeleteClick(Sender: TObject); var sFPcCfg:String; begin if LiBo_Select.Count>0 then begin if LiBo_Select.ItemIndex>=0 then begin sFpcCfg:=LiBo_Select.Items.Strings[LiBo_Select.ItemIndex]; if MessageDlg(Format(rsAreYouSureTo, [sFpcCfg]), mtConfirmation, [mbYes, mbNo], 0)=mrYes then begin if DeleteFile(sFpcCfg) then begin //LiBo_Select.Items.Delete(LiBo_Select.ItemIndex); MessageDlg(Format(rsFileDeleted, [sFpcCfg]), mtInformation, [mbOK], 0 ); SearchConfigFiles; end else begin MessageDlg(rsAnErrorOccur, mtError, [mbOK], 0); end; end; end else begin MessageDlg(rsNoConfigFile, mtWarning, [mbOK], 0); end; end; end; //create Template procedure TForm_Select.Btn_CreateClick(Sender: TObject); var s, s2, sFpcCfg:String; i:Integer; tmpSL:TStringList; begin if DirectoryExists(LUFpcInstDir) then begin tmpSL:=TStringlist.Create; Form_FpcCfg.Memo_FpcCfg.Clear; {$IFDEF WINDOWS} tmpSL.Text:=FpcCfgWin; sFpcCfg:=setPathDelim(LUFpcInstDir)+'bin'+PathDelim+LUFpcInfo.CPU+'-'+LUFpcInfo.OS+PathDelim+'fpc.cfg'; {$ELSE WINDOWS} tmpSL.Text:=FpcCfgUnix; {$ifdef DARWIN} sFpcCfg:=setPathDelim(LUFpcInstDir)+'etc'+PathDelim+'fpc.cfg'; {$else DARWIN} sFpcCfg:=setPathDelim(LUFpcInstDir)+'lib'+PathDelim+'fpc'+PathDelim+'etc'+PathDelim+'fpc.cfg'; {$endif DARWIN} {$ENDIF WINDOWS} for i:=0 to tmpSl.Count-1 do begin s:=tmpSL.Strings[i]; if Pos('*FPCPath*', s)<>0 then begin s2:=Copy(s, 1, Pos('*FPCPath*', s)-1); delete(s, 1, Pos('*FPCPath*', s)+8); s2:=s2+setPathDelim(LUFpcInstDir); s2:=s2+s; s:=s2; end; Form_FpcCfg.Memo_FpcCfg.Append(s); Form_FpcCfg.Memo_FpcCfg.Modified:=True; end; //prepare form fpccfg.FpcCfgPath:=sFpcCfg; Form_FpcCfg.Caption:='Edit '+sFpcCfg; //show form Form_FpcCfg.ShowModal; tmpSL.Free; SearchConfigFiles; end else begin MessageDlg(rsAnErrorOccur2, mtError, [mbOK], 0); end; end; procedure TForm_Select.Btn_CloseClick(Sender: TObject); begin Close; end; procedure TForm_Select.FormCloseQuery(Sender: TObject; var CanClose: boolean); begin myINI:=TINIFile.Create(LUConfigFile); myINI.WriteInteger('SWindow', 'Left', Left); myINI.WriteInteger('SWindow', 'Top', Top); myINI.WriteInteger('SWindow', 'Width', Width); myINI.WriteInteger('SWindow', 'Height', Height); myINI.Free; CanClose:=True; end; procedure TForm_Select.FormShow(Sender: TObject); begin SelectFirst; myINI:=TINIFile.Create(LUConfigFile); //-Select-Window Left:=myINI.ReadInteger('SWindow', 'Left', 10); Top:=myINI.ReadInteger('SWindow', 'Top', 10); Width:=myINI.ReadInteger('SWindow', 'Width', 520); Height:=myINI.ReadInteger('SWindow', 'Height', 250); myINI.Free; SearchConfigFiles; end; procedure TForm_Select.LiBo_SelectDblClick(Sender: TObject); begin Btn_Open.Click; end; {******************************************************************************* search for all fpc.cfg files *******************************************************************************} procedure TForm_Select.SearchConfigFiles(); var sPPC_CONFIG_PATH:String; begin LiBo_Select.Clear; {$ifdef WINDOWS} //getFpcInfo; //check paths //1st PPC_CONFIG_PATH sPPC_CONFIG_PATH:=GetEnvironmentVariable('PPC_CONFIG_PATH'); if (sPPC_CONFIG_PATH<>'') and DirectoryExists(sPPC_CONFIG_PATH) then begin if FileExists(setPathDelim(sPPC_CONFIG_PATH)+'fpc.cfg') then LiBo_Select.Items.Append(setPathDelim(sPPC_CONFIG_PATH)+'fpc.cfg'); end; //2nd binray path if DirectoryExists(LUFpcInstDir) then begin if FileExists(setPathDelim(LUFpcInstDir)+'bin'+PathDelim+LUFpcInfo.CPU+'-'+LUFpcInfo.OS+PathDelim+'fpc.cfg') then LiBo_Select.Items.Append(setPathDelim(LUFpcInstDir)+'bin'+PathDelim+LUFpcInfo.CPU+'-'+LUFpcInfo.OS+PathDelim+'fpc.cfg'); end else begin MessageDlg(rsMaybeNotAllF, mtWarning, [mbOK], 0); end; {$else WINDOWS} //1st Homedir if FileExists(setPathDelim(Homedir)+'.fpc.cfg') then LiBo_Select.Items.Append(setPathDelim(Homedir)+'.fpc.cfg'); //2nd PPC_CONFIG_PATH sPPC_CONFIG_PATH:=GetEnvironmentVariable('PPC_CONFIG_PATH'); if (sPPC_CONFIG_PATH<>'') and DirectoryExists(sPPC_CONFIG_PATH) then begin if FileExists(setPathDelim(sPPC_CONFIG_PATH)+'fpc.cfg') then LiBo_Select.Items.Append(setPathDelim(sPPC_CONFIG_PATH)+'fpc.cfg'); end; //3rd binary path/../etc {$ifdef DARWIN} if DirectoryExists(LUFpcInstDir) then begin if FileExists(setPathDelim(LUFpcInstDir)+'etc'+PathDelim+'fpc.cfg') then LiBo_Select.Items.Append(setPathDelim(LUFpcInstDir)+'etc'+PathDelim+'fpc.cfg'); end else begin MessageDlg(rsMaybeNotAllF, mtWarning, [mbOK], 0); end; {$else DARWIN} if DirectoryExists(LUFpcInstDir) then begin if FileExists(setPathDelim(LUFpcInstDir)+'lib'+PathDelim+'fpc'+PathDelim+'etc'+PathDelim+'fpc.cfg') then LiBo_Select.Items.Append(setPathDelim(LUFpcInstDir)+'lib'+PathDelim+'fpc'+PathDelim+'etc'+PathDelim+'fpc.cfg'); end else begin MessageDlg(rsMaybeNotAllF, mtWarning, [mbOK], 0); end; {$endif DARWIN} //4th /etc if FileExists('/etc/fpc.cfg') then LiBo_Select.Items.Append('/etc/fpc.cfg'); {$endif WINDOWS} end; initialization {$I fselect_fpccfg.lrs} end.