install.pas 58 KB

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