install.pas 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055
  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-2009 Florian Klaempfl';
  81. maxpacks=30;
  82. maxpackages=29;
  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. end
  792. else
  793. if DosLoadModule (@ErrPath, SizeOf (ErrPath), @BFD2EName, Handle) = 0 then
  794. begin
  795. WLibPath := false;
  796. DosFreeModule (Handle);
  797. end
  798. else
  799. begin
  800. WLibPath := true;
  801. Inc (YB, 2);
  802. end;
  803. {$ENDIF}
  804. {$ENDIF}
  805. R.Assign(6, 6, 74, YB);
  806. inherited init(r,'Installation successful.');
  807. Options:=Options or ofCentered;
  808. {$IFNDEF UNIX}
  809. if WPath then
  810. begin
  811. R.Assign(2, 3, 64, 5);
  812. P:=new(pstatictext,init(r,'Extend your PATH variable with '''+S+''''));
  813. insert(P);
  814. end;
  815. {$IFDEF OS2}
  816. if WLibPath then
  817. begin
  818. if WPath then
  819. S := 'and your LIBPATH with ''' + S + '\dll'''
  820. else
  821. S := 'Extend your LIBPATH with ''' + S + '\dll''';
  822. R.Assign (2, YB - 14, 64, YB - 12);
  823. P := New (PStaticText, Init (R, S));
  824. Insert (P);
  825. end;
  826. {$ELSE OS2}
  827. if MixedCasePath then
  828. begin
  829. R.Assign(2, 5, 64, 6);
  830. P:=new(pstatictext,init(r,'You need to use setpath.bat file if you want to use Makefiles'));
  831. insert(P);
  832. end;
  833. {$ENDIF OS2}
  834. {$ENDIF}
  835. R.Assign(2, YB - 13, 64, YB - 12);
  836. P:=new(pstatictext,init(r,'To compile files enter fpc [file]'''));
  837. insert(P);
  838. if haside then
  839. begin
  840. R.Assign(2, YB - 12, 64, YB - 10);
  841. P:=new(pstatictext,init(r,'To start the IDE (Integrated Development Environment) type ''fp'' at a command line prompt'));
  842. insert(P);
  843. end;
  844. R.Assign (29, YB - 9, 39, YB - 7);
  845. Control := New (PButton, Init (R,'~O~k', cmOK, bfDefault));
  846. Insert (Control);
  847. end;
  848. {*****************************************************************************
  849. TInstallDialog
  850. *****************************************************************************}
  851. {$ifdef MAYBE_LFN}
  852. var
  853. islfn : boolean;
  854. procedure lfnreport( Retcode : longint;Rec : pReportRec );
  855. var
  856. p : pathstr;
  857. n : namestr;
  858. e : extstr;
  859. begin
  860. fsplit(strpas(rec^.Filename),p,n,e);
  861. if (length(n)>8) or (length(e)>4) or
  862. (pos('.',n)>0) or (upper(p+n+e)<>upper(strpas(rec^.Filename))) then
  863. islfn:=true;
  864. end;
  865. function haslfn(const zipfile : string) : boolean;
  866. var
  867. buf : array[0..255] of char;
  868. begin
  869. strpcopy(buf,zipfile);
  870. islfn:=false;
  871. {$ifdef FPC}
  872. ViewZip(buf,AllFiles,@lfnreport);
  873. {$else FPC}
  874. ViewZip(buf,AllFiles,lfnreport);
  875. {$endif FPC}
  876. haslfn:=islfn;
  877. end;
  878. {$endif MAYBE_LFN}
  879. var
  880. AllFilesPresent : boolean;
  881. procedure presentreport( Retcode : longint;Rec : pReportRec );
  882. var
  883. st : string;
  884. f : file;
  885. size,time : longint;
  886. p : pathstr;
  887. n : namestr;
  888. e : extstr;
  889. begin
  890. if not ALLFilesPresent then
  891. exit;
  892. st:=Data.BasePath+strpas(rec^.Filename);
  893. fsplit(st,p,n,e);
  894. if not file_exists(n+e,p) then
  895. AllFilesPresent:=false
  896. else
  897. begin
  898. Assign(f,st);
  899. Reset(f,1);
  900. if IOresult<>0 then
  901. begin
  902. ALLfilesPresent:=false;
  903. exit;
  904. end;
  905. GetFtime(f,time);
  906. size:=FileSize(f);
  907. if (rec^.Time<>time) or (rec^.size<>size) then
  908. ALLFilesPresent:=false;
  909. close(f);
  910. end;
  911. end;
  912. function AreAllFilesPresent(const zipfile : string) : boolean;
  913. var
  914. buf : array[0..255] of char;
  915. begin
  916. strpcopy(buf,zipfile);
  917. AllFilesPresent:=true;
  918. {$ifdef FPC}
  919. ViewZip(buf,AllFiles,@presentreport);
  920. {$else FPC}
  921. ViewZip(buf,AllFiles,presentreport);
  922. {$endif FPC}
  923. AreAllFilesPresent:=AllFilesPresent;
  924. end;
  925. constructor tinstalldialog.init;
  926. const
  927. width = 76;
  928. height = 20;
  929. x1 = (79-width) div 2;
  930. y1 = (23-height) div 2;
  931. x2 = x1+width;
  932. y2 = y1+height;
  933. var
  934. tabr,tabir,r : trect;
  935. packmask : array[1..maxpacks] of longint;
  936. enabmask : array[1..maxpacks] of longint;
  937. i,line,j : integer;
  938. items : array[1..maxpacks] of psitem;
  939. f : pview;
  940. found : boolean;
  941. okbut,cancelbut : pbutton;
  942. firstitem : array[1..maxpacks] of integer;
  943. packcbs : array[1..maxpacks] of pcheckboxes;
  944. packtd : ptabdef;
  945. labpath : plabel;
  946. ilpath : pspecialinputline;
  947. tab : ptab;
  948. titletext : pcoloredtext;
  949. labcfg : plabel;
  950. cfgcb : pcheckboxes;
  951. scrollbox: pscrollbox;
  952. sbr,sbsbr: trect;
  953. sbsb: pscrollbar;
  954. zipfile : string;
  955. begin
  956. f:=nil;
  957. { walk packages reverse and insert a newsitem for each, and set the mask }
  958. for j:=1 to cfg.packs do
  959. with cfg.pack[j] do
  960. begin
  961. firstitem[j]:=0;
  962. items[j]:=nil;
  963. packmask[j]:=0;
  964. enabmask[j]:=0;
  965. for i:=packages downto 1 do
  966. begin
  967. zipfile:='';
  968. if file_exists(package[i].zip,startpath) then
  969. zipfile:=startpath+DirSep+package[i].zip
  970. else if file_exists(package[i].zipshort,startpath) then
  971. begin
  972. zipfile:=startpath+DirSep+package[i].zipshort;
  973. { update package to replace the full zipname with the short name }
  974. package[i].zip:=package[i].zipshort;
  975. end;
  976. if zipfile<>'' then
  977. begin
  978. { get diskspace required }
  979. package[i].diskspace:=diskspaceN(zipfile);
  980. {$ifdef MAYBE_LFN}
  981. if not(locallfnsupport) then
  982. begin
  983. if not(haslfn(zipfile)) then
  984. begin
  985. items[j]:=newsitem(package[i].name+diskspacestr(package[i].diskspace),items[j]);
  986. packmask[j]:=packmask[j] or packagemask(i);
  987. enabmask[j]:=enabmask[j] or packagemask(i);
  988. firstitem[j]:=i-1;
  989. WriteLog ('Checking lfn usage for ' + zipfile + ' ... no lfn');
  990. end
  991. else
  992. begin
  993. items[j]:=newsitem(package[i].name+' (requires LFN support)',items[j]);
  994. enabmask[j]:=enabmask[j] or packagemask(i);
  995. firstitem[j]:=i-1;
  996. WriteLog ('Checking lfn usage for ' + zipfile + ' ... uses lfn');
  997. end;
  998. end
  999. else
  1000. {$endif MAYBE_LFN}
  1001. begin
  1002. items[j]:=newsitem(package[i].name+diskspacestr(package[i].diskspace)
  1003. {$ifdef DEBUG}
  1004. +' ('+dotstr(i)+')'
  1005. {$endif DEBUG}
  1006. ,items[j]);
  1007. packmask[j]:=packmask[j] or packagemask(i);
  1008. enabmask[j]:=enabmask[j] or packagemask(i);
  1009. firstitem[j]:=i-1;
  1010. end;
  1011. end
  1012. else
  1013. items[j]:=newsitem(package[i].name
  1014. {$ifdef DEBUG}
  1015. +' ('+dotstr(i)+')'
  1016. {$endif DEBUG}
  1017. ,items[j]);
  1018. end;
  1019. end;
  1020. { If no component found abort }
  1021. found:=false;
  1022. for j:=1 to cfg.packs do
  1023. if packmask[j]<>0 then
  1024. found:=true;
  1025. if not found then
  1026. begin
  1027. messagebox('No components found to install, aborting.',nil,mferror+mfokbutton);
  1028. if CreateLog then
  1029. WriteLog ('No components found to install, aborting.');
  1030. errorhalt;
  1031. end;
  1032. r.assign(x1,y1,x2,y2);
  1033. inherited init(r,'');
  1034. Options:=Options or ofCentered;
  1035. GetExtent(R);
  1036. R.Grow(-2,-1);
  1037. Dec(R.B.Y,2);
  1038. TabR.Copy(R);
  1039. TabIR.Copy(R);
  1040. TabIR.Grow(-2,-2);
  1041. TabIR.Move(-2,0);
  1042. {-------- General Sheets ----------}
  1043. R.Copy(TabIR);
  1044. r.move(0,1);
  1045. r.b.x:=r.a.x+40;
  1046. r.b.y:=r.a.y+1;
  1047. new(titletext,init(r,cfg.title,$71));
  1048. r.move(0,2);
  1049. r.b.x:=r.a.x+40;
  1050. new(labpath,init(r,'~B~ase path',f));
  1051. r.move(0,1);
  1052. r.b.x:=r.a.x+40;
  1053. r.b.y:=r.a.y+1;
  1054. new(ilpath,init(r,high(DirStr)));
  1055. r.move(0,2);
  1056. r.b.x:=r.a.x+40;
  1057. new(labcfg,init(r,'Con~f~ig',f));
  1058. r.move(0,1);
  1059. r.b.x:=r.a.x+40;
  1060. r.b.y:=r.a.y+1;
  1061. new(cfgcb,init(r,newsitem('create fpc.cfg',nil)));
  1062. data.cfgval:=1;
  1063. {-------- Pack Sheets ----------}
  1064. for j:=1 to cfg.packs do
  1065. begin
  1066. R.Copy(TabIR);
  1067. if R.A.Y+cfg.pack[j].packages>R.B.Y then
  1068. R.B.Y:=R.A.Y+cfg.pack[j].packages;
  1069. new(packcbs[j],init(r,items[j]));
  1070. if data.packmask[j]=high(sw_word) then
  1071. data.packmask[j]:=packmask[j];
  1072. packcbs[j]^.enablemask:={$ifdef DEV}$7fffffff{$else}enabmask[j]{$endif};
  1073. packcbs[j]^.sel:=firstitem[j];
  1074. end;
  1075. {--------- Main ---------}
  1076. packtd:=nil;
  1077. sbr.assign(1,3,tabr.b.x-tabr.a.x-3,tabr.b.y-tabr.a.y-1);
  1078. for j:=cfg.packs downto 1 do
  1079. begin
  1080. if (sbr.b.y-sbr.a.y)<cfg.pack[j].packages then
  1081. begin
  1082. sbsbr.assign(sbr.b.x,sbr.a.y,sbr.b.x+1,sbr.b.y);
  1083. sbsb:=CreateIdScrollBar (sbsbr.a.x, sbsbr.a.y,sbsbr.b.y-sbsbr.a.y,j,false);
  1084. sbsb^.SetRange(0,cfg.pack[j].packages-(sbsbr.b.y-sbsbr.a.y)-1);
  1085. sbsb^.SetStep(5,1);
  1086. //New(sbsb, init(sbsbr));
  1087. end
  1088. else
  1089. sbsb:=nil;
  1090. New(ScrollBox, Init(sbr, nil, sbsb));
  1091. PackCbs[j]^.MoveTo(0,0);
  1092. ScrollBox^.Insert(PackCbs[j]);
  1093. packtd:=NewTabDef(
  1094. cfg.pack[j].name,ScrollBox,
  1095. NewTabItem(sbsb,
  1096. NewTabItem(ScrollBox,
  1097. nil)),
  1098. packtd);
  1099. end;
  1100. New(Tab, Init(TabR,
  1101. NewTabDef('~G~eneral',IlPath,
  1102. NewTabItem(TitleText,
  1103. NewTabItem(LabPath,
  1104. NewTabItem(ILPath,
  1105. NewTabItem(LabCfg,
  1106. NewTabItem(CfgCB,
  1107. nil))))),
  1108. packtd)
  1109. ));
  1110. Tab^.GrowMode:=0;
  1111. Insert(Tab);
  1112. line:=tabr.b.y;
  1113. r.assign((width div 2)-18,line,(width div 2)-4,line+2);
  1114. new(okbut,init(r,'~C~ontinue',cmok,bfdefault));
  1115. Insert(OkBut);
  1116. r.assign((width div 2)+4,line,(width div 2)+14,line+2);
  1117. new(cancelbut,init(r,'~Q~uit',cmcancel,bfnormal));
  1118. Insert(CancelBut);
  1119. Tab^.Select;
  1120. end;
  1121. procedure tinstalldialog.handleevent(var event : tevent);
  1122. begin
  1123. if event.what=evcommand then
  1124. if event.command=cmquit then
  1125. begin
  1126. putevent(event);
  1127. event.command:=cmCancel;
  1128. end;
  1129. inherited handleevent(event);
  1130. end;
  1131. {*****************************************************************************
  1132. TSpecialInputLine
  1133. *****************************************************************************}
  1134. { this should use AreAllFilesPresent if the base dir is changed...
  1135. but what if the installer has already choosen which files he wants ... }
  1136. procedure TSpecialInputLine.GetData(var Rec);
  1137. begin
  1138. inherited GetData(Rec);
  1139. end;
  1140. {*****************************************************************************
  1141. TApp
  1142. *****************************************************************************}
  1143. const
  1144. cmstart = 1000;
  1145. procedure tapp.do_installdialog;
  1146. var
  1147. p : pinstalldialog;
  1148. p3 : penddialog;
  1149. r : trect;
  1150. result,
  1151. c : word;
  1152. i,j : longint;
  1153. found : boolean;
  1154. {$ifndef Unix}
  1155. DSize,Space,ASpace : int64;
  1156. S: DirStr;
  1157. {$endif}
  1158. procedure doconfigwrite;
  1159. var
  1160. i : longint;
  1161. begin
  1162. for i:=1 to cfg.packs do
  1163. begin
  1164. if cfg.pack[i].defcfgfile<>'' then
  1165. writedefcfg(data.basepath+cfg.pack[i].binsub+DirSep+cfg.pack[i].defcfgfile,cfg.defcfg,cfg.defcfgs,cfg.pack[i].targetname);
  1166. if cfg.pack[i].setpathfile<>'' then
  1167. writedefcfg(data.basepath+cfg.pack[i].binsub+DirSep+cfg.pack[i].setpathfile,cfg.defsetpath,cfg.defsetpaths,cfg.pack[i].targetname);
  1168. end;
  1169. if haside then
  1170. begin
  1171. for i:=1 to cfg.packs do
  1172. if cfg.pack[i].defidecfgfile<>'' then
  1173. writedefcfg(data.basepath+cfg.pack[i].binsub+DirSep+cfg.pack[i].defidecfgfile,cfg.defidecfg,cfg.defidecfgs,cfg.pack[i].targetname);
  1174. for i:=1 to cfg.packs do
  1175. if cfg.pack[i].defideinifile<>'' then
  1176. writedefcfg(data.basepath+cfg.pack[i].binsub+DirSep+cfg.pack[i].defideinifile,cfg.defideini,cfg.defideinis,cfg.pack[i].targetname);
  1177. if hashtmlhelp then
  1178. writehlpindex(data.basepath+DirSep+cfg.DocSub+DirSep+cfg.helpidx);
  1179. end;
  1180. end;
  1181. begin
  1182. data.basepath:=cfg.basepath;
  1183. data.cfgval:=0;
  1184. for j:=1 to cfg.packs do
  1185. data.packmask[j]:=high(sw_word);
  1186. repeat
  1187. { select components }
  1188. p:=new(pinstalldialog,init);
  1189. c:=executedialog(p,@data);
  1190. if (c=cmok) then
  1191. begin
  1192. if Data.BasePath = '' then
  1193. messagebox('Please, choose the directory for installation first.',nil,mferror+mfokbutton)
  1194. else
  1195. begin
  1196. found:=false;
  1197. for j:=1 to cfg.packs do
  1198. if data.packmask[j]>0 then
  1199. found:=true;
  1200. if found then
  1201. begin
  1202. {$IFNDEF UNIX}
  1203. { TH - check the available disk space here }
  1204. DSize := 0;
  1205. for j:=1 to cfg.packs do
  1206. with cfg.pack[j] do
  1207. begin
  1208. for i:=1 to packages do
  1209. begin
  1210. if data.packmask[j] and packagemask(i)<>0 then
  1211. begin
  1212. ASpace := package[i].diskspace;
  1213. if ASpace = -1 then
  1214. begin
  1215. MessageBox ('File ' + package[i].zip +
  1216. ' is probably corrupted!', nil,
  1217. mferror + mfokbutton);
  1218. WriteLog ('File ' + package[i].zip +
  1219. ' is probably corrupted!');
  1220. end
  1221. else Inc (DSize, ASpace);
  1222. end;
  1223. end;
  1224. end;
  1225. WriteLog ('Diskspace needed: ' + DotStr (DSize) + ' Kb');
  1226. S := FExpand (Data.BasePath);
  1227. if S [Length (S)] = DirSep then
  1228. Dec (S [0]);
  1229. Space := DiskFree (byte (Upcase(S [1])) - 64);
  1230. { -1 means that the drive is invalid }
  1231. if Space=-1 then
  1232. begin
  1233. WriteLog ('The drive ' + S [1] + ': is not valid');
  1234. if messagebox('The drive '+S[1]+': is not valid. Do you ' +
  1235. 'want to change the installation path?',nil,
  1236. mferror+mfyesbutton+mfnobutton) = cmYes then
  1237. Continue;
  1238. Space:=0;
  1239. end;
  1240. Space := Space shr 10;
  1241. WriteLog ('Free space on drive ' + S [1] + ': ' +
  1242. DotStr (Space) + ' Kb');
  1243. if Space < DSize then
  1244. S := 'is not '
  1245. else
  1246. S := '';
  1247. if (Space < DSize + 500) then
  1248. begin
  1249. if S = '' then
  1250. S := 'might not be ';
  1251. if messagebox('There ' + S + 'enough space on the target ' +
  1252. 'drive for all the selected components. Do you ' +
  1253. 'want to change the installation path?',nil,
  1254. mferror+mfyesbutton+mfnobutton) = cmYes then
  1255. Continue;
  1256. end;
  1257. {$ENDIF}
  1258. if createinstalldir(data.basepath) then
  1259. break;
  1260. end
  1261. else
  1262. begin
  1263. { maybe only config }
  1264. if (data.cfgval and 1)<>0 then
  1265. begin
  1266. result:=messagebox('No components selected.'#13#13'Create a configfile ?',nil,
  1267. mfinformation+mfyesbutton+mfnobutton);
  1268. if (result=cmYes) and createinstalldir(data.basepath) then
  1269. doconfigwrite;
  1270. exit;
  1271. end
  1272. else
  1273. begin
  1274. result:=messagebox('No components selected.'#13#13'Abort installation?',nil,
  1275. mferror+mfyesbutton+mfnobutton);
  1276. if result=cmYes then
  1277. exit;
  1278. end;
  1279. end;
  1280. end;
  1281. end
  1282. else
  1283. exit;
  1284. until false;
  1285. { extract packages }
  1286. for j:=1 to cfg.packs do
  1287. with cfg.pack[j] do
  1288. begin
  1289. r.assign(10,7,70,18);
  1290. UnzDlg:=new(punzipdialog,init(r,'Extracting Packages'));
  1291. desktop^.insert(UnzDlg);
  1292. for i:=1 to packages do
  1293. begin
  1294. if data.packmask[j] and packagemask(i)<>0 then
  1295. begin
  1296. UnzDlg^.do_unzip(package[i].zip,data.basepath);
  1297. { gather some information about the installed files }
  1298. if copy(package[i].zip,1,3)='ide' then
  1299. haside:=true;
  1300. if copy(package[i].zip,1,7)='doc-htm' then
  1301. begin
  1302. hashtmlhelp:=true;
  1303. { correct the fpctoc file name if .html files are used }
  1304. if package[i].zip='doc-html.zip' then
  1305. if copy(cfg.helpidx,length(cfg.helpidx)-3,4)='.htm' then
  1306. cfg.helpidx:=cfg.helpidx+'l';
  1307. end;
  1308. end;
  1309. end;
  1310. desktop^.delete(UnzDlg);
  1311. dispose(UnzDlg,done);
  1312. end;
  1313. { write config }
  1314. if (data.cfgval and 1)<>0 then
  1315. doconfigwrite;
  1316. { show end message }
  1317. p3:=new(penddialog,init);
  1318. executedialog(p3,nil);
  1319. end;
  1320. procedure tapp.readcfg(const fn:string);
  1321. var
  1322. t : text;
  1323. i,j,k,
  1324. line : longint;
  1325. item,
  1326. s,hs : string;
  1327. params : array[0..0] of pointer;
  1328. {$ifndef FPC}
  1329. procedure readln(var t:text;var s:string);
  1330. var
  1331. c : char;
  1332. i : longint;
  1333. begin
  1334. c:=#0;
  1335. i:=0;
  1336. while (not eof(t)) and (c<>#10) do
  1337. begin
  1338. read(t,c);
  1339. if c<>#10 then
  1340. begin
  1341. inc(i);
  1342. s[i]:=c;
  1343. end;
  1344. end;
  1345. if (i>0) and (s[i]=#13) then
  1346. dec(i);
  1347. s[0]:=chr(i);
  1348. end;
  1349. {$endif}
  1350. begin
  1351. assign(t,StartPath + DirSep + fn);
  1352. {$I-}
  1353. reset(t);
  1354. {$I+}
  1355. if ioresult<>0 then
  1356. begin
  1357. StartPath := GetProgDir;
  1358. assign(t,StartPath + DirSep + fn);
  1359. {$I-}
  1360. reset(t);
  1361. {$I+}
  1362. if ioresult<>0 then
  1363. begin
  1364. params[0]:=@fn;
  1365. messagebox('File %s not found!',@params,mferror+mfokbutton);
  1366. WriteLog ('File "' + fn + '" not found!');
  1367. errorhalt;
  1368. end;
  1369. end;
  1370. line:=0;
  1371. while not eof(t) do
  1372. begin
  1373. readln(t,s);
  1374. inc(line);
  1375. if (s<>'') and not(s[1] in ['#',';']) then
  1376. begin
  1377. i:=pos('=',s);
  1378. if i>0 then
  1379. begin
  1380. item:=upper(Copy(s,1,i-1));
  1381. system.delete(s,1,i);
  1382. if item='VERSION' then
  1383. cfg.version:=s
  1384. else
  1385. if item='TITLE' then
  1386. cfg.title:=s
  1387. else
  1388. if item='BASEPATH' then
  1389. cfg.basepath:=s
  1390. else
  1391. if item='HELPIDX' then
  1392. cfg.helpidx:=s
  1393. else
  1394. if item='DOCSUB' then
  1395. cfg.docsub:=s
  1396. else
  1397. if item='DEFAULTCFG' then
  1398. begin
  1399. repeat
  1400. readln(t,s);
  1401. if upper(s)='ENDCFG' then
  1402. break;
  1403. if cfg.defcfgs<maxdefcfgs then
  1404. begin
  1405. inc(cfg.defcfgs);
  1406. cfg.defcfg[cfg.defcfgs]:=newstr(s);
  1407. end;
  1408. until false;
  1409. end
  1410. else
  1411. if item='DEFAULTIDECFG' then
  1412. begin
  1413. repeat
  1414. readln(t,s);
  1415. if upper(s)='ENDCFG' then
  1416. break;
  1417. if cfg.defidecfgs<maxdefcfgs then
  1418. begin
  1419. inc(cfg.defidecfgs);
  1420. cfg.defidecfg[cfg.defidecfgs]:=newstr(s);
  1421. end;
  1422. until false;
  1423. end
  1424. else
  1425. if item='DEFAULTSETPATH' then
  1426. begin
  1427. repeat
  1428. readln(t,s);
  1429. if upper(s)='ENDCFG' then
  1430. break;
  1431. if cfg.defsetpaths<maxdefcfgs then
  1432. begin
  1433. inc(cfg.defsetpaths);
  1434. cfg.defsetpath[cfg.defsetpaths]:=newstr(s);
  1435. end;
  1436. until false;
  1437. end
  1438. else
  1439. if item='DEFAULTIDEINI' then
  1440. begin
  1441. repeat
  1442. readln(t,s);
  1443. if upper(s)='ENDCFG' then
  1444. break;
  1445. if cfg.defideinis<maxdefcfgs then
  1446. begin
  1447. inc(cfg.defideinis);
  1448. cfg.defideini[cfg.defideinis]:=newstr(s);
  1449. end;
  1450. until false;
  1451. end
  1452. else
  1453. if item='PACK' then
  1454. begin
  1455. inc(cfg.packs);
  1456. if cfg.packs>maxpacks then
  1457. begin
  1458. MessageBox ('Too many packs!', nil,
  1459. mfError + mfOkButton);
  1460. if CreateLog then
  1461. begin
  1462. WriteLn (Log, 'Too many packs');
  1463. close(log);
  1464. end;
  1465. halt(1);
  1466. end;
  1467. cfg.pack[cfg.packs].name:=s;
  1468. end
  1469. else
  1470. if item='CFGFILE' then
  1471. begin
  1472. if cfg.packs=0 then
  1473. begin
  1474. MessageBox ('No pack set found!', nil,
  1475. mfError + mfOkButton);
  1476. if CreateLog then
  1477. begin
  1478. WriteLn (Log, 'No pack set');
  1479. close(Log);
  1480. end;
  1481. halt(1);
  1482. end;
  1483. cfg.pack[cfg.packs].defcfgfile:=s
  1484. end
  1485. else
  1486. if item='IDECFGFILE' then
  1487. begin
  1488. if cfg.packs=0 then
  1489. begin
  1490. MessageBox ('No pack set found!', nil,
  1491. mfError + mfOkButton);
  1492. if CreateLog then
  1493. begin
  1494. WriteLn (Log, 'No pack set');
  1495. Close(Log);
  1496. end;
  1497. halt(1);
  1498. end;
  1499. cfg.pack[cfg.packs].defidecfgfile:=s
  1500. end
  1501. else
  1502. if item='SETPATHFILE' then
  1503. begin
  1504. if cfg.packs=0 then
  1505. begin
  1506. MessageBox ('No pack set found!', nil,
  1507. mfError + mfOkButton);
  1508. if CreateLog then
  1509. begin
  1510. WriteLn (Log, 'No pack set');
  1511. close(Log);
  1512. end;
  1513. halt(1);
  1514. end;
  1515. cfg.pack[cfg.packs].setpathfile:=s
  1516. end
  1517. else
  1518. if item='IDEINIFILE' then
  1519. begin
  1520. if cfg.packs=0 then
  1521. begin
  1522. MessageBox ('No pack set found!', nil,
  1523. mfError + mfOkButton);
  1524. if CreateLog then
  1525. begin
  1526. WriteLn (Log, 'No pack set');
  1527. Close(Log);
  1528. end;
  1529. halt(1);
  1530. end;
  1531. cfg.pack[cfg.packs].defideinifile:=s
  1532. end
  1533. else
  1534. if item='PPC386' then
  1535. begin
  1536. if cfg.packs=0 then
  1537. begin
  1538. MessageBox ('No pack set found!', nil,
  1539. mfError + mfOkButton);
  1540. if CreateLog then
  1541. begin
  1542. WriteLn (Log, 'No pack set');
  1543. Close(Log);
  1544. end;
  1545. halt(1);
  1546. end;
  1547. cfg.pack[cfg.packs].ppc386:=s;
  1548. end
  1549. else
  1550. if item='BINSUB' then
  1551. begin
  1552. if cfg.packs=0 then
  1553. begin
  1554. MessageBox ('No pack set found!', nil,
  1555. mfError + mfOkButton);
  1556. if CreateLog then
  1557. begin
  1558. WriteLn (Log, 'No pack set');
  1559. Close(Log);
  1560. end;
  1561. halt(1);
  1562. end;
  1563. cfg.pack[cfg.packs].binsub:=s;
  1564. end
  1565. {else: Obsolete PM }
  1566. { if item='FILECHECK' then
  1567. begin
  1568. if cfg.packs=0 then
  1569. begin
  1570. MessageBox ('No pack set found!', nil,
  1571. mfError + mfOkButton);
  1572. if CreateLog then
  1573. WriteLn (Log, 'No pack set');
  1574. halt(1);
  1575. end;
  1576. cfg.pack[cfg.packs].filechk:=s;
  1577. end }
  1578. else
  1579. if item='TARGETNAME' then
  1580. begin
  1581. if cfg.packs=0 then
  1582. begin
  1583. MessageBox ('No pack set found!', nil,
  1584. mfError + mfOkButton);
  1585. if CreateLog then
  1586. begin
  1587. WriteLn (Log, 'No pack set');
  1588. Close(Log);
  1589. end;
  1590. halt(1);
  1591. end;
  1592. cfg.pack[cfg.packs].targetname:=s;
  1593. end
  1594. else
  1595. if item='PACKAGE' then
  1596. begin
  1597. if cfg.packs=0 then
  1598. begin
  1599. MessageBox ('No pack set found!', nil,
  1600. mfError + mfOkButton);
  1601. if CreateLog then
  1602. begin
  1603. WriteLn (Log, 'No pack set');
  1604. Close(Log);
  1605. end;
  1606. halt(1);
  1607. end;
  1608. with cfg.pack[cfg.packs] do
  1609. begin
  1610. j:=pos(',',s);
  1611. if (j>0) and (packages<maxpackages) then
  1612. begin
  1613. inc(packages);
  1614. hs:=copy(s,1,j-1);
  1615. k:=pos('[',hs);
  1616. if (k>0) then
  1617. begin
  1618. package[packages].zip:=Copy(hs,1,k-1);
  1619. package[packages].zipshort:=Copy(hs,k+1,length(hs)-k-1);
  1620. end
  1621. else
  1622. package[packages].zip:=hs;
  1623. package[packages].name:=copy(s,j+1,255);
  1624. end;
  1625. package[packages].diskspace:=-1;
  1626. end;
  1627. end
  1628. end;
  1629. end;
  1630. end;
  1631. close(t);
  1632. end;
  1633. procedure tapp.checkavailpack;
  1634. var
  1635. i, j : longint;
  1636. one_found : boolean;
  1637. begin
  1638. { check the packages }
  1639. j:=0;
  1640. while (j<cfg.packs) do
  1641. begin
  1642. inc(j);
  1643. one_found:=false;
  1644. {if cfg.pack[j].filechk<>'' then}
  1645. for i:=1 to cfg.pack[j].packages do
  1646. begin
  1647. if file_exists(cfg.pack[j].package[i].zip,startpath) or
  1648. file_exists(cfg.pack[j].package[i].zipshort,startpath) then
  1649. begin
  1650. one_found:=true;
  1651. break;
  1652. end;
  1653. end;
  1654. if not one_found then
  1655. begin
  1656. { remove the package }
  1657. move(cfg.pack[j+1],cfg.pack[j],sizeof(tpack)*(cfg.packs-j));
  1658. dec(cfg.packs);
  1659. dec(j);
  1660. end;
  1661. end;
  1662. end;
  1663. procedure tapp.initmenubar;
  1664. var
  1665. r : trect;
  1666. begin
  1667. getextent(r);
  1668. r.b.y:=r.a.y+1;
  1669. menubar:=new(pmenubar,init(r,newmenu(
  1670. newsubmenu('Free Pascal Installer',hcnocontext,newmenu(nil
  1671. ),
  1672. nil))));
  1673. end;
  1674. procedure tapp.initstatusline;
  1675. var
  1676. R: TRect;
  1677. begin
  1678. GetExtent(R);
  1679. R.A.Y := R.B.Y - 1;
  1680. //R.B.X := R.B.X - 2;
  1681. New(StatusLine,
  1682. Init(R,
  1683. NewStatusDef(0, $EFFF,nil,nil
  1684. )
  1685. )
  1686. );
  1687. end;
  1688. procedure tapp.handleevent(var event : tevent);
  1689. begin
  1690. inherited handleevent(event);
  1691. if event.what=evcommand then
  1692. if event.command=cmstart then
  1693. begin
  1694. clearevent(event);
  1695. do_installdialog;
  1696. if successfull then
  1697. begin
  1698. event.what:=evcommand;
  1699. event.command:=cmquit;
  1700. handleevent(event);
  1701. end;
  1702. end;
  1703. end;
  1704. {$IFDEF DOSSTUB}
  1705. function CheckOS2: boolean;
  1706. var
  1707. OwnName: PathStr;
  1708. OwnDir: DirStr;
  1709. Name: NameStr;
  1710. Ext: ExtStr;
  1711. DosV, W: word;
  1712. P: PChar;
  1713. const
  1714. Title: string [15] = 'FPC Installer'#0;
  1715. RunBlock: TRunBlock = (Length: $32;
  1716. Dependent: 0;
  1717. Background: 0;
  1718. TraceLevel: 0;
  1719. PrgTitle: @Title [1];
  1720. PrgName: nil;
  1721. Args: nil;
  1722. TermQ: 0;
  1723. Environment: nil;
  1724. Inheritance: 0;
  1725. SesType: 2;
  1726. Icon: nil;
  1727. PgmHandle: 0;
  1728. PgmControl: 2;
  1729. Column: 0;
  1730. Row: 0;
  1731. Width: 80;
  1732. Height: 25);
  1733. begin
  1734. CheckOS2 := false;
  1735. asm
  1736. mov ah, 30h
  1737. int 21h
  1738. xchg ah, al
  1739. mov DosV, ax
  1740. mov ax, 4010h
  1741. int 2Fh
  1742. cmp ax, 4010h
  1743. jnz @0
  1744. xor bx, bx
  1745. @0:
  1746. mov W, bx
  1747. end;
  1748. if DosV > 3 shl 8 then
  1749. begin
  1750. OwnName := FExpand (ParamStr (0));
  1751. FSplit (OwnName, OwnDir, Name, Ext);
  1752. if (DosV >= 20 shl 8 + 10) and (W >= 20 shl 8 + 10) then
  1753. (* OS/2 version 2.1 or later running (double-checked) *)
  1754. begin
  1755. OwnName [Succ (byte (OwnName [0]))] := #0;
  1756. RunBlock.PrgName := @OwnName [1];
  1757. P := Ptr (PrefixSeg, $80);
  1758. if PByte (P)^ <> 0 then
  1759. begin
  1760. Inc (P);
  1761. RunBlock.Args := Ptr (PrefixSeg, $81);
  1762. end;
  1763. asm
  1764. mov ax, 6400h
  1765. mov bx, 0025h
  1766. mov cx, 636Ch
  1767. mov si, offset RunBlock
  1768. int 21h
  1769. jc @0
  1770. mov DosV, 0
  1771. @0:
  1772. end;
  1773. CheckOS2 := DosV = 0;
  1774. end;
  1775. end;
  1776. end;
  1777. {$ENDIF}
  1778. procedure usagescreen;
  1779. begin
  1780. writeln('FPC Installer ',installerversion,' ',installercopyright);
  1781. writeln('Command line options:');
  1782. writeln(' -l create log file');
  1783. {$ifdef MAYBE_LFN}
  1784. writeln(' --nolfn force installation with short file names');
  1785. {$endif MAYBE_LFN}
  1786. writeln;
  1787. writeln(' -h displays this help');
  1788. end;
  1789. var
  1790. OldExit: pointer;
  1791. procedure NewExit;
  1792. begin
  1793. ExitProc := OldExit;
  1794. if CreateLog then
  1795. begin
  1796. {$I-}
  1797. if ErrorAddr <> nil then
  1798. begin
  1799. WriteLn (Log, 'Installer crashed with RTE ', ExitCode);
  1800. Close (Log);
  1801. end
  1802. else
  1803. if ExitCode <> 0 then
  1804. begin
  1805. WriteLn (Log, 'Installer ended with non-zero exit code ', ExitCode);
  1806. Close (Log);
  1807. end
  1808. {$I+}
  1809. end;
  1810. end;
  1811. var
  1812. i : longint;
  1813. { vm : tvideomode;}
  1814. begin
  1815. OldExit := ExitProc;
  1816. ExitProc := @NewExit;
  1817. { register objects for help streaming }
  1818. RegisterWHTMLScan;
  1819. {$IFDEF OS2}
  1820. { TH - no error boxes if checking an inaccessible disk etc. }
  1821. {$IFDEF FPC}
  1822. DosCalls.DosError (0);
  1823. {$ELSE FPC}
  1824. {$IFDEF VirtualPascal}
  1825. OS2Base.DosError (ferr_DisableHardErr);
  1826. {$ELSE VirtualPascal}
  1827. BseDos.DosError (0);
  1828. {$ENDIF VirtualPascal}
  1829. {$ENDIF FPC}
  1830. {$ENDIF}
  1831. {$IFDEF DOSSTUB}
  1832. if CheckOS2 then Halt;
  1833. {$ENDIF}
  1834. createlog:=false;
  1835. {$ifdef MAYBE_LFN}
  1836. locallfnsupport:=system.lfnsupport;
  1837. {$endif MAYBE_LFN}
  1838. for i:=1 to paramcount do
  1839. begin
  1840. if paramstr(i)='-l' then
  1841. createlog:=true
  1842. {$ifdef MAYBE_LFN}
  1843. else if paramstr(i)='--nolfn' then
  1844. begin
  1845. locallfnsupport:=false;
  1846. {$ifdef GO32V2}
  1847. { lfnsupport is a const in win32 RTL }
  1848. system.lfnsupport:=locallfnsupport;
  1849. {$endif GO32V2}
  1850. end
  1851. {$endif MAYBE_LFN}
  1852. else if paramstr(i)='-h' then
  1853. begin
  1854. usagescreen;
  1855. halt(0);
  1856. end
  1857. else
  1858. begin
  1859. usagescreen;
  1860. halt(1);
  1861. end;
  1862. end;
  1863. if createlog then
  1864. begin
  1865. assign(log,'install.log');
  1866. rewrite(log);
  1867. {$ifdef MAYBE_LFN}
  1868. if not(locallfnsupport) then
  1869. WriteLog ('OS doesn''t have LFN support');
  1870. {$endif}
  1871. end;
  1872. getdir(0,startpath);
  1873. successfull:=false;
  1874. fillchar(cfg, SizeOf(cfg), 0);
  1875. fillchar(data, SizeOf(data), 0);
  1876. installapp.init;
  1877. { vm.col:=80;
  1878. vm.row:=25;
  1879. vm.color:=true;
  1880. installapp.SetScreenVideoMode(vm);
  1881. }
  1882. FSplit (FExpand (ParamStr (0)), DStr, CfgName, EStr);
  1883. installapp.readcfg(CfgName + CfgExt);
  1884. installapp.checkavailpack;
  1885. { installapp.readcfg(startpath+dirsep+cfgfile);}
  1886. {$ifdef GO32V2}
  1887. if not(lfnsupport) then
  1888. MessageBox('The operating system doesn''t support LFN (long file names),'+
  1889. ' so some packages will get shorten filenames when installed',nil,mfinformation or mfokbutton);
  1890. {$endif}
  1891. installapp.do_installdialog;
  1892. installapp.done;
  1893. if createlog then
  1894. close(log);
  1895. end.