140 lines
3.1 KiB
ObjectPascal
140 lines
3.1 KiB
ObjectPascal
unit settingsutils;
|
|
|
|
{$mode ObjFPC}{$H+}
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Classes, SysUtils;
|
|
|
|
|
|
type
|
|
TImpostazioniDati=record
|
|
Latitudine, Longitudine :Double;
|
|
OraSimulazione: integer;
|
|
httpsIsEnabled:boolean;
|
|
LinguaApp:string;
|
|
end;
|
|
|
|
|
|
function LeggiImpostazioni():TImpostazioniDati;
|
|
procedure ScriviImpostazioni(dati:TImpostazioniDati);
|
|
|
|
|
|
var
|
|
FileImpostazioni:TextFile;
|
|
filenome:string='./.starstreet_data/settings.dat';
|
|
|
|
implementation
|
|
|
|
|
|
procedure ScriviImpostazioni(dati:TImpostazioniDati);
|
|
begin
|
|
|
|
{$ifdef darwin}
|
|
|
|
filenome:= SysUtils.ExtractFilePath(ParamStr(0))+'.starstreet_data/settings.dat';
|
|
|
|
{$endif}
|
|
|
|
if not(SysUtils.FileExists(filenome))then
|
|
begin
|
|
{$ifdef darwin}
|
|
|
|
SysUtils.CreateDir(SysUtils.ExtractFilePath(ParamStr(0))+'.starstreet_data');
|
|
|
|
|
|
{$else}
|
|
|
|
SysUtils.CreateDir('./.starstreet_data');
|
|
{Comportamento: crea una cartella nel punto di esecuzione del
|
|
programma, concide con home/<user name> nel caso l'eseguibile venga eseguito
|
|
in /bin diversamente coincide dalla directory nel quale è stato aperto}
|
|
FileSetAttr('./.starstreet_data', faDirectory or faHidden); //rende la cartella nascosta su windows
|
|
|
|
|
|
{$endif}
|
|
|
|
|
|
|
|
|
|
end;
|
|
AssignFile(fileimpostazioni, filenome);
|
|
Rewrite(FileImpostazioni);
|
|
|
|
WriteLn(FileImpostazioni, ('LAT'+ ' '+ floattostr(dati.Latitudine)));
|
|
WriteLn(FileImpostazioni, ('LONG'+ ' '+ floattostr(dati.Longitudine)));
|
|
WriteLn(FileImpostazioni, ('LANGUAGE'+ ' '+ dati.LinguaApp));
|
|
WriteLn(FileImpostazioni, ('HOUR_SIMULATION'+ ' '+ inttostr(dati.OraSimulazione)));
|
|
WriteLn(FileImpostazioni, ('HTTPS_ENABLED'+ ' '+ booltostr(dati.httpsIsEnabled)));
|
|
|
|
CloseFile(FileImpostazioni);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function LeggiImpostazioni():TImpostazioniDati;
|
|
var
|
|
ElementoDati: TStringList;
|
|
tmpstring:string;
|
|
begin
|
|
ElementoDati:= TStringList.Create;
|
|
ElementoDati.Delimiter:=' ';
|
|
|
|
{$ifdef darwin}
|
|
|
|
filenome:= SysUtils.ExtractFilePath(ParamStr(0))+'.starstreet_data/settings.dat';
|
|
|
|
{$endif}
|
|
|
|
if SysUtils.FileExists(filenome) then
|
|
begin
|
|
AssignFile(fileimpostazioni, filenome);
|
|
Reset(fileimpostazioni);
|
|
repeat
|
|
ReadLn(fileimpostazioni, tmpstring);
|
|
ElementoDati.DelimitedText:=tmpstring;
|
|
|
|
case ElementoDati[0] of
|
|
'LAT': LeggiImpostazioni.Latitudine:=strtofloat(ElementoDati[1]) ;
|
|
'LONG': LeggiImpostazioni.Longitudine:=strtofloat(ElementoDati[1]);
|
|
'LANGUAGE': LeggiImpostazioni.LinguaApp:=ElementoDati[1] ;
|
|
'HOUR_SIMULATION': LeggiImpostazioni.OraSimulazione:=strtoint(ElementoDati[1]) ;
|
|
'HTTPS_ENABLED': LeggiImpostazioni.httpsIsEnabled:=strtobool(ElementoDati[1]) ;
|
|
|
|
end;
|
|
|
|
until eof(fileimpostazioni);
|
|
CloseFile(fileimpostazioni);
|
|
end else
|
|
begin
|
|
LeggiImpostazioni.Latitudine:=39;
|
|
LeggiImpostazioni.Longitudine:=9;
|
|
LeggiImpostazioni.LinguaApp:='Italiano';
|
|
LeggiImpostazioni.OraSimulazione:=21;
|
|
{$ifdef darwin}
|
|
LeggiImpostazioni.httpsIsEnabled:=False;
|
|
{$else}
|
|
LeggiImpostazioni.httpsIsEnabled:=True;
|
|
{$endif}
|
|
end;
|
|
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end.
|
|
|