fpini.pas 23 KB

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