/ide/ideprotocol.pas

http://github.com/graemeg/lazarus · Pascal · 133 lines · 85 code · 18 blank · 30 comment · 2 complexity · 4ea8e413c414102ed2f54023ced79801 MD5 · raw file

  1. {
  2. ***************************************************************************
  3. * *
  4. * This source is free software; you can redistribute it and/or modify *
  5. * it under the terms of the GNU General Public License as published by *
  6. * the Free Software Foundation; either version 2 of the License, or *
  7. * (at your option) any later version. *
  8. * *
  9. * This code is distributed in the hope that it will be useful, but *
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  12. * General Public License for more details. *
  13. * *
  14. * A copy of the GNU General Public License is available on the World *
  15. * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
  16. * obtain it by writing to the Free Software Foundation, *
  17. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. * *
  19. ***************************************************************************
  20. Author: Mattias Gaertner
  21. Abstract:
  22. The IDE keeps book about loading projects and forms. When an error occurs,
  23. that kills the IDE, it will not open it automatically again the next time.
  24. }
  25. unit IDEProtocol;
  26. {$mode objfpc}{$H+}
  27. interface
  28. uses
  29. Classes, SysUtils, LCLProc, LazConf, BaseIDEIntf, LazConfigStorage,
  30. LazFileUtils;
  31. const
  32. IDEProtocolOptsVersion: integer = 1;
  33. IDEProtocolFilename = 'protocol.xml';
  34. type
  35. { TIDEProtocol }
  36. TIDEProtocol = class
  37. private
  38. FFilename: string;
  39. FLastProjectLoadingCrashed: boolean;
  40. public
  41. constructor Create;
  42. destructor Destroy; override;
  43. procedure Load;
  44. procedure Save;
  45. procedure LoadFromConfig(Config: TConfigStorage; const Path: string);
  46. procedure SaveToConfig(Config: TConfigStorage; const Path: string);
  47. public
  48. property Filename: string read FFilename write FFilename;
  49. property LastProjectLoadingCrashed: boolean read FLastProjectLoadingCrashed
  50. write FLastProjectLoadingCrashed;
  51. end;
  52. var
  53. IDEProtocolOpts: TIDEProtocol;
  54. implementation
  55. { TIDEProtocol }
  56. constructor TIDEProtocol.Create;
  57. begin
  58. end;
  59. destructor TIDEProtocol.Destroy;
  60. begin
  61. inherited Destroy;
  62. end;
  63. procedure TIDEProtocol.Load;
  64. var
  65. Config: TConfigStorage;
  66. begin
  67. if Filename='' then
  68. Filename:=AppendPathDelim(GetPrimaryConfigPath)+IDEProtocolFilename;
  69. try
  70. Config:=DefaultConfigClass.Create(Filename,true);
  71. try
  72. LoadFromConfig(Config,'Protocol/');
  73. finally
  74. Config.Free;
  75. end;
  76. except
  77. on E: Exception do begin
  78. DebugLn('[TIDEProtocol.Load] error reading "',Filename,'": ',E.Message);
  79. end;
  80. end;
  81. end;
  82. procedure TIDEProtocol.Save;
  83. var
  84. Config: TConfigStorage;
  85. begin
  86. if Filename='' then
  87. Filename:=AppendPathDelim(GetPrimaryConfigPath)+IDEProtocolFilename;
  88. try
  89. Config:=DefaultConfigClass.Create(Filename,false);
  90. try
  91. SaveToConfig(Config,'Protocol/');
  92. Config.WriteToDisk;
  93. finally
  94. Config.Free;
  95. end;
  96. except
  97. on E: Exception do begin
  98. DebugLn('[TIDEProtocol.Save] error writing "',Filename,'": ',E.Message);
  99. end;
  100. end;
  101. end;
  102. procedure TIDEProtocol.LoadFromConfig(Config: TConfigStorage; const Path: string);
  103. begin
  104. FLastProjectLoadingCrashed:=Config.GetValue(Path+'LastProjectLoading/Failed',false);
  105. end;
  106. procedure TIDEProtocol.SaveToConfig(Config: TConfigStorage; const Path: string);
  107. begin
  108. Config.SetValue(Path+'Version',IDEProtocolOptsVersion);
  109. Config.SetDeleteValue(Path+'LastProjectLoading/Failed',
  110. FLastProjectLoadingCrashed,false);
  111. end;
  112. end.