1 {
2 *****************************************************************************
3 *                                                                           *
4 *  This file is part of the ZCAD                                            *
5 *                                                                           *
6 *  See the file COPYING.modifiedLGPL.txt, included in this distribution,    *
7 *  for details about the copyright.                                         *
8 *                                                                           *
9 *  This program is distributed in the hope that it will be useful,          *
10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
12 *                                                                           *
13 *****************************************************************************
14 }
15 {
16 @author(Andrey Zubarev <zamtmn@yandex.ru>)
17 }
18 
19 unit uzcsysparams;
20 {$INCLUDE def.inc}
21 interface
22 uses XMLConf,XMLPropStorage,LazConfigStorage,fileutil,
23   LCLProc,uzclog,uzbpaths,uzbtypesbase,Forms,uzbtypes{$IFNDEF DELPHI},LazUTF8{$ENDIF},sysutils;
24 {$INCLUDE revision.inc}
25 type
26 {EXPORT+}
27   TmyFileVersionInfo=packed record
28     major,minor,release,build,revision:GDBInteger;
29     versionstring:GDBstring;
30   end;
31   tsavedparams=packed record
32     UniqueInstance:GDBBoolean;(*'Unique instance'*)
33     NoSplash:GDBBoolean;(*'No splash screen'*)
34     NoLoadLayout:GDBBoolean;(*'No load layout'*)
35     UpdatePO:GDBBoolean;(*'Update PO file'*)
36   end;
37   tnotsavedparams=packed record
38     ScreenX:GDBInteger;(*'Screen X'*)(*oi_readonly*)
39     ScreenY:GDBInteger;(*'Screen Y'*)(*oi_readonly*)
40     otherinstancerun:GDBBoolean;(*'Other instance run'*)(*oi_readonly*)
41     PreloadedFile:GDBString;(*'Preloaded file'*)(*oi_readonly*)
42     Ver:TmyFileVersionInfo;(*'Version'*)(*oi_readonly*)
43     DefaultHeight:GDBInteger;(*'Default controls height'*)(*oi_readonly*)
44   end;
45   ptsysparam=^tsysparam;
46   tsysparam=packed record
47     saved:tsavedparams;(*'Saved params'*)
48     notsaved:tnotsavedparams;(*'Not saved params'*)(*oi_readonly*)
49   end;
50 {EXPORT-}
51 const
52   DefaultSavedParams:tsavedparams=(UniqueInstance:true;
53                                    NoSplash:false;
54                                    NoLoadLayout:false;
55                                    UpdatePO:false);
56 var
57   SysParam: tsysparam;
58 
59 procedure SaveParams(xmlfile:string;var Params:tsavedparams);
60 procedure LoadParams(xmlfile:string;out Params:tsavedparams);
61 implementation
62 procedure SaveParamToConfig(Config: TConfigStorage; var Params:tsavedparams);
63 begin
64   Config.AppendBasePath('Stage0Params/');
65   Config.SetDeleteValue('UniqueInstance',Params.UniqueInstance,DefaultSavedParams.UniqueInstance);
66   Config.SetDeleteValue('NoSplash',Params.NoSplash,DefaultSavedParams.NoSplash);
67   Config.SetDeleteValue('NoLoadLayout',Params.NoLoadLayout,DefaultSavedParams.NoLoadLayout);
68   Config.SetDeleteValue('UpdatePO',Params.UpdatePO,DefaultSavedParams.UpdatePO);
69   Config.UndoAppendBasePath;
70 end;
71 
72 procedure SaveParams(xmlfile:string;var Params:tsavedparams);
73 var
74   XMLConfig: TXMLConfig;
75   Config: TXMLConfigStorage;
76 begin
77   If FileExists(xmlfile) then
78     DeleteFile(xmlfile);
79   XMLConfig:=TXMLConfig.Create(nil);
80   try
81     XMLConfig.StartEmpty:=true;
82     XMLConfig.Filename:=xmlfile;
83     Config:=TXMLConfigStorage.Create(XMLConfig);
84     try
85       SaveParamToConfig(Config,Params);
86     finally
87       Config.Free;
88     end;
89     XMLConfig.Flush;
90   finally
91     XMLConfig.Free;
92   end;
93 end;
94 procedure LoadParams(xmlfile:string;out Params:tsavedparams);
95 var
96   XMLConfig:TXMLConfig;
97 begin
98   Params:=DefaultSavedParams;
99   XMLConfig:=TXMLConfig.Create(nil);
100   XMLConfig.Filename:=xmlfile;
101   XMLConfig.OpenKey('Stage0Params');
102   Params.UniqueInstance:=XMLConfig.GetValue('UniqueInstance',DefaultSavedParams.UniqueInstance);
103   Params.NoSplash:=XMLConfig.GetValue('NoSplash',DefaultSavedParams.NoSplash);
104   Params.NoLoadLayout:=XMLConfig.GetValue('NoLoadLayout',DefaultSavedParams.NoLoadLayout);
105   Params.UpdatePO:=XMLConfig.GetValue('UpdatePO',DefaultSavedParams.UpdatePO);
106   XMLConfig.CloseKey;
107 end;
108 
109 
110 
111 end.
112