fpini.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Write/Read Options to INI File
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit FPIni;
  12. interface
  13. {$i globdir.inc}
  14. uses
  15. FPUtils;
  16. procedure InitDirs;
  17. procedure InitINIFile;
  18. procedure CheckINIFile;
  19. function ReadINIFile: boolean;
  20. function WriteINIFile(FromSaveAs : boolean) : boolean;
  21. function GetPrinterDevice: string;
  22. procedure SetPrinterDevice(const Device: string);
  23. implementation
  24. uses
  25. Dos,Objects,Drivers,
  26. FVConsts,
  27. Version,
  28. {$ifdef USE_EXTERNAL_COMPILER}
  29. fpintf, { superseeds version_string of version unit }
  30. {$endif USE_EXTERNAL_COMPILER}
  31. WConsts,WUtils,WINI,WViews,WEditor,WCEdit,
  32. {$ifndef NODEBUG}FPDebug,{$endif}FPConst,FPVars,
  33. FPIntf,FPTools,FPSwitch,FPString;
  34. const
  35. PrinterDevice : string = 'prn';
  36. function GetPrinterDevice: string;
  37. begin
  38. GetPrinterDevice:=PrinterDevice;
  39. end;
  40. procedure SetPrinterDevice(const Device: string);
  41. begin
  42. PrinterDevice:=Device;
  43. end;
  44. const
  45. { INI file sections }
  46. secFiles = 'Files';
  47. secRun = 'Run';
  48. secCompile = 'Compile';
  49. secColors = 'Colors';
  50. secHelp = 'Help';
  51. secEditor = 'Editor';
  52. secBreakpoint = 'Breakpoints';
  53. secWatches = 'Watches';
  54. secHighlight = 'Highlight';
  55. secMouse = 'Mouse';
  56. secSearch = 'Search';
  57. secTools = 'Tools';
  58. secSourcePath = 'SourcePath';
  59. secPreferences = 'Preferences';
  60. secMisc = 'Misc';
  61. { INI file tags }
  62. ieRecentFile = 'RecentFile';
  63. iePrinterDevice = 'PrinterDevice';
  64. (* ieOpenFile = 'OpenFile';
  65. ieOpenFileCount = 'OpenFileCount'; *)
  66. ieRunDir = 'RunDirectory';
  67. ieRunParameters = 'Parameters';
  68. ieDebuggeeRedir = 'DebugRedirection';
  69. ieRemoteMachine = 'RemoteMachine';
  70. ieRemotePort = 'RemotePort';
  71. ieRemoteSendCommand = 'RemoteSendCommand';
  72. ieRemoteConfig = 'RemoteSendConfig';
  73. ieRemoteIdent = 'RemoteSendIdent';
  74. ieRemoteDirectory = 'RemoteDirectory';
  75. iePrimaryFile = 'PrimaryFile';
  76. ieCompileMode = 'CompileMode';
  77. iePalette = 'Palette';
  78. ieHelpFiles = 'Files';
  79. ieDefaultTabSize = 'DefaultTabSize';
  80. ieDefaultIndentSize = 'DefaultIndentSize';
  81. ieDefaultEditorFlags='DefaultFlags';
  82. ieDefaultSaveExt = 'DefaultSaveExt';
  83. ieOpenExts = 'OpenExts';
  84. ieHighlightExts = 'Exts';
  85. ieTabsPattern = 'NeedsTabs';
  86. ieDoubleClickDelay = 'DoubleDelay';
  87. ieReverseButtons = 'ReverseButtons';
  88. ieAltClickAction = 'AltClickAction';
  89. ieCtrlClickAction = 'CtrlClickAction';
  90. ieFindFlags = 'FindFlags';
  91. ieToolName = 'Title';
  92. ieToolProgram = 'Program';
  93. ieToolParams = 'Params';
  94. ieToolHotKey = 'HotKey';
  95. ieBreakpointTyp = 'Type';
  96. ieBreakpointCount = 'Count';
  97. ieBreakpointState = 'State';
  98. ieBreakpointName = 'Name';
  99. ieBreakpointFile = 'FileName';
  100. ieBreakpointLine = 'LineNumber';
  101. ieBreakpointCond = 'Condition';
  102. ieWatchCount = 'Count';
  103. ieWatchName = 'Watch';
  104. ieSourceList = 'SourceList';
  105. { ieVideoMode = 'VideoMode';}
  106. ieAutoSave = 'AutoSaveFlags';
  107. ieMiscOptions = 'MiscOptions';
  108. ieDesktopLocation = 'DesktopLocation';
  109. ieDesktopFlags = 'DesktopFileFlags';
  110. ieCenterDebuggerRow= 'CenterCurrentLineWhileDebugging';
  111. ieShowReadme = 'ShowReadme';
  112. Procedure InitDirs;
  113. begin
  114. StartupDir:=CompleteDir(FExpand('.'));
  115. {$ifndef unix}
  116. IDEDir:=CompleteDir(DirOf(system.Paramstr(0)));
  117. {$else}
  118. SystemIDEDir:='/usr/lib/fpc/'+version_string+'/ide/text';
  119. IDEdir:=CompleteDir(FExpand('~/.fp'));
  120. If Not ExistsDir(IDEdir) Then
  121. begin
  122. IDEDir:=SystemIDEDir;
  123. if Not ExistsDir(IDEDir) then
  124. begin
  125. if DirOf(system.paramstr(0))<>'' then
  126. IDEDir:=CompleteDir(DirOf(system.ParamStr(0)))
  127. else
  128. IDEDir:=StartupDir;
  129. end;
  130. end;
  131. {$endif}
  132. end;
  133. procedure InitINIFile;
  134. var S: string;
  135. begin
  136. S:=LocateFile(INIFileName);
  137. if S<>'' then
  138. IniFileName:=S;
  139. IniFileName:=FExpand(IniFileName);
  140. end;
  141. procedure CheckINIFile;
  142. var IniDir,CurDir: DirStr;
  143. INI: PINIFile;
  144. const Btns : array[1..2] of string = (btn_config_copyexisting,btn_config_createnew);
  145. begin
  146. IniDir:=DirOf(IniFileName); CurDir:=GetCurDir;
  147. if CompareText(IniDir,CurDir)<>0 then
  148. if not ExistsFile(CurDir+DirInfoName) then
  149. if ConfirmBox(FormatStrStr(msg_doyouwanttocreatelocalconfigfile,IniDir),nil,false)=cmYes then
  150. begin
  151. if (not ExistsFile(IniFileName)) or
  152. (ChoiceBox(msg_configcopyexistingorcreatenew,nil,
  153. Btns,false)=cmUserBtn2) then
  154. begin
  155. { create new config here }
  156. IniFileName:=CurDir+IniName;
  157. SwitchesPath:=CurDir+SwitchesName;
  158. end
  159. else
  160. begin
  161. { copy config here }
  162. if CopyFile(IniFileName,CurDir+IniName)=false then
  163. ErrorBox(FormatStrStr(msg_errorwritingfile,CurDir+IniName),nil)
  164. else
  165. IniFileName:=CurDir+IniName;
  166. if CopyFile(SwitchesPath,CurDir+SwitchesName)=false then
  167. ErrorBox(FormatStrStr(msg_errorwritingfile,CurDir+SwitchesName),nil)
  168. else
  169. SwitchesPath:=CurDir+SwitchesName;
  170. end;
  171. end
  172. else
  173. begin
  174. New(INI, Init(CurDir+DirInfoName));
  175. INI^.SetEntry(MainSectionName,'Comment','Do NOT delete this file!!!');
  176. if INI^.Update=false then
  177. ErrorBox(FormatStrStr(msg_errorwritingfile,INI^.GetFileName),nil);
  178. Dispose(INI, Done);
  179. end;
  180. end;
  181. function PaletteToStr(S: string): string;
  182. var C: string;
  183. I: integer;
  184. begin
  185. C:='';
  186. for I:=1 to length(S) do
  187. begin
  188. Insert('#$'+IntToHex(ord(S[I]),2),C,Length(C)+1);
  189. end;
  190. PaletteToStr:=C;
  191. end;
  192. function StrToPalette(S: string): string;
  193. var I,P,X: integer;
  194. C: string;
  195. Hex: boolean;
  196. OK: boolean;
  197. begin
  198. C:=''; I:=1;
  199. OK:=S<>'';
  200. while OK and (I<=length(S)) and (S[I]='#') do
  201. begin
  202. Inc(I); Hex:=false;
  203. if S[I]='$' then begin Inc(I); Hex:=true; end;
  204. P:=Pos('#',copy(S,I,High(S))); if P>0 then P:=I+P-1 else P:=length(S)+1;
  205. if Hex=false then
  206. begin
  207. X:=StrToInt(copy(S,I,P-I));
  208. OK:=(LastStrToIntResult=0) and (0<=X) and (X<=High(S));
  209. end
  210. else
  211. begin
  212. X:=HexToInt(copy(S,I,P-I));
  213. OK:=(LastHexToIntResult=0) and (0<=X) and (X<=255);
  214. end;
  215. if OK then C:=C+chr(X);
  216. Inc(I,P-I);
  217. end;
  218. StrToPalette:=C;
  219. end;
  220. {$ifndef NODEBUG}
  221. procedure WriteOneWatchEntry(I : Longint;INIFile : PINIFile);
  222. var
  223. PW : PWatch;
  224. S : String;
  225. begin
  226. Str(I,S);
  227. PW:=WatchesCollection^.At(I);
  228. With PW^ do
  229. begin
  230. INIFile^.SetEntry(secWatches,ieWatchName+S,GetStr(expr));
  231. end;
  232. end;
  233. procedure WriteOneBreakPointEntry(I : longint;INIFile : PINIFile);
  234. var PB : PBreakpoint;
  235. S : String;
  236. begin
  237. Str(I,S);
  238. PB:=BreakpointsCollection^.At(I);
  239. If assigned(PB) then
  240. With PB^ do
  241. Begin
  242. INIFile^.SetEntry(secBreakpoint,ieBreakpointTyp+S,BreakpointTypeStr[typ]);
  243. INIFile^.SetEntry(secBreakpoint,ieBreakpointState+S,BreakpointStateStr[state]);
  244. if typ=bt_file_line then
  245. begin
  246. INIFile^.SetEntry(secBreakpoint,ieBreakpointFile+S,FileName^);
  247. INIFile^.SetIntEntry(secBreakpoint,ieBreakpointLine+S,Line);
  248. end
  249. else
  250. INIFile^.SetEntry(secBreakpoint,ieBreakpointName+S,Name^);
  251. if assigned(Conditions) then
  252. INIFile^.SetEntry(secBreakpoint,ieBreakpointCond+S,Conditions^)
  253. else
  254. INIFile^.SetEntry(secBreakpoint,ieBreakpointCond+S,'');
  255. end;
  256. end;
  257. procedure ReadOneWatchEntry(I : Longint;INIFile : PINIFile);
  258. var
  259. PW : PWatch;
  260. S : String;
  261. begin
  262. Str(I,S);
  263. PW:=new(PWatch,Init(INIFile^.GetEntry(secWatches,ieWatchName+S,'')));
  264. WatchesCollection^.Insert(PW);
  265. end;
  266. procedure ReadOneBreakPointEntry(i : longint;INIFile : PINIFile);
  267. var PB : PBreakpoint;
  268. S,S2,SC : string;
  269. Line : longint;
  270. typ : BreakpointType;
  271. state : BreakpointState;
  272. begin
  273. Str(I,S2);
  274. typ:=bt_invalid;
  275. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointTyp+S2,BreakpointTypeStr[typ]);
  276. for typ:=low(BreakpointType) to high(BreakpointType) do
  277. If pos(BreakpointTypeStr[typ],S)>0 then break;
  278. state:=bs_deleted;
  279. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointState+S2,BreakpointStateStr[state]);
  280. for state:=low(BreakpointState) to high(BreakpointState) do
  281. If pos(BreakpointStateStr[state],S)>0 then break;
  282. case typ of
  283. bt_invalid :;
  284. bt_file_line :
  285. begin
  286. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointFile+S2,'');
  287. Line:=INIFile^.GetIntEntry(secBreakpoint,ieBreakpointLine+S2,0);
  288. end;
  289. else
  290. begin
  291. S:=INIFile^.GetEntry(secBreakpoint,ieBreakpointName+S2,'');
  292. end;
  293. end;
  294. SC:=INIFile^.GetEntry(secBreakpoint,ieBreakpointCond+S2,'');
  295. if (typ=bt_function) and (S<>'') then
  296. new(PB,init_function(S))
  297. else if (typ=bt_file_line) and (S<>'') then
  298. new(PB,init_file_line(S,Line))
  299. else
  300. new(PB,init_type(typ,S));
  301. If assigned(PB) then
  302. begin
  303. PB^.state:=state;
  304. If SC<>'' then
  305. PB^.conditions:=NewStr(SC);
  306. BreakpointsCollection^.Insert(PB);
  307. end;
  308. end;
  309. {$endif NODEBUG}
  310. function ReadINIFile: boolean;
  311. var INIFile: PINIFile;
  312. S,PS,S1,S2,S3: string;
  313. I,P: integer;
  314. BreakPointCount,WatchesCount:longint;
  315. OK: boolean;
  316. ts : TSwitchMode;
  317. W: word;
  318. begin
  319. OK:=ExistsFile(IniFileName);
  320. if OK then
  321. begin
  322. New(INIFile, Init(IniFileName));
  323. { Files }
  324. OpenExts:=INIFile^.GetEntry(secFiles,ieOpenExts,OpenExts);
  325. RecentFileCount:=High(RecentFiles);
  326. for I:=Low(RecentFiles) to High(RecentFiles) do
  327. begin
  328. S:=INIFile^.GetEntry(secFiles,ieRecentFile+IntToStr(I),'');
  329. if (S='') and (RecentFileCount>I-1) then RecentFileCount:=I-1;
  330. with RecentFiles[I] do
  331. begin
  332. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  333. FileName:=copy(S,1,P-1); Delete(S,1,P);
  334. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  335. LastPos.X:=Max(0,StrToInt(copy(S,1,P-1))); Delete(S,1,P);
  336. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  337. LastPos.Y:=Max(0,StrToInt(copy(S,1,P-1))); Delete(S,1,P);
  338. end;
  339. end;
  340. { Run }
  341. SetRunDir(INIFile^.GetEntry(secRun,ieRunDir,GetRunDir));
  342. SetRunParameters(INIFile^.GetEntry(secRun,ieRunParameters,GetRunParameters));
  343. SetPrinterDevice(INIFile^.GetEntry(secFiles,iePrinterDevice,GetPrinterDevice));
  344. { First read the primary file, which can also set the parameters which can
  345. be overruled with the parameter loading }
  346. SetPrimaryFile(INIFile^.GetEntry(secCompile,iePrimaryFile,PrimaryFile));
  347. DebuggeeTTY := INIFile^.GetEntry(secRun,ieDebuggeeRedir,DebuggeeTTY);
  348. {$ifdef SUPPORT_REMOTE}
  349. RemoteMachine :=INIFile^.GetEntry(secRun,ieRemoteMachine,RemoteMachine);
  350. RemotePort :=INIFile^.GetEntry(secRun,ieRemotePort,RemotePort);
  351. RemoteSendCommand :=INIFile^.GetEntry(secRun,ieRemoteSendCommand,RemoteSendCommand);
  352. RemoteConfig :=INIFile^.GetEntry(secRun,ieRemoteConfig,RemoteConfig);
  353. RemoteIdent :=INIFile^.GetEntry(secRun,ieRemoteIdent,RemoteIdent);
  354. RemoteDir :=INIFile^.GetEntry(secRun,ieRemoteDirectory,RemoteDir);
  355. {$endif SUPPORT_REMOTE}
  356. { Compile }
  357. S:=INIFile^.GetEntry(secCompile,ieCompileMode,'');
  358. for ts:=low(TSwitchMode) to high(TSwitchMode) do
  359. begin
  360. if SwitchesModeStr[ts]=S then
  361. SwitchesMode:=ts;
  362. end;
  363. { Help }
  364. S:=INIFile^.GetEntry(secHelp,ieHelpFiles,'');
  365. repeat
  366. P:=Pos(';',S); if P=0 then P:=length(S)+1;
  367. PS:=copy(S,1,P-1);
  368. if PS<>'' then HelpFiles^.Insert(NewStr(PS));
  369. Delete(S,1,P);
  370. until S='';
  371. { Editor }
  372. DefaultTabSize:=INIFile^.GetIntEntry(secEditor,ieDefaultTabSize,DefaultTabSize);
  373. DefaultIndentSize:=INIFile^.GetIntEntry(secEditor,ieDefaultIndentSize,DefaultIndentSize);
  374. DefaultCodeEditorFlags:=INIFile^.GetIntEntry(secEditor,ieDefaultEditorFlags,DefaultCodeEditorFlags);
  375. DefaultSaveExt:=INIFile^.GetEntry(secEditor,ieDefaultSaveExt,DefaultSaveExt);
  376. { Highlight }
  377. HighlightExts:=INIFile^.GetEntry(secHighlight,ieHighlightExts,HighlightExts);
  378. TabsPattern:=INIFile^.GetEntry(secHighlight,ieTabsPattern,TabsPattern);
  379. { SourcePath }
  380. SourceDirs:=INIFile^.GetEntry(secSourcePath,ieSourceList,SourceDirs);
  381. { Mouse }
  382. DoubleDelay:=INIFile^.GetIntEntry(secMouse,ieDoubleClickDelay,DoubleDelay);
  383. MouseReverse:=boolean(INIFile^.GetIntEntry(secMouse,ieReverseButtons,byte(MouseReverse)));
  384. AltMouseAction:=INIFile^.GetIntEntry(secMouse,ieAltClickAction,AltMouseAction);
  385. CtrlMouseAction:=INIFile^.GetIntEntry(secMouse,ieCtrlClickAction,CtrlMouseAction);
  386. { Search }
  387. FindFlags:=INIFile^.GetIntEntry(secSearch,ieFindFlags,FindFlags);
  388. { Breakpoints }
  389. {$ifndef NODEBUG}
  390. BreakpointCount:=INIFile^.GetIntEntry(secBreakpoint,ieBreakpointCount,0);
  391. for i:=1 to BreakpointCount do
  392. ReadOneBreakPointEntry(i-1,INIFile);
  393. WatchesCount:=INIFile^.GetIntEntry(secWatches,ieWatchCount,0);
  394. for i:=1 to WatchesCount do
  395. ReadOneWatchEntry(i-1,INIFile);
  396. {$endif}
  397. { Tools }
  398. for I:=1 to MaxToolCount do
  399. begin
  400. S:=IntToStr(I);
  401. S1:=INIFile^.GetEntry(secTools,ieToolName+S,'');
  402. if S1='' then Break; { !!! }
  403. S2:=INIFile^.GetEntry(secTools,ieToolProgram+S,'');
  404. S3:=INIFile^.GetEntry(secTools,ieToolParams+S,'');
  405. W:=Max(0,Min(65535,INIFile^.GetIntEntry(secTools,ieToolHotKey+S,0)));
  406. AddTool(S1,S2,S3,W);
  407. end;
  408. { Colors }
  409. S:=AppPalette;
  410. PS:=StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_1_40',PaletteToStr(copy(S,1,40))));
  411. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_41_80',PaletteToStr(copy(S,41,40))));
  412. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_81_120',PaletteToStr(copy(S,81,40))));
  413. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_121_160',PaletteToStr(copy(S,121,40))));
  414. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_161_200',PaletteToStr(copy(S,161,40))));
  415. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_201_240',PaletteToStr(copy(S,201,40))));
  416. if length(PS)<length(CIDEAppColor) then
  417. PS:=PS+copy(CIDEAppColor,length(PS)+1,255);
  418. AppPalette:=PS;
  419. (* { Open files }
  420. for I:=INIFile^.GetIntEntry(secFiles,ieOpenFileCount,0) downto 1 do
  421. begin
  422. S:=INIFile^.GetEntry(secFiles,ieOpenFile+IntToStr(I),'');
  423. if (S='') then
  424. break;
  425. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  426. S1:=copy(S,1,P-1);
  427. Delete(S,1,P);
  428. P:=Pos(',',S);
  429. if P=0 then P:=length(S)+1;
  430. X:=Max(0,StrToInt(copy(S,1,P-1)));
  431. Delete(S,1,P);
  432. P:=Pos(',',S);
  433. if P=0 then P:=length(S)+1;
  434. Y:=Max(0,StrToInt(copy(S,1,P-1)));
  435. Delete(S,1,P);
  436. P:=Pos(',',S);
  437. if P=0 then P:=length(S)+1;
  438. R.A.X:=Max(0,StrToInt(copy(S,1,P-1)));
  439. Delete(S,1,P);
  440. P:=Pos(',',S);
  441. if P=0 then P:=length(S)+1;
  442. R.A.Y:=Max(0,StrToInt(copy(S,1,P-1)));
  443. Delete(S,1,P);
  444. P:=Pos(',',S);
  445. if P=0 then P:=length(S)+1;
  446. R.B.X:=Max(0,StrToInt(copy(S,1,P-1)));
  447. Delete(S,1,P);
  448. P:=Pos(',',S);
  449. if P=0 then P:=length(S)+1;
  450. R.B.Y:=Max(0,StrToInt(copy(S,1,P-1)));
  451. if (R.A.X<R.B.X) and (R.A.Y<R.B.Y) then
  452. TryToOpenFile(@R,S1,X,Y,false)
  453. else
  454. TryToOpenFile(nil,S1,X,Y,false);
  455. { remove it because otherwise we allways keep old files }
  456. INIFile^.DeleteEntry(secFiles,ieOpenFile+IntToStr(I));
  457. end;
  458. *)
  459. { Desktop }
  460. DesktopFileFlags:=INIFile^.GetIntEntry(secPreferences,ieDesktopFlags,DesktopFileFlags);
  461. { Debugger }
  462. IniCenterDebuggerRow:=INIFile^.GetIntEntry(secPreferences,ieCenterDebuggerRow,1)<>0;
  463. { Preferences }
  464. AutoSaveOptions:=INIFile^.GetIntEntry(secPreferences,ieAutoSave,AutoSaveOptions);
  465. MiscOptions:=INIFile^.GetIntEntry(secPreferences,ieMiscOptions,MiscOptions);
  466. DesktopLocation:=INIFile^.GetIntEntry(secPreferences,ieDesktopLocation,DesktopLocation);
  467. { Misc }
  468. ShowReadme:=INIFile^.GetIntEntry(secMisc,ieShowReadme,{integer(ShowReadme)}1)<>0;
  469. Dispose(INIFile, Done);
  470. end;
  471. ReadINIFile:=OK;
  472. end;
  473. function WriteINIFile (FromSaveAs : boolean): boolean;
  474. var INIFile: PINIFile;
  475. S: string;
  476. S1,S2,S3: string;
  477. W: word;
  478. BreakPointCount,WatchesCount:longint;
  479. I(*,OpenFileCount*): integer;
  480. OK: boolean;
  481. procedure ConcatName(P: PString); {$ifndef FPC}far;{$endif}
  482. begin
  483. if (S<>'') then S:=S+';';
  484. S:=S+P^;
  485. end;
  486. begin
  487. {$ifdef Unix}
  488. if not FromSaveAs and (DirOf(IniFileName)=DirOf(SystemIDEDir)) then
  489. begin
  490. IniFileName:=FExpand('~/.fp/'+IniName);
  491. If not ExistsDir(DirOf(IniFileName)) then
  492. MkDir(FExpand('~/.fp'));
  493. end;
  494. {$endif Unix}
  495. New(INIFile, Init(IniFileName));
  496. { Files }
  497. { avoid keeping old files }
  498. INIFile^.DeleteSection(secFiles);
  499. INIFile^.SetEntry(secFiles,ieOpenExts,'"'+OpenExts+'"');
  500. for I:=1 to High(RecentFiles) do
  501. begin
  502. if I<=RecentFileCount then
  503. with RecentFiles[I] do S:=FileName+','+IntToStr(LastPos.X)+','+IntToStr(LastPos.Y)
  504. else
  505. S:='';
  506. INIFile^.SetEntry(secFiles,ieRecentFile+IntToStr(I),S);
  507. end;
  508. (*
  509. PW:=FirstEditorWindow;
  510. PPW:=PW;
  511. I:=1;
  512. while assigned(PW) do
  513. begin
  514. If PW^.HelpCtx=hcSourceWindow then
  515. begin
  516. With PW^.editor^ do
  517. S:=FileName+','+IntToStr(CurPos.X)+','+IntToStr(CurPos.Y);
  518. PW^.GetBounds(R);
  519. S:=S+','+IntToStr(R.A.X)+','+IntToStr(R.A.Y)+','+
  520. IntToStr(R.B.X)+','+IntToStr(R.B.Y);
  521. INIFile^.SetEntry(secFiles,ieOpenFile+IntToStr(I),S);
  522. Inc(I);
  523. OpenFileCount:=I-1;
  524. end;
  525. PW:=PSourceWindow(PW^.next);
  526. While assigned(PW) and (PW<>PPW) and (PW^.HelpCtx<>hcSourceWindow) do
  527. PW:=PSourceWindow(PW^.next);
  528. If PW=PPW then
  529. break;
  530. end;
  531. INIFile^.SetIntEntry(secFiles,ieOpenFileCount,OpenFileCount);
  532. *)
  533. { Run }
  534. INIFile^.SetEntry(secRun,ieRunDir,GetRunDir);
  535. INIFile^.SetEntry(secRun,ieRunParameters,GetRunParameters);
  536. INIFile^.SetEntry(secFiles,iePrinterDevice,GetPrinterDevice);
  537. { If DebuggeeTTY<>'' then }
  538. INIFile^.SetEntry(secRun,ieDebuggeeRedir,DebuggeeTTY);
  539. {$ifdef SUPPORT_REMOTE}
  540. INIFile^.SetEntry(secRun,ieRemoteMachine,RemoteMachine);
  541. INIFile^.SetEntry(secRun,ieRemotePort,RemotePort);
  542. INIFile^.SetEntry(secRun,ieRemoteSendCommand,RemoteSendCommand);
  543. INIFile^.SetEntry(secRun,ieRemoteConfig,RemoteConfig);
  544. INIFile^.SetEntry(secRun,ieRemoteIdent,RemoteIdent);
  545. INIFile^.SetEntry(secRun,ieRemoteDirectory,RemoteDir);
  546. {$endif SUPPORT_REMOTE}
  547. { Compile }
  548. INIFile^.SetEntry(secCompile,iePrimaryFile,PrimaryFile);
  549. INIFile^.SetEntry(secCompile,ieCompileMode,SwitchesModeStr[SwitchesMode]);
  550. { Help }
  551. S:='';
  552. HelpFiles^.ForEach(@ConcatName);
  553. INIFile^.SetEntry(secHelp,ieHelpFiles,'"'+S+'"');
  554. { Editor }
  555. INIFile^.SetIntEntry(secEditor,ieDefaultTabSize,DefaultTabSize);
  556. INIFile^.SetIntEntry(secEditor,ieDefaultIndentSize,DefaultIndentSize);
  557. INIFile^.SetIntEntry(secEditor,ieDefaultEditorFlags,DefaultCodeEditorFlags);
  558. INIFile^.SetEntry(secEditor,ieDefaultSaveExt,DefaultSaveExt);
  559. { Highlight }
  560. INIFile^.SetEntry(secHighlight,ieHighlightExts,'"'+HighlightExts+'"');
  561. INIFile^.SetEntry(secHighlight,ieTabsPattern,'"'+TabsPattern+'"');
  562. { SourcePath }
  563. INIFile^.SetEntry(secSourcePath,ieSourceList,'"'+SourceDirs+'"');
  564. { Mouse }
  565. INIFile^.SetIntEntry(secMouse,ieDoubleClickDelay,DoubleDelay);
  566. INIFile^.SetIntEntry(secMouse,ieReverseButtons,byte(MouseReverse));
  567. INIFile^.SetIntEntry(secMouse,ieAltClickAction,AltMouseAction);
  568. INIFile^.SetIntEntry(secMouse,ieCtrlClickAction,CtrlMouseAction);
  569. { Search }
  570. INIFile^.SetIntEntry(secSearch,ieFindFlags,FindFlags);
  571. { Breakpoints }
  572. {$ifndef NODEBUG}
  573. BreakPointCount:=BreakpointsCollection^.Count;
  574. INIFile^.SetIntEntry(secBreakpoint,ieBreakpointCount,BreakpointCount);
  575. for i:=1 to BreakpointCount do
  576. WriteOneBreakPointEntry(I-1,INIFile);
  577. WatchesCount:=WatchesCollection^.Count;
  578. INIFile^.SetIntEntry(secWatches,ieWatchCount,WatchesCount);
  579. for i:=1 to WatchesCount do
  580. WriteOneWatchEntry(I-1,INIFile);
  581. {$endif}
  582. { Tools }
  583. INIFile^.DeleteSection(secTools);
  584. for I:=1 to GetToolCount do
  585. begin
  586. S:=IntToStr(I);
  587. GetToolParams(I-1,S1,S2,S3,W);
  588. if S1<>'' then S1:='"'+S1+'"';
  589. if S2<>'' then S2:='"'+S2+'"';
  590. if S3<>'' then S3:='"'+S3+'"';
  591. INIFile^.SetEntry(secTools,ieToolName+S,S1);
  592. INIFile^.SetEntry(secTools,ieToolProgram+S,S2);
  593. INIFile^.SetEntry(secTools,ieToolParams+S,S3);
  594. INIFile^.SetIntEntry(secTools,ieToolHotKey+S,W);
  595. end;
  596. { Colors }
  597. if AppPalette<>CIDEAppColor then
  598. begin
  599. { this has a bug. if a different palette has been read on startup, and
  600. then changed back to match the default, this will not update it in the
  601. ini file, eg. the original (non-default) will be left unmodified... }
  602. S:=AppPalette;
  603. INIFile^.SetEntry(secColors,iePalette+'_1_40',PaletteToStr(copy(S,1,40)));
  604. INIFile^.SetEntry(secColors,iePalette+'_41_80',PaletteToStr(copy(S,41,40)));
  605. INIFile^.SetEntry(secColors,iePalette+'_81_120',PaletteToStr(copy(S,81,40)));
  606. INIFile^.SetEntry(secColors,iePalette+'_121_160',PaletteToStr(copy(S,121,40)));
  607. INIFile^.SetEntry(secColors,iePalette+'_161_200',PaletteToStr(copy(S,161,40)));
  608. INIFile^.SetEntry(secColors,iePalette+'_201_240',PaletteToStr(copy(S,201,40)));
  609. end;
  610. { Desktop }
  611. INIFile^.SetIntEntry(secPreferences,ieDesktopFlags,DesktopFileFlags);
  612. INIFile^.SetIntEntry(secPreferences,ieCenterDebuggerRow,byte(IniCenterDebuggerRow));
  613. { Preferences }
  614. INIFile^.SetIntEntry(secPreferences,ieAutoSave,AutoSaveOptions);
  615. INIFile^.SetIntEntry(secPreferences,ieMiscOptions,MiscOptions);
  616. INIFile^.SetIntEntry(secPreferences,ieDesktopLocation,DesktopLocation);
  617. { Misc }
  618. INIFile^.SetIntEntry(secMisc,ieShowReadme,integer(ShowReadme));
  619. OK:=INIFile^.Update;
  620. Dispose(INIFile, Done);
  621. WriteINIFile:=OK;
  622. end;
  623. end.