install.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993-98 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. This is the install program for the DOS version of Free Pascal
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$A+,B-,D+,E+,F-,G-,I-,L+,N-,O-,P-,Q+,R+,S+,T-,V-,X+,Y+}
  14. program install;
  15. uses
  16. app,dialogs,views,objects,menus,drivers,strings,msgbox,dos,unzip,ziptypes;
  17. var
  18. binpath,startpath : string;
  19. successfull : boolean;
  20. const
  21. version = '0';
  22. release = '99';
  23. patchlevel = '8';
  24. filenr = version+release+patchlevel;
  25. doc_version = '110';
  26. {*****************************************************************************
  27. Helpers
  28. *****************************************************************************}
  29. procedure uppervar(var s : string);
  30. var
  31. i : integer;
  32. begin
  33. for i:=1 to length(s) do
  34. s[i]:=upcase(s[i]);
  35. end;
  36. function file_exists(const f : string;const path : string) : boolean;
  37. begin
  38. file_exists:=fsearch(f,path)<>'';
  39. end;
  40. function diskspace(const path,zipfile : string) : string;
  41. var
  42. compressed,uncompressed : longint;
  43. s : string;
  44. begin
  45. s:=path+zipfile+#0;
  46. uncompressed:=UnzipSize(@s[1],compressed);
  47. uncompressed:=uncompressed shr 10;
  48. str(uncompressed,s);
  49. diskspace:=' ('+s+' Kb)';
  50. end;
  51. function createdir(const s : string) : boolean;
  52. var
  53. result : longint;
  54. begin
  55. chdir(s);
  56. if ioresult=0 then
  57. begin
  58. result:=messagebox('The installation directory exists already. '+
  59. 'Do want to enter a new installation directory ?',nil,
  60. mferror+mfyesbutton+mfnobutton);
  61. createdir:=result=cmyes;
  62. exit;
  63. end;
  64. mkdir(s);
  65. if ioresult<>0 then
  66. begin
  67. messagebox('The installation directory couldn''t be created',
  68. @s,mferror+mfokbutton);
  69. createdir:=true;
  70. exit;
  71. end;
  72. createdir:=false;
  73. end;
  74. procedure changedir(const s : string);
  75. begin
  76. chdir(s);
  77. if ioresult<>0 then
  78. begin
  79. messagebox('Error when changing directory ',@s,mferror+mfokbutton);
  80. halt(1);
  81. end;
  82. end;
  83. {*****************************************************************************
  84. TUnZipDialog
  85. *****************************************************************************}
  86. type
  87. punzipdialog=^tunzipdialog;
  88. tunzipdialog=object(tdialog)
  89. filetext : pstatictext;
  90. constructor Init(var Bounds: TRect; ATitle: TTitleStr);
  91. procedure do_unzip(s:string);
  92. end;
  93. constructor tunzipdialog.init;
  94. var
  95. r : trect;
  96. begin
  97. inherited init(bounds,atitle);
  98. R.Assign(11, 4, 38, 5);
  99. filetext:=new(pstatictext,init(r,'File: '));
  100. insert(filetext);
  101. end;
  102. procedure tunzipdialog.do_unzip(s : string);
  103. var
  104. fn,dir,wild : string;
  105. begin
  106. s:=s+'.ZIP';
  107. Disposestr(filetext^.text);
  108. filetext^.Text:=NewStr('File: '+s);
  109. filetext^.drawview;
  110. if not(file_exists(s,startpath)) then
  111. begin
  112. messagebox('File: '+s+' missed for the selected installation. '+
  113. 'Installation doesn''t becomes complete',nil,mferror+mfokbutton);
  114. halt(1);
  115. end;
  116. fn:=startpath+'\'+s+#0;
  117. dir:='.'#0;
  118. wild:='*.*'#0;
  119. FileUnzipEx(@fn[1],@dir[1],@wild[1]);
  120. if doserror<>0 then
  121. begin
  122. messagebox('Error when extracting. Disk full?',nil,mferror+mfokbutton);
  123. halt(1);
  124. end;
  125. end;
  126. {*****************************************************************************
  127. TInstallDialog
  128. *****************************************************************************}
  129. type
  130. pinstalldialog = ^tinstalldialog;
  131. tinstalldialog = object(tdialog)
  132. constructor init;
  133. end;
  134. var
  135. mask_components : longint;
  136. constructor tinstalldialog.init;
  137. var
  138. r : trect;
  139. line : integer;
  140. p,f : pview;
  141. s : string;
  142. const breite = 76;
  143. hoehe = 20;
  144. x1 = (80-breite) div 2;
  145. y1 = (23-hoehe) div 2;
  146. x2 = x1+breite;
  147. y2 = y1+hoehe;
  148. begin
  149. r.assign(x1,y1,x2,y2);
  150. inherited init(r,'Install');
  151. line:=2;
  152. r.assign(3,line+1,28,line+2);
  153. p:=new(pinputline,init(r,79));
  154. f:=p;
  155. s:='C:\PP';
  156. p^.setdata(s);
  157. insert(p);
  158. r.assign(3,line,8,line+1);
  159. insert(new(plabel,init(r,'~P~ath',p)));
  160. insert(p);
  161. inc(line,3);
  162. r.assign(3,line+1,breite-3,line+11);
  163. p:=new(pcheckboxes,init(r,
  164. newsitem('~B~asic system (required)'+diskspace(startpath,'BASEDOS.ZIP'),
  165. newsitem('GNU ~L~inker and GNU Assembler (required)'+diskspace(startpath,'GNUASLD.ZIP'),
  166. newsitem('D~e~mos'+diskspace(startpath,'DEMO.ZIP'),
  167. newsitem('GNU ~D~ebugger'+diskspace(startpath,'GDB.ZIP'),
  168. newsitem('GNU ~U~tilities (required to recompile run time library)'+diskspace(startpath,'GNUUTILS.ZIP'),
  169. newsitem('Documentation (~H~TML)'+diskspace(startpath,'DOCS.ZIP'),
  170. newsitem('Documentation (~P~ostscript)'+diskspace(startpath,'DOC'+doc_version+'PS.ZIP'),
  171. newsitem('~R~un time library sources'+diskspace(startpath,'RL'+filenr+'S.ZIP'),
  172. newsitem('~C~ompiler sources'+diskspace(startpath,'PP'+filenr+'S.ZIP'),
  173. newsitem('Documentation sources (La~T~eX)'+diskspace(startpath,'DOC'+doc_version+'.ZIP'),
  174. nil
  175. ))))))))))));
  176. pcluster(p)^.enablemask:=mask_components;
  177. insert(p);
  178. r.assign(3,line,14,line+1);
  179. insert(new(plabel,init(r,'~C~omponents',p)));
  180. inc(line,12);
  181. { Free Vision
  182. r.assign(3,line+1,breite-3,line+3);
  183. p:=new(pcheckboxes,init(r,
  184. newsitem('~B~asic system',
  185. newsitem('~D~ocumentation',
  186. newsitem('S~a~mples',
  187. newsitem('~S~ources',
  188. nil
  189. ))))));
  190. pcluster(p)^.enablemask:=mask_freevision;
  191. insert(p);
  192. r.assign(3,line,15,line+1);
  193. insert(new(plabel,init(r,'~F~ree Vision',p)));
  194. inc(line,4);
  195. }
  196. r.assign((breite div 2)-14,line,(breite div 2)-4,line+2);
  197. insert(new(pbutton,init(r,'~O~k',cmok,bfdefault)));
  198. r.assign((breite div 2)+4,line,(breite div 2)+14,line+2);
  199. insert(new(pbutton,init(r,'~C~ancel',cmcancel,bfnormal)));
  200. f^.select;
  201. end;
  202. {*****************************************************************************
  203. TApp
  204. *****************************************************************************}
  205. const
  206. cmstart = 1000;
  207. type
  208. tapp = object(tapplication)
  209. procedure initmenubar;virtual;
  210. procedure handleevent(var event : tevent);virtual;
  211. procedure do_installdialog;
  212. end;
  213. procedure tapp.do_installdialog;
  214. var
  215. p : pinstalldialog;
  216. p2 : punzipdialog;
  217. p3 : pstatictext;
  218. r : trect;
  219. c : word;
  220. t : text;
  221. installdata : record
  222. path : string[79];
  223. components : word;
  224. end;
  225. f : file;
  226. label
  227. newpath;
  228. begin
  229. installdata.path:='C:\PP';
  230. installdata.components:=0;
  231. mask_components:=$0;
  232. { searching files }
  233. if file_exists('BASEDOS.ZIP',startpath) then
  234. inc(mask_components,1);
  235. if file_exists('GNUASLD.ZIP',startpath) then
  236. inc(mask_components,2);
  237. if file_exists('DEMO.ZIP',startpath) then
  238. inc(mask_components,4);
  239. if file_exists('GDB.ZIP',startpath) then
  240. inc(mask_components,8);
  241. if file_exists('GNUUTILS.ZIP',startpath) then
  242. inc(mask_components,16);
  243. if file_exists('DOCS.ZIP',startpath) then
  244. inc(mask_components,32);
  245. if file_exists('DOC+doc_version+PS.ZIP',startpath) then
  246. inc(mask_components,64);
  247. if file_exists('RL'+filenr+'S.ZIP',startpath) then
  248. inc(mask_components,128);
  249. if file_exists('PP'+filenr+'S.ZIP',startpath) then
  250. inc(mask_components,256);
  251. if file_exists('DOC+doc_version+S.ZIP',startpath) then
  252. inc(mask_components,512);
  253. while true do
  254. begin
  255. newpath:
  256. p:=new(pinstalldialog,init);
  257. { default settings }
  258. c:=executedialog(p,@installdata);
  259. if c=cmok then
  260. begin
  261. if installdata.path[length(installdata.path)]='\' then
  262. dec(byte(installdata.path[0]));
  263. uppervar(installdata.path);
  264. binpath:=installdata.path+'\BIN';
  265. if createdir(installdata.path) then
  266. goto newpath;
  267. changedir(installdata.path);
  268. r.assign(20,7,60,16);
  269. p2:=new(punzipdialog,init(r,'Extracting files'));
  270. desktop^.insert(p2);
  271. if (installdata.components and 1)<>0 then
  272. p2^.do_unzip('BASEDOS');
  273. if (installdata.components and 2)<>0 then
  274. p2^.do_unzip('GNUASLD');
  275. if (installdata.components and 4)<>0 then
  276. p2^.do_unzip('DEMO');
  277. if (installdata.components and 8)<>0 then
  278. p2^.do_unzip('GDB');
  279. if (installdata.components and 16)<>0 then
  280. p2^.do_unzip('GNUUTILS');
  281. if (installdata.components and 32)<>0 then
  282. p2^.do_unzip('DOCS');
  283. if (installdata.components and 64)<>0 then
  284. p2^.do_unzip('DOC+doc_version+PS');
  285. if (installdata.components and 128)<>0 then
  286. p2^.do_unzip('RL'+filenr+'S');
  287. if (installdata.components and 256)<>0 then
  288. p2^.do_unzip('PP'+filenr+'S');
  289. if (installdata.components and 512)<>0 then
  290. p2^.do_unzip('DOC+doc_version+S');
  291. assign(t,'BIN\PPC386.CFG');
  292. rewrite(t);
  293. writeln(t,'-l');
  294. writeln(t,'#ifdef GO32V1');
  295. writeln(t,'-Up',installdata.path+'\RTL\DOS\GO32V1');
  296. writeln(t,'#endif GO32V1');
  297. writeln(t,'#ifdef GO32V2');
  298. writeln(t,'-Up',installdata.path+'\RTL\DOS\GO32V2');
  299. writeln(t,'#endif GO32V2');
  300. writeln(t,'#ifdef Win32');
  301. writeln(t,'-Up',installdata.path+'\RTL\WIN32');
  302. writeln(t,'#endif Win32');
  303. close(t);
  304. desktop^.delete(p2);
  305. dispose(p2,done);
  306. messagebox('Installation successfull',nil,mfinformation+mfokbutton);
  307. successfull:=true;
  308. end;
  309. break;
  310. end;
  311. end;
  312. procedure tapp.handleevent(var event : tevent);
  313. label
  314. insertdisk1,insertdisk2,newpath;
  315. begin
  316. inherited handleevent(event);
  317. if event.what=evcommand then
  318. if event.command=cmstart then
  319. begin
  320. clearevent(event);
  321. do_installdialog;
  322. if successfull then
  323. begin
  324. event.what:=evcommand;
  325. event.command:=cmquit;
  326. handleevent(event);
  327. end;
  328. end;
  329. end;
  330. procedure tapp.initmenubar;
  331. var
  332. r : trect;
  333. begin
  334. getextent(r);
  335. r.b.y:=r.a.y+1;
  336. menubar:=new(pmenubar,init(r,newmenu(
  337. newsubmenu('~I~nstallation',hcnocontext,newmenu(
  338. newitem('~S~tart','',kbnokey,cmstart,hcnocontext,
  339. newline(
  340. newitem('~E~xit','Alt+X',kbaltx,cmquit,hcnocontext,
  341. nil)))
  342. ),
  343. nil))));
  344. end;
  345. var
  346. installapp : tapp;
  347. begin
  348. getdir(0,startpath);
  349. successfull:=false;
  350. installapp.init;
  351. installapp.do_installdialog;
  352. installapp.done;
  353. if successfull then
  354. begin
  355. writeln('Extend your PATH variable with');
  356. writeln(binpath);
  357. writeln;
  358. writeln('To compile files enter PPC386 [file]');
  359. chdir(startpath);
  360. end;
  361. end.
  362. {
  363. $Log$
  364. Revision 1.4 1998-09-10 10:50:49 florian
  365. * DOS install program updated
  366. Revision 1.3 1998/09/09 13:39:58 peter
  367. + internal unzip
  368. * dialog is showed automaticly
  369. Revision 1.2 1998/04/07 22:47:57 florian
  370. + version/release/patch numbers as string added
  371. }