/* 
*   All The Extraction Methods For Diffrent Files. Soon To All Be Re-Coded And
*   Made completly Internal
*
*/




#include <Includes/Main_Global.h>

void Output_List( Object *m ){}

void Main_Lister_ActiveChanged( Object *m) 
{
  struct ListerTransfer *Current; 
 DoMethod(App->Main_Lister,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&Current);
 set(Data->Description,MUIA_DIZ_Contents,Current->Description); 
}
void Found_Lister_ChangeActive( Object *m)
{
// char *buffer;
 //DoMethod(App->Found_Lister,MUIM_List_GetEntry,MUIA_List_GetEntry_Active,&buffer);
 
}


void FileName_Delete( Object *m )
{

}
void FileName_Update( Object *m ){}
void FileName_Extract( Object *m ){}


void Main_Lister_DoubleClick( Object *m )
{
 struct ListerTransfer *Current;
 DoMethod(App->Main_Lister,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&Current);
 Problem(Current->Description);
}
void Button_CreateBase( Object *m )
{

Create_Base(); 
}
void Description_Lister_ChangeActive( Object *m){}
void Button_FindFile( Object *m ){}
void Button_HardCopy( Object *m ){}
void Button_OpenLister( Object *m )
{
// set(App->DIZ_Window,MUIA_Window_Open,TRUE);
}
void Button_ArchiveExtract( Object *m ){}
void Button_ArchiveInformation( Object *m ){}
void Button_ArchiveDirectory( Object *m ){}
void Button_ArchiveDelete( Object *m )
{
 struct ListerTransfer *Current;
 char	*Buffer;
 LONG   Entries;
 int Question=0;
 
 get(App->Main_Lister,MUIA_List_Entries,&Entries);
     if(!Entries)
	{
	  MUI_Request(App->App, App->Main_Window, NULL, "Warning...", "*_OK", "No Files To Delete!");
	  return;
	}
	
 Buffer = Allocate_Memory(1024); 
 DoMethod(App->Main_Lister,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&Current);
 Question = MUI_Request(App->App, App->Main_Window, NULL, "Warning...", "*_Delete|_Cancel", "\33b\33uSure To Delete:\33n\n%s",Current->Description);
 if(Question)
   {
    sprintf(Buffer,"%s/%s",Current->FilePath,Current->FileName);
    DeleteFile(Buffer);
    DoMethod(App->Main_Lister,MUIM_List_Remove,MUIV_List_Remove_Active);
    Deallocate_Memory(Buffer);
   }
   
}

void Button_NormalFind( Object *m)
{
 LONG	Entries;
 char	*SearchString;
 char	*FileName;
 struct ListerTransfer *Current;
 int	Counter=0;
 get(App->Main_Lister,MUIA_List_Entries,&Entries);
     if(!Entries)
	{
	  MUI_Request(App->App, App->Main_Window, NULL, "Warning...", "*_OK", "No Files To Search!");
	  return;
	}
 FileName = Allocate_Memory(1024);
 
 get(App->Search_String,MUIA_String_Contents,&SearchString);
 set(App->Progress_Gauge,MUIA_Gauge_Max,Entries);
 set(App->Progress_Window,MUIA_Window_Open,TRUE);

 for(Counter=0;Counter<Entries;Counter++)
    {
    DoMethod(App->Main_Lister,MUIM_List_GetEntry,Counter,&Current);
    set(App->Progress_Gauge,MUIA_Gauge_Current,Counter);
    set(App->Progress_Gauge,MUIA_Gauge_InfoText,Current->FileName);
      set(App->Main_Lister,MUIA_List_Active,Counter);
     
     sprintf(FileName,"%s/%s",Current->FilePath,Current->FileName);
     NormalFind(FileName,SearchString);
 //      MUI_Request(App->App,App->Main_Window,NULL,"_Continue","\033rFile: %s\n\033bFound\033n Inside: %s",SearchString,Current->FileName);   
    }
 set(App->Progress_Window,MUIA_Window_Open,FALSE);

}
void Button_LoadBase( Object *m )
{
Load_Base();
}
void Button_SaveBase( Object *m )
{
LONG Entries;
get(App->Main_Lister,MUIA_List_Entries,&Entries);
     if(!Entries)
	{
	  MUI_Request(App->App, App->Main_Window, NULL, "Warning...", "*_OK", "Nothing To Save!");
	  return;
	}
Save_Base();
}
void ABORT( Object *m ){}


ASM LONG  Main_Lister_Compare( REG(a1) struct ListerTransfer *s1,
					     REG(a2) struct ListerTransfer *s2)
{
 return(stricmp(s1->FileName,s2->FileName));
}

ASM struct ListerTransfer * Main_Lister_Construct(  REG(a1) char *File )
{
	struct ListerTransfer	*OutGoing;
	struct FileInfoBlock	*Info;
	char	*FilePath;
	BPTR	File_Lock;
	
	OutGoing = Allocate_Memory(sizeof(struct ListerTransfer) );
	File_Lock = Lock(File,ACCESS_READ);
	if(File_Lock)
	 {
	  Info = AllocDosObject(DOS_FIB,TAG_DONE);
	  if(Info)
	  {
	   
	    Examine(File_Lock,Info);
	    //______ FileType _______
	    OutGoing->FileType = Allocate_Memory(10);
	    stcgfe(OutGoing->FileType,File);
	    OutGoing->FileType = strupr(OutGoing->FileType);
	    //______ FilePath _______
	    FilePath    = PathPart(File);
	    FilePath[0] = NULL;
	    OutGoing->FilePath = Allocate_Memory(strlen(File));
	    strcpy(OutGoing->FilePath,File);
	    //______ FileName _______
	    OutGoing->FileName = Allocate_Memory(strlen(Info->fib_FileName)+1);
	    strcpy(OutGoing->FileName,Info->fib_FileName);
	    OutGoing->FileName[strlen(OutGoing->FileName)+1]=NULL;	//WHY!!?!?!
	    //______ FileSize _______
	    OutGoing->FileSize = Allocate_Memory(10);
	    sprintf(OutGoing->FileSize,"%d",Info->fib_Size);
	    //______ Compression ____
	    //OutGoing->FileCompressed = Allocate_Memory(10);
	    //sprintf(OutGoing->FileCompressed,"%d",NormalCompressed());
	    Data->Total_Size = Data->Total_Size + Info->fib_Size;
	    Data->Total_Files++;
	    sprintf(Data->Files_String,"%d",Data->Total_Files);
	    sprintf(Data->Size_String,"%d",(Data->Total_Size/1024));
	    set(App->Total_Files,MUIA_Text_Contents,Data->Files_String);
           set(App->Total_Size,MUIA_Text_Contents,Data->Size_String);
	    FreeDosObject(DOS_FIB,Info);
	  }
	 UnLock(File_Lock);
	}
	
	return(OutGoing);
}
/*
	char	*FileName;		
	char	*FilePath;		
	char	*FileSize;		
	char	*FileType;		
	char    *FileDate;		
	char    *Description;
*/
ASM void Main_Lister_Destruct( REG(a1) struct ListerTransfer *InComing )
{
	int	Size;
	Size = atoi(InComing->FileSize);
	Data->Total_Files--;
        Data->Total_Size = Data->Total_Size - Size;
        sprintf(Data->Size_String,"%d",(Data->Total_Size/1024));
        sprintf(Data->Files_String,"%d",Data->Total_Files);
        set(App->Total_Files,MUIA_Text_Contents,Data->Files_String);
           set(App->Total_Size,MUIA_Text_Contents,Data->Size_String);
	if(InComing->FileName)
     		Deallocate_Memory(InComing->FileName);
     	if(InComing->FilePath)
     		Deallocate_Memory(InComing->FilePath);
     	if(InComing->FileSize)
		Deallocate_Memory(InComing->FileSize);
	if(InComing->FileType)
		Deallocate_Memory(InComing->FileType);
	if(InComing->FileDate)
		Deallocate_Memory(InComing->FileDate);
	if(InComing->Description)
		Deallocate_Memory(InComing->Description);
		
	Deallocate_Memory(InComing);
}
ASM void Main_Lister_Display( REG(a1) struct ListerTransfer *Pending, REG(a2) char **Array)
{
	 *Array++ =  Pending->FileName;
	 *Array++ =  Pending->FileSize;
	 *Array   =  Pending->FileType;
       //  *Array++   =  Pending->FilePath;
}
