| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- unit ScConfig;
- interface
- uses IniFiles, Classes, ConstVarUnit, SysUtils, ConstMethodUnit;
- type
- TScConfigInfo = class(TObject)
- private
- FStrings : TStrings;
- {string}
- FIniFileName : string;
- {boolean}
- FAutoSaveProjects : Boolean;
- FAllowMfyCode : Boolean;
- FSaveAllProjects : Boolean;
- FSaveRestorePoint : Boolean;
- FAutoCollapse : Boolean;
- FRealTimeCalc : Boolean;
- FMatchCodeOnly : Boolean;
- {integer}
- FAutoSaveInterval : Integer;
- FSearchURL: string;
- FLoginURL: string;
- FRegURL: string;
- FCheckOnLineURL: string;
- FLogoutURL: string;
- FPwdURL: string;
- FServerDateTimeURL: string;
- FOldUserResetPwdURL: string;
- FWebSoftURL: string;
- FWebLoginURL: string;
- FJumpURL: string;
- FShowDrawingCode: Boolean;
- FShowEconomicMark: Boolean;
- FShowDesignQuantity: Boolean;
- FUploadURL: string;
- function CreateInitFile: TIniFile;
- function GetStandardItemLibs(const AProjType: string): TStrings;
- public
- destructor Destroy; override;
- procedure LoadIniFile(const AIniFileName: string);
- procedure SaveIniFile;
- property Strings: TStrings read FStrings;
- {all kinds of properties}
- property AutoSaveInterval : Integer read FAutoSaveInterval write FAutoSaveInterval;
- property AllowMfyCode : Boolean read FAllowMfyCode write FAllowMfyCode;
- property AutoSaveProjects : Boolean read FAutoSaveProjects write FAutoSaveProjects;
- property SaveAllProjects : Boolean read FSaveAllProjects write FSaveAllProjects;
- property SaveRestorePoint : Boolean read FSaveRestorePoint write FSaveRestorePoint;
- property AutoCollapse : Boolean read FAutoCollapse write FAutoCollapse;
- property RealTimeCalc : Boolean read FRealTimeCalc write FRealTimeCalc;
- property MatchCodeOnly : Boolean read FMatchCodeOnly write FMatchCodeOnly;
- property ShowDesignQuantity: Boolean read FShowDesignQuantity write FShowDesignQuantity;
- property ShowEconomicMark : Boolean read FShowEconomicMark write FShowEconomicMark;
- property ShowDrawingCode : Boolean read FShowDrawingCode write FShowDrawingCode;
- // ÒÔÏÂURL by chenshilong, 2012-6-4
- property SearchURL: string read FSearchURL;
- property WebSoftURL: string read FWebSoftURL;
- property LoginURL: string read FLoginURL;
- property WebLoginURL: string read FWebLoginURL;
- property LogoutURL: string read FLogoutURL;
- property RegURL: string read FRegURL;
- property PwdURL: string read FPwdURL;
- property CheckOnLineURL: string read FCheckOnLineURL;
- property ServerDateTimeURL: string read FServerDateTimeURL;
- property OldUserResetPwdURL: string read FOldUserResetPwdURL;
- Property JumpURL: string read FJumpURL;
- property UploadURL: string read FUploadURL;
- end;
- var
- ScConfigInfo: TScConfigInfo;
- function ConfigInfo: TScConfigInfo;
- implementation
- function ConfigInfo: TScConfigInfo;
- begin
- Result := ScConfigInfo;
- end;
- { TScConfigInfo }
- function IniFileFullPath: string;
- begin
- Result := ExtractFilePath(ParamStr(0)) + 'config.ini';
- end;
- function TScConfigInfo.CreateInitFile: TIniFile;
- var
- sFileName: string;
- begin
- sFileName := FIniFileName;
- if not FileExists(sFileName) then
- begin
- Result := nil;
- Exit;
- end;
- Result := TIniFile.Create(sFileName);
- end;
- destructor TScConfigInfo.Destroy;
- begin
- FStrings.Free;
- inherited;
- end;
- function TScConfigInfo.GetStandardItemLibs(
- const AProjType: string): TStrings;
- var
- Ini: TIniFile;
- KeyNames: TStringList;
- I: Integer;
- sTemp: string;
- sKeyNamePrefix: string;
- begin
- Result := TStringList.Create;
-
- Ini := CreateInitFile;
- if Ini = nil then Exit;
- KeyNames := TStringList.Create;
- try
- Ini.ReadSection(SStandardLibs, KeyNames);
- sKeyNamePrefix := AProjType + 'Lib';
- for I := 0 to KeyNames.Count - 1 do
- begin
- if AnsiPos(sKeyNamePrefix, KeyNames[I]) > 0 then
- begin
- sTemp := Trim(Ini.ReadString(SStandardLibs, KeyNames[I], ''));
- if sTemp <> '' then
- Result.Add(FixPathByAppPath(sTemp));
- end;
- end;
- finally
- KeyNames.Free;
- Ini.Free;
- end;
- end;
- procedure TScConfigInfo.LoadIniFile(const AIniFileName: string);
- var
- Ini: TIniFile;
- begin
- Ini := TIniFile.Create(AIniFileName);
- try
- FIniFileName := AIniFileName;
- {Load std Bills Lib}
- FStrings := GetStandardItemLibs(SProjectType);
- {Load other options}
- FAllowMfyCode := Ini.ReadBool(SGeneralOptions, SAllowMfyCode, False);
- FAutoSaveProjects := Ini.ReadBool(SGeneralOptions, SAutoSaveProjects, True);
- FSaveAllProjects := Ini.ReadBool(SGeneralOptions, SSaveAllProjects, True);
- FSaveRestorePoint := Ini.ReadBool(SGeneralOptions, SSaveRestorePoint, True);
- FAutoCollapse := Ini.ReadBool(SGeneralOptions, SAutoCollapse, True);
- FRealTimeCalc := Ini.ReadBool(SGeneralOptions, SRealTimeCalc, True);
- FMatchCodeOnly := Ini.ReadBool(SGatherOptions, SMatchCodeOnly, True);
- FShowDesignQuantity := Ini.ReadBool('ViewOptions', 'ShowDesignQuantity', True);
- FShowEconomicMark := Ini.ReadBool('ViewOptions', 'ShowEconomicMark', True);
- FShowDrawingCode := Ini.ReadBool('ViewOptions', 'ShowDrawingCode', False);
- FAutoSaveInterval := Ini.ReadInteger(SGeneralOptions, SAutoSaveInterval, 5);
- FSearchURL := Ini.ReadString('URL', 'SearchURL', '');
- FWebSoftURL := Ini.ReadString('URL', 'WebSoftURL', '');
- FLoginURL := FWebSoftURL + Ini.ReadString('URL', 'LoginURL', '');
- FWebLoginURL := FWebSoftURL + Ini.ReadString('URL', 'WebLoginURL', '');
- FRegURL := FWebSoftURL + Ini.ReadString('URL', 'RegURL', '');
- FPwdURL := FWebSoftURL + Ini.ReadString('URL', 'PwdURL', '');
- FCheckOnLineURL := FWebSoftURL + Ini.ReadString('URL', 'CheckOnLineURL', '');
- FLogoutURL := FWebSoftURL + Ini.ReadString('URL', 'LogoutURL', '');
- FServerDateTimeURL := FWebSoftURL + Ini.ReadString('URL', 'ServerDateTimeURL', '');
- FOldUserResetPwdURL := FWebSoftURL + Ini.ReadString('URL', 'OldUserResetPwdURL', '');
- FJumpURL := FWebSoftURL + Ini.ReadString('URL', 'JumpURL', 'ScJump.php');
- FUploadURL := FWebSoftURL + Ini.ReadString('URL', 'UploadURL', 'ScUploadFile.php');
- finally
- Ini.Free;
- end;
- end;
- procedure TScConfigInfo.SaveIniFile;
- var
- Ini: TIniFile;
- begin
- Ini := TIniFile.Create(FIniFileName);
- try
- {save other options}
- Ini.WriteBool(SGeneralOptions, SAllowMfyCode, FAllowMfyCode);
- Ini.WriteBool(SGeneralOptions, SAutoSaveProjects, FAutoSaveProjects);
- Ini.WriteBool(SGeneralOptions, SSaveAllProjects, FSaveAllProjects);
- Ini.WriteBool(SGeneralOptions, SSaveRestorePoint, FSaveRestorePoint);
- Ini.WriteBool(SGeneralOptions, SAutoCollapse, FAutoCollapse);
- Ini.WriteBool(SGeneralOptions, SRealTimeCalc, FRealTimeCalc);
- Ini.WriteBool(SGatherOptions, SMatchCodeOnly, FMatchCodeOnly);
- Ini.WriteBool('ViewOptions', 'ShowDesignQuantity', FShowDesignQuantity);
- Ini.WriteBool('ViewOptions', 'ShowEconomicMark', FShowEconomicMark);
- Ini.WriteBool('ViewOptions', 'ShowDrawingCode', FShowDrawingCode);
- Ini.WriteInteger(SGeneralOptions, SAutoSaveInterval, FAutoSaveInterval);
- finally
- Ini.Free;
- end;
- end;
- initialization
- ScConfigInfo := TScConfigInfo.Create;
- ScConfigInfo.LoadIniFile(IniFileFullPath);
- finalization
- ScConfigInfo.Free;
- end.
|