fpini.pas 21 KB

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