/* $Revision Header *** Header built automatically - do not edit! ***********
 *
 *	(C) Copyright 1992 by Metalworx
 *
 *	Name .....: extract.c
 *	Created ..: Sun 12-Jul-92 15:02
 *	Revision .: 0
 *
 *	Date		Author		Comment
 *	=========	========	====================
 *	12-Jul-92	Mtwx		Created this file!
 *
 * $Revision Header ********************************************************/
 #define REVISION 0

/* ------------------------------- includes ----------------------------- */

#include <exec/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <proto/intuition.h>

#include <mtwx_defs.h>

#include "install_defs.h"

/* ------------------------------- internal globals --------------------- */

static BOOL rwert=TRUE;  /* Rückgabewert von InstallChemest() */

/* ------------------------------- prototypes --------------------------- */

void CheckError(int,char *,struct Screen *);

/* ------------------------------- routines ----------------------------- */

/*##########################################################################
# InstallChemest(): installiert ausgewählte Dateien in spezifizierten      #
#		    Pfaden						   #
#									   #
#   Übergabe: struct InstallStruct *InstallStruct - Pointer auf die	   #
#						    ausgewählten Daten	   #
#	      struct Screen *Screen - Pointer auf den Screen		   #
#   Rückgabe: BOOL TRUE (1)  - wenn alles OK ist                           #
#		   FALSE (0) - wenn ein Fehler aufgetreten ist             #
##########################################################################*/
BOOL InstallChemest(struct InstallStruct *InstallStruct,
		    struct Screen *Screen)
{
  char Command[300],Opts[20];
  char archive[20];
  struct Window *msgwin;

  strcpy(Opts,"-aCmT -Qh64");
  strcpy(archive,"ChemDist");

  if(InstallStruct->ExecGerman)
  {
    msgwin=Messagewin(Screen,"extracting...",
		      "German executable (ChemestheticsD)",0);
    sprintf(Command,"%slha %s e %s ChemestheticsD %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    sprintf(Command,"%slha %s e %s ChemestheticsD.info %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    sprintf(Command,"%slha %s e %s chems_g.dat %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }
  if(InstallStruct->ExecEnglish)
  {
    msgwin=Messagewin(Screen,"extracting...",
		      "English executable (ChemestheticsE)",0);
    sprintf(Command,"%slha %s e %s ChemestheticsE %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    sprintf(Command,"%slha %s e %s ChemestheticsE.info %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    sprintf(Command,"%slha %s e %s chems_e.dat %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }
  if(InstallStruct->ExecFPU)
  {
    msgwin=Messagewin(Screen,"extracting...",
		      "FPU version (ChemestheticsFPU81 - English only)",0);
    sprintf(Command,"%slha %s e %s ChemestheticsFPU81 %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    sprintf(Command,"%slha %s e %s ChemestheticsFPU81.info %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    sprintf(Command,"%slha %s e %s chems_e.dat %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }
  if(InstallStruct->ExecIEEE)
  {
    msgwin=Messagewin(Screen,"extracting...",
		      "IEEE version (ChemestheticsIEEE - English only)",0);
    sprintf(Command,"%slha %s e %s ChemestheticsIEEE %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    sprintf(Command,"%slha %s e %s ChemestheticsIEEE.info %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    sprintf(Command,"%slha %s e %s chems_e.dat %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }
  if(InstallStruct->ExecUtil)
  {
    msgwin=Messagewin(Screen,"extracting...",
		      "Utilities (CDM2DKB, ConvM3D)",0);
    sprintf(Command,"%slha %s e %s CDM2DKB %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    sprintf(Command,"%slha %s e %s ConvM3D %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExecPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }

  if(InstallStruct->DocGerman)
  {
    msgwin=Messagewin(Screen,"extracting...",
		      "German documentation (ChemestheticsD.doc*)",0);
    sprintf(Command,"%slha %s e %s ChemestheticsD.doc* %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->DocPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }
  if(InstallStruct->DocEnglish)
  {
    msgwin=Messagewin(Screen,"extracting...",
		      "English documentation (ChemestheticsE.doc*)",0);
    sprintf(Command,"%slha %s e %s ChemestheticsE.doc* %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->DocPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }
  if(InstallStruct->DocUtil)
  {
    msgwin=Messagewin(Screen,"extracting...",
		      "utilities documentation",0);
    sprintf(Command,"%slha %s e %s ConvM3D?.doc* %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->DocPath);
    CheckError(system(Command),Command,Screen);
    sprintf(Command,"%slha %s e %s CDM2DKB.doc* %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->DocPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }
  if(InstallStruct->DocQuicktrans)
  {
    msgwin=Messagewin(Screen,"extracting...",
		      "documentation for quicktrans.library",0);
    sprintf(Command,"%slha %s e %s QuickTrans.doc %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->DocPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }

  if(InstallStruct->Examples)
  {
    msgwin=Messagewin(Screen,"extracting...", "Examples",0);
    sprintf(Command,"%slha %s e %s *.cdm %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->ExamplesPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }

  if(InstallStruct->LibsArp)
  {
    msgwin=Messagewin(Screen,"extracting...", "arp.library",0);
    sprintf(Command,"%slha %s e %s arp.library %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->LibsPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }
  if(InstallStruct->LibsReq)
  {
    msgwin=Messagewin(Screen,"extracting...", "req.library",0);
    sprintf(Command,"%slha %s e %s req.library %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->LibsPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }
  if(InstallStruct->LibsQuicktrans)
  {
    msgwin=Messagewin(Screen,"extracting...", "quicktrans.library",0);
    sprintf(Command,"%slha %s e %s mathtrans.library %s",
	    InstallStruct->LHAPath,Opts,archive,InstallStruct->LibsPath);
    CheckError(system(Command),Command,Screen);
    CloseWindow(msgwin);
  }
  Messagewin(Screen,"Message","Installation complete!",-1);
  return rwert;
}


/*##########################################################################
# CheckError(): zeigt ggf. Fehlermeldung an                                #
#									   #
#   Übergabe: int error - Rückgabewert des system()-calls                  #
#	      char *Command - Pointer auf das Kommando			   #
#	      struct Screen *Screen - Pointer auf den Screen		   #
#   Rückgabe: keine (void)                                                 #
##########################################################################*/
void CheckError(int error, char *Command,struct Screen *Screen)
{
  char temp[80];

  if(error)
  {
    sprintf(temp,"Error returned by system(): #%d",error);
    Messagewin(Screen,Command,temp,-1);
    rwert=FALSE;
  }
}
