home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Internet / Strony_WWW / Opus4.x / DOpus414JRsrc.lha / DirectoryOpus4 / Program / main4.c < prev    next >
C/C++ Source or Header  |  2000-03-24  |  16KB  |  524 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  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.
  11.  
  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.
  16.  
  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.
  20.  
  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.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopus.h"
  32. #include <proto/powerpacker.h>
  33. #include <proto/cybergraphics.h>
  34. #include <cybergraphx/cybergraphics.h>
  35.  
  36. void makedir(rexx)
  37. int rexx;
  38. {
  39.     int len,a,success,win,err;
  40.     char dirname[FILEBUF_SIZE],new_directory[256];
  41.     struct FileInfoBlock __aligned fileinfo;
  42.     BPTR lock;
  43.  
  44.     win=data_active_window;
  45.     dirname[0]=new_directory[0]=0;
  46.     if (config->iconflags&ICONFLAG_MAKEDIRICON) len=FILEBUF_SIZE-7;
  47.     else len=FILEBUF_SIZE-2;
  48.  
  49.     FOREVER {
  50.         if (rexx) {
  51.             for (a=0;a<256;a++) {
  52.                 if (!rexx_args[0][a] || rexx_args[0][a]=='/' || rexx_args[0][a]==':') break;
  53.             }
  54.             if (!rexx_args[0][a]) {
  55.                 if (!(isvalidwindow(data_active_window))) return;
  56.                 strcpy(new_directory,str_pathbuffer[data_active_window]);
  57.                 TackOn(new_directory,rexx_args[0],256);
  58.             }
  59.             else {
  60.                 strcpy(new_directory,rexx_args[0]);
  61.                 win=-1;
  62.             }
  63.         }
  64.         else if (status_iconified) {
  65.             if (!(status_flags&STATUS_ISINBUTTONS) ||
  66.                 (!(getdummypath(new_directory,STR_ENTER_DIRECTORY_NAME)))) return;
  67.             win=-1;
  68.         }
  69.         else {
  70.             if (!(isvalidwindow(data_active_window))) return;
  71.             strcpy(new_directory,str_pathbuffer[data_active_window]);
  72.  
  73.             if (!(whatsit(globstring[STR_ENTER_DIRECTORY_NAME],len,dirname,NULL)) ||
  74.                 !dirname[0]) {
  75.                 myabort();
  76.                 return;
  77.             }
  78.             for (a=0;dirname[a];a++) {
  79.                 if (dirname[a]=='/' || dirname[a]==':') {
  80.                     dirname[a]=0;
  81.                     break;
  82.                 }
  83.             }
  84.             if (!dirname[0]) {
  85.                 myabort();
  86.                 return;
  87.             }
  88.             TackOn(new_directory,dirname,256);
  89.         }
  90.  
  91.         if (!(lock=CreateDir(new_directory))) {
  92.             doerror((err=IoErr()));
  93.             if (rexx || (a=checkerror(globstring[STR_CREATING_DIRECTORY],
  94.                 BaseName(new_directory),-err))==3) {
  95.                 myabort();
  96.                 return;
  97.             }
  98.             continue;
  99.         }
  100.  
  101.         Examine(lock,&fileinfo);
  102.         UnLock(lock);
  103.  
  104.         if (win>-1) {
  105.             addfile(dopus_curwin[win],win,fileinfo.fib_FileName,-1,
  106.                 fileinfo.fib_DirEntryType,&fileinfo.fib_Date,
  107.                 NULL,fileinfo.fib_Protection,0,TRUE,NULL,NULL,
  108.                 fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
  109.             seename(win);
  110.             update_buffer_stamp(win,1);
  111.         }
  112.  
  113.         success=1;
  114.         if (config->iconflags&ICONFLAG_MAKEDIRICON) {
  115.             strcat(new_directory,".info");
  116.             if ((iconwrite(ICONTYPE_DRAWER,new_directory))==1 &&
  117.                 (lockandexamine(new_directory,&fileinfo))) {
  118.                 if (win>-1) {
  119.                     addfile(dopus_curwin[win],win,fileinfo.fib_FileName,
  120.                         fileinfo.fib_Size,fileinfo.fib_DirEntryType,&fileinfo.fib_Date,
  121.                         fileinfo.fib_Comment,fileinfo.fib_Protection,0,TRUE,NULL,NULL,
  122.                         fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
  123.                     seename(win);
  124.                     update_buffer_stamp(win,1);
  125.                 }
  126.             }
  127.             else success=0;
  128.         }
  129.         break;
  130.     }
  131.     if (success) dostatustext(globstring[STR_DIRECTORY_CREATED]);
  132. }
  133.  
  134. void blackout(screen,backupmap)
  135. struct Screen *screen;
  136. ULONG *backupmap;
  137. {
  138.     get_palette(screen,backupmap);
  139.     LoadRGB4(&screen->ViewPort,nullpalette,1<<screen->RastPort.BitMap->Depth);
  140. }
  141.  
  142. iconwrite(type,name)
  143. int type;
  144. char *name;
  145. {
  146.     int suc,err;
  147.     struct DiskObject *diskobj;
  148.     char namebuf[256],*ptr,*originalicon,sourcebuf[256];
  149.     struct dopusfiletype *ftype;
  150.  
  151.     if (!IconBase) return(0);
  152.  
  153.     strcpy(namebuf,name);
  154.     if ((ptr=strstri(namebuf,".info"))) *ptr=0;
  155.  
  156.     if (type==ICONTYPE_DRAWER) originalicon=config->drawericon;
  157.     else if (type==ICONTYPE_TRASH) originalicon=NULL;
  158.     else {
  159.         ftype=checkfiletype(namebuf,-2,0);
  160.         if (ftype && ftype->iconpath) originalicon=ftype->iconpath;
  161.         else if (type==ICONTYPE_TOOL) originalicon=config->toolicon;
  162.         else originalicon=config->projecticon;
  163.     }
  164.  
  165.     if (originalicon) {
  166.         strcpy(sourcebuf,originalicon);
  167.         if (!(strstri(sourcebuf,".info"))) strcat(sourcebuf,".info");
  168.     }
  169.  
  170.     FOREVER {
  171.         if (originalicon && originalicon[0] && (CheckExist(sourcebuf,NULL)<0)) {
  172.             if ((copyicon(originalicon,namebuf,&err))>0) return(1);
  173.         }
  174.         else {
  175.             if (system_version2 && (diskobj=GetDefDiskObject(type+2))) {
  176.                 if (diskobj->do_Type==WBPROJECT && config->defaulttool[0]) {
  177.                     ptr=diskobj->do_DefaultTool;
  178.                     diskobj->do_DefaultTool=config->defaulttool;
  179.                 }
  180.                 else ptr=NULL;
  181.                 suc=PutDiskObject(namebuf,diskobj);
  182.                 if (ptr) diskobj->do_DefaultTool=ptr;
  183.                 FreeDiskObject(diskobj);
  184.                 if (suc) return(1);
  185.                 err=IoErr();
  186.             }
  187.             else {
  188.                 if (type==ICONTYPE_PROJECT)
  189.                     icontable[ICONTYPE_PROJECT]->do_DefaultTool=config->defaulttool;
  190.                 if (PutDiskObject(namebuf,icontable[type])) return(1);
  191.                 err=IoErr();
  192.             }
  193.         }
  194.         if ((suc=checkerror(globstring[STR_ADDING_ICON],BaseName(namebuf),err))==3)
  195.             return(-1);
  196.         if (suc==0 || suc==2) return(0);
  197.     }
  198. }
  199.  
  200. copyicon(srce,dest,err)
  201. char *srce,*dest;
  202. int *err;
  203. {
  204.     int suc;
  205.     struct DiskObject *diskobj;
  206.     char buf[256],buf1[256],*ptr;
  207.  
  208.     strcpy(buf1,srce);
  209.     if ((ptr=strstri(buf1,".info"))) *ptr=0;
  210.  
  211.     if (diskobj=GetDiskObject(buf1)) {
  212.         suc=PutDiskObject(dest,diskobj);
  213.         FreeDiskObject(diskobj);
  214.         if (!suc || CheckExist(dest,NULL)>=0) *err=IoErr();
  215.     }
  216.     else {
  217.         StrCombine(buf,dest,".info",256);
  218.         suc=copyfile(srce,buf,err,-1,NULL,0);
  219.     }
  220.     return(suc);
  221. }
  222.  
  223. char *isicon(name)
  224. char *name;
  225. {
  226.     int a;
  227.  
  228.     if ((a=strlen(name))<6) return(NULL);
  229.     if (LStrCmpI(&name[a-5],".info")==0) return(&name[a-5]);
  230.     return(NULL);
  231. }
  232.  
  233. char *getarexxpath(rexx,win,num,argnum)
  234. int rexx,win,num,argnum;
  235. {
  236.     int a,b;
  237.     char *ptr;
  238.     struct FileInfoBlock __aligned fblock;
  239.     APTR save;
  240.  
  241.     if (!rexx || !rexx_argcount) return(str_pathbuffer[win]);
  242.     if ((strchr(rexx_args[argnum],':') || strchr(rexx_args[argnum],'/')) &&
  243.         (a=CheckExist(rexx_args[argnum],&b))) {
  244.         if (!num) {
  245.             save=main_proc->pr_WindowPtr;
  246.             main_proc->pr_WindowPtr=(APTR)-1;
  247.             dos_global_entry.subtype=0;
  248.             if (lockandexamine(rexx_args[argnum],&fblock)) {
  249.                 dos_global_entry.protection=fblock.fib_Protection;
  250.                 dos_global_entry.comment=dos_copy_comment;
  251.                 strcpy(dos_copy_comment,fblock.fib_Comment);
  252.                 dos_global_entry.dispstr=NULL;
  253.                 getprot(dos_global_entry.protection,dos_global_entry.protbuf);
  254.                 CopyMem(&fblock.fib_Date,&dos_global_entry.date,sizeof(struct DateStamp));
  255.                 seedate(&dos_global_entry.date,dos_global_entry.datebuf,1);
  256.                 dos_global_entry.selected=0;
  257.             }
  258.             main_proc->pr_WindowPtr=save;
  259.             ptr=BaseName(rexx_args[argnum]);
  260.             strcpy(dos_global_entry.name,ptr);
  261.             if (ptr>rexx_args[argnum]) {
  262.                 *ptr=0;
  263.                 strcpy(rexx_pathbuffer[win],rexx_args[argnum]);
  264.                 TackOn(rexx_pathbuffer[win],NULL,256);
  265.             }
  266.             else rexx_pathbuffer[win][argnum]=0;
  267.             dos_global_entry.last=dos_global_entry.next=NULL;
  268.             dos_global_entry.type=a;
  269.             dos_global_entry.size=b;
  270.             func_single_entry=&dos_global_entry;
  271.             removeargstring(argnum);
  272.             return(rexx_pathbuffer[win]);
  273.         }
  274.         else {
  275.             strcpy(rexx_pathbuffer[win],rexx_args[argnum]);
  276.             TackOn(rexx_pathbuffer[win],NULL,256);
  277.             removeargstring(argnum);
  278.             return(rexx_pathbuffer[win]);
  279.         }
  280.     }
  281.     return(str_pathbuffer[win]);
  282. }
  283.  
  284. readfile(name,buf,size)
  285. char *name,**buf;
  286. int *size;
  287. {
  288.     int in,loadpp=0;
  289.  
  290.     if (PPBase) {
  291.         if ((in=ppLoadData(name,DECR_POINTER,MEMF_CLEAR,buf,size,NULL))) {
  292.             if (in==-1 || in==-2) return(-1);
  293.             if (in==-3) return(-2);
  294.         }
  295.         else loadpp=1;
  296.     }
  297.     if (!loadpp) {
  298.         if (CheckExist(name,size)>=0 || !(in=Open(name,MODE_OLDFILE))) return(-1);
  299.         if (!(*buf=AllocMem(*size,MEMF_CLEAR))) {
  300.             Close(in);
  301.             return(-2);
  302.         }
  303.         Read(in,*buf,*size);
  304.         Close(in);
  305.     }
  306.     return(0);
  307. }
  308.  
  309. getnewprot(old,new,mask)
  310. int old,new,mask;
  311. {
  312.     int val,a;
  313.  
  314.     if (!mask) return(new);
  315.     val=old&(~255);
  316.     for (a=0;a<8;a++) {
  317.         if (mask&(1<<a)) {
  318.             if (old&(1<<a)) val|=(1<<a);
  319.         }
  320.         else if (new&(1<<a)) val|=(1<<a);
  321.     }
  322.     return(val);
  323. }
  324.  
  325. dateformat(flag)
  326. int flag;
  327. {
  328.     int a;
  329.  
  330.     for (a=0;a<4;a++) {
  331.         if (flag&(1<<a)) return(a);
  332.     }
  333.     return(a);
  334. }
  335.  
  336. void dosound(type)
  337. int type;
  338. {
  339.     struct IOAudio audio;
  340.     static UBYTE achannels[8]={3,5,10,12,1,2,4,8};
  341.     int a;
  342.  
  343. #ifdef DEBUG
  344. KPrintF("beepwave at %lx\n",beepwave);
  345. #endif
  346.     if (type==0 && system_version2>=OSVER_38) DisplayBeep(NULL);
  347.     else {
  348.         audio.ioa_Request.io_Message.mn_ReplyPort=general_port;
  349.         audio.ioa_Request.io_Message.mn_Node.ln_Pri=90;
  350.         audio.ioa_Data=achannels;
  351.         audio.ioa_Length=sizeof(achannels);
  352.         if (!(a=OpenDevice("audio.device",0,(struct IORequest *)&audio,0))) {
  353.             audio.ioa_Request.io_Command=CMD_WRITE;
  354.             audio.ioa_Request.io_Flags=ADIOF_PERVOL;
  355.             audio.ioa_Volume=64;
  356.             audio.ioa_Data=(UBYTE *)beepwave;
  357.             audio.ioa_Length=8;
  358.             switch (type) {
  359.                 case 0:
  360.                     audio.ioa_Period=500;
  361.                     audio.ioa_Cycles=100;
  362.                     BeginIO((struct IORequest *)&audio);
  363.                     WaitIO((struct IORequest *)&audio);
  364.                     break;
  365.                 case 1:
  366.                     audio.ioa_Cycles=60;
  367.                     for (a=0;a<5;a++) {
  368.                         audio.ioa_Period=800;
  369.                         BeginIO((struct IORequest *)&audio);
  370.                         WaitIO((struct IORequest *)&audio);
  371.                         audio.ioa_Period=1200;
  372.                         BeginIO((struct IORequest *)&audio);
  373.                         WaitIO((struct IORequest *)&audio);
  374.                     }
  375.                     audio.ioa_Period=800;
  376.                     BeginIO((struct IORequest *)&audio);
  377.                     WaitIO((struct IORequest *)&audio);
  378.                     break;
  379.             }
  380.             CloseDevice((struct IORequest *)&audio);
  381.         }
  382.     }
  383. }
  384.  
  385. checkscreenmode(mode)
  386. int mode;
  387. {
  388.     DisplayInfoHandle *handle;
  389.     struct DimensionInfo *dimension;
  390.     char buf[256];
  391.     int flags,minw,defw;
  392.  
  393.     if (mode==MODE_WORKBENCHUSE || mode==MODE_WORKBENCHCLONE || mode==MODE_PUBLICSCREEN)
  394.         return(mode);
  395.     if (!system_version2) {
  396.         if (mode==HIRES_KEY || mode==HIRESLACE_KEY) return(mode);
  397.         return(MODE_WORKBENCHCLONE);
  398.     }
  399.     if (!(handle=FindDisplayInfo(mode)) ||
  400.         !(GetDisplayInfoData(handle,buf,256,DTAG_DISP,0)) ||
  401.         ((struct DisplayInfo *)buf)->NotAvailable)
  402.         return(MODE_WORKBENCHCLONE);
  403.     if (CyberGfxBase)
  404.      {
  405.       if (IsCyberModeID(mode))
  406.        {
  407.         if (GetCyberIDAttr(CYBRIDATTR_WIDTH,mode) >= 640) return (mode);
  408.        }
  409.      }
  410.     flags=((struct DisplayInfo *)buf)->PropertyFlags;
  411.     if (flags&DIPF_IS_DUALPF || flags&DIPF_IS_PF2PRI || flags&DIPF_IS_HAM ||
  412.         !(GetDisplayInfoData(handle,buf,256,DTAG_DIMS,0)))
  413.         return(MODE_WORKBENCHCLONE);
  414.     dimension=(struct DimensionInfo *)buf;
  415.     if (mode&HIRES_KEY || mode&HIRESLACE_KEY) minw=640;
  416.     else {
  417.         minw=dimension->MinRasterWidth;
  418.         if (minw<160) minw*=10;
  419.     }
  420.     defw=(dimension->TxtOScan.MaxX-dimension->TxtOScan.MinX)+1;
  421.     if (minw<640 || defw<640 && dimension->MaxDepth>=5)
  422.         return(MODE_WORKBENCHCLONE);
  423.     return(mode);
  424. }
  425.  
  426. void doarrowgadgets(gad,dir)
  427. struct Gadget *gad;
  428. int dir;
  429. {
  430.     int a;
  431.  
  432.     for (a=0;a<2;a++) {
  433.         if (!gad) break;
  434.         do3dbox(main_rp,
  435.             gad->LeftEdge+2,
  436.             gad->TopEdge+1,
  437.             gad->Width-4,
  438.             gad->Height-2);
  439.         DoArrow(main_rp,
  440.             gad->LeftEdge+2,
  441.             gad->TopEdge+1,
  442.             gad->Width-4,
  443.             gad->Height-2,
  444.             screen_pens[config->arrowfg].pen,
  445.             screen_pens[config->arrowbg].pen,dir);
  446.         gad=gad->NextGadget;
  447.     }
  448. }
  449.  
  450. void makermbgad(rmbgad,gad,high)
  451. struct RMBGadget *rmbgad;
  452. struct Gadget *gad;
  453. int high;
  454. {
  455.     rmbgad->x=gad->LeftEdge;
  456.     rmbgad->y=gad->TopEdge;
  457.     rmbgad->w=gad->Width;
  458.     rmbgad->h=gad->Height;
  459.     if (high && gad->GadgetRender) {
  460.         rmbgad->flags|=RGF_ALTBORD;
  461.         rmbgad->high_bord[0]=gad->GadgetRender;
  462.         rmbgad->high_bord[1]=gad->SelectRender;
  463.     }
  464.     else rmbgad->flags&=~RGF_ALTBORD;
  465. }
  466.  
  467. void dolittlegads(gad,txt,num)
  468. struct Gadget *gad;
  469. char *txt;
  470. int num;
  471. {
  472.     int a,y;
  473.     struct TextFont *font;
  474.  
  475.     if (status_iconified || !Window) return;
  476.  
  477.     font=main_rp->Font;
  478.     SetFont(main_rp,scr_font[FONT_GENERAL]);
  479.     for (a=0;a<num;a++) {
  480.         do3dbox(main_rp,gad->LeftEdge+2,gad->TopEdge+1,gad->Width-4,gad->Height-2);
  481.         SetAPen(main_rp,screen_pens[config->littlegadbg].pen);
  482.         rectfill(main_rp,gad->LeftEdge+2,gad->TopEdge+1,gad->Width-4,gad->Height-2);
  483.         SetAPen(main_rp,screen_pens[config->littlegadfg].pen);
  484.         SetBPen(main_rp,screen_pens[config->littlegadbg].pen);
  485.         y=gad->TopEdge+1+(((gad->Height-2)-scr_font[FONT_GENERAL]->tf_YSize)/2);
  486.         if (y<gad->TopEdge+1) y=gad->TopEdge+1;
  487.         y+=scr_font[FONT_GENERAL]->tf_Baseline;
  488.         Move(main_rp,gad->LeftEdge+((gad->Width-scr_font[FONT_GENERAL]->tf_XSize)/2),y);
  489.         Text(main_rp,&txt[a],1);
  490.         RefreshGList(gad,Window,NULL,1);
  491.         if (!(gad=gad->NextGadget)) break;
  492.     }
  493.     SetFont(main_rp,font);
  494. }
  495.  
  496. void rectfill(r,x,y,w,h)
  497. struct RastPort *r;
  498. int x,y,w,h;
  499. {
  500.     if (w<0 || h<0) return;
  501.     RectFill(r,x,y,x+w-1,y+h-1);
  502. }
  503.  
  504. isinwindow(x,y)
  505. int x,y;
  506. {
  507.     int win;
  508.  
  509.     for (win=0;win<2;win++) {
  510.         if (x>=scrdata_dirwin_xpos[win] && x<scrdata_dirwin_xpos[win]+scrdata_dirwin_width[win] &&
  511.             y>=scrdata_dirwin_ypos[win] && y<scrdata_dirwin_height+scrdata_dirwin_ypos[win]) return(win);
  512.     }
  513.     return(-1);
  514. }
  515.  
  516. isvalidwindow(win)
  517. int win;
  518. {
  519.     if (!str_pathbuffer[win]) return(0);
  520.     if (dopus_curwin[win]->total>0 && dopus_curwin[win]->firstentry->type==ENTRY_CUSTOM)
  521.         return(0);
  522.     return(1);
  523. }
  524.