home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / fm2000 / drives.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-04  |  4.3 KB  |  174 lines

  1. /*
  2.      Filemaster - Multitasking directory utility.
  3.      Copyright (C) 2000  Toni Wilen
  4.      
  5.      This program is free software; you can redistribute it and/or
  6.      modify it under the terms of the GNU General Public License
  7.      as published by the Free Software Foundation; either version 2
  8.      of the License, or (at your option) any later version.
  9.      
  10.      This program is distributed in the hope that it will be useful,
  11.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.      GNU General Public License for more details.
  14.      
  15.      You should have received a copy of the GNU General Public License
  16.      along with this program; if not, write to the Free Software
  17.      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. #include <exec/types.h>
  21. #include <exec/memory.h>
  22. #include <dos/dosextens.h>
  23. #include <proto/all.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "fmnode.h"
  27. #include "fmdos.h"
  28. #include "fmlocale.h"
  29.  
  30. WORD infodata(UBYTE*,UBYTE*,WORD);
  31. void drives(struct FMList*);
  32.  
  33. void clearlisti(struct List*);
  34. void shellsortlist(struct FMList*,struct FMNode*,struct Library*,WORD,WORD,WORD);
  35.  
  36. extern struct Window *ikkuna;
  37. extern struct Gadget string1;
  38. extern struct Gadget string2;
  39. extern UBYTE buffer1[];
  40. extern UBYTE buffer2[];
  41. extern struct Library *UtilityBase;
  42. extern struct FMMain fmmain;
  43. extern struct FMList fmlist[];
  44.  
  45. void getkeybytes(void); //HC
  46.  
  47. UBYTE* siirrabstr(UBYTE *ptr1,UBYTE *ptr2)
  48. {
  49. UBYTE cnt;
  50. cnt=*ptr1++;
  51. while(cnt--) *ptr2++=*ptr1++;
  52. *ptr2=0;
  53. return ptr2;
  54. }
  55.  
  56. struct FMNode* adddevice(struct FMList *list,struct DosList *doslist,WORD type)
  57. {
  58. struct FMNode *node;
  59. UBYTE empty[80];
  60. UBYTE *ptr;
  61. struct FMNode *ret=0;
  62.  
  63. if(doslist->dol_Type!=type) return(0);
  64. if(type==DLT_DEVICE && !doslist->dol_Task) return(0);
  65. ptr=siirrabstr((UBYTE*)((doslist->dol_Name)<<2),empty);
  66. *ptr++=':'; *ptr=0;
  67. if (node=allocnode()) {
  68.     node->flags=NASSIGN;
  69.     strcpy(NDFILE(node),empty);
  70.     AddTail((struct List*)list,(struct Node*)node);
  71.     ret=node;
  72. }
  73. return(ret);
  74. }
  75.  
  76. void drives(struct FMList *list)
  77. {
  78. struct Process *proc;
  79. struct DosList *doslist;
  80. APTR ooldwinptr;
  81. struct FMNode *node,*node2;
  82. struct FileInfoBlock *fib;
  83. BPTR lock;
  84. UBYTE *ptr;
  85.  
  86. proc=(struct Process*)FindTask(0);
  87. clearlist(list); list->flags&=~LDIRLIST; list->flags|=LDEVLIST;
  88. if (list->li) {
  89.     list->path[0]=0;
  90.     RefreshGList(&list->li->string,fmmain.ikkuna,0,1);
  91. }
  92. fib=allocvec(list,sizeof(struct FileInfoBlock),MEMF_CLEAR);
  93. if(!fib) return;
  94. ooldwinptr=proc->pr_WindowPtr;
  95. proc->pr_WindowPtr=(APTR)-1;
  96. doslist=LockDosList(LDF_DEVICES|LDF_READ);
  97. while (doslist=NextDosEntry(doslist,LDF_DEVICES)) adddevice(list,doslist,DLT_DEVICE);
  98. UnLockDosList(LDF_DEVICES|LDF_READ);
  99.  
  100. node=list->head;
  101. while(node->succ) {
  102.     if(node->flags==NASSIGN) {
  103.         if(IsFileSystem(NDFILE(node))) {
  104.             if (lock=Lock(NDFILE(node),SHARED_LOCK)) {
  105.                 if (Examine(lock,fib)) {
  106.                     ptr=NDCOMM(node);
  107.                     strcpy(ptr,fib->fib_FileName);
  108.                     ptr+=strlen(ptr);
  109.                     *ptr++=':'; *ptr=0;
  110.                     infodata(NDFILE(node),NDCOMM(node)+fmmain.commlen/2,0);
  111.                 }
  112.                 UnLock(lock);
  113.             }
  114.             node->flags=NDEVICE;
  115.             node=node->succ;
  116.         } else {
  117.             node2=node;
  118.             node=node->succ;
  119.             Remove((struct Node*)node2);
  120.             freevecpooled(node2);
  121.         }
  122.     } else {
  123.         node=node->succ;
  124.     }
  125. }
  126. freemem(fib);
  127. shellsortlist(list,list->head->succ,UtilityBase,fmmain.fileoffset,0,0);
  128.  
  129. doslist=LockDosList(LDF_ASSIGNS|LDF_READ);
  130. while (doslist=NextDosEntry(doslist,LDF_ASSIGNS)) adddevice(list,doslist,DLT_DIRECTORY);
  131. UnLockDosList(LDF_ASSIGNS|LDF_READ);
  132. node=list->head->succ;
  133. while(node->flags&NDEVICE) node=node->succ;
  134. shellsortlist(list,node,UtilityBase,fmmain.fileoffset,0,0);
  135.  
  136. clearlisti((struct List*)&fmmain.dlist);
  137. duplist(list,&fmmain.dlist);
  138. proc->pr_WindowPtr=ooldwinptr;
  139. list->fmmessage1[0]=0;
  140. list->fmmessage2[0]=0;
  141. fmmessage(list);
  142. list->firstlinew=0;
  143. parselist(list,0);
  144. outputlist(list);
  145. updadirmeter(list);
  146.  
  147. }
  148.  
  149. void bdrives(struct FMList *list)
  150. {
  151. struct FMList *dlist;
  152.  
  153. dlist=&fmmain.dlist;
  154. if(dlist->head->succ) {
  155.     clearlist(list);
  156.     list->flags&=~LDIRLIST;
  157.     list->flags|=LDEVLIST;
  158.     if (list->li) {
  159.         list->path[0]=0;
  160.         RefreshGList(&list->li->string,fmmain.ikkuna,0,1);
  161.     }
  162.     duplist(dlist,list);
  163.     list->fmmessage1[0]=0;
  164.     list->fmmessage2[0]=0;
  165.     fmmessage(list);
  166.     parselist(list,0);
  167.     outputlist(list);
  168.     updadirmeter(list);
  169.     return;
  170. } else {
  171.     drives(list);
  172. }
  173. }
  174.