/**************************************************************************/
/*                                                                        */
/*  Multitool II   -   DOS-Hilfsprogramm                Version 1.3r000   */
/*                                                                        */
/*  ©1992 Boris Jakubaschk                                                */
/*                                                                        */
/*  Modul 6 - Archiv: LHA-Archiv anlegen                                  */
/*                                                                        */
/**************************************************************************/

#include "MToolDefs.h"

Archiv( char Act )
    {
    char ArcName[30];
    char FileName[130];
    char Command[256];
    struct FileHandle *FH;
    LONG   SysResponse;

    if ( VL_Valid[Act] & VL_Valid[1-Act] & TestSelect( Act ) )
        {
        strcpy( ArcName, ".lha" );
        if (StringRequest( LS[MSG_6_T_Archiv1], LS[MSG_6_T_Archiv2], ArcName ) && Ana_Command[8] )
            {
            if ( PutMT_Temp(Act) )
                {
                if (FH=(struct FileHandle *)OpenConsole())
                    {
                    strcpy( FileName, VL_Name[1-Act] );
                    AddPart( FileName, ArcName, 130 );
                    sprintf( Command, Ana_Command[8], FileName ); 
                    SysResponse = SystemTags( Command, SYS_Input, FH, SYS_Output, NULL, TAG_DONE);
                    if (SysResponse!=0)
                        ErrorMsg( LS[MSG_6_T_LHAFail] );
                    CloseConsole(FH);
                    GetDir( 1-Act, VL_Name[1-Act] );
                    ClrSelect( Act );
                    ShowDir( Act, VL_OldFI[Act], 1 );
                    };
                RemMT_Temp();
                };
            };
        };
    }


LONG PutMT_Temp( Act )
    {
    struct ExAllData *EAD;
    short i;
    char FileName[130];
    struct FileHandle *FH;

    if (FH = (struct FileHandle *)Open( "T:MT_Temp", MODE_NEWFILE ))
        {
        EAD = VL_Data[Act];

        if ( Act!=VL_Archiv )
            {
            FileName[0]=34;
            strcpy( FileName+1, VL_Name[Act] );
            AddPart( FileName, "\"\n", 130 );
            FPuts( (BPTR)FH, FileName );
            };

        for (i=0; i<VL_NumEntry[Act]; i++)
            {
            if ( VL_Select[Act][i] )
                {
                FileName[0]=34;
                strcpy( FileName+1, EAD->ed_Name );
                if (EAD->ed_Type>=0)
                    strcat( FileName, "/*");
                strcat( FileName, "\"\n" );
                FPuts((BPTR)FH, FileName);
                };
            EAD = EAD->ed_Next;
            };
        Close((BPTR)FH);
        return( 1l );
        }
    else return( 0l );
    }

RemMT_Temp()
    {
    DeleteFile( "T:MT_Temp" );
    };

