IOFS is gone.
[AROS-Contrib.git] / dopus / Program / main12.c
blob90ed4c59707b8fe29880492c92da9803d3f37a1b
1 /*
3 Directory Opus 4
4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
31 #include <dos/filehandler.h>
33 #include "dopus.h"
35 #ifdef __SASC__
36 #include <i64.h>
37 #endif
39 void setupchangestate(void)
41 int unit;
42 struct IOStdReq *diskreq;
44 disk_change_state=0;
45 if (diskreq=(struct IOStdReq *)LCreateExtIO(general_port,sizeof(struct IOStdReq))) {
46 for (unit=0;unit<4;unit++) {
47 if (!(OpenDevice("trackdisk.device",unit,(struct IORequest *)diskreq,0))) {
48 diskreq->io_Command=TD_CHANGESTATE;
49 DoIO((struct IORequest *)diskreq);
50 if (!diskreq->io_Actual) disk_change_state|=1<<unit;
51 CloseDevice((struct IORequest *)diskreq);
54 LDeleteExtIO((struct IORequest *)diskreq);
58 #define ITEM_NUM 11
60 static short
61 diskinfo_heads[]={
62 STR_DISKINFO_DEVICE,
63 STR_DISKINFO_NAME,
64 STR_DISKINFO_SIZE,
65 STR_DISKINFO_USED,
66 STR_DISKINFO_FREE,
67 STR_DISKINFO_PERCENT,
68 STR_DISKINFO_DENSITY,
69 STR_DISKINFO_ERRORS,
70 STR_DISKINFO_STATUS,
71 STR_DISKINFO_DATE,
72 STR_DISKINFO_FILESYSTEM};
74 void dodiskinfo(path)
75 char *path;
77 struct InfoData __aligned infodata;
78 struct RastPort *dirp;
79 long i;
80 #ifdef __SASC__
81 bigint a;
82 #else
83 unsigned long long a;
84 #endif
85 int b,c,isd=-1,cx,cy,fail=0,xoffset,yoffset,titwidth;
86 static char disktxt[11][60],buf[256],formstr[80],diskname[256],dname[10],buf1[40];
87 float f;
88 struct DateStamp ds;
89 struct MsgPort *prt;
90 struct Gadget contgad;
91 char *gad_gads[2], *uscore,cont_key;
92 BPTR lock;
93 UBYTE old_change_state;
94 ULONG class;
95 UWORD code;
96 struct DOpusRemember *key=NULL;
98 if (!path || !path[0]) return;
100 cx=scr_font[FONT_REQUEST]->tf_XSize;
101 cy=scr_font[FONT_REQUEST]->tf_YSize;
103 for (i=0;i<ITEM_NUM;i++) {
104 disktxt[i][0]='-';
105 disktxt[i][1]=0;
107 main_proc->pr_WindowPtr=(APTR)-1;
108 getnewdisk:
109 strcpy(diskname,path);
110 if (getroot(diskname,&ds)) {
111 strcat(diskname,":");
112 if ((prt=(struct MsgPort *)DeviceProc(diskname))) {
113 if (lock=Lock(diskname,ACCESS_READ)) {
114 Forbid();
115 get_device_task(lock,disktxt[0],prt);
117 for (i=0;i<4;i++) {
118 lsprintf(dname,"DF%ld:",i);
119 if (Stricmp(disktxt[0],dname)==0) {
120 isd=i;
121 break;
124 Permit();
125 Info(lock,&infodata);
126 UnLock(lock);
127 switch (infodata.id_DiskType) {
128 case ID_UNREADABLE_DISK:
129 strcpy(disktxt[1],globstring[STR_UNREADABLE_DISK]);
130 break;
131 case ID_NOT_REALLY_DOS:
132 strcpy(disktxt[1],globstring[STR_NOT_A_DOS_DISK]);
133 break;
134 case ID_KICKSTART_DISK:
135 strcpy(disktxt[1],globstring[STR_KICKSTART_DISK]);
136 break;
137 default:
138 strcpy(buf,path);
139 strcpy(disktxt[1],diskname);
140 disktxt[1][(strlen(disktxt[1])-1)]=0;
141 #ifdef __SASC__
142 a = i64_uumul( infodata.id_NumBlocks, infodata.id_BytesPerBlock );
143 i64_itoa( a, buf1, 40 );
144 #else
145 a=((long long)infodata.id_NumBlocks)*infodata.id_BytesPerBlock;
146 sprintf(buf1,"%qd",a);
147 #endif
148 b=strlen(buf1);
149 lsprintf(buf,"%ld",infodata.id_NumBlocks);
150 lsprintf(formstr,"%%%lds %s; %%%ldld %s; %%s",
151 b,globstring[STR_DISKINFO_BYTES],
152 strlen(buf),globstring[STR_DISKINFO_BLOCKS]);
153 getsizestring(buf,a);
154 lsprintf(disktxt[2],formstr,buf1,infodata.id_NumBlocks,buf);
155 #ifdef __SASC__
156 a = i64_uumul( infodata.id_NumBlocksUsed, infodata.id_BytesPerBlock );
157 getsizestring(buf,a);
158 i64_itoa( a, buf1, 40 );
159 #else
160 a=((long long)infodata.id_NumBlocksUsed)*infodata.id_BytesPerBlock;
161 getsizestring(buf,a);
162 sprintf(buf1,"%qd",a);
163 #endif
164 lsprintf(disktxt[3],formstr,buf1,infodata.id_NumBlocksUsed,buf);
165 #ifdef __SASC__
166 a = i64_uumul( ( infodata.id_NumBlocks-infodata.id_NumBlocksUsed ), infodata.id_BytesPerBlock );
167 getsizestring(buf,a);
168 i64_itoa( a, buf1, 40 );
169 #else
170 a=(infodata.id_NumBlocks-infodata.id_NumBlocksUsed)*((long long)infodata.id_BytesPerBlock);
171 getsizestring(buf,a);
172 sprintf(buf1,"%qd",a);
173 #endif
174 lsprintf(disktxt[4],formstr,buf1,(infodata.id_NumBlocks-infodata.id_NumBlocksUsed),buf);
176 if (infodata.id_NumBlocks) f = ((infodata.id_NumBlocksUsed*100.0)/infodata.id_NumBlocks);
177 else f=100.0;
178 sprintf(buf,"%.1f",f); sprintf(buf1,"%.1f",100.0-f);
179 lsprintf(disktxt[5],"%s%% %s; %s%% %s",
180 buf,globstring[STR_DISKINFO_FULL],
181 buf1,globstring[STR_DISKINFO_SFREE]);
182 lsprintf(disktxt[6],"%ld %s",
183 infodata.id_BytesPerBlock,
184 globstring[STR_DISKINFO_BYTESPERBLOCK]);
185 lsprintf(disktxt[7],"%ld",infodata.id_NumSoftErrors);
186 switch (infodata.id_DiskState) {
187 case ID_VALIDATING:
188 strcpy(disktxt[8],globstring[STR_VALIDATING]);
189 break;
190 case ID_WRITE_PROTECTED:
191 strcpy(disktxt[8],globstring[STR_WRITE_PROTECTED]);
192 break;
193 default:
194 strcpy(disktxt[8],globstring[STR_READ_WRITE]);
195 break;
197 seedate(&ds,disktxt[9],0);
198 //#ifndef __AROS__
199 // DosType fix
201 struct DosList *dl;
202 struct FileSysStartupMsg *fssm;
203 struct DosEnvec *de;
204 char buf[32];
206 if (dl = LockDosList(LDF_DEVICES | LDF_READ))
208 strcpy(buf,disktxt[0]);
209 buf[strlen(buf)-1] = 0;
210 if (dl = FindDosEntry(dl,buf,LDF_DEVICES))
212 if (fssm = BADDR(((struct DeviceNode *)dl)->dn_Startup))
214 if (de = BADDR(fssm->fssm_Environ)) infodata.id_DiskType = de->de_DosType;
216 // else infodata.id_DiskType = 0x3F3F3F3F;
218 UnLockDosList(LDF_DEVICES | LDF_READ);
221 //#endif
222 // end
223 #ifndef __AROS__
224 /* old code
225 disktxt[10][0]=(char)((infodata.id_DiskType>>24)&0xff);
226 disktxt[10][1]=(char)((infodata.id_DiskType>>16)&0xff);
227 disktxt[10][2]=(char)((infodata.id_DiskType>>8)&0xff);
228 disktxt[10][3]=(char)(infodata.id_DiskType&0xff)+'0';
230 // new code
231 *((ULONG *)disktxt[10]) = infodata.id_DiskType;
232 if (disktxt[10][3] < 32) disktxt[10][3] += '0';
233 // end
234 #else
235 disktxt[10][0]=(char)((infodata.id_DiskType>>24)&0xff);
236 disktxt[10][1]=(char)((infodata.id_DiskType>>16)&0xff);
237 disktxt[10][2]=(char)((infodata.id_DiskType>>8)&0xff);
238 disktxt[10][3]=(char)(infodata.id_DiskType&0xff);
239 if (disktxt[10][3] < 32) disktxt[10][3] += '0';
240 #endif
241 disktxt[10][4]=0;
242 switch (infodata.id_DiskType) {
243 case ID_DOS_DISK:
244 strcat(disktxt[10]," (OFS)");
245 break;
246 case ID_FFS_DISK:
247 strcat(disktxt[10]," (FFS)");
248 break;
249 case ID_INTER_DOS_DISK:
250 strcat(disktxt[10]," (I-OFS)");
251 break;
252 case ID_INTER_FFS_DISK:
253 strcat(disktxt[10]," (I-FFS)");
254 break;
255 case ID_FASTDIR_DOS_DISK:
256 strcat(disktxt[10]," (DC-OFS)");
257 break;
258 case ID_FASTDIR_FFS_DISK:
259 strcat(disktxt[10]," (DC-FFS)");
260 break;
261 case ID_MSDOS_DISK:
262 strcat(disktxt[10]," (MS-DOS)");
263 break;
264 case ID_SFS_BE_DISK:
265 strcat(disktxt[10]," (SFS)");
266 break;
267 #ifdef __AROS__
268 case AROS_MAKE_ID('F','A','T',0):
269 strcat(disktxt[10]," (FAT)");
270 break;
271 #endif
273 break;
276 else {
277 i=IoErr();
278 doerror(i);
279 switch (i) {
280 case ERROR_DEVICE_NOT_MOUNTED:
281 strcpy(disktxt[1],globstring[STR_DEVICE_NOT_MOUNTED]);
282 break;
283 case ERROR_NOT_A_DOS_DISK:
284 strcpy(disktxt[1],globstring[STR_NOT_A_DOS_DISK]);
285 break;
286 case ERROR_NO_DISK:
287 strcpy(disktxt[1],globstring[STR_NO_DISK_IN_DRIVE]);
288 break;
289 default:
290 lsprintf(disktxt[1],globstring[STR_DOS_ERROR_CODE],a);
291 break;
295 else fail=1;
297 else fail=1;
299 if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
300 if (fail) {
301 doerror(-1);
302 return;
305 b=0; titwidth=0;
306 for (i=0;i<ITEM_NUM;i++) {
307 if ((c=strlen(disktxt[i]))>b) b=c;
308 if ((c=strlen(globstring[diskinfo_heads[i]]))>titwidth) titwidth=c;
311 disk_win.Width=((b+titwidth+3)*cx)+16;
312 disk_win.Height=(ITEM_NUM*(cy+1))+19;
313 if (config->generalscreenflags&SCR_GENERAL_REQDRAG) {
314 disk_win.Flags=WFLG_RMBTRAP|WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_DEPTHGADGET;
315 xoffset=Window->WScreen->WBorLeft;
316 yoffset=Window->WScreen->WBorTop+Window->WScreen->Font->ta_YSize+1;
317 disk_win.Width+=xoffset+Window->WScreen->WBorRight;
318 disk_win.Height+=yoffset+Window->WScreen->WBorBottom;
319 disk_win.Title="DiskInfo";
321 else {
322 disk_win.Flags=WFLG_BORDERLESS|WFLG_RMBTRAP|WFLG_ACTIVATE;
323 xoffset=2;
324 yoffset=1;
325 disk_win.Width+=4;
326 disk_win.Height+=2;
327 disk_win.Title=NULL;
329 centerwindow(&disk_win);
331 contgad.NextGadget=NULL;
332 contgad.Width=(strlen(globstring[STR_CONTINUE])+4)*cx;
333 contgad.Height=cy+5;
334 contgad.LeftEdge=(disk_win.Width-contgad.Width)/2;
335 contgad.TopEdge=disk_win.Height-cy-10;
336 contgad.Flags=GFLG_GADGHCOMP;
337 contgad.Activation=GACT_RELVERIFY;
338 contgad.GadgetType=GTYP_BOOLGADGET;
339 contgad.GadgetRender=NULL;
340 contgad.SelectRender=NULL;
341 contgad.GadgetText=NULL;
342 contgad.MutualExclude=0;
343 contgad.SpecialInfo=NULL;
344 contgad.GadgetID=0;
346 // StrCombine(buf,"_",globstring[STR_CONTINUE],256);
347 gad_gads[0]=globstring[STR_CONTINUE]/*buf*/;
348 gad_gads[1]=NULL;
350 if (!(fontwindow=OpenWindow(&disk_win))) return;
352 dirp=fontwindow->RPort;
353 setupwindreq(fontwindow);
354 SetFont(dirp,scr_font[FONT_REQUEST]);
355 for (i=0;i<ITEM_NUM;i++) {
356 Move(dirp,xoffset+8,yoffset+5+(i*cy)+scr_font[FONT_REQUEST]->tf_Baseline);
357 Text(dirp,globstring[diskinfo_heads[i]],strlen(globstring[diskinfo_heads[i]]));
358 Move(dirp,xoffset+8+(titwidth*cx),yoffset+5+(i*cy)+scr_font[FONT_REQUEST]->tf_Baseline);
359 Text(dirp," : ",3);
360 Text(dirp,disktxt[i],strlen(disktxt[i]));
362 AddGadgetBorders(&key,
363 &contgad,1,
364 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
365 AddGadgets(fontwindow,
366 &contgad,
367 gad_gads,
369 screen_pens[config->gadgettopcol].pen,
370 screen_pens[config->gadgetbotcol].pen,1);
371 i=0;
373 if (uscore = strchr(globstring[STR_CONTINUE],'_')) cont_key = uscore[1];
374 else cont_key = globstring[STR_CONTINUE][0];
375 cont_key = ToLower(cont_key);
377 FOREVER {
378 while (IMsg=(struct IntuiMessage *)GetMsg(fontwindow->UserPort)) {
379 class=IMsg->Class; code=IMsg->Code;
380 ReplyMsg((struct Message *)IMsg);
381 switch (class) {
382 case IDCMP_DISKREMOVED:
383 setupchangestate();
384 break;
385 case IDCMP_DISKINSERTED:
386 if (isd!=-1) {
387 old_change_state=disk_change_state;
388 setupchangestate();
389 if ((old_change_state&(1<<isd))!=(disk_change_state&(1<<isd))) {
390 i=2;
391 break;
394 break;
395 case IDCMP_VANILLAKEY:
396 if (code!='\r' && ToLower(code)!=cont_key)
397 break;
398 SelectGadget(fontwindow,&contgad);
399 case IDCMP_GADGETUP:
400 i=1;
401 break;
404 if (i) break;
405 Wait(1<<fontwindow->UserPort->mp_SigBit);
407 CloseWindow(fontwindow);
408 fontwindow=NULL;
409 LFreeRemember(&key);
410 if (i==2) goto getnewdisk;
413 void get_device_task(lock,buffer,port)
414 BPTR lock;
415 char *buffer;
416 struct MsgPort *port;
418 struct DeviceList *devlist,*dl;
419 struct RootNode *rootnode;
420 struct DosInfo *dosinfo;
421 struct FileLock *lock2;
423 rootnode=(struct RootNode *) DOSBase->dl_Root;
424 dosinfo=(struct DosInfo *) BADDR(rootnode->rn_Info);
425 devlist=(struct DeviceList *) BADDR(dosinfo->di_DevInfo);
426 lock2=(struct FileLock *)BADDR(lock);
427 dl=(struct DeviceList *)BADDR(lock2->fl_Volume);
429 while (devlist) {
430 if (devlist->dl_Type==DLT_DEVICE && devlist->dl_Task==dl->dl_Task) break;
431 devlist=(struct DeviceList *) BADDR(devlist->dl_Next);
433 if (devlist) BtoCStr((BPTR)devlist->dl_Name,buffer,31);
434 else strcpy(buffer,((struct Task *)port->mp_SigTask)->tc_Node.ln_Name);
435 strcat(buffer,":");
438 #ifdef __SASC__
439 void getsizestring(buf,a)
440 char *buf;
441 bigint a;
443 bigint temp1, temp2, temp3, quot, rema;
445 temp1 = i64_atoi( "1024" );
446 i64_udiv( a, temp1, &quot, &rema );
448 a = quot;
450 temp1 = i64_atoi( "1073741824" );
451 temp2 = i64_atoi( "1048576" );
452 temp3 = i64_atoi( "1024" );
454 if ( i64_cmp( quot, temp1 ) == I64_GREATER )
456 lsprintf( buf, "HUGE" );
458 else if ( i64_cmp( quot, temp2 ) == I64_GREATER )
460 i64_udiv( a, temp2, &quot, &rema );
462 sprintf(buf,"%.1fG", (double)quot.lo + ( (double)rema.lo / 1048576 ));
464 else if ( i64_cmp( quot, temp3 ) == I64_GREATER )
466 i64_udiv( a, temp3, &quot, &rema );
468 sprintf(buf,"%.1fM", (double)quot.lo + ( (double)rema.lo / 1024 ));
470 else lsprintf( buf, "%ldK", (long)a.lo );
472 #else
473 void getsizestring(buf,a)
474 char *buf;
475 unsigned long long a;
477 a/=1024;
478 if (a>1073741824) lsprintf(buf,"HUGE");
479 else if (a>1048576) sprintf(buf,"%.1fG",(double)((double)a/1048576));
480 else if (a>1024) sprintf(buf,"%.1fM",(double)((double)a/1024));
481 else lsprintf(buf,"%ldK",(long)a);
483 #endif
485 void getfloatstr(f,buf)
486 double f;
487 char *buf;
489 int a,b,c,d;
490 char buf1[20];
492 a=(int)f; f-=a;
493 b=(int)(f*100);
494 c=(b/10)*10; d=b-c;
495 if (d>4) c+=10;
496 if (c==100) {
497 c=0; ++a;
499 lsprintf(buf1,"%ld",c); buf1[1]=0;
500 lsprintf(buf,"%ld.%s",a,buf1);