Fixed settings storing.

This commit is contained in:
meffi@lab313.ru
2014-04-10 21:54:08 +00:00
parent a249cc5f89
commit 1d63ac1b95
5 changed files with 53 additions and 59 deletions

View File

@@ -529,7 +529,9 @@ object frmMain: TfrmMain
Height = 28
Align = alLeft
Caption = 'Stop Scan'
DoubleBuffered = False
Enabled = False
ParentDoubleBuffered = False
TabOrder = 0
OnClick = btnStopScanClick
end
@@ -683,6 +685,8 @@ object frmMain: TfrmMain
Height = 27
Align = alRight
Caption = 'CLUT'
DoubleBuffered = False
ParentDoubleBuffered = False
TabOrder = 0
OnClick = btnShowClutClick
end
@@ -697,8 +701,10 @@ object frmMain: TfrmMain
AutoCloseUp = True
Style = csDropDownList
Anchors = []
DoubleBuffered = False
Enabled = False
ItemIndex = 0
ParentDoubleBuffered = False
TabOrder = 1
Text = 'Real'
OnChange = actDrawSelectedTimExecute
@@ -721,8 +727,10 @@ object frmMain: TfrmMain
AutoCloseUp = True
Style = csDropDownList
Anchors = []
DoubleBuffered = False
Enabled = False
ItemIndex = 0
ParentDoubleBuffered = False
TabOrder = 2
Text = 'Full transparence'
OnChange = cbbTranspModeChange
@@ -799,11 +807,11 @@ object frmMain: TfrmMain
object N4: TMenuItem
Caption = '-'
end
object IMInfo1: TMenuItem
object mnTimInfoMain: TMenuItem
Action = actTimInfo
end
end
object mnConfig: TMenuItem
object mnOptions: TMenuItem
Caption = '&Options'
object mnAssociate: TMenuItem
Action = actAssocTims
@@ -898,7 +906,7 @@ object frmMain: TfrmMain
OnExecute = actOpenLabExecute
end
object actAbout: TAction
Caption = 'About...'
Caption = '&About...'
OnExecute = actAboutExecute
end
object actStretch: TAction
@@ -907,32 +915,26 @@ object frmMain: TfrmMain
OnExecute = actStretchExecute
end
object actTimInfo: TAction
Caption = 'TIM Info'
Caption = '&TIM Info'
Enabled = False
OnExecute = actTimInfoExecute
end
object actAssocTims: TAction
Caption = 'Open TIMs with T2V'
Caption = '&Open TIMs with T2V'
OnExecute = actAssocTimsExecute
end
object actExtractList: TAction
Caption = 'Extract TIMs'
Caption = '&Extract TIMs'
Enabled = False
ShortCut = 112
OnExecute = actExtractListExecute
end
object actChangeClutIdx: TAction
Caption = 'actChangeClutIdx'
end
object actChangeBackColor: TAction
Caption = '&Change Background Color'
end
object actReturnFocus: TAction
Caption = 'actReturnFocus'
OnExecute = actReturnFocusExecute
end
object actDrawSelectedTim: TAction
Caption = 'actDrawSelectedTim'
OnExecute = actDrawSelectedTimExecute
end
end

View File

@@ -32,7 +32,7 @@ type
N3: TMenuItem;
mnAbout: TMenuItem;
pbProgress: TProgressBar;
mnConfig: TMenuItem;
mnOptions: TMenuItem;
pnlStatus: TPanel;
lblStatus: TLabel;
btnStopScan: TButton;
@@ -74,7 +74,7 @@ type
actStretch: TAction;
actTimInfo: TAction;
mnTIMInfo: TMenuItem;
IMInfo1: TMenuItem;
mnTimInfoMain: TMenuItem;
actAssocTims: TAction;
mnAssociate: TMenuItem;
N6: TMenuItem;
@@ -83,7 +83,6 @@ type
pbTim: TImage;
btnShowClut: TButton;
cbbCLUT: TComboBox;
actChangeBackColor: TAction;
actReturnFocus: TAction;
actDrawSelectedTim: TAction;
procedure btnStopScanClick(Sender: TObject);
@@ -682,7 +681,7 @@ procedure TfrmMain.FormCreate(Sender: TObject);
var
hGridRect: TGridRect;
begin
Settings := TSettings.Create;
Settings := TSettings.Create(ExtractFilePath(ParamStr(0)));
Settings.LoadFromFile;
actStretch.Checked := Settings.StretchMode;

View File

@@ -8,6 +8,7 @@ unit uSettings;
type
TCustomSettings = class
private
FFileName: string;
procedure LoadFromStream(const Stream: TStream) ;
procedure SaveToStream(const Stream: TStream) ;
public
@@ -21,31 +22,26 @@ unit uSettings;
FStretchMode: Boolean;
FLastDir: string;
public
constructor Create;
constructor Create(const DirPath: string);
published
property TranspMode: Integer read FTranspMode write FTranspMode;
property StretchMode: Boolean read FStretchMode write FStretchMode;
property LastDir: string read FLastDir write FLastDir;
end;
var
Settings: TSettings;
implementation
uses TypInfo, Sysutils;
const FileName = 'settings.t2v';
{ TSettings }
procedure TCustomSettings.LoadFromFile() ;
var
Stream: TStream;
begin
if not FileExists(FileName) then Exit;
if not FileExists(FFileName) then Exit;
Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite) ;
Stream := TFileStream.Create(FFileName, fmOpenRead or fmShareDenyWrite) ;
try
LoadFromStream(Stream) ;
finally
@@ -76,7 +72,7 @@ unit uSettings;
var
Stream: TStream;
begin
Stream := TFileStream.Create(FileName, fmCreate) ;
Stream := TFileStream.Create(FFileName, fmCreate) ;
try
SaveToStream(Stream) ;
finally
@@ -84,46 +80,43 @@ unit uSettings;
end;
end;
procedure TCustomSettings.SaveToStream(const Stream: TStream) ;
var
PropName, PropValue: string;
cnt: Integer;
lPropInfo: PPropInfo;
lPropCount: Integer;
lPropList: PPropList;
lPropType: PPTypeInfo;
Writer: TWriter;
procedure TCustomSettings.SaveToStream(const Stream: TStream) ;
var
PropName, PropValue: string;
cnt: Integer;
lPropInfo: PPropInfo;
lPropCount: Integer;
lPropList: PPropList;
lPropType: PPTypeInfo;
Writer: TWriter;
begin
lPropCount := GetPropList(PTypeInfo(ClassInfo), lPropList) ;
Writer := TWriter.Create(Stream, $FFF) ;
Stream.Size := 0;
Writer.WriteListBegin;
for cnt := 0 to lPropCount - 1 do
begin
lPropCount := GetPropList(PTypeInfo(ClassInfo), lPropList) ;
Writer := TWriter.Create(Stream, $FFF) ;
Stream.Size := 0;
Writer.WriteListBegin;
for cnt := 0 to lPropCount - 1 do
begin
lPropInfo := lPropList^[cnt];
lPropType := lPropInfo^.PropType;
if lPropType^.Kind = tkMethod then Continue;
lPropInfo := lPropList^[cnt];
lPropType := lPropInfo^.PropType;
if lPropType^.Kind = tkMethod then Continue;
PropName := lPropInfo.Name;
PropValue := GetPropValue(Self, lPropInfo) ;
Writer.WriteString(PropName) ;
Writer.WriteString(PropValue) ;
end;
Writer.WriteListEnd;
FreeAndNil(Writer) ;
PropName := lPropInfo.Name;
PropValue := GetPropValue(Self, lPropInfo) ;
Writer.WriteString(PropName) ;
Writer.WriteString(PropValue) ;
end;
{ TSettings }
Writer.WriteListEnd;
FreeAndNil(Writer) ;
end;
constructor TSettings.Create;
{ TSettings }
constructor TSettings.Create(const DirPath: string);
begin
FFileName := IncludeTrailingPathDelimiter(DirPath) + 'settings.t2v';
FTranspMode := 0;
FStretchMode := False;
end;
initialization
Settings := TSettings.Create;
finalization
FreeAndNil(Settings) ;
end.
end.