mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-07 10:58:42 +02:00
134 lines
3.2 KiB
ObjectPascal
134 lines
3.2 KiB
ObjectPascal
{
|
|
/***************************************************************************
|
|
* *
|
|
* 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 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
***************************************************************************/
|
|
|
|
Author: Mattias Gaertner
|
|
|
|
Abstract:
|
|
Miscellaneous options of the lazarus IDE.
|
|
}
|
|
unit MiscOptions;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, SysUtils, BuildLazDialog, LazConf, IDEProcs, XMLCfg;
|
|
|
|
type
|
|
TMiscellaneousOptions = class
|
|
private
|
|
fBuildLazOpts: TBuildLazarusOptions;
|
|
fFilename: string;
|
|
function GetFilename: string;
|
|
public
|
|
constructor Create;
|
|
destructor Destroy; override;
|
|
procedure Load;
|
|
procedure Save;
|
|
property BuildLazOpts: TBuildLazarusOptions
|
|
read fBuildLazOpts write fBuildLazOpts;
|
|
property Filename: string read GetFilename;
|
|
end;
|
|
|
|
|
|
var MiscellaneousOptions: TMiscellaneousOptions;
|
|
|
|
|
|
implementation
|
|
|
|
|
|
const
|
|
MiscOptsFilename = 'miscellaneousoptions.xml';
|
|
MiscOptsVersion = 1;
|
|
|
|
{ TMiscellaneousOptions }
|
|
|
|
constructor TMiscellaneousOptions.Create;
|
|
begin
|
|
inherited Create;
|
|
BuildLazOpts:=TBuildLazarusOptions.Create;
|
|
end;
|
|
|
|
destructor TMiscellaneousOptions.Destroy;
|
|
begin
|
|
BuildLazOpts.Free;
|
|
inherited Destroy;
|
|
end;
|
|
|
|
function TMiscellaneousOptions.GetFilename: string;
|
|
var
|
|
ConfFileName: string;
|
|
begin
|
|
if fFilename='' then begin
|
|
ConfFileName:=SetDirSeparators(GetPrimaryConfigPath+'/'+MiscOptsFilename);
|
|
CopySecondaryConfigFile(MiscOptsFilename);
|
|
if (not FileExists(ConfFileName)) then begin
|
|
writeln('Note: miscellaneous options file not found - using defaults');
|
|
end;
|
|
FFilename:=ConfFilename;
|
|
end;
|
|
Result:=fFilename;
|
|
end;
|
|
|
|
procedure TMiscellaneousOptions.Load;
|
|
var XMLConfig: TXMLConfig;
|
|
FileVersion: integer;
|
|
begin
|
|
try
|
|
XMLConfig:=TXMLConfig.Create(GetFilename);
|
|
except
|
|
writeln('Error: unable to open miscellaneous options "',GetFilename,'"');
|
|
exit;
|
|
end;
|
|
try
|
|
try
|
|
FileVersion:=XMLConfig.GetValue('MiscellaneousOptions/Version/Value',0);
|
|
|
|
if FileVersion<MiscOptsVersion then
|
|
writeln('Note: converting old miscellaneous options ...');
|
|
|
|
BuildLazOpts.Load(XMLConfig,'MiscellaneousOptions/BuildLazarusOptions/');
|
|
finally
|
|
XMLConfig.Free;
|
|
end;
|
|
except
|
|
writeln('Error: unable read miscellaneous options from "',GetFilename,'"');
|
|
end;
|
|
end;
|
|
|
|
procedure TMiscellaneousOptions.Save;
|
|
var XMLConfig: TXMLConfig;
|
|
begin
|
|
try
|
|
XMLConfig:=TXMLConfig.Create(GetFilename);
|
|
except
|
|
writeln('Error: unable to open miscellaneous options "',GetFilename,'"');
|
|
exit;
|
|
end;
|
|
try
|
|
try
|
|
XMLConfig.SetValue('MiscellaneousOptions/Version/Value',MiscOptsVersion);
|
|
|
|
BuildLazOpts.Save(XMLConfig,'MiscellaneousOptions/BuildLazarusOptions/');
|
|
|
|
XMLConfig.Flush;
|
|
finally
|
|
XMLConfig.Free;
|
|
end;
|
|
except
|
|
writeln('Error: unable read miscellaneous options from "',GetFilename,'"');
|
|
end;
|
|
end;
|
|
|
|
end.
|
|
|
|
|