home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / wbgames / shuffle / source / shuffle_files.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  8KB  |  246 lines

  1.  
  2. #include "shuffle.h"
  3.  
  4. #define SHUFFLE_HEADER "*Shuffle*"
  5.  
  6. /* sc:src/shuffle/sh_icon.c --- Data for Shell icon
  7.  *
  8.  */
  9.  
  10. UWORD chip ShellI1Data[] =
  11. {
  12. /* Plane 0 */
  13.     0x0000,0x0000,0x0000,0x0400,0x0800,0x0000,0x0041,0x0400,
  14.     0x0800,0x0000,0x0041,0x0400,0x7FFF,0xFFFF,0xFFFF,0xFC00,
  15.     0x2000,0x0000,0x0000,0x0400,0x2000,0x0000,0x0000,0x0400,
  16.     0x2330,0x0000,0x0000,0x0400,0x270C,0x0000,0x0000,0x0400,
  17.     0x2303,0x0000,0x0000,0x0400,0x230C,0x0000,0x0000,0x0400,
  18.     0x2330,0x0000,0x0000,0x0400,0x2000,0x0000,0x0000,0x0400,
  19.     0x2000,0x0000,0x0000,0x0400,0x2000,0x0000,0x0000,0x0400,
  20.     0x2000,0x0000,0x0000,0x0400,0x2000,0x0000,0x0000,0x0400,
  21.     0x2000,0x0000,0x0000,0x0400,0x2000,0x0000,0x0000,0x0400,
  22.     0x2000,0x0000,0x0000,0x0400,0x2000,0x0000,0x0000,0x0400,
  23.     0x2000,0x0000,0x0000,0x0400,0x7FFF,0xFFFF,0xFFFF,0xFC00,
  24. /* Plane 1 */
  25.     0xFFFF,0xFFFF,0xFFFF,0xF800,0x8400,0x0000,0x0020,0x8000,
  26.     0x8400,0x0000,0x0020,0x8000,0x8000,0x0000,0x0000,0x0000,
  27.     0x8000,0x0000,0x0000,0x8000,0x8000,0x0000,0x0000,0x8000,
  28.     0x8000,0x0000,0x0000,0x8000,0x8000,0x0000,0x0000,0x8000,
  29.     0x8000,0x0000,0x0000,0x8000,0x8000,0x0000,0x0000,0x8000,
  30.     0x8000,0x0000,0x0000,0x8000,0x8000,0x0000,0x0000,0x8000,
  31.     0x8000,0x0000,0x0000,0x8000,0x8000,0x0000,0x0000,0x8000,
  32.     0x8000,0x0000,0x0000,0x8000,0x8000,0x0000,0x0000,0x8000,
  33.     0x8000,0x0000,0x0000,0x8000,0x8000,0x0000,0x0000,0x8000,
  34.     0x8000,0x0000,0x0000,0x8000,0x8000,0x0000,0x0000,0x8000,
  35.     0x8000,0x0000,0x0000,0x8000,0x8000,0x0000,0x0000,0x0000,
  36. };
  37.  
  38. struct Image ShellI1 =
  39. {
  40.     0, 0,            /* Upper left corner */
  41.     54, 22, 2,            /* Width, Height, Depth */
  42.     ShellI1Data,        /* Image data */
  43.     0x0003, 0x0000,        /* PlanePick, PlaneOnOff */
  44.     NULL            /* Next image */
  45. };
  46.  
  47. UWORD chip ShellI2Data[] =
  48. {
  49. /* Plane 0 */
  50.     0x0000,0x0000,0x0000,0x0400,0x7BEF,0x7DEF,0xBDCF,0x7C00,
  51.     0x7BEF,0x7DEF,0xBDCF,0x7C00,0x7BEF,0x7DEF,0xBDEF,0xFC00,
  52.     0x6000,0x0000,0x0000,0x7C00,0x0000,0x0000,0x0000,0x0400,
  53.     0x6320,0x0000,0x0000,0x7C00,0x630C,0x0000,0x0000,0x7C00,
  54.     0x6303,0x0000,0x0000,0x7C00,0x630C,0x0000,0x0000,0x7C00,
  55.     0x6320,0x0000,0x0000,0x7C00,0x4000,0x0000,0x0000,0x0400,
  56.     0x6000,0x0000,0x0000,0x7C00,0x6000,0x0000,0x0000,0x7C00,
  57.     0x6000,0x0000,0x0000,0x7C00,0x6000,0x0000,0x0000,0x7C00,
  58.     0x6000,0x0000,0x0000,0x7C00,0x4000,0x0000,0x0000,0x0C00,
  59.     0x6000,0x0000,0x0000,0x7C00,0x6000,0x0000,0x0000,0x7C00,
  60.     0x6000,0x0000,0x0000,0x7C00,0x7BEF,0x7DEF,0xBDEF,0xFC00,
  61. /* Plane 1 */
  62.     0xFFFF,0xFFFF,0xFFFF,0xF800,0xF7FF,0xFFFF,0xFFBE,0xF800,
  63.     0xF7FF,0xFFFF,0xFFBE,0xF800,0x8410,0x8210,0x4210,0x0000,
  64.     0xC410,0x8210,0x4210,0xF800,0xFFFF,0xFFFF,0xFFFF,0xF800,
  65.     0xC410,0xBE10,0x4210,0xF800,0xC410,0xBE10,0x4210,0xF800,
  66.     0xC410,0xBE10,0x4210,0xF800,0xC410,0xBE10,0x4210,0xF800,
  67.     0xC410,0xBE10,0x4210,0xF800,0xFFFF,0xFFFF,0xFFFF,0xF800,
  68.     0xC410,0x8210,0x4210,0xF800,0xC410,0x8210,0x4210,0xF800,
  69.     0xC410,0x8210,0x4210,0xF800,0xC410,0x8210,0x4210,0xF800,
  70.     0xC410,0x8210,0x4210,0xF800,0xFFFF,0xFFFF,0xFFFF,0xF800,
  71.     0xC410,0x8210,0x4210,0xF800,0xC410,0x8210,0x4210,0xF800,
  72.     0xC410,0x8210,0x4210,0xF800,0x8410,0x8210,0x4210,0x0000,
  73. };
  74.  
  75. struct Image ShellI2 =
  76. {
  77.     0, 0,            /* Upper left corner */
  78.     54, 22, 2,            /* Width, Height, Depth */
  79.     ShellI2Data,        /* Image data */
  80.     0x0003, 0x0000,        /* PlanePick, PlaneOnOff */
  81.     NULL            /* Next image */
  82. };
  83.  
  84. struct DiskObject Shell =
  85. {
  86.     WB_DISKMAGIC,        /* Magic Number */
  87.     WB_DISKVERSION,        /* Version */
  88.     {                /* Embedded Gadget Structure */
  89.     NULL,            /* Next Gadget Pointer */
  90.     0, 0, 54, 23,        /* Left,Top,Width,Height */
  91.     GADGIMAGE | GADGHIMAGE,    /* Flags */
  92.     RELVERIFY,        /* Activation Flags */
  93.     BOOLGADGET,        /* Gadget Type */
  94.     (APTR)&ShellI1,    /* Render Image */
  95.     (APTR)&ShellI2,    /* Select Image */
  96.     NULL,            /* Gadget Text */
  97.     NULL,            /* Mutual Exclude */
  98.     NULL,            /* Special Info */
  99.     100,            /* Gadget ID */
  100.     (APTR) 0x0001,        /* User Data (Revision) */
  101.     },
  102.     WBPROJECT,            /* Icon Type */
  103.     (char *)"Shuffle",        /* Default Tool */
  104.     NULL,            /* Tool Type Array */
  105.     NO_ICON_POSITION,        /* Current X */
  106.     NO_ICON_POSITION,        /* Current Y */
  107.     NULL,            /* Drawer Structure */
  108.     NULL,            /* Tool Window */
  109. };
  110.  
  111.  
  112.  
  113. struct TagItem       FRTags[] =
  114.                      {
  115.                       ASL_Hail,NULL,
  116.                       ASL_FuncFlags,0L,
  117.                       ASL_LeftEdge,0L,
  118.                       ASL_TopEdge,0L,
  119.                       ASL_Dir,0L,
  120.                       ASL_Pattern,(ULONG)"~(#?.info)",
  121.                       ASL_File,0L,
  122.                       TAG_DONE,0L
  123.                      };
  124.                      
  125. struct EasyStruct ExistsReq =
  126.        {
  127.         0L,0L,(UBYTE *)"Shuffle... Error",
  128.               (UBYTE *)"The File\n%s\nalready exists !",
  129.               (UBYTE *)" Overwrite | CANCEL",
  130.        };
  131.  
  132.  
  133.  
  134. void save_config(ULONG mode)
  135. {
  136.  struct FileRequester *FileReq;
  137.  UBYTE fname[256];
  138.  int save = FALSE;
  139.  FILE *f;
  140.  switch(mode)
  141.  {
  142.   case SAVE_NAME   : strcpy(fname,info.f_dir);
  143.                      AddPart(fname,info.f_file,256);
  144.                      save = TRUE;
  145.                      break;
  146.   case SAVE_AS     : FRTags[0].ti_Data = (ULONG)"Save Shuffle Configuration";
  147.                      FRTags[1].ti_Data = FILF_SAVE;
  148.                      FRTags[4].ti_Data = (ULONG)info.f_dir;
  149.                      FRTags[6].ti_Data = (ULONG)info.f_file;
  150.                      if(FileReq = (struct FileRequester *)AllocAslRequest(ASL_FileRequest,FRTags))
  151.                      {
  152.                       if(RequestFile(FileReq))
  153.                       { 
  154.                        strcpy(info.f_dir,FileReq->rf_Dir);
  155.                        strcpy(info.f_file,FileReq->rf_File);
  156.                        strcpy(fname,FileReq->rf_Dir);
  157.                        AddPart(fname,FileReq->rf_File,256);
  158.                        save = TRUE;
  159.                       }
  160.                       FreeAslRequest((APTR)FileReq);
  161.                      }
  162.                      break;
  163.   case SAVE_DEF_ENVARC :
  164.                      strcpy(fname,"ENVARC:");
  165.                      AddPart(fname,"shuffle.config",256);
  166.                      save = TRUE;
  167.                      break;
  168.  case SAVE_DEF_ENV     :
  169.                      strcpy(fname,"ENV:");
  170.                      AddPart(fname,"shuffle.config",256);
  171.                      save = TRUE;
  172.                      break;
  173.  
  174.  }
  175.  if(save)
  176.  {
  177.   if(f = fopen(fname,"w"))
  178.   {
  179.    fprintf(f,"%s\n",SHUFFLE_HEADER);
  180.    fprintf(f,"%ld\n",info.res);
  181.    fprintf(f,"%ld\n",info.numbers);
  182.    fprintf(f,"&ld\n",info.mode);
  183.    fprintf(f,"%ld\n",info.m_shuffles);
  184.    fclose(f);
  185.    if(info.writeicon)
  186.    {
  187.     PutDiskObject(fname,&Shell);
  188.    }
  189.   }
  190.  }
  191. }
  192.  
  193. void load_config(UBYTE *name)
  194. {
  195.  struct FileRequester *FileReq;
  196.  UBYTE fname[256];
  197.  int load = FALSE;
  198.  FILE *f;
  199.  if(name != NULL)
  200.  {
  201.   strcpy(fname,name);
  202.   load = TRUE;
  203.  }
  204.  else
  205.  {
  206.   FRTags[0].ti_Data = (ULONG)"Load Shuffle Configuration";
  207.   FRTags[1].ti_Data = 0L;
  208.   if(FileReq = (struct FileRequester *)AllocAslRequest(ASL_FileRequest,FRTags))
  209.   {
  210.    if(RequestFile(FileReq))
  211.    {
  212.     strcpy(fname,FileReq->rf_Dir);
  213.     AddPart(fname,FileReq->rf_File,256);
  214.     load = TRUE;
  215.    }
  216.    FreeAslRequest((APTR)FileReq);
  217.   }
  218.  }
  219.  if(load)
  220.   {
  221.    if(f = fopen(fname,"r"))
  222.    {
  223.     fgets(fname,256,f);
  224.     if(!strncmp(fname,SHUFFLE_HEADER,strlen(SHUFFLE_HEADER)))
  225.     {
  226.      fgets(fname,256,f);info.res        = atol(fname); 
  227.      GT_SetGadgetAttrs(Project0Gadgets[GDX_tiles],Project0Wnd,NULL,
  228.                        GTCY_Active,info.res,TAG_DONE);
  229.      fgets(fname,256,f);info.numbers    = atol(fname); 
  230.      GT_SetGadgetAttrs(Project0Gadgets[GDX_numbers],Project0Wnd,NULL,
  231.                        GTCB_Checked,info.numbers,TAG_DONE);
  232.      fgets(fname,256,f);info.mode       = atol(fname);   
  233.      GT_SetGadgetAttrs(Project0Gadgets[GDX_mode],Project0Wnd,NULL,
  234.                        GTCY_Active,info.mode,TAG_DONE);
  235.      fgets(fname,256,f);info.m_shuffles = atol(fname); 
  236.      info.shuffle = atol(shuffle0Labels[info.m_shuffles]); 
  237.      GT_SetGadgetAttrs(Project0Gadgets[GDX_shuffle],Project0Wnd,NULL,
  238.                        GTCY_Active,info.m_shuffles,TAG_DONE);
  239.     }
  240.     fclose(f);
  241.    }
  242.   }
  243.  
  244. }
  245.  
  246.