fpini.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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. case crc32(upcase(INIFile^.GetEntry(secKeyboard,ieEditKeys,''))) of
  401. $86a4c898: {crc32 for 'MICROSOFT'}
  402. EditKeys:=ekm_microsoft;
  403. $b20b87b3: {crc32 for 'BORLAND'}
  404. EditKeys:=ekm_borland;
  405. else
  406. EditKeys:=ekm_default;
  407. end;
  408. { Search }
  409. FindFlags:=INIFile^.GetIntEntry(secSearch,ieFindFlags,FindFlags);
  410. { Breakpoints }
  411. {$ifndef NODEBUG}
  412. BreakpointCount:=INIFile^.GetIntEntry(secBreakpoint,ieBreakpointCount,0);
  413. for i:=1 to BreakpointCount do
  414. ReadOneBreakPointEntry(i-1,INIFile);
  415. WatchesCount:=INIFile^.GetIntEntry(secWatches,ieWatchCount,0);
  416. for i:=1 to WatchesCount do
  417. ReadOneWatchEntry(i-1,INIFile);
  418. {$endif}
  419. { Tools }
  420. for I:=1 to MaxToolCount do
  421. begin
  422. S:=IntToStr(I);
  423. S1:=INIFile^.GetEntry(secTools,ieToolName+S,'');
  424. if S1='' then Break; { !!! }
  425. S2:=INIFile^.GetEntry(secTools,ieToolProgram+S,'');
  426. S3:=INIFile^.GetEntry(secTools,ieToolParams+S,'');
  427. W:=Max(0,Min(65535,INIFile^.GetIntEntry(secTools,ieToolHotKey+S,0)));
  428. AddTool(S1,S2,S3,W);
  429. end;
  430. { Colors }
  431. S:=AppPalette;
  432. PS:=StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_1_40',PaletteToStr(copy(S,1,40))));
  433. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_41_80',PaletteToStr(copy(S,41,40))));
  434. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_81_120',PaletteToStr(copy(S,81,40))));
  435. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_121_160',PaletteToStr(copy(S,121,40))));
  436. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_161_200',PaletteToStr(copy(S,161,40))));
  437. PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_201_240',PaletteToStr(copy(S,201,40))));
  438. if length(PS)<length(CIDEAppColor) then
  439. PS:=PS+copy(CIDEAppColor,length(PS)+1,255);
  440. AppPalette:=PS;
  441. (* { Open files }
  442. for I:=INIFile^.GetIntEntry(secFiles,ieOpenFileCount,0) downto 1 do
  443. begin
  444. S:=INIFile^.GetEntry(secFiles,ieOpenFile+IntToStr(I),'');
  445. if (S='') then
  446. break;
  447. P:=Pos(',',S); if P=0 then P:=length(S)+1;
  448. S1:=copy(S,1,P-1);
  449. Delete(S,1,P);
  450. P:=Pos(',',S);
  451. if P=0 then P:=length(S)+1;
  452. X:=Max(0,StrToInt(copy(S,1,P-1)));
  453. Delete(S,1,P);
  454. P:=Pos(',',S);
  455. if P=0 then P:=length(S)+1;
  456. Y:=Max(0,StrToInt(copy(S,1,P-1)));
  457. Delete(S,1,P);
  458. P:=Pos(',',S);
  459. if P=0 then P:=length(S)+1;
  460. R.A.X:=Max(0,StrToInt(copy(S,1,P-1)));
  461. Delete(S,1,P);
  462. P:=Pos(',',S);
  463. if P=0 then P:=length(S)+1;
  464. R.A.Y:=Max(0,StrToInt(copy(S,1,P-1)));
  465. Delete(S,1,P);
  466. P:=Pos(',',S);
  467. if P=0 then P:=length(S)+1;
  468. R.B.X:=Max(0,StrToInt(copy(S,1,P-1)));
  469. Delete(S,1,P);
  470. P:=Pos(',',S);
  471. if P=0 then P:=length(S)+1;
  472. R.B.Y:=Max(0,StrToInt(copy(S,1,P-1)));
  473. if (R.A.X<R.B.X) and (R.A.Y<R.B.Y) then
  474. TryToOpenFile(@R,S1,X,Y,false)
  475. else
  476. TryToOpenFile(nil,S1,X,Y,false);
  477. { remove it because otherwise we allways keep old files }
  478. INIFile^.DeleteEntry(secFiles,ieOpenFile+IntToStr(I));
  479. end;
  480. *)
  481. { Desktop }
  482. DesktopFileFlags:=INIFile^.GetIntEntry(secPreferences,ieDesktopFlags,DesktopFileFlags);
  483. { Debugger }
  484. IniCenterDebuggerRow:=tcentre(INIFile^.GetIntEntry(secPreferences,ieCenterDebuggerRow,1));
  485. { Preferences }
  486. AutoSaveOptions:=INIFile^.GetIntEntry(secPreferences,ieAutoSave,AutoSaveOptions);
  487. MiscOptions:=INIFile^.GetIntEntry(secPreferences,ieMiscOptions,MiscOptions);
  488. DesktopLocation:=INIFile^.GetIntEntry(secPreferences,ieDesktopLocation,DesktopLocation);
  489. { Misc }
  490. ShowReadme:=INIFile^.GetIntEntry(secMisc,ieShowReadme,{integer(ShowReadme)}1)<>0;
  491. Dispose(INIFile, Done);
  492. end;
  493. ReadINIFile:=OK;
  494. end;
  495. function WriteINIFile (FromSaveAs : boolean): boolean;
  496. var INIFile: PINIFile;
  497. S: string;
  498. S1,S2,S3: string;
  499. W: word;
  500. BreakPointCount,WatchesCount:longint;
  501. I(*,OpenFileCount*): integer;
  502. OK: boolean;
  503. procedure ConcatName(P: PString); {$ifndef FPC}far;{$endif}
  504. begin
  505. if (S<>'') then S:=S+';';
  506. S:=S+P^;
  507. end;
  508. begin
  509. {$ifdef Unix}
  510. if not FromSaveAs and (DirOf(IniFileName)=DirOf(SystemIDEDir)) then
  511. begin
  512. IniFileName:=FExpand('~/.fp/'+IniName);
  513. If not ExistsDir(DirOf(IniFileName)) then
  514. MkDir(FExpand('~/.fp'));
  515. end;
  516. {$endif Unix}
  517. New(INIFile, Init(IniFileName));
  518. { Files }
  519. { avoid keeping old files }
  520. INIFile^.DeleteSection(secFiles);
  521. INIFile^.SetEntry(secFiles,ieOpenExts,'"'+OpenExts+'"');
  522. for I:=1 to High(RecentFiles) do
  523. begin
  524. if I<=RecentFileCount then
  525. with RecentFiles[I] do S:=FileName+','+IntToStr(LastPos.X)+','+IntToStr(LastPos.Y)
  526. else
  527. S:='';
  528. INIFile^.SetEntry(secFiles,ieRecentFile+IntToStr(I),S);
  529. end;
  530. (*
  531. PW:=FirstEditorWindow;
  532. PPW:=PW;
  533. I:=1;
  534. while assigned(PW) do
  535. begin
  536. If PW^.HelpCtx=hcSourceWindow then
  537. begin
  538. With PW^.editor^ do
  539. S:=FileName+','+IntToStr(CurPos.X)+','+IntToStr(CurPos.Y);
  540. PW^.GetBounds(R);
  541. S:=S+','+IntToStr(R.A.X)+','+IntToStr(R.A.Y)+','+
  542. IntToStr(R.B.X)+','+IntToStr(R.B.Y);
  543. INIFile^.SetEntry(secFiles,ieOpenFile+IntToStr(I),S);
  544. Inc(I);
  545. OpenFileCount:=I-1;
  546. end;
  547. PW:=PSourceWindow(PW^.next);
  548. While assigned(PW) and (PW<>PPW) and (PW^.HelpCtx<>hcSourceWindow) do
  549. PW:=PSourceWindow(PW^.next);
  550. If PW=PPW then
  551. break;
  552. end;
  553. INIFile^.SetIntEntry(secFiles,ieOpenFileCount,OpenFileCount);
  554. *)
  555. { Run }
  556. INIFile^.SetEntry(secRun,ieRunDir,GetRunDir);
  557. INIFile^.SetEntry(secRun,ieRunParameters,GetRunParameters);
  558. INIFile^.SetEntry(secFiles,iePrinterDevice,GetPrinterDevice);
  559. { If DebuggeeTTY<>'' then }
  560. INIFile^.SetEntry(secRun,ieDebuggeeRedir,DebuggeeTTY);
  561. {$ifdef SUPPORT_REMOTE}
  562. INIFile^.SetEntry(secRun,ieRemoteMachine,RemoteMachine);
  563. INIFile^.SetEntry(secRun,ieRemotePort,RemotePort);
  564. INIFile^.SetEntry(secRun,ieRemoteSendCommand,RemoteSendCommand);
  565. INIFile^.SetEntry(secRun,ieRemoteConfig,RemoteConfig);
  566. INIFile^.SetEntry(secRun,ieRemoteIdent,RemoteIdent);
  567. INIFile^.SetEntry(secRun,ieRemoteDirectory,RemoteDir);
  568. {$endif SUPPORT_REMOTE}
  569. { Compile }
  570. INIFile^.SetEntry(secCompile,iePrimaryFile,PrimaryFile);
  571. INIFile^.SetEntry(secCompile,ieCompileMode,SwitchesModeStr[SwitchesMode]);
  572. { Help }
  573. S:='';
  574. HelpFiles^.ForEach(@ConcatName);
  575. INIFile^.SetEntry(secHelp,ieHelpFiles,'"'+S+'"');
  576. { Editor }
  577. INIFile^.SetIntEntry(secEditor,ieDefaultTabSize,DefaultTabSize);
  578. INIFile^.SetIntEntry(secEditor,ieDefaultIndentSize,DefaultIndentSize);
  579. INIFile^.SetIntEntry(secEditor,ieDefaultEditorFlags,DefaultCodeEditorFlags);
  580. INIFile^.SetEntry(secEditor,ieDefaultSaveExt,DefaultSaveExt);
  581. { Highlight }
  582. INIFile^.SetEntry(secHighlight,ieHighlightExts,'"'+HighlightExts+'"');
  583. INIFile^.SetEntry(secHighlight,ieTabsPattern,'"'+TabsPattern+'"');
  584. { SourcePath }
  585. INIFile^.SetEntry(secSourcePath,ieSourceList,'"'+SourceDirs+'"');
  586. { Mouse }
  587. INIFile^.SetIntEntry(secMouse,ieDoubleClickDelay,DoubleDelay);
  588. INIFile^.SetIntEntry(secMouse,ieReverseButtons,byte(MouseReverse));
  589. INIFile^.SetIntEntry(secMouse,ieAltClickAction,AltMouseAction);
  590. INIFile^.SetIntEntry(secMouse,ieCtrlClickAction,CtrlMouseAction);
  591. { Keyboard }
  592. if EditKeys=ekm_microsoft then
  593. INIFile^.SetEntry(secKeyboard,ieEditKeys,'microsoft')
  594. else
  595. INIFile^.SetEntry(secKeyboard,ieEditKeys,'borland');
  596. { Search }
  597. INIFile^.SetIntEntry(secSearch,ieFindFlags,FindFlags);
  598. { Breakpoints }
  599. {$ifndef NODEBUG}
  600. BreakPointCount:=BreakpointsCollection^.Count;
  601. INIFile^.SetIntEntry(secBreakpoint,ieBreakpointCount,BreakpointCount);
  602. for i:=1 to BreakpointCount do
  603. WriteOneBreakPointEntry(I-1,INIFile);
  604. WatchesCount:=WatchesCollection^.Count;
  605. INIFile^.SetIntEntry(secWatches,ieWatchCount,WatchesCount);
  606. for i:=1 to WatchesCount do
  607. WriteOneWatchEntry(I-1,INIFile);
  608. {$endif}
  609. { Tools }
  610. INIFile^.DeleteSection(secTools);
  611. for I:=1 to GetToolCount do
  612. begin
  613. S:=IntToStr(I);
  614. GetToolParams(I-1,S1,S2,S3,W);
  615. if S1<>'' then S1:='"'+S1+'"';
  616. if S2<>'' then S2:='"'+S2+'"';
  617. if S3<>'' then S3:='"'+S3+'"';
  618. INIFile^.SetEntry(secTools,ieToolName+S,S1);
  619. INIFile^.SetEntry(secTools,ieToolProgram+S,S2);
  620. INIFile^.SetEntry(secTools,ieToolParams+S,S3);
  621. INIFile^.SetIntEntry(secTools,ieToolHotKey+S,W);
  622. end;
  623. { Colors }
  624. if AppPalette<>CIDEAppColor then
  625. begin
  626. { this has a bug. if a different palette has been read on startup, and
  627. then changed back to match the default, this will not update it in the
  628. ini file, eg. the original (non-default) will be left unmodified... }
  629. S:=AppPalette;
  630. INIFile^.SetEntry(secColors,iePalette+'_1_40',PaletteToStr(copy(S,1,40)));
  631. INIFile^.SetEntry(secColors,iePalette+'_41_80',PaletteToStr(copy(S,41,40)));
  632. INIFile^.SetEntry(secColors,iePalette+'_81_120',PaletteToStr(copy(S,81,40)));
  633. INIFile^.SetEntry(secColors,iePalette+'_121_160',PaletteToStr(copy(S,121,40)));
  634. INIFile^.SetEntry(secColors,iePalette+'_161_200',PaletteToStr(copy(S,161,40)));
  635. INIFile^.SetEntry(secColors,iePalette+'_201_240',PaletteToStr(copy(S,201,40)));
  636. end;
  637. { Desktop }
  638. INIFile^.SetIntEntry(secPreferences,ieDesktopFlags,DesktopFileFlags);
  639. INIFile^.SetIntEntry(secPreferences,ieCenterDebuggerRow,byte(IniCenterDebuggerRow));
  640. { Preferences }
  641. INIFile^.SetIntEntry(secPreferences,ieAutoSave,AutoSaveOptions);
  642. INIFile^.SetIntEntry(secPreferences,ieMiscOptions,MiscOptions);
  643. INIFile^.SetIntEntry(secPreferences,ieDesktopLocation,DesktopLocation);
  644. { Misc }
  645. INIFile^.SetIntEntry(secMisc,ieShowReadme,integer(ShowReadme));
  646. OK:=INIFile^.Update;
  647. Dispose(INIFile, Done);
  648. WriteINIFile:=OK;
  649. end;
  650. end.