home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 1 / Mecomp-CD.iso / amiga / tools / cd / indexcd / bin / sources.lha / sources / Config_mui.c next >
C/C++ Source or Header  |  1997-02-22  |  8KB  |  317 lines

  1. /* dcc dh1:IndexCD/Bin/Config_mui.c -l DLIB:muis.lib -3.0 */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "demo.h"
  6.  
  7. #define    ID_DISPLAY        1
  8. #define    ID_RIPRISTINA    2
  9. #define    ID_SALVA            3
  10. #define    ID_ESCI            4
  11.  
  12. static Object * App;                    /* Application object       */
  13. static Object * WI_Browser;        /* Window object            */
  14. static Object * BT_RIPRISTINA;    /* RIPRISTINA Button object */
  15. static Object * BT_SALVA;            /* SALVA Button object      */
  16. static Object * BT_ESCI;            /* ESCI Button object       */
  17.  
  18. static Object * pop1;
  19. static Object * pop2;
  20. static Object * pop3;
  21. static Object * pop4;
  22. static Object * pop5;
  23. static Object * pop6;
  24. static Object * pop7;
  25. static Object * pop8;
  26. static Object * pop9;
  27.  
  28.  
  29. char destdir [90];    // Configuration data
  30. char clha    [90];
  31. char clzx    [90];
  32. char ctext   [90];
  33. char cpic    [90];
  34. char cmod    [90];
  35. char cdms    [90];
  36. char destdms [90];
  37. char font    [90];
  38.  
  39. char buff[255];
  40. char path[255];
  41.  
  42. char *Config    =    "S:Aminet-Config";
  43. char *ptr;
  44.  
  45. int main(int argc,char *argv[])
  46. {
  47.     static char buffer[2048];
  48.     BOOL running = TRUE;
  49.     ULONG signal;
  50.  
  51.     init();
  52.  
  53.     LoadConfiguration();
  54.  
  55.     App = ApplicationObject,
  56.         MUIA_Application_Title      , "Prefs IndexCD",
  57.         MUIA_Application_Version    , "$VER: IndexCD 2.3 (22-02-97)",
  58.         MUIA_Application_Copyright  , "©1996, Claudio Buraglio",
  59.         MUIA_Application_Author     , "Claudio Buraglio",
  60.         MUIA_Application_Description, "Configuration of IndexCD",
  61.         MUIA_Application_Base       , "CONFIG-IndexCD",
  62.  
  63.         SubWindow, WI_Browser = WindowObject,
  64.             MUIA_Window_Title, "Configuration IndexCD - ©1997 Claudio Buraglio.",
  65.             MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  66.  
  67.             WindowContents, VGroup,
  68.  
  69.                 Child, ColGroup(2),
  70.  
  71.                     Child, KeyLabel2("Destination:",0),
  72.                     Child, pop1 = PopaslObject,
  73.                         MUIA_Popstring_String, KeyString(destdir,256,0),
  74.                         MUIA_Popstring_Button, PopButton(MUII_PopDrawer),
  75.                         ASLFR_TitleText  , "Select the destination directory...",
  76.                         ASLFR_DrawersOnly, TRUE,
  77.                         End,
  78. // StringFile
  79.                     Child, KeyLabel2("Command LHA:",0),
  80.                     Child, pop2 = PopaslObject,
  81.                         MUIA_Popstring_String, KeyString(clha,256,0),
  82.                         MUIA_Popstring_Button, PopButton(MUII_PopFile),
  83.                         ASLFR_TitleText, "Select LHA...",
  84.                         End,
  85.                     Child, KeyLabel2("Command LZX:",0),
  86.                     Child, pop3 = PopaslObject,
  87.                         MUIA_Popstring_String, KeyString(clzx,256,0),
  88.                         MUIA_Popstring_Button, PopButton(MUII_PopFile),
  89.                         ASLFR_TitleText, "Select LZX...",
  90.                         End,
  91.                     Child, KeyLabel2("Text Viewer:",0),
  92.                     Child, pop4 = PopaslObject,
  93.                         MUIA_Popstring_String, KeyString(ctext,256,0),
  94.                         MUIA_Popstring_Button, PopButton(MUII_PopFile),
  95.                         ASLFR_TitleText, "Select a text viewer...",
  96.                         End,
  97.                     Child, KeyLabel2("Picture Viewer:",0),
  98.                     Child, pop5 = PopaslObject,
  99.                         MUIA_Popstring_String, KeyString(cpic,256,0),
  100.                         MUIA_Popstring_Button, PopButton(MUII_PopFile),
  101.                         ASLFR_TitleText  , "Select a picture viewer...",
  102.                         End,
  103.                     Child, KeyLabel2("Mod Player:",0),
  104.                     Child, pop6 = PopaslObject,
  105.                         MUIA_Popstring_String, KeyString(cmod,256,0),
  106.                         MUIA_Popstring_Button, PopButton(MUII_PopFile),
  107.                         ASLFR_TitleText  , "Select a modules player...",
  108.                         End,
  109.                     Child, KeyLabel2("Command DMS:",0),
  110.                     Child, pop7 = PopaslObject,
  111.                         MUIA_Popstring_String, KeyString(cdms,256,0),
  112.                         MUIA_Popstring_Button, PopButton(MUII_PopFile),
  113.                         ASLFR_TitleText  , "Select DMS...",
  114.                         End,
  115.                     Child, KeyLabel2("Destination Drawer of DMS:",0),
  116.                     Child, pop8 = PopaslObject,
  117.                         MUIA_Popstring_String, KeyString(destdms,256,0),
  118.                         MUIA_Popstring_Button, PopButton(MUII_PopDrawer),
  119.                         ASLFR_TitleText, "Seleziona the destination drawer for dms...",
  120.                         ASLFR_DrawersOnly, TRUE,
  121.                         End,
  122.                     Child, KeyLabel2("Font:",0),
  123.                     Child, pop9 = PopaslObject,
  124.                         MUIA_Popstring_String, KeyString(font,80,0),
  125.                         MUIA_Popstring_Button, PopButton(MUII_PopUp),
  126.                         MUIA_Popasl_Type , ASL_FontRequest,
  127.                         ASLFO_TitleText  , "Select font...",
  128.                         End,
  129.                 End,
  130. // Bottoni
  131.                 Child, HGroup, MUIA_Group_SameSize, TRUE,
  132.                     Child, BT_RIPRISTINA    = SimpleButton("_Last saved"  ),
  133.                     Child, BT_SALVA        = SimpleButton("_Save configuration"),
  134.                     Child, BT_ESCI            = SimpleButton("_Exit"  ),
  135.                 End,
  136.  
  137.             End,
  138.         End,
  139.     End;
  140.  
  141.     if (!App) fail(App,"Can't open application.");
  142.  
  143.     DoMethod(WI_Browser,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,App,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  144.     DoMethod(BT_SALVA  ,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,ID_SALVA);
  145.     DoMethod(BT_ESCI   ,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,ID_ESCI  );
  146.     DoMethod(BT_RIPRISTINA   ,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,ID_RIPRISTINA  );
  147.  
  148.     DoMethod(WI_Browser,MUIM_Window_SetCycleChain,BT_RIPRISTINA,BT_SALVA,BT_ESCI,NULL);
  149.  
  150.     set(WI_Browser,MUIA_Window_Open,TRUE);
  151.  
  152.     while (running)
  153.     {
  154.         switch (DoMethod(App,MUIM_Application_Input,&signal))
  155.         {
  156.             case MUIV_Application_ReturnID_Quit:
  157.                 running = FALSE;
  158.                 break;
  159.  
  160.             case ID_SALVA:
  161.             {
  162.                 FILE *fp;
  163.                 if ( fp = fopen(Config, "w"))
  164.                 {
  165.                     LONG x;
  166.                     get(pop1, MUIA_String_Contents, &x);
  167.                     sprintf(buff, "destdir=%s\n", x);
  168.                     ptr = strrchr(buff, '/');
  169.                     if (ptr == 0)    {    ptr = strrchr(buff, ':');    }
  170.                     *++ptr = 0xa;    *++ptr = 0x0;
  171.                     fputs(buff, fp);
  172.  
  173.                     get(pop2, MUIA_String_Contents, &x);
  174.                     fprintf(fp, "    lha=%s\n", x);
  175.                     get(pop3, MUIA_String_Contents, &x);
  176.                     fprintf(fp, "    lzx=%s\n", x);
  177.                     get(pop4, MUIA_String_Contents, &x);
  178.                     fprintf(fp, "   text=%s\n", x);
  179.                     get(pop5, MUIA_String_Contents, &x);
  180.                     fprintf(fp, "    pic=%s\n", x);
  181.                     get(pop6, MUIA_String_Contents, &x);
  182.                     fprintf(fp, "    mod=%s\n", x);
  183.                     get(pop7, MUIA_String_Contents, &x);
  184.                     fprintf(fp, "    dms=%s\n", x);
  185.  
  186.                     get(pop8, MUIA_String_Contents, &x);
  187.                     sprintf(buff, "destdms=%s\n", x);
  188.                     ptr = strrchr(buff, ':');
  189.                     if (ptr == 0)    {    strcpy(buff,"DF0:\n");    } else
  190.                     { *++ptr = 0xa;    *++ptr = 0x0;    }
  191.                     fputs(buff, fp);
  192.  
  193.                     get(pop9, MUIA_String_Contents, &x);
  194.                     fprintf(fp, "   font=%s\n", x);
  195.  
  196.                     fclose(fp);
  197.                 }
  198.                 running = FALSE;
  199.                 break;
  200.             }
  201.  
  202.             case ID_ESCI:
  203.             {
  204.                 running = FALSE;
  205.                 break;
  206.             }
  207.  
  208.             case ID_RIPRISTINA:
  209.             {
  210.                 LoadConfiguration();
  211.                 setstring(pop1, destdir);
  212.                 setstring(pop2, clha);
  213.                 setstring(pop3, clzx);
  214.                 setstring(pop4, ctext);
  215.                 setstring(pop5, cpic);
  216.                 setstring(pop6, cmod);
  217.                 setstring(pop7, cdms);
  218.                 setstring(pop8, destdms);
  219.                 setstring(pop9, font);
  220.                 break;
  221.             }
  222.         }
  223.         if (running && signal)
  224.             Wait(signal);
  225.     }
  226.     fail(App,NULL);
  227. }
  228.  
  229. LoadConfiguration()
  230. {
  231.     FILE *fp;
  232.     char *coda;
  233.  
  234.     strcpy(destdir, "RAM:");
  235.     strcpy(   clha, "CD0:Tools/LhA");
  236.     strcpy(  ctext, "CD0:Tools/PowerGuide");
  237.     strcpy(   cpic, "CD0:Tools/VT");
  238.     strcpy(   cmod, "CD0:Tools/DeliTracker2");
  239.  
  240.     strcpy(   clzx, "C:LZX");
  241.     strcpy(   cdms, "CD0:Tools/DMS");
  242.     strcpy(destdms, "DF0:");
  243.     strcpy(   font, "topaz/11");
  244.  
  245.     if (fp = fopen(Config, "r"))
  246.     {
  247.        while (fgets(buff, sizeof(buff)-1, fp))
  248.         {
  249.             if ((ptr = strstr(buff, "destdir=")) != NULL)
  250.             {
  251.                 ptr = strchr(buff, '=');
  252.                 ptr++;
  253.                 coda = stpcpy(destdir, ptr);
  254.                 *--coda = 0;
  255.             }
  256.             if ((ptr = strstr(buff, "lha=")) != NULL)
  257.             {
  258.                 ptr = strchr(buff, '=');
  259.                 ptr++;
  260.                 coda = stpcpy(clha, ptr);
  261.                 *--coda = 0;
  262.             }
  263.             if ((ptr = strstr(buff, "lzx=")) != NULL)
  264.             {
  265.                 ptr = strchr(buff, '=');
  266.                 ptr++;
  267.                 coda = stpcpy(clzx, ptr);
  268.                 *--coda = 0;
  269.             }
  270.             if ((ptr = strstr(buff, "text=")) != NULL)
  271.             {
  272.                 ptr = strchr(buff, '=');
  273.                 ptr++;
  274.                 coda = stpcpy(ctext, ptr);
  275.                 *--coda = 0;
  276.             }
  277.             if ((ptr = strstr(buff, "pic=")) != NULL)
  278.             {
  279.                 ptr = strchr(buff, '=');
  280.                 ptr++;
  281.                 coda = stpcpy(cpic, ptr);
  282.                 *--coda = 0;
  283.             }
  284.             if ((ptr = strstr(buff, "mod=")) != NULL)
  285.             {
  286.                 ptr = strchr(buff, '=');
  287.                 ptr++;
  288.                 coda = stpcpy(cmod, ptr);
  289.                 *--coda = 0;
  290.             }
  291.             if ((ptr = strstr(buff, " dms=")) != NULL)
  292.             {
  293.                 ptr = strchr(buff, '=');
  294.                 ptr++;
  295.                 coda = stpcpy(cdms, ptr);
  296.                 *--coda = 0;
  297.             }
  298.             if ((ptr = strstr(buff, "destdms=")) != NULL)
  299.             {
  300.                 ptr = strchr(buff, '=');
  301.                 ptr++;
  302.                 coda = stpcpy(destdms, ptr);
  303.                 *--coda = 0;
  304.             }
  305.             if ((ptr = strstr(buff, "font=")) != NULL)
  306.             {
  307.                 ptr = strchr(buff, '=');
  308.                 ptr++;
  309.                 coda = stpcpy(font, ptr);
  310.                 *--coda = 0;
  311.             }
  312.         }
  313.         fclose(fp);
  314.     }
  315. }
  316.  
  317.