ScConfig.pas 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. unit ScConfig;
  2. interface
  3. uses IniFiles, Classes, ConstVarUnit, SysUtils, ConstMethodUnit;
  4. type
  5. TScConfigInfo = class(TObject)
  6. private
  7. FStrings : TStrings;
  8. {string}
  9. FIniFileName : string;
  10. {boolean}
  11. FAutoSaveProjects : Boolean;
  12. FAllowMfyCode : Boolean;
  13. FSaveAllProjects : Boolean;
  14. FSaveRestorePoint : Boolean;
  15. FAutoCollapse : Boolean;
  16. FRealTimeCalc : Boolean;
  17. FMatchCodeOnly : Boolean;
  18. {integer}
  19. FAutoSaveInterval : Integer;
  20. FSearchURL: string;
  21. FLoginURL: string;
  22. FRegURL: string;
  23. FCheckOnLineURL: string;
  24. FLogoutURL: string;
  25. FPwdURL: string;
  26. FServerDateTimeURL: string;
  27. FOldUserResetPwdURL: string;
  28. FWebSoftURL: string;
  29. FWebLoginURL: string;
  30. FJumpURL: string;
  31. FShowDrawingCode: Boolean;
  32. FShowEconomicMark: Boolean;
  33. FShowDesignQuantity: Boolean;
  34. FUploadURL: string;
  35. function CreateInitFile: TIniFile;
  36. function GetStandardItemLibs(const AProjType: string): TStrings;
  37. public
  38. destructor Destroy; override;
  39. procedure LoadIniFile(const AIniFileName: string);
  40. procedure SaveIniFile;
  41. property Strings: TStrings read FStrings;
  42. {all kinds of properties}
  43. property AutoSaveInterval : Integer read FAutoSaveInterval write FAutoSaveInterval;
  44. property AllowMfyCode : Boolean read FAllowMfyCode write FAllowMfyCode;
  45. property AutoSaveProjects : Boolean read FAutoSaveProjects write FAutoSaveProjects;
  46. property SaveAllProjects : Boolean read FSaveAllProjects write FSaveAllProjects;
  47. property SaveRestorePoint : Boolean read FSaveRestorePoint write FSaveRestorePoint;
  48. property AutoCollapse : Boolean read FAutoCollapse write FAutoCollapse;
  49. property RealTimeCalc : Boolean read FRealTimeCalc write FRealTimeCalc;
  50. property MatchCodeOnly : Boolean read FMatchCodeOnly write FMatchCodeOnly;
  51. property ShowDesignQuantity: Boolean read FShowDesignQuantity write FShowDesignQuantity;
  52. property ShowEconomicMark : Boolean read FShowEconomicMark write FShowEconomicMark;
  53. property ShowDrawingCode : Boolean read FShowDrawingCode write FShowDrawingCode;
  54. // ÒÔÏÂURL by chenshilong, 2012-6-4
  55. property SearchURL: string read FSearchURL;
  56. property WebSoftURL: string read FWebSoftURL;
  57. property LoginURL: string read FLoginURL;
  58. property WebLoginURL: string read FWebLoginURL;
  59. property LogoutURL: string read FLogoutURL;
  60. property RegURL: string read FRegURL;
  61. property PwdURL: string read FPwdURL;
  62. property CheckOnLineURL: string read FCheckOnLineURL;
  63. property ServerDateTimeURL: string read FServerDateTimeURL;
  64. property OldUserResetPwdURL: string read FOldUserResetPwdURL;
  65. Property JumpURL: string read FJumpURL;
  66. property UploadURL: string read FUploadURL;
  67. end;
  68. var
  69. ScConfigInfo: TScConfigInfo;
  70. function ConfigInfo: TScConfigInfo;
  71. implementation
  72. function ConfigInfo: TScConfigInfo;
  73. begin
  74. Result := ScConfigInfo;
  75. end;
  76. { TScConfigInfo }
  77. function IniFileFullPath: string;
  78. begin
  79. Result := ExtractFilePath(ParamStr(0)) + 'config.ini';
  80. end;
  81. function TScConfigInfo.CreateInitFile: TIniFile;
  82. var
  83. sFileName: string;
  84. begin
  85. sFileName := FIniFileName;
  86. if not FileExists(sFileName) then
  87. begin
  88. Result := nil;
  89. Exit;
  90. end;
  91. Result := TIniFile.Create(sFileName);
  92. end;
  93. destructor TScConfigInfo.Destroy;
  94. begin
  95. FStrings.Free;
  96. inherited;
  97. end;
  98. function TScConfigInfo.GetStandardItemLibs(
  99. const AProjType: string): TStrings;
  100. var
  101. Ini: TIniFile;
  102. KeyNames: TStringList;
  103. I: Integer;
  104. sTemp: string;
  105. sKeyNamePrefix: string;
  106. begin
  107. Result := TStringList.Create;
  108. Ini := CreateInitFile;
  109. if Ini = nil then Exit;
  110. KeyNames := TStringList.Create;
  111. try
  112. Ini.ReadSection(SStandardLibs, KeyNames);
  113. sKeyNamePrefix := AProjType + 'Lib';
  114. for I := 0 to KeyNames.Count - 1 do
  115. begin
  116. if AnsiPos(sKeyNamePrefix, KeyNames[I]) > 0 then
  117. begin
  118. sTemp := Trim(Ini.ReadString(SStandardLibs, KeyNames[I], ''));
  119. if sTemp <> '' then
  120. Result.Add(FixPathByAppPath(sTemp));
  121. end;
  122. end;
  123. finally
  124. KeyNames.Free;
  125. Ini.Free;
  126. end;
  127. end;
  128. procedure TScConfigInfo.LoadIniFile(const AIniFileName: string);
  129. var
  130. Ini: TIniFile;
  131. begin
  132. Ini := TIniFile.Create(AIniFileName);
  133. try
  134. FIniFileName := AIniFileName;
  135. {Load std Bills Lib}
  136. FStrings := GetStandardItemLibs(SProjectType);
  137. {Load other options}
  138. FAllowMfyCode := Ini.ReadBool(SGeneralOptions, SAllowMfyCode, False);
  139. FAutoSaveProjects := Ini.ReadBool(SGeneralOptions, SAutoSaveProjects, True);
  140. FSaveAllProjects := Ini.ReadBool(SGeneralOptions, SSaveAllProjects, True);
  141. FSaveRestorePoint := Ini.ReadBool(SGeneralOptions, SSaveRestorePoint, True);
  142. FAutoCollapse := Ini.ReadBool(SGeneralOptions, SAutoCollapse, True);
  143. FRealTimeCalc := Ini.ReadBool(SGeneralOptions, SRealTimeCalc, True);
  144. FMatchCodeOnly := Ini.ReadBool(SGatherOptions, SMatchCodeOnly, True);
  145. FShowDesignQuantity := Ini.ReadBool('ViewOptions', 'ShowDesignQuantity', True);
  146. FShowEconomicMark := Ini.ReadBool('ViewOptions', 'ShowEconomicMark', True);
  147. FShowDrawingCode := Ini.ReadBool('ViewOptions', 'ShowDrawingCode', False);
  148. FAutoSaveInterval := Ini.ReadInteger(SGeneralOptions, SAutoSaveInterval, 5);
  149. FSearchURL := Ini.ReadString('URL', 'SearchURL', '');
  150. FWebSoftURL := Ini.ReadString('URL', 'WebSoftURL', '');
  151. FLoginURL := FWebSoftURL + Ini.ReadString('URL', 'LoginURL', '');
  152. FWebLoginURL := FWebSoftURL + Ini.ReadString('URL', 'WebLoginURL', '');
  153. FRegURL := FWebSoftURL + Ini.ReadString('URL', 'RegURL', '');
  154. FPwdURL := FWebSoftURL + Ini.ReadString('URL', 'PwdURL', '');
  155. FCheckOnLineURL := FWebSoftURL + Ini.ReadString('URL', 'CheckOnLineURL', '');
  156. FLogoutURL := FWebSoftURL + Ini.ReadString('URL', 'LogoutURL', '');
  157. FServerDateTimeURL := FWebSoftURL + Ini.ReadString('URL', 'ServerDateTimeURL', '');
  158. FOldUserResetPwdURL := FWebSoftURL + Ini.ReadString('URL', 'OldUserResetPwdURL', '');
  159. FJumpURL := FWebSoftURL + Ini.ReadString('URL', 'JumpURL', 'ScJump.php');
  160. FUploadURL := FWebSoftURL + Ini.ReadString('URL', 'UploadURL', 'ScUploadFile.php');
  161. finally
  162. Ini.Free;
  163. end;
  164. end;
  165. procedure TScConfigInfo.SaveIniFile;
  166. var
  167. Ini: TIniFile;
  168. begin
  169. Ini := TIniFile.Create(FIniFileName);
  170. try
  171. {save other options}
  172. Ini.WriteBool(SGeneralOptions, SAllowMfyCode, FAllowMfyCode);
  173. Ini.WriteBool(SGeneralOptions, SAutoSaveProjects, FAutoSaveProjects);
  174. Ini.WriteBool(SGeneralOptions, SSaveAllProjects, FSaveAllProjects);
  175. Ini.WriteBool(SGeneralOptions, SSaveRestorePoint, FSaveRestorePoint);
  176. Ini.WriteBool(SGeneralOptions, SAutoCollapse, FAutoCollapse);
  177. Ini.WriteBool(SGeneralOptions, SRealTimeCalc, FRealTimeCalc);
  178. Ini.WriteBool(SGatherOptions, SMatchCodeOnly, FMatchCodeOnly);
  179. Ini.WriteBool('ViewOptions', 'ShowDesignQuantity', FShowDesignQuantity);
  180. Ini.WriteBool('ViewOptions', 'ShowEconomicMark', FShowEconomicMark);
  181. Ini.WriteBool('ViewOptions', 'ShowDrawingCode', FShowDrawingCode);
  182. Ini.WriteInteger(SGeneralOptions, SAutoSaveInterval, FAutoSaveInterval);
  183. finally
  184. Ini.Free;
  185. end;
  186. end;
  187. initialization
  188. ScConfigInfo := TScConfigInfo.Create;
  189. ScConfigInfo.LoadIniFile(IniFileFullPath);
  190. finalization
  191. ScConfigInfo.Free;
  192. end.