fpini.pas 23 KB

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