install.pas 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. member of the Free Pascal development team
  5. This is the install program for the DOS and OS/2 versions of Free Pascal
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. program install;
  13. { $DEFINE DLL} (* TH - if defined, UNZIP32.DLL library is used to unpack. *)
  14. { $DEFINE DOSSTUB} (* TH - should _not_ be defined unless creating a bound DOS and OS/2 installer!!! *)
  15. (* Defining DOSSTUB causes adding a small piece of code *)
  16. (* for starting the OS/2 part from the DOS part of a bound *)
  17. (* application if running in OS/2 VDM (DOS) window. Used *)
  18. (* only if compiling with TP/BP (see conditionals below). *)
  19. {$IFDEF OS2}
  20. {$DEFINE DLL}
  21. {$ENDIF DLL}
  22. {$IFDEF VER60}
  23. {$DEFINE TP}
  24. {$ENDIF}
  25. {$IFDEF VER70}
  26. {$DEFINE TP}
  27. {$ENDIF}
  28. {$IFNDEF TP}
  29. {$UNDEF DOSSTUB}
  30. {$ELSE}
  31. {$IFDEF OS2}
  32. {$UNDEF DOSSTUB}
  33. {$ENDIF}
  34. {$ENDIF}
  35. {$IFDEF DPMI}
  36. {$UNDEF DOSSTUB}
  37. {$ENDIF}
  38. {$ifdef go32v2}
  39. {$define MAYBE_LFN}
  40. {$endif}
  41. {$ifdef debug}
  42. {$ifdef win32}
  43. {$define MAYBE_LFN}
  44. {$endif win32}
  45. {$endif debug}
  46. {$ifdef TP}
  47. {$define MAYBE_LFN}
  48. {$endif}
  49. uses
  50. {$IFDEF OS2}
  51. {$IFDEF FPC}
  52. DosCalls,
  53. {$ELSE FPC}
  54. {$IFDEF VirtualPascal}
  55. OS2Base,
  56. {$ELSE VirtualPascal}
  57. BseDos,
  58. {$ENDIF VirtualPascal}
  59. {$ENDIF FPC}
  60. {$ENDIF OS2}
  61. {$IFDEF GO32V2}
  62. emu387,
  63. {$ENDIF}
  64. {$ifdef HEAPTRC}
  65. heaptrc,
  66. {$endif HEAPTRC}
  67. strings,dos,objects,drivers,
  68. {$IFNDEF FVISION}
  69. commands,
  70. HelpCtx,
  71. {$ENDIF}
  72. unzip51g,ziptypes,
  73. {$IFDEF DLL}
  74. unzipdll,
  75. {$ENDIF}
  76. app,dialogs,views,menus,msgbox,colortxt,tabs,scroll,
  77. WHTMLScn,insthelp;
  78. const
  79. installerversion='2.5.1';
  80. installercopyright='Copyright (c) 1993-2011 Florian Klaempfl';
  81. maxpacks=20;
  82. maxpackages=40;
  83. maxdefcfgs=1024;
  84. HTMLIndexExt = '.htx';
  85. CfgExt = '.dat';
  86. MaxStatusPos = 4;
  87. StatusChars: string [MaxStatusPos] = '/-\|';
  88. StatusPos: byte = 1;
  89. { this variable is set to true if an ide is installed }
  90. haside : boolean = false;
  91. hashtmlhelp : boolean = false;
  92. {$ifdef Unix}
  93. DirSep='/';
  94. {$else}
  95. DirSep='\';
  96. {$endif}
  97. type
  98. tpackage=record
  99. name : string[60];
  100. zip : string[40]; { default zipname }
  101. zipshort : string[12]; { 8.3 zipname }
  102. diskspace : int64; { diskspace required }
  103. end;
  104. tpack=record
  105. name : string[12];
  106. binsub : string[40];
  107. ppc386 : string[20];
  108. targetname : string[40];
  109. defidecfgfile,
  110. defideinifile,
  111. defcfgfile,
  112. setpathfile : string[12];
  113. include : boolean;
  114. { filechk : string[40]; Obsolete }
  115. packages : longint;
  116. package : array[1..maxpackages] of tpackage;
  117. end;
  118. tcfgarray = array[1..maxdefcfgs] of pstring;
  119. cfgrec=record
  120. title : string[80];
  121. version : string[20];
  122. helpidx,
  123. docsub,
  124. basepath : DirStr;
  125. packs : word;
  126. pack : array[1..maxpacks] of tpack;
  127. defideinis,
  128. defidecfgs,
  129. defcfgs,
  130. defsetpaths : longint;
  131. defideini,
  132. defidecfg,
  133. defcfg,
  134. defsetpath : tcfgarray;
  135. end;
  136. datarec=record
  137. basepath : DirStr;
  138. cfgval : word;
  139. packmask : array[1..maxpacks] of sw_word;
  140. end;
  141. punzipdialog=^tunzipdialog;
  142. tunzipdialog=object(tdialog)
  143. filetext : pstatictext;
  144. extractfiletext : pstatictext;
  145. currentfile : string;
  146. constructor Init(var Bounds: TRect; ATitle: TTitleStr);
  147. procedure do_unzip(s,topath:string);
  148. end;
  149. penddialog = ^tenddialog;
  150. tenddialog = object(tdialog)
  151. constructor init;
  152. end;
  153. pinstalldialog = ^tinstalldialog;
  154. tinstalldialog = object(tdialog)
  155. constructor init;
  156. procedure handleevent(var event : tevent);virtual;
  157. end;
  158. PFPHTMLFileLinkScanner = ^TFPHTMLFileLinkScanner;
  159. TFPHTMLFileLinkScanner = object(THTMLFileLinkScanner)
  160. function CheckURL(const URL: string): boolean; virtual;
  161. function CheckText(const Text: string): boolean; virtual;
  162. procedure ProcessDoc(Doc: PHTMLLinkScanFile); virtual;
  163. end;
  164. phtmlindexdialog = ^thtmlindexdialog;
  165. thtmlindexdialog = object(tdialog)
  166. text : pstatictext;
  167. constructor init(var Bounds: TRect; ATitle: TTitleStr);
  168. end;
  169. tapp = object(tapplication)
  170. procedure initmenubar;virtual;
  171. procedure initstatusline;virtual;
  172. procedure handleevent(var event : tevent);virtual;
  173. procedure do_installdialog;
  174. procedure readcfg(const fn:string);
  175. procedure checkavailpack;
  176. end;
  177. PSpecialInputLine= ^TSpecialInputLine;
  178. TSpecialInputLine = object (TInputLine)
  179. procedure GetData(var Rec); virtual;
  180. end;
  181. {$IFDEF DOSSTUB}
  182. PByte = ^byte;
  183. PRunBlock = ^TRunBlock;
  184. TRunBlock = record
  185. Length: word;
  186. Dependent: word;
  187. Background: word;
  188. TraceLevel: word;
  189. PrgTitle: PChar;
  190. PrgName: PChar;
  191. Args: PChar;
  192. TermQ: longint;
  193. Environment: pointer;
  194. Inheritance: word;
  195. SesType: word;
  196. Icon: pointer;
  197. PgmHandle: longint;
  198. PgmControl: word;
  199. Column: word;
  200. Row: word;
  201. Width: word;
  202. Height: word;
  203. end;
  204. {$ENDIF}
  205. var
  206. installapp : tapp;
  207. startpath : string;
  208. successfull : boolean;
  209. cfg : cfgrec;
  210. data : datarec;
  211. CfgName: NameStr;
  212. DStr: DirStr;
  213. EStr: ExtStr;
  214. UnzDlg : punzipdialog;
  215. log : text;
  216. createlog : boolean;
  217. {$IFNDEF DLL}
  218. const
  219. UnzipErr: longint = 0;
  220. {$ENDIF}
  221. {$ifdef MAYBE_LFN}
  222. const
  223. locallfnsupport : boolean = false;
  224. {$endif MAYBE_LFN}
  225. {*****************************************************************************
  226. Helpers
  227. *****************************************************************************}
  228. procedure errorhalt;
  229. begin
  230. installapp.done;
  231. if CreateLog then
  232. begin
  233. WriteLn (Log, 'Installation hasn''t been completed.');
  234. Close (Log);
  235. end;
  236. halt(1);
  237. end;
  238. procedure WriteLog (const S: string);
  239. begin
  240. if CreateLog then
  241. begin
  242. WriteLn (Log, S);
  243. Flush (Log);
  244. end;
  245. end;
  246. function packagemask(i:longint):longint;
  247. begin
  248. packagemask:=1 shl (i-1);
  249. end;
  250. function upper(const s : string):string;
  251. var
  252. i : integer;
  253. begin
  254. for i:=1 to length(s) do
  255. if s[i] in ['a'..'z'] then
  256. upper[i]:=chr(ord(s[i])-32)
  257. else
  258. upper[i]:=s[i];
  259. upper[0]:=s[0];
  260. end;
  261. procedure Replace(var s:string;const s1,s2:string);
  262. var
  263. i : longint;
  264. begin
  265. repeat
  266. i:=pos(s1,s);
  267. if i>0 then
  268. begin
  269. Delete(s,i,length(s1));
  270. Insert(s2,s,i);
  271. end;
  272. until i=0;
  273. end;
  274. function DotStr(l:longint):string;
  275. var
  276. TmpStr : string[32];
  277. i : longint;
  278. begin
  279. Str(l,TmpStr);
  280. i:=Length(TmpStr);
  281. while (i>3) do
  282. begin
  283. i:=i-3;
  284. if TmpStr[i]<>'-' then
  285. Insert('.',TmpStr,i+1);
  286. end;
  287. DotStr:=TmpStr;
  288. end;
  289. function file_exists(const f : string;const path : string) : boolean;
  290. begin
  291. file_exists:=fsearch(f,path)<>'';
  292. end;
  293. function createdir(s:string):boolean;
  294. var
  295. s1,start : string;
  296. err : boolean;
  297. i : longint;
  298. begin
  299. err:=false;
  300. {$I-}
  301. getdir(0,start);
  302. {$ifndef Unix}
  303. if (s[2]=':') and (s[3]=DirSep) then
  304. begin
  305. chdir(Copy(s,1,3));
  306. Delete(S,1,3);
  307. end;
  308. {$endif}
  309. repeat
  310. i:=Pos(DirSep,s);
  311. if i=0 then
  312. i:=255;
  313. s1:=Copy(s,1,i-1);
  314. Delete(s,1,i);
  315. ChDir(s1);
  316. if ioresult<>0 then
  317. begin
  318. mkdir(s1);
  319. chdir(s1);
  320. if ioresult<>0 then
  321. begin
  322. err:=true;
  323. break;
  324. end;
  325. end;
  326. until s='';
  327. chdir(start);
  328. {$I+}
  329. createdir:=err;
  330. end;
  331. function DiskSpaceN(const zipfile : string) : longint;
  332. var
  333. compressed,uncompressed : longint;
  334. s : string;
  335. begin
  336. s:=zipfile+#0;
  337. if not (IsZip (@S [1])) then
  338. DiskSpaceN := -1
  339. else
  340. begin
  341. Uncompressed:=UnzipSize(@s[1],compressed);
  342. DiskSpaceN:=uncompressed shr 10;
  343. end;
  344. end;
  345. function diskspacestr(uncompressed : longint) : string;
  346. begin
  347. if Uncompressed = -1 then
  348. DiskSpacestr := ' [INVALID]'
  349. else
  350. diskspacestr:=' ('+DotStr(uncompressed)+' KB)';
  351. end;
  352. function createinstalldir(s : string) : boolean;
  353. var
  354. err : boolean;
  355. dir : searchrec;
  356. params : array[0..0] of pointer;
  357. begin
  358. if s[length(s)]=DirSep then
  359. dec(s[0]);
  360. FindFirst(s,AnyFile,dir);
  361. if doserror=0 then
  362. begin
  363. if Dir.Attr and Directory = 0 then
  364. begin
  365. messagebox('A file with the name chosen as the installation '+
  366. 'directory exists already. Cannot create this directory!',nil,
  367. mferror+mfokbutton);
  368. createinstalldir:=false;
  369. end else
  370. createinstalldir:=messagebox('The installation directory exists already. '+
  371. 'Do you want to continue ?',nil,
  372. mferror+mfyesbutton+mfnobutton)=cmYes;
  373. exit;
  374. end;
  375. err:=Createdir(s);
  376. if err then
  377. begin
  378. params[0]:=@s;
  379. messagebox('The installation directory %s couldn''t be created',
  380. @params,mferror+mfokbutton);
  381. createinstalldir:=false;
  382. exit;
  383. end;
  384. {$ifndef TP}
  385. {$IFNDEF OS2}
  386. FindClose (dir);
  387. {$ENDIF}
  388. {$endif}
  389. createinstalldir:=true;
  390. end;
  391. function GetProgDir: DirStr;
  392. var
  393. D: DirStr;
  394. N: NameStr;
  395. E: ExtStr;
  396. begin
  397. FSplit (FExpand (ParamStr (0)), D, N, E);
  398. if (D [0] <> #0) and (D [byte (D [0])] = '\') then Dec (D [0]);
  399. GetProgDir := D;
  400. end;
  401. function GetZipErrorInfo(error : longint) : string;
  402. var
  403. ErrorStr : string;
  404. begin
  405. case error of
  406. unzip_CRCErr : GetZipErrorInfo:='CRC error';
  407. unzip_WriteErr : GetZipErrorInfo:='Write error';
  408. unzip_ReadErr : GetZipErrorInfo:='Read error';
  409. unzip_ZipFileErr : GetZipErrorInfo:='ZipFile erroe';
  410. unzip_UserAbort : GetZipErrorInfo:='User abort';
  411. unzip_NotSupported : GetZipErrorInfo:='Not supported';
  412. unzip_Encrypted : GetZipErrorInfo:='File is encrypted';
  413. unzip_InUse : GetZipErrorInfo:='Fie is in use';
  414. unzip_InternalError : GetZipErrorInfo:='Internal error'; {Error in zip format}
  415. unzip_NoMoreItems : GetZipErrorInfo:='No more items';
  416. unzip_FileError : GetZipErrorInfo:='File error'; {Error Accessing file}
  417. unzip_NotZipfile : GetZipErrorInfo:='Not a zipfile'; {not a zip file}
  418. unzip_SeriousError : GetZipErrorInfo:='Serious error'; {serious error}
  419. unzip_MissingParameter : GetZipErrorInfo:='Missing parameter'; {missing parameter}
  420. else
  421. begin
  422. Str(Error,ErrorStr);
  423. GetZipErrorInfo:='Unknown error '+errorstr;
  424. end;
  425. end;
  426. end;
  427. {*****************************************************************************
  428. HTML-Index Generation
  429. *****************************************************************************}
  430. var
  431. indexdlg : phtmlindexdialog;
  432. constructor thtmlindexdialog.Init(var Bounds: TRect; ATitle: TTitleStr);
  433. var
  434. r : trect;
  435. begin
  436. inherited init(bounds,atitle);
  437. Options:=Options or ofCentered;
  438. R.Assign (4, 2,bounds.B.X-Bounds.A.X-2, 4);
  439. text:=new(pstatictext,init(r,'Please wait ...'));
  440. insert(text);
  441. end;
  442. procedure TFPHTMLFileLinkScanner.ProcessDoc(Doc: PHTMLLinkScanFile);
  443. var
  444. oldtext : pstring;
  445. begin
  446. oldtext:=indexdlg^.text^.text;
  447. indexdlg^.text^.text:=newstr('Processing '+Doc^.GetDocumentURL);
  448. indexdlg^.text^.drawview;
  449. inherited ProcessDoc(Doc);
  450. disposestr(indexdlg^.text^.text);
  451. indexdlg^.text^.text:=oldtext;
  452. indexdlg^.text^.drawview;
  453. end;
  454. function TFPHTMLFileLinkScanner.CheckURL(const URL: string): boolean;
  455. var OK: boolean;
  456. const HTTPPrefix = 'http:';
  457. FTPPrefix = 'ftp:';
  458. begin
  459. OK:=inherited CheckURL(URL);
  460. if OK then OK:=DirAndNameOf(URL)<>'';
  461. if OK then OK:=CompareText(copy(ExtOf(URL),1,4),'.HTM')=0;
  462. if OK then OK:=CompareText(copy(URL,1,length(HTTPPrefix)),HTTPPrefix)<>0;
  463. if OK then OK:=CompareText(copy(URL,1,length(FTPPrefix)),FTPPrefix)<>0;
  464. CheckURL:=OK;
  465. end;
  466. function TFPHTMLFileLinkScanner.CheckText(const Text: string): boolean;
  467. var OK: boolean;
  468. S: string;
  469. begin
  470. S:=Trim(Text);
  471. OK:=(S<>'') and (copy(S,1,1)<>'[');
  472. CheckText:=OK;
  473. end;
  474. procedure writehlpindex(filename : string);
  475. var
  476. LS : PFPHTMLFileLinkScanner;
  477. BS : PBufStream;
  478. Re : Word;
  479. params : array[0..0] of pointer;
  480. dir : searchrec;
  481. r : trect;
  482. begin
  483. r.assign(10,10,70,15);
  484. indexdlg:=new(phtmlindexdialog,init(r,'Creating HTML index file, please wait ...'));
  485. desktop^.insert(indexdlg);
  486. { warning FIXME !!!!, don't know what is to fix here ... PM }
  487. New(LS, Init(DirOf(FileName)));
  488. LS^.ProcessDocument(FileName,[soSubDocsOnly]);
  489. if LS^.GetDocumentCount=0 then
  490. begin
  491. params[0]:=@filename;
  492. MessageBox('Problem creating help index %1, aborting',@params,
  493. mferror+mfokbutton);
  494. end
  495. else
  496. begin
  497. FileName:=DirAndNameOf(FileName)+HTMLIndexExt;
  498. findfirst(filename,AnyFile,dir);
  499. if doserror=0 then
  500. begin
  501. params[0]:=@filename;
  502. Re:=MessageBox('Help index %s already exists, overwrite it?',@params,
  503. mfinformation+mfyesbutton+mfnobutton);
  504. end
  505. else
  506. Re:=cmYes;
  507. if Re<>cmNo then
  508. begin
  509. New(BS, Init(FileName, stCreate, 4096));
  510. if Assigned(BS)=false then
  511. begin
  512. MessageBox('Error while writing help index! '+
  513. 'No help index is created',@params,
  514. mferror+mfokbutton);
  515. Re:=cmCancel;
  516. end
  517. else
  518. begin
  519. LS^.StoreDocuments(BS^);
  520. if BS^.Status<>stOK then
  521. begin
  522. MessageBox('Error while writing help index!'#13+
  523. 'No help index is created',@params,
  524. mferror+mfokbutton);
  525. Re:=cmCancel;
  526. end;
  527. Dispose(BS, Done);
  528. end;
  529. end;
  530. end;
  531. Dispose(LS, Done);
  532. desktop^.delete(indexdlg);
  533. dispose(indexdlg,done);
  534. end;
  535. {*****************************************************************************
  536. Writing of fpc.cfg
  537. *****************************************************************************}
  538. procedure writedefcfg(const fn:string;const cfgdata : tcfgarray;count : longint;const targetname : string);
  539. var
  540. t : text;
  541. i : longint;
  542. s : string;
  543. dir : searchrec;
  544. params : array[0..0] of pointer;
  545. d : dirstr;
  546. n : namestr;
  547. e : extstr;
  548. begin
  549. { already exists }
  550. findfirst(fn,AnyFile,dir);
  551. if doserror=0 then
  552. begin
  553. params[0]:=@fn;
  554. if MessageBox('Config %s already exists, continue writing default config?',@params,
  555. mfinformation+mfyesbutton+mfnobutton)=cmNo then
  556. exit;
  557. end;
  558. { create directory }
  559. fsplit(fn,d,n,e);
  560. createdir(d);
  561. { create the fpc.cfg }
  562. assign(t,fn);
  563. {$I-}
  564. rewrite(t);
  565. {$I+}
  566. if ioresult<>0 then
  567. begin
  568. params[0]:=@fn;
  569. MessageBox(#3'A config not written.'#13#3'%s'#13#3'couldn''t be created',@params,mfinformation+mfokbutton);
  570. exit;
  571. end;
  572. for i:=1 to count do
  573. if assigned(cfgdata[i]) then
  574. begin
  575. s:=cfgdata[i]^;
  576. Replace(s,'%basepath%',data.basepath);
  577. Replace(s,'%targetname%',targetname);
  578. if pos('-',targetname)=0 then
  579. begin
  580. Replace(s,'%targetos%',targetname);
  581. Replace(s,'%fpctargetmacro%','$FPCOS')
  582. end
  583. else
  584. begin
  585. Replace(s,'%targetos%',Copy(targetname,pos('-',targetname)+1,255));
  586. Replace(s,'%fpctargetmacro%','$FPCTARGET');
  587. end;
  588. writeln(t,s);
  589. end
  590. else
  591. writeln(t,'');
  592. close(t);
  593. end;
  594. {*****************************************************************************
  595. TUnZipDialog
  596. *****************************************************************************}
  597. constructor tunzipdialog.Init(var Bounds: TRect; ATitle: TTitleStr);
  598. var
  599. r : trect;
  600. begin
  601. inherited init(bounds,atitle);
  602. Options:=Options or ofCentered;
  603. (* R.Assign (11, 4, 38, 6);*)
  604. R.Assign (1, 4,bounds.B.X-Bounds.A.X-2, 6);
  605. filetext:=new(pstatictext,init(r,#3'File: '));
  606. insert(filetext);
  607. R.Assign (1, 7,bounds.B.X-Bounds.A.X-2, 9);
  608. extractfiletext:=new(pstatictext,init(r,#3' '));
  609. insert(extractfiletext);
  610. end;
  611. {$IFNDEF DLL}
  612. procedure UnzipCheckFn (Retcode: longint; Rec: pReportRec );{$ifdef Delphi32}STDCALL;{$endif}
  613. {$ifndef fpc}{$IFNDEF BIT32} FAR;{$ENDIF BIT32}{$endif}
  614. var
  615. name : string;
  616. begin
  617. case Rec^.Status of
  618. unzip_starting:
  619. UnzipErr := 0;
  620. file_starting:
  621. begin
  622. with UnzDlg^.extractfiletext^ do
  623. begin
  624. Disposestr(text);
  625. name:=Strpas(Rec^.FileName);
  626. UnzDlg^.currentfile:=name;
  627. Text:=NewStr(#3+name);
  628. DrawView;
  629. end;
  630. end;
  631. file_failure:
  632. UnzipErr := RetCode;
  633. file_unzipping:
  634. begin
  635. with UnzDlg^.FileText^ do
  636. begin
  637. Inc (StatusPos);
  638. if StatusPos > MaxStatusPos then StatusPos := 1;
  639. Text^ [Length (Text^)] := StatusChars [StatusPos];
  640. DrawView;
  641. end;
  642. end;
  643. end;
  644. end;
  645. {$ENDIF}
  646. procedure tunzipdialog.do_unzip(s,topath : string);
  647. var
  648. {$ifdef MAYBE_LFN}
  649. p : pathstr;
  650. n : namestr;
  651. e : extstr;
  652. islfn : boolean;
  653. {$endif MAYBE_LFN}
  654. again : boolean;
  655. st2,fn,dir,wild : string;
  656. begin
  657. Disposestr(filetext^.text);
  658. filetext^.Text:=NewStr(#3'File: '+s + #13#3' ');
  659. filetext^.drawview;
  660. if not(file_exists(s,startpath)) then
  661. begin
  662. messagebox('File "'+s+'" missing for the selected installation. '+
  663. 'Installation hasn''t been completed.',nil,mferror+mfokbutton);
  664. WriteLog ('File "' + S +
  665. '" missing for the selected installation!');
  666. errorhalt;
  667. end;
  668. {$IFNDEF DLL}
  669. {$IFDEF FPC}
  670. SetUnzipReportProc (@UnzipCheckFn);
  671. {$ELSE FPC}
  672. SetUnzipReportProc (UnzipCheckFn);
  673. {$ENDIF FPC}
  674. {$ENDIF DLL}
  675. WriteLog ('Unpacking ' + AllFiles + ' from '
  676. + StartPath + DirSep + S + ' to ' + ToPath);
  677. repeat
  678. fn:=startpath+DirSep+s+#0;
  679. dir:=topath+#0;
  680. wild:=AllFiles + #0;
  681. again:=false;
  682. FileUnzipEx(@fn[1],@dir[1],@wild[1]);
  683. if (UnzipErr <> 0) and (UnzipErr <> 1) then
  684. begin
  685. if CreateLog then
  686. begin
  687. WriteLn (Log, 'Error ', UnzipErr, ' while unpacking!');
  688. Flush (Log);
  689. end;
  690. s:=GetZipErrorInfo(UnzipErr);
  691. { Str(UnzipErr,s);}
  692. st2:='';
  693. if UnzipErr=unzip_WriteErr then
  694. begin
  695. {$ifdef MAYBE_LFN}
  696. if not(locallfnsupport) then
  697. begin
  698. islfn:=false;
  699. fsplit(currentfile,p,n,e);
  700. if (length(n)>8) or (length(e)>4) or
  701. (pos('.',n)>0) or (upper(p+n+e)<>upper(currentfile)) then
  702. islfn:=true;
  703. if islfn then
  704. begin
  705. WriteLog ('Error while extracting ' +
  706. CurrentFile + ' because of missing LFN support,' +
  707. LineEnding + ' skipping rest of ZIP file.');
  708. messagebox('Error while extracting '+currentfile+
  709. #13#3'because of missing lfn support'+
  710. #13#3'skipping rest of zipfile '+s
  711. ,nil,mferror+mfOkButton);
  712. again:=false;
  713. exit;
  714. end;
  715. end
  716. else
  717. {$endif MAYBE_LFN}
  718. st2:=' Disk full?';
  719. end;
  720. if CreateLog then
  721. WriteLog ('Error (' + S + ') while extracting.' + ST2);
  722. if messagebox('Error (' + S + ') while extracting.'+st2+#13+
  723. #13#3'Try again?',nil,mferror+mfyesbutton+mfnobutton)=cmYes then
  724. again:=true
  725. else
  726. errorhalt;
  727. end;
  728. until not again;
  729. end;
  730. {*****************************************************************************
  731. TEndDialog
  732. *****************************************************************************}
  733. constructor tenddialog.init;
  734. var
  735. R : TRect;
  736. P : PStaticText;
  737. Control : PButton;
  738. YB: word;
  739. {$IFNDEF UNIX}
  740. i : longint;
  741. S: string;
  742. WPath: boolean;
  743. MixedCasePath: boolean;
  744. {$ENDIF}
  745. {$IFDEF OS2}
  746. ErrPath: array [0..259] of char;
  747. Handle: longint;
  748. WLibPath: boolean;
  749. const
  750. EMXName: array [1..4] of char = 'EMX'#0;
  751. BFD2EName: array [1..6] of char = 'BFD2E'#0;
  752. {$ENDIF}
  753. begin
  754. if haside then
  755. YB := 15
  756. else
  757. YB := 14;
  758. {$IFNDEF UNIX}
  759. s:='';
  760. for i:=1 to cfg.packs do
  761. if cfg.pack[i].binsub<>'' then
  762. begin
  763. if s<>'' then
  764. s:=s+';';
  765. S := s+Data.BasePath + Cfg.pack[i].BinSub;
  766. end;
  767. if Pos (Upper (S), Upper (GetEnv ('PATH'))) = 0 then
  768. begin
  769. WPath := true;
  770. Inc (YB, 3);
  771. end
  772. else
  773. WPath := false;
  774. { look if path is set as Path,
  775. this leads to problems for mingw32 make PM }
  776. MixedCasePath:=false;
  777. for i:=1 to EnvCount do
  778. begin
  779. if Pos('PATH=',Upper(EnvStr(i)))=1 then
  780. if Pos('PATH=',EnvStr(i))<>1 then
  781. Begin
  782. MixedCasePath:=true;
  783. Inc(YB, 2);
  784. End;
  785. end;
  786. {$IFDEF OS2}
  787. if DosLoadModule (@ErrPath, SizeOf (ErrPath), @EMXName, Handle) = 0 then
  788. begin
  789. WLibPath := false;
  790. DosFreeModule (Handle);
  791. if DosLoadModule (@ErrPath, SizeOf (ErrPath), @BFD2EName, Handle) = 0 then
  792. begin
  793. WLibPath := false;
  794. DosFreeModule (Handle);
  795. end
  796. else
  797. begin
  798. WLibPath := true;
  799. Inc (YB, 2);
  800. end;
  801. end
  802. else
  803. begin
  804. WLibPath := true;
  805. Inc (YB, 2);
  806. end;
  807. {$ENDIF}
  808. {$ENDIF}
  809. R.Assign(6, 6, 74, YB);
  810. inherited init(r,'Installation successful.');
  811. Options:=Options or ofCentered;
  812. {$IFNDEF UNIX}
  813. if WPath then
  814. begin
  815. R.Assign(2, 3, 64, 5);
  816. P:=new(pstatictext,init(r,'Extend your PATH variable with '''+S+''''));
  817. insert(P);
  818. end;
  819. {$IFDEF OS2}
  820. if WLibPath then
  821. begin
  822. if WPath then
  823. S := 'and your LIBPATH with ''' + S
  824. else
  825. S := 'Extend your LIBPATH with ''' + S;
  826. System.Delete (S, Length (S) - 3, 4);
  827. S := S + '\dll''';
  828. R.Assign (2, YB - 14, 64, YB - 12);
  829. P := New (PStaticText, Init (R, S));
  830. Insert (P);
  831. end;
  832. {$ELSE OS2}
  833. if MixedCasePath then
  834. begin
  835. R.Assign(2, 5, 64, 6);
  836. P:=new(pstatictext,init(r,'You need to use setpath.bat file if you want to use Makefiles'));
  837. insert(P);
  838. end;
  839. {$ENDIF OS2}
  840. {$ENDIF}
  841. R.Assign(2, YB - 13, 64, YB - 12);
  842. P:=new(pstatictext,init(r,'To compile files enter ''fpc [file]'''));
  843. insert(P);
  844. if haside then
  845. begin
  846. R.Assign(2, YB - 12, 64, YB - 10);
  847. P:=new(pstatictext,init(r,'To start the IDE (Integrated Development Environment) type ''fp'' at a command line prompt'));
  848. insert(P);
  849. end;
  850. R.Assign (29, YB - 9, 39, YB - 7);
  851. Control := New (PButton, Init (R,'~O~k', cmOK, bfDefault));
  852. Insert (Control);
  853. end;
  854. {*****************************************************************************
  855. TInstallDialog
  856. *****************************************************************************}
  857. {$ifdef MAYBE_LFN}
  858. var
  859. islfn : boolean;
  860. procedure lfnreport( Retcode : longint;Rec : pReportRec );
  861. var
  862. p : pathstr;
  863. n : namestr;
  864. e : extstr;
  865. begin
  866. fsplit(strpas(rec^.Filename),p,n,e);
  867. if (length(n)>8) or (length(e)>4) or
  868. (pos('.',n)>0) or (upper(p+n+e)<>upper(strpas(rec^.Filename))) then
  869. islfn:=true;
  870. end;
  871. function haslfn(const zipfile : string) : boolean;
  872. var
  873. buf : array[0..255] of char;
  874. begin
  875. strpcopy(buf,zipfile);
  876. islfn:=false;
  877. {$ifdef FPC}
  878. ViewZip(buf,AllFiles,@lfnreport);
  879. {$else FPC}
  880. ViewZip(buf,AllFiles,lfnreport);
  881. {$endif FPC}
  882. haslfn:=islfn;
  883. end;
  884. {$endif MAYBE_LFN}
  885. var
  886. AllFilesPresent : boolean;
  887. procedure presentreport( Retcode : longint;Rec : pReportRec );
  888. var
  889. st : string;
  890. f : file;
  891. size,time : longint;
  892. p : pathstr;
  893. n : namestr;
  894. e : extstr;
  895. begin
  896. if not ALLFilesPresent then
  897. exit;
  898. st:=Data.BasePath+strpas(rec^.Filename);
  899. fsplit(st,p,n,e);
  900. if not file_exists(n+e,p) then
  901. AllFilesPresent:=false
  902. else
  903. begin
  904. Assign(f,st);
  905. Reset(f,1);
  906. if IOresult<>0 then
  907. begin
  908. ALLfilesPresent:=false;
  909. exit;
  910. end;
  911. GetFtime(f,time);
  912. size:=FileSize(f);
  913. if (rec^.Time<>time) or (rec^.size<>size) then
  914. ALLFilesPresent:=false;
  915. close(f);
  916. end;
  917. end;
  918. function AreAllFilesPresent(const zipfile : string) : boolean;
  919. var
  920. buf : array[0..255] of char;
  921. begin
  922. strpcopy(buf,zipfile);
  923. AllFilesPresent:=true;
  924. {$ifdef FPC}
  925. ViewZip(buf,AllFiles,@presentreport);
  926. {$else FPC}
  927. ViewZip(buf,AllFiles,presentreport);
  928. {$endif FPC}
  929. AreAllFilesPresent:=AllFilesPresent;
  930. end;
  931. constructor tinstalldialog.init;
  932. const
  933. width = 76;
  934. height = 20;
  935. x1 = (79-width) div 2;
  936. y1 = (23-height) div 2;
  937. x2 = x1+width;
  938. y2 = y1+height;
  939. var
  940. tabr,tabir,r : trect;
  941. packmask : array[1..maxpacks] of longint;
  942. enabmask : array[1..maxpacks] of longint;
  943. i,line,j : integer;
  944. items : array[1..maxpacks] of psitem;
  945. f : pview;
  946. found : boolean;
  947. okbut,cancelbut : pbutton;
  948. firstitem : array[1..maxpacks] of integer;
  949. packcbs : array[1..maxpacks] of pcheckboxes;
  950. packtd : ptabdef;
  951. labpath : plabel;
  952. ilpath : pspecialinputline;
  953. tab : ptab;
  954. titletext : pcoloredtext;
  955. labcfg : plabel;
  956. cfgcb : pcheckboxes;
  957. scrollbox: pscrollbox;
  958. sbr,sbsbr: trect;
  959. sbsb: pscrollbar;
  960. zipfile : string;
  961. begin
  962. f:=nil;
  963. { walk packages reverse and insert a newsitem for each, and set the mask }
  964. for j:=1 to cfg.packs do
  965. with cfg.pack[j] do
  966. begin
  967. firstitem[j]:=0;
  968. items[j]:=nil;
  969. packmask[j]:=0;
  970. enabmask[j]:=0;
  971. for i:=packages downto 1 do
  972. begin
  973. zipfile:='';
  974. if file_exists(package[i].zip,startpath) then
  975. zipfile:=startpath+DirSep+package[i].zip
  976. else if file_exists(package[i].zipshort,startpath) then
  977. begin
  978. zipfile:=startpath+DirSep+package[i].zipshort;
  979. { update package to replace the full zipname with the short name }
  980. package[i].zip:=package[i].zipshort;
  981. end;
  982. if zipfile<>'' then
  983. begin
  984. { get diskspace required }
  985. package[i].diskspace:=diskspaceN(zipfile);
  986. {$ifdef MAYBE_LFN}
  987. if not(locallfnsupport) then
  988. begin
  989. if not(haslfn(zipfile)) then
  990. begin
  991. items[j]:=newsitem(package[i].name+diskspacestr(package[i].diskspace),items[j]);
  992. packmask[j]:=packmask[j] or packagemask(i);
  993. enabmask[j]:=enabmask[j] or packagemask(i);
  994. firstitem[j]:=i-1;
  995. WriteLog ('Checking lfn usage for ' + zipfile + ' ... no lfn');
  996. end
  997. else
  998. begin
  999. items[j]:=newsitem(package[i].name+' (requires LFN support)',items[j]);
  1000. enabmask[j]:=enabmask[j] or packagemask(i);
  1001. firstitem[j]:=i-1;
  1002. WriteLog ('Checking lfn usage for ' + zipfile + ' ... uses lfn');
  1003. end;
  1004. end
  1005. else
  1006. {$endif MAYBE_LFN}
  1007. begin
  1008. items[j]:=newsitem(package[i].name+diskspacestr(package[i].diskspace)
  1009. {$ifdef DEBUG}
  1010. +' ('+dotstr(i)+')'
  1011. {$endif DEBUG}
  1012. ,items[j]);
  1013. packmask[j]:=packmask[j] or packagemask(i);
  1014. enabmask[j]:=enabmask[j] or packagemask(i);
  1015. firstitem[j]:=i-1;
  1016. end;
  1017. end
  1018. else
  1019. items[j]:=newsitem(package[i].name
  1020. {$ifdef DEBUG}
  1021. +' ('+dotstr(i)+')'
  1022. {$endif DEBUG}
  1023. ,items[j]);
  1024. end;
  1025. end;
  1026. { If no component found abort }
  1027. found:=false;
  1028. for j:=1 to cfg.packs do
  1029. if packmask[j]<>0 then
  1030. found:=true;
  1031. if not found then
  1032. begin
  1033. messagebox('No components found to install, aborting.',nil,mferror+mfokbutton);
  1034. if CreateLog then
  1035. WriteLog ('No components found to install, aborting.');
  1036. errorhalt;
  1037. end;
  1038. r.assign(x1,y1,x2,y2);
  1039. inherited init(r,'');
  1040. Options:=Options or ofCentered;
  1041. GetExtent(R);
  1042. R.Grow(-2,-1);
  1043. Dec(R.B.Y,2);
  1044. TabR.Copy(R);
  1045. TabIR.Copy(R);
  1046. TabIR.Grow(-2,-2);
  1047. TabIR.Move(-2,0);
  1048. {-------- General Sheets ----------}
  1049. R.Copy(TabIR);
  1050. r.move(0,1);
  1051. r.b.x:=r.a.x+40;
  1052. r.b.y:=r.a.y+1;
  1053. new(titletext,init(r,cfg.title,$71));
  1054. r.move(0,2);
  1055. r.b.x:=r.a.x+40;
  1056. new(labpath,init(r,'~B~ase path',f));
  1057. r.move(0,1);
  1058. r.b.x:=r.a.x+40;
  1059. r.b.y:=r.a.y+1;
  1060. new(ilpath,init(r,high(DirStr)));
  1061. r.move(0,2);
  1062. r.b.x:=r.a.x+40;
  1063. new(labcfg,init(r,'Con~f~ig',f));
  1064. r.move(0,1);
  1065. r.b.x:=r.a.x+40;
  1066. r.b.y:=r.a.y+1;
  1067. new(cfgcb,init(r,newsitem('create fpc.cfg',nil)));
  1068. data.cfgval:=1;
  1069. {-------- Pack Sheets ----------}
  1070. for j:=1 to cfg.packs do
  1071. begin
  1072. R.Copy(TabIR);
  1073. if R.A.Y+cfg.pack[j].packages>R.B.Y then
  1074. R.B.Y:=R.A.Y+cfg.pack[j].packages;
  1075. new(packcbs[j],init(r,items[j]));
  1076. if data.packmask[j]=high(sw_word) then
  1077. data.packmask[j]:=packmask[j];
  1078. packcbs[j]^.enablemask:={$ifdef DEV}$7fffffff{$else}enabmask[j]{$endif};
  1079. packcbs[j]^.sel:=firstitem[j];
  1080. end;
  1081. {--------- Main ---------}
  1082. packtd:=nil;
  1083. sbr.assign(1,3,tabr.b.x-tabr.a.x-3,tabr.b.y-tabr.a.y-1);
  1084. for j:=cfg.packs downto 1 do
  1085. begin
  1086. if (sbr.b.y-sbr.a.y)<cfg.pack[j].packages then
  1087. begin
  1088. sbsbr.assign(sbr.b.x,sbr.a.y,sbr.b.x+1,sbr.b.y);
  1089. sbsb:=CreateIdScrollBar (sbsbr.a.x, sbsbr.a.y,sbsbr.b.y-sbsbr.a.y,j,false);
  1090. sbsb^.SetRange(0,cfg.pack[j].packages-(sbsbr.b.y-sbsbr.a.y)-1);
  1091. sbsb^.SetStep(5,1);
  1092. //New(sbsb, init(sbsbr));
  1093. end
  1094. else
  1095. sbsb:=nil;
  1096. New(ScrollBox, Init(sbr, nil, sbsb));
  1097. PackCbs[j]^.MoveTo(0,0);
  1098. ScrollBox^.Insert(PackCbs[j]);
  1099. packtd:=NewTabDef(
  1100. cfg.pack[j].name,ScrollBox,
  1101. NewTabItem(sbsb,
  1102. NewTabItem(ScrollBox,
  1103. nil)),
  1104. packtd);
  1105. end;
  1106. New(Tab, Init(TabR,
  1107. NewTabDef('~G~eneral',IlPath,
  1108. NewTabItem(TitleText,
  1109. NewTabItem(LabPath,
  1110. NewTabItem(ILPath,
  1111. NewTabItem(LabCfg,
  1112. NewTabItem(CfgCB,
  1113. nil))))),
  1114. packtd)
  1115. ));
  1116. Tab^.GrowMode:=0;
  1117. Insert(Tab);
  1118. line:=tabr.b.y;
  1119. r.assign((width div 2)-18,line,(width div 2)-4,line+2);
  1120. new(okbut,init(r,'~C~ontinue',cmok,bfdefault));
  1121. Insert(OkBut);
  1122. r.assign((width div 2)+4,line,(width div 2)+14,line+2);
  1123. new(cancelbut,init(r,'~Q~uit',cmcancel,bfnormal));
  1124. Insert(CancelBut);
  1125. Tab^.Select;
  1126. end;
  1127. procedure tinstalldialog.handleevent(var event : tevent);
  1128. begin
  1129. if event.what=evcommand then
  1130. if event.command=cmquit then
  1131. begin
  1132. putevent(event);
  1133. event.command:=cmCancel;
  1134. end;
  1135. inherited handleevent(event);
  1136. end;
  1137. {*****************************************************************************
  1138. TSpecialInputLine
  1139. *****************************************************************************}
  1140. { this should use AreAllFilesPresent if the base dir is changed...
  1141. but what if the installer has already choosen which files he wants ... }
  1142. procedure TSpecialInputLine.GetData(var Rec);
  1143. begin
  1144. inherited GetData(Rec);
  1145. end;
  1146. {*****************************************************************************
  1147. TApp
  1148. *****************************************************************************}
  1149. const
  1150. cmstart = 1000;
  1151. procedure tapp.do_installdialog;
  1152. var
  1153. p : pinstalldialog;
  1154. p3 : penddialog;
  1155. r : trect;
  1156. result,
  1157. c : word;
  1158. i,j : longint;
  1159. found : boolean;
  1160. {$ifndef Unix}
  1161. DSize,Space,ASpace : int64;
  1162. S: DirStr;
  1163. {$endif}
  1164. procedure doconfigwrite;
  1165. var
  1166. i : longint;
  1167. begin
  1168. for i:=1 to cfg.packs do
  1169. begin
  1170. if cfg.pack[i].defcfgfile<>'' then
  1171. writedefcfg(data.basepath+cfg.pack[i].binsub+DirSep+cfg.pack[i].defcfgfile,cfg.defcfg,cfg.defcfgs,cfg.pack[i].targetname);
  1172. if cfg.pack[i].setpathfile<>'' then
  1173. writedefcfg(data.basepath+cfg.pack[i].binsub+DirSep+cfg.pack[i].setpathfile,cfg.defsetpath,cfg.defsetpaths,cfg.pack[i].targetname);
  1174. end;
  1175. if haside then
  1176. begin
  1177. for i:=1 to cfg.packs do
  1178. if cfg.pack[i].defidecfgfile<>'' then
  1179. writedefcfg(data.basepath+cfg.pack[i].binsub+DirSep+cfg.pack[i].defidecfgfile,cfg.defidecfg,cfg.defidecfgs,cfg.pack[i].targetname);
  1180. for i:=1 to cfg.packs do
  1181. if cfg.pack[i].defideinifile<>'' then
  1182. writedefcfg(data.basepath+cfg.pack[i].binsub+DirSep+cfg.pack[i].defideinifile,cfg.defideini,cfg.defideinis,cfg.pack[i].targetname);
  1183. if hashtmlhelp then
  1184. writehlpindex(data.basepath+DirSep+cfg.DocSub+DirSep+cfg.helpidx);
  1185. end;
  1186. end;
  1187. begin
  1188. data.basepath:=cfg.basepath;
  1189. data.cfgval:=0;
  1190. for j:=1 to cfg.packs do
  1191. data.packmask[j]:=high(sw_word);
  1192. repeat
  1193. { select components }
  1194. p:=new(pinstalldialog,init);
  1195. c:=executedialog(p,@data);
  1196. if (c=cmok) then
  1197. begin
  1198. if Data.BasePath = '' then
  1199. messagebox('Please, choose the directory for installation first.',nil,mferror+mfokbutton)
  1200. else
  1201. begin
  1202. found:=false;
  1203. for j:=1 to cfg.packs do
  1204. if data.packmask[j]>0 then
  1205. found:=true;
  1206. if found then
  1207. begin
  1208. {$IFNDEF UNIX}
  1209. { TH - check the available disk space here }
  1210. DSize := 0;
  1211. for j:=1 to cfg.packs do
  1212. with cfg.pack[j] do
  1213. begin
  1214. for i:=1 to packages do
  1215. begin
  1216. if data.packmask[j] and packagemask(i)<>0 then
  1217. begin
  1218. ASpace := package[i].diskspace;
  1219. if ASpace = -1 then
  1220. begin
  1221. MessageBox ('File ' + package[i].zip +
  1222. ' is probably corrupted!', nil,
  1223. mferror + mfokbutton);
  1224. WriteLog ('File ' + package[i].zip +
  1225. ' is probably corrupted!');
  1226. end
  1227. else Inc (DSize, ASpace);
  1228. end;
  1229. end;
  1230. end;
  1231. WriteLog ('Diskspace needed: ' + DotStr (DSize) + ' Kb');
  1232. S := FExpand (Data.BasePath);
  1233. if S [Length (S)] = DirSep then
  1234. Dec (S [0]);
  1235. Space := DiskFree (byte (Upcase(S [1])) - 64);
  1236. { -1 means that the drive is invalid }
  1237. if Space=-1 then
  1238. begin
  1239. WriteLog ('The drive ' + S [1] + ': is not valid');
  1240. if messagebox('The drive '+S[1]+': is not valid. Do you ' +
  1241. 'want to change the installation path?',nil,
  1242. mferror+mfyesbutton+mfnobutton) = cmYes then
  1243. Continue;
  1244. Space:=0;
  1245. end;
  1246. Space := Space shr 10;
  1247. WriteLog ('Free space on drive ' + S [1] + ': ' +
  1248. DotStr (Space) + ' Kb');
  1249. if Space < DSize then
  1250. S := 'is not '
  1251. else
  1252. S := '';
  1253. if (Space < DSize + 500) then
  1254. begin
  1255. if S = '' then
  1256. S := 'might not be ';
  1257. if messagebox('There ' + S + 'enough space on the target ' +
  1258. 'drive for all the selected components. Do you ' +
  1259. 'want to change the installation path?',nil,
  1260. mferror+mfyesbutton+mfnobutton) = cmYes then
  1261. Continue;
  1262. end;
  1263. {$ENDIF}
  1264. if createinstalldir(data.basepath) then
  1265. break;
  1266. end
  1267. else
  1268. begin
  1269. { maybe only config }
  1270. if (data.cfgval and 1)<>0 then
  1271. begin
  1272. result:=messagebox('No components selected.'#13#13'Create a configfile ?',nil,
  1273. mfinformation+mfyesbutton+mfnobutton);
  1274. if (result=cmYes) and createinstalldir(data.basepath) then
  1275. doconfigwrite;
  1276. exit;
  1277. end
  1278. else
  1279. begin
  1280. result:=messagebox('No components selected.'#13#13'Abort installation?',nil,
  1281. mferror+mfyesbutton+mfnobutton);
  1282. if result=cmYes then
  1283. exit;
  1284. end;
  1285. end;
  1286. end;
  1287. end
  1288. else
  1289. exit;
  1290. until false;
  1291. { extract packages }
  1292. for j:=1 to cfg.packs do
  1293. with cfg.pack[j] do
  1294. begin
  1295. r.assign(10,7,70,18);
  1296. UnzDlg:=new(punzipdialog,init(r,'Extracting Packages'));
  1297. desktop^.insert(UnzDlg);
  1298. for i:=1 to packages do
  1299. begin
  1300. if data.packmask[j] and packagemask(i)<>0 then
  1301. begin
  1302. UnzDlg^.do_unzip(package[i].zip,data.basepath);
  1303. { gather some information about the installed files }
  1304. if copy(package[i].zip,1,3)='ide' then
  1305. haside:=true;
  1306. if copy(package[i].zip,1,7)='doc-htm' then
  1307. begin
  1308. hashtmlhelp:=true;
  1309. { correct the fpctoc file name if .html files are used }
  1310. if package[i].zip='doc-html.zip' then
  1311. if copy(cfg.helpidx,length(cfg.helpidx)-3,4)='.htm' then
  1312. cfg.helpidx:=cfg.helpidx+'l';
  1313. end;
  1314. end;
  1315. end;
  1316. desktop^.delete(UnzDlg);
  1317. dispose(UnzDlg,done);
  1318. end;
  1319. { write config }
  1320. if (data.cfgval and 1)<>0 then
  1321. doconfigwrite;
  1322. { show end message }
  1323. p3:=new(penddialog,init);
  1324. executedialog(p3,nil);
  1325. end;
  1326. procedure tapp.readcfg(const fn:string);
  1327. var
  1328. t : text;
  1329. i,j,k,
  1330. line : longint;
  1331. item,
  1332. s,hs : string;
  1333. params : array[0..0] of pointer;
  1334. {$ifndef FPC}
  1335. procedure readln(var t:text;var s:string);
  1336. var
  1337. c : char;
  1338. i : longint;
  1339. begin
  1340. c:=#0;
  1341. i:=0;
  1342. while (not eof(t)) and (c<>#10) do
  1343. begin
  1344. read(t,c);
  1345. if c<>#10 then
  1346. begin
  1347. inc(i);
  1348. s[i]:=c;
  1349. end;
  1350. end;
  1351. if (i>0) and (s[i]=#13) then
  1352. dec(i);
  1353. s[0]:=chr(i);
  1354. end;
  1355. {$endif}
  1356. begin
  1357. assign(t,StartPath + DirSep + fn);
  1358. {$I-}
  1359. reset(t);
  1360. {$I+}
  1361. if ioresult<>0 then
  1362. begin
  1363. StartPath := GetProgDir;
  1364. assign(t,StartPath + DirSep + fn);
  1365. {$I-}
  1366. reset(t);
  1367. {$I+}
  1368. if ioresult<>0 then
  1369. begin
  1370. params[0]:=@fn;
  1371. messagebox('File %s not found!',@params,mferror+mfokbutton);
  1372. WriteLog ('File "' + fn + '" not found!');
  1373. errorhalt;
  1374. end;
  1375. end;
  1376. line:=0;
  1377. while not eof(t) do
  1378. begin
  1379. readln(t,s);
  1380. inc(line);
  1381. if (s<>'') and not(s[1] in ['#',';']) then
  1382. begin
  1383. i:=pos('=',s);
  1384. if i>0 then
  1385. begin
  1386. item:=upper(Copy(s,1,i-1));
  1387. system.delete(s,1,i);
  1388. if item='VERSION' then
  1389. cfg.version:=s
  1390. else
  1391. if item='TITLE' then
  1392. cfg.title:=s
  1393. else
  1394. if item='BASEPATH' then
  1395. cfg.basepath:=s
  1396. else
  1397. if item='HELPIDX' then
  1398. cfg.helpidx:=s
  1399. else
  1400. if item='DOCSUB' then
  1401. cfg.docsub:=s
  1402. else
  1403. if item='DEFAULTCFG' then
  1404. begin
  1405. repeat
  1406. readln(t,s);
  1407. if upper(s)='ENDCFG' then
  1408. break;
  1409. if cfg.defcfgs<maxdefcfgs then
  1410. begin
  1411. inc(cfg.defcfgs);
  1412. cfg.defcfg[cfg.defcfgs]:=newstr(s);
  1413. end;
  1414. until false;
  1415. end
  1416. else
  1417. if item='DEFAULTIDECFG' then
  1418. begin
  1419. repeat
  1420. readln(t,s);
  1421. if upper(s)='ENDCFG' then
  1422. break;
  1423. if cfg.defidecfgs<maxdefcfgs then
  1424. begin
  1425. inc(cfg.defidecfgs);
  1426. cfg.defidecfg[cfg.defidecfgs]:=newstr(s);
  1427. end;
  1428. until false;
  1429. end
  1430. else
  1431. if item='DEFAULTSETPATH' then
  1432. begin
  1433. repeat
  1434. readln(t,s);
  1435. if upper(s)='ENDCFG' then
  1436. break;
  1437. if cfg.defsetpaths<maxdefcfgs then
  1438. begin
  1439. inc(cfg.defsetpaths);
  1440. cfg.defsetpath[cfg.defsetpaths]:=newstr(s);
  1441. end;
  1442. until false;
  1443. end
  1444. else
  1445. if item='DEFAULTIDEINI' then
  1446. begin
  1447. repeat
  1448. readln(t,s);
  1449. if upper(s)='ENDCFG' then
  1450. break;
  1451. if cfg.defideinis<maxdefcfgs then
  1452. begin
  1453. inc(cfg.defideinis);
  1454. cfg.defideini[cfg.defideinis]:=newstr(s);
  1455. end;
  1456. until false;
  1457. end
  1458. else
  1459. if item='PACK' then
  1460. begin
  1461. inc(cfg.packs);
  1462. if cfg.packs>maxpacks then
  1463. begin
  1464. MessageBox ('Too many packs!', nil,
  1465. mfError + mfOkButton);
  1466. if CreateLog then
  1467. begin
  1468. WriteLn (Log, 'Too many packs');
  1469. close(log);
  1470. end;
  1471. halt(1);
  1472. end;
  1473. cfg.pack[cfg.packs].name:=s;
  1474. end
  1475. else
  1476. if item='CFGFILE' then
  1477. begin
  1478. if cfg.packs=0 then
  1479. begin
  1480. MessageBox ('No pack set found!', nil,
  1481. mfError + mfOkButton);
  1482. if CreateLog then
  1483. begin
  1484. WriteLn (Log, 'No pack set');
  1485. close(Log);
  1486. end;
  1487. halt(1);
  1488. end;
  1489. cfg.pack[cfg.packs].defcfgfile:=s
  1490. end
  1491. else
  1492. if item='IDECFGFILE' then
  1493. begin
  1494. if cfg.packs=0 then
  1495. begin
  1496. MessageBox ('No pack set found!', nil,
  1497. mfError + mfOkButton);
  1498. if CreateLog then
  1499. begin
  1500. WriteLn (Log, 'No pack set');
  1501. Close(Log);
  1502. end;
  1503. halt(1);
  1504. end;
  1505. cfg.pack[cfg.packs].defidecfgfile:=s
  1506. end
  1507. else
  1508. if item='SETPATHFILE' then
  1509. begin
  1510. if cfg.packs=0 then
  1511. begin
  1512. MessageBox ('No pack set found!', nil,
  1513. mfError + mfOkButton);
  1514. if CreateLog then
  1515. begin
  1516. WriteLn (Log, 'No pack set');
  1517. close(Log);
  1518. end;
  1519. halt(1);
  1520. end;
  1521. cfg.pack[cfg.packs].setpathfile:=s
  1522. end
  1523. else
  1524. if item='IDEINIFILE' then
  1525. begin
  1526. if cfg.packs=0 then
  1527. begin
  1528. MessageBox ('No pack set found!', nil,
  1529. mfError + mfOkButton);
  1530. if CreateLog then
  1531. begin
  1532. WriteLn (Log, 'No pack set');
  1533. Close(Log);
  1534. end;
  1535. halt(1);
  1536. end;
  1537. cfg.pack[cfg.packs].defideinifile:=s
  1538. end
  1539. else
  1540. if item='PPC386' then
  1541. begin
  1542. if cfg.packs=0 then
  1543. begin
  1544. MessageBox ('No pack set found!', nil,
  1545. mfError + mfOkButton);
  1546. if CreateLog then
  1547. begin
  1548. WriteLn (Log, 'No pack set');
  1549. Close(Log);
  1550. end;
  1551. halt(1);
  1552. end;
  1553. cfg.pack[cfg.packs].ppc386:=s;
  1554. end
  1555. else
  1556. if item='BINSUB' then
  1557. begin
  1558. if cfg.packs=0 then
  1559. begin
  1560. MessageBox ('No pack set found!', nil,
  1561. mfError + mfOkButton);
  1562. if CreateLog then
  1563. begin
  1564. WriteLn (Log, 'No pack set');
  1565. Close(Log);
  1566. end;
  1567. halt(1);
  1568. end;
  1569. cfg.pack[cfg.packs].binsub:=s;
  1570. end
  1571. {else: Obsolete PM }
  1572. { if item='FILECHECK' then
  1573. begin
  1574. if cfg.packs=0 then
  1575. begin
  1576. MessageBox ('No pack set found!', nil,
  1577. mfError + mfOkButton);
  1578. if CreateLog then
  1579. WriteLn (Log, 'No pack set');
  1580. halt(1);
  1581. end;
  1582. cfg.pack[cfg.packs].filechk:=s;
  1583. end }
  1584. else
  1585. if item='TARGETNAME' then
  1586. begin
  1587. if cfg.packs=0 then
  1588. begin
  1589. MessageBox ('No pack set found!', nil,
  1590. mfError + mfOkButton);
  1591. if CreateLog then
  1592. begin
  1593. WriteLn (Log, 'No pack set');
  1594. Close(Log);
  1595. end;
  1596. halt(1);
  1597. end;
  1598. cfg.pack[cfg.packs].targetname:=s;
  1599. end
  1600. else
  1601. if item='PACKAGE' then
  1602. begin
  1603. if cfg.packs=0 then
  1604. begin
  1605. MessageBox ('No pack set found!', nil,
  1606. mfError + mfOkButton);
  1607. if CreateLog then
  1608. begin
  1609. WriteLn (Log, 'No pack set');
  1610. Close(Log);
  1611. end;
  1612. halt(1);
  1613. end;
  1614. with cfg.pack[cfg.packs] do
  1615. begin
  1616. j:=pos(',',s);
  1617. if (j>0) and (packages<maxpackages) then
  1618. begin
  1619. inc(packages);
  1620. hs:=copy(s,1,j-1);
  1621. k:=pos('[',hs);
  1622. if (k>0) then
  1623. begin
  1624. package[packages].zip:=Copy(hs,1,k-1);
  1625. package[packages].zipshort:=Copy(hs,k+1,length(hs)-k-1);
  1626. end
  1627. else
  1628. package[packages].zip:=hs;
  1629. package[packages].name:=copy(s,j+1,255);
  1630. end;
  1631. package[packages].diskspace:=-1;
  1632. end;
  1633. end
  1634. end;
  1635. end;
  1636. end;
  1637. close(t);
  1638. end;
  1639. procedure tapp.checkavailpack;
  1640. var
  1641. i, j : longint;
  1642. one_found : boolean;
  1643. begin
  1644. { check the packages }
  1645. j:=0;
  1646. while (j<cfg.packs) do
  1647. begin
  1648. inc(j);
  1649. one_found:=false;
  1650. {if cfg.pack[j].filechk<>'' then}
  1651. for i:=1 to cfg.pack[j].packages do
  1652. begin
  1653. if file_exists(cfg.pack[j].package[i].zip,startpath) or
  1654. file_exists(cfg.pack[j].package[i].zipshort,startpath) then
  1655. begin
  1656. one_found:=true;
  1657. break;
  1658. end;
  1659. end;
  1660. if not one_found then
  1661. begin
  1662. { remove the package }
  1663. move(cfg.pack[j+1],cfg.pack[j],sizeof(tpack)*(cfg.packs-j));
  1664. dec(cfg.packs);
  1665. dec(j);
  1666. end;
  1667. end;
  1668. end;
  1669. procedure tapp.initmenubar;
  1670. var
  1671. r : trect;
  1672. begin
  1673. getextent(r);
  1674. r.b.y:=r.a.y+1;
  1675. menubar:=new(pmenubar,init(r,newmenu(
  1676. newsubmenu('Free Pascal Installer',hcnocontext,newmenu(nil
  1677. ),
  1678. nil))));
  1679. end;
  1680. procedure tapp.initstatusline;
  1681. var
  1682. R: TRect;
  1683. begin
  1684. GetExtent(R);
  1685. R.A.Y := R.B.Y - 1;
  1686. //R.B.X := R.B.X - 2;
  1687. New(StatusLine,
  1688. Init(R,
  1689. NewStatusDef(0, $EFFF,nil,nil
  1690. )
  1691. )
  1692. );
  1693. end;
  1694. procedure tapp.handleevent(var event : tevent);
  1695. begin
  1696. inherited handleevent(event);
  1697. if event.what=evcommand then
  1698. if event.command=cmstart then
  1699. begin
  1700. clearevent(event);
  1701. do_installdialog;
  1702. if successfull then
  1703. begin
  1704. event.what:=evcommand;
  1705. event.command:=cmquit;
  1706. handleevent(event);
  1707. end;
  1708. end;
  1709. end;
  1710. {$IFDEF DOSSTUB}
  1711. function CheckOS2: boolean;
  1712. var
  1713. OwnName: PathStr;
  1714. OwnDir: DirStr;
  1715. Name: NameStr;
  1716. Ext: ExtStr;
  1717. DosV, W: word;
  1718. P: PChar;
  1719. const
  1720. Title: string [15] = 'FPC Installer'#0;
  1721. RunBlock: TRunBlock = (Length: $32;
  1722. Dependent: 0;
  1723. Background: 0;
  1724. TraceLevel: 0;
  1725. PrgTitle: @Title [1];
  1726. PrgName: nil;
  1727. Args: nil;
  1728. TermQ: 0;
  1729. Environment: nil;
  1730. Inheritance: 0;
  1731. SesType: 2;
  1732. Icon: nil;
  1733. PgmHandle: 0;
  1734. PgmControl: 2;
  1735. Column: 0;
  1736. Row: 0;
  1737. Width: 80;
  1738. Height: 25);
  1739. begin
  1740. CheckOS2 := false;
  1741. asm
  1742. mov ah, 30h
  1743. int 21h
  1744. xchg ah, al
  1745. mov DosV, ax
  1746. mov ax, 4010h
  1747. int 2Fh
  1748. cmp ax, 4010h
  1749. jnz @0
  1750. xor bx, bx
  1751. @0:
  1752. mov W, bx
  1753. end;
  1754. if DosV > 3 shl 8 then
  1755. begin
  1756. OwnName := FExpand (ParamStr (0));
  1757. FSplit (OwnName, OwnDir, Name, Ext);
  1758. if (DosV >= 20 shl 8 + 10) and (W >= 20 shl 8 + 10) then
  1759. (* OS/2 version 2.1 or later running (double-checked) *)
  1760. begin
  1761. OwnName [Succ (byte (OwnName [0]))] := #0;
  1762. RunBlock.PrgName := @OwnName [1];
  1763. P := Ptr (PrefixSeg, $80);
  1764. if PByte (P)^ <> 0 then
  1765. begin
  1766. Inc (P);
  1767. RunBlock.Args := Ptr (PrefixSeg, $81);
  1768. end;
  1769. asm
  1770. mov ax, 6400h
  1771. mov bx, 0025h
  1772. mov cx, 636Ch
  1773. mov si, offset RunBlock
  1774. int 21h
  1775. jc @0
  1776. mov DosV, 0
  1777. @0:
  1778. end;
  1779. CheckOS2 := DosV = 0;
  1780. end;
  1781. end;
  1782. end;
  1783. {$ENDIF}
  1784. procedure usagescreen;
  1785. begin
  1786. writeln('FPC Installer ',installerversion,' ',installercopyright);
  1787. writeln('Command line options:');
  1788. writeln(' -l create log file');
  1789. {$ifdef MAYBE_LFN}
  1790. writeln(' --nolfn force installation with short file names');
  1791. {$endif MAYBE_LFN}
  1792. writeln;
  1793. writeln(' -h displays this help');
  1794. end;
  1795. var
  1796. OldExit: pointer;
  1797. procedure NewExit;
  1798. begin
  1799. ExitProc := OldExit;
  1800. if CreateLog then
  1801. begin
  1802. {$I-}
  1803. if ErrorAddr <> nil then
  1804. begin
  1805. WriteLn (Log, 'Installer crashed with RTE ', ExitCode);
  1806. Close (Log);
  1807. end
  1808. else
  1809. if ExitCode <> 0 then
  1810. begin
  1811. WriteLn (Log, 'Installer ended with non-zero exit code ', ExitCode);
  1812. Close (Log);
  1813. end
  1814. {$I+}
  1815. end;
  1816. end;
  1817. var
  1818. i : longint;
  1819. { vm : tvideomode;}
  1820. begin
  1821. OldExit := ExitProc;
  1822. ExitProc := @NewExit;
  1823. { register objects for help streaming }
  1824. RegisterWHTMLScan;
  1825. {$IFDEF OS2}
  1826. { TH - no error boxes if checking an inaccessible disk etc. }
  1827. {$IFDEF FPC}
  1828. DosCalls.DosError (0);
  1829. {$ELSE FPC}
  1830. {$IFDEF VirtualPascal}
  1831. OS2Base.DosError (ferr_DisableHardErr);
  1832. {$ELSE VirtualPascal}
  1833. BseDos.DosError (0);
  1834. {$ENDIF VirtualPascal}
  1835. {$ENDIF FPC}
  1836. {$ENDIF}
  1837. {$IFDEF DOSSTUB}
  1838. if CheckOS2 then Halt;
  1839. {$ENDIF}
  1840. createlog:=false;
  1841. {$ifdef MAYBE_LFN}
  1842. locallfnsupport:=system.lfnsupport;
  1843. {$endif MAYBE_LFN}
  1844. for i:=1 to paramcount do
  1845. begin
  1846. if paramstr(i)='-l' then
  1847. createlog:=true
  1848. {$ifdef MAYBE_LFN}
  1849. else if paramstr(i)='--nolfn' then
  1850. begin
  1851. locallfnsupport:=false;
  1852. {$ifdef GO32V2}
  1853. { lfnsupport is a const in win32 RTL }
  1854. system.lfnsupport:=locallfnsupport;
  1855. {$endif GO32V2}
  1856. end
  1857. {$endif MAYBE_LFN}
  1858. else if paramstr(i)='-h' then
  1859. begin
  1860. usagescreen;
  1861. halt(0);
  1862. end
  1863. else
  1864. begin
  1865. usagescreen;
  1866. halt(1);
  1867. end;
  1868. end;
  1869. if createlog then
  1870. begin
  1871. assign(log,'install.log');
  1872. rewrite(log);
  1873. {$ifdef MAYBE_LFN}
  1874. if not(locallfnsupport) then
  1875. WriteLog ('OS doesn''t have LFN support');
  1876. {$endif}
  1877. end;
  1878. getdir(0,startpath);
  1879. successfull:=false;
  1880. fillchar(cfg, SizeOf(cfg), 0);
  1881. fillchar(data, SizeOf(data), 0);
  1882. installapp.init;
  1883. { vm.col:=80;
  1884. vm.row:=25;
  1885. vm.color:=true;
  1886. installapp.SetScreenVideoMode(vm);
  1887. }
  1888. FSplit (FExpand (ParamStr (0)), DStr, CfgName, EStr);
  1889. installapp.readcfg(CfgName + CfgExt);
  1890. installapp.checkavailpack;
  1891. { installapp.readcfg(startpath+dirsep+cfgfile);}
  1892. {$ifdef GO32V2}
  1893. if not(lfnsupport) then
  1894. MessageBox('The operating system doesn''t support LFN (long file names),'+
  1895. ' so some packages will get shorten filenames when installed',nil,mfinformation or mfokbutton);
  1896. {$endif}
  1897. installapp.do_installdialog;
  1898. installapp.done;
  1899. if createlog then
  1900. close(log);
  1901. end.