#include "Global.h"

/*
void __saveds __asm InformationCode(register __a1 int *);
void __saveds __asm Update( void );

struct Hook InformationHook = { {NULL,NULL}, (void *)InformationCode, NULL,NULL };



void __asm __saveds Output_List( void )
{
 	 FILE 		*OutFile;
	  int 		Counter=0;

      OutFile = fopen("Ram:Output","ab");
      if(OutFile)
           {
	     while(Counter!=Number)
	           {
         	     fprintf(OutFile,"%s\n%s\n\n",Base_PTR[Counter].FileName,Base_PTR[Counter].Description);
	             Counter++;
	           }
	     fclose(OutFile);
           } 
      else
     	{
	printf("Unable To Lock Suggested File For ASCII OutPut.\n");
    	}
    
*/
}

void Base_To_List( void )
{
}
/*
    int Counter=0;
    char  *Text_Field;
    struct TextFont *New_Font;
    struct TextAttr *MyFont;
    
    MyFont = (struct TextAttr *)Allocate_Memory(sizeof(struct TextAttr));
    
    MyFont->ta_Name = "XEN.font";
    MyFont->ta_YSize = 9;
    MyFont->ta_Style = 0;
    MyFont->ta_Flags = 0x00;
   
    
    New_Font = OpenDiskFont(MyFont);
    if(!New_Font)
    	{
	    printf("Unable To Find The Font\n");
	}
	else
    set(App->Diz_Display_Lister,MUIA_Font,New_Font);
   
	        Text_Field = malloc(530*Number);
		if(!Text_Field)
			{
			    printf("Sorry Not Enough Memory For Main Lister\n");
			}
			else
			{ 
    while(Counter!=Number)
    	{
		strcat(Text_Field,Base_PTR[Counter].Description);
		strcat(Text_Field,"************************************************\n");
		Counter++;
        }
	set(App->Diz_Display_Lister,MUIA_Floattext_Text,Text_Field);
	
    }
}
/*
*/
void __asm __saveds FileName_Update( void )
{
    	int Counter =0;
	int Copy_Counter=0;
	int FakeLock;
	struct Base_Entry *Base_Copy;
	char	*Handy_Buffer;
	
	Handy_Buffer = malloc(200);
	Base_Copy = (struct Base_Entry *)malloc(sizeof(struct Base_Entry)*(Number+1));
	if(Base_Copy && Handy_Buffer)
	{
		while(Counter!=Number)
		{
   		 strcpy(Handy_Buffer,Base_PTR[Counter].FilePath);
		 strcat(Handy_Buffer,"/");
		 strcat(Handy_Buffer,Base_PTR[Counter].FileName);
		 FakeLock = Lock(Handy_Buffer,ACCESS_READ);
		 if(FakeLock)
		     {
			UnLock(FakeLock);
			strcpy(Base_Copy[Copy_Counter].FilePath,Base_PTR[Counter].FilePath);
			strcpy(Base_Copy[Copy_Counter].FileName,Base_PTR[Counter].FileName);
			strcpy(Base_Copy[Copy_Counter].Description,Base_PTR[Counter].Description);
			Base_Copy[Copy_Counter].FileSize=Base_PTR[Counter].FileSize;
			Base_Copy[Copy_Counter].FileDate=Base_PTR[Counter].FileDate;	
			Copy_Counter++;
			//printf("These aren't the droids you are looking for, you can go about your business, move along.\n");
		     }
	          	else
		     {
			
			
		     }
		     Counter++;
		}
		if(Number!=Copy_Counter)
			{
			    printf("%d Files, Added/Subtracted During Update.\n",Number-Copy_Counter);
			}
		//printf("Old Number was %d, new number is %d.\n",Number,Copy_Counter);
		//printf("About to Copy From %p to %p %d Bytes.\n",Base_Copy,Base_PTR,(sizeof(struct Base_Entry)*Number));
		Number = Copy_Counter;
	
		CopyMem(Base_Copy,Base_PTR,(sizeof(struct Base_Entry)*Number));
		free(Base_Copy);
		free(Handy_Buffer);

	}
	

}
/*
*/
void __asm __saveds FileName_Extract( void )
{
        
}

void __asm __saveds FileName_Delete( void )
{
  
    int  response;
    int  active;
    char *ArchivePath;
	ArchivePath = malloc(120);

    get(App->Main_List,MUIA_List_Active,&active);

    if(Base_PTR[active].FileName && Base_PTR[active].FilePath)
    	{
	    strcpy(ArchivePath,Base_PTR[active].FilePath);
	    strcat(ArchivePath,"/");
	    strcat(ArchivePath,Base_PTR[active].FileName);
	    response = MUI_Request(App->App,App->Out_Line_Window,0,"Dizzer II","*_Yeah|_No","Sure To Delete:\n%s",Base_PTR[active].Description);
    	    if(response==1)
	    	{
		    DoMethod(App->Main_List,MUIM_List_Remove,active);
		    remove(ArchivePath);
		    FileName_Update();
		   // printf("The Base Should Be Updated NOW\n");
		}
		else
		{
		    //printf("Ok But Be More Carefull\n");
	        }
    	    
    	    free(ArchivePath);
    	   
        }
}


void __asm __saveds Information( void )
{
 	FILE *Archive_Status;
	char *ArchiveCommand,*ArchiveName,*ArchivePath,*FileBuffer;
	int 	File_Lock;
	BOOL	Lister_Open;
	struct FileInfoBlock *FIB;
	
	get(App->Main_Information_List, MUIA_ShowMe, &Lister_Open);
	if(Lister_Open)
		{
		set(App->Main_Information_List,MUIA_ShowMe,FALSE);
		return;
		}
	set(App->Main_Information_List,MUIA_ShowMe,TRUE);
	FIB = malloc(sizeof(struct FileInfoBlock));
	
	ArchiveCommand =  malloc(200);
	ArchiveName    =  malloc(36);
	ArchivePath    =  malloc(120);
	if(ArchiveCommand && ArchivePath && ArchiveName && FIB)
	{ 
	   get(App->Archive_Name,MUIA_Text_Contents,&ArchiveName);
	   get(App->Archive_Path,MUIA_Text_Contents,&ArchivePath);
	   strcat(ArchivePath,"/");
	   strcat(ArchivePath,ArchiveName);
           sprintf(ArchiveCommand,"lha >nil: l %s >T:Something_Wonderful",ArchivePath);	
	   Execute(ArchiveCommand,0,0);
	
	   File_Lock = Lock("T:Something_Wonderful",ACCESS_READ);
	   if(File_Lock)
	      {
	       Examine(File_Lock,FIB); 
	       UnLock(File_Lock);
	       Archive_Status = fopen("T:Something_Wonderful","r"); 
	       if(Archive_Status)
	       	   {
		     FileBuffer = malloc(FIB->fib_Size);
		     if(FileBuffer)
		     	{
		     	 fread(FileBuffer,FIB->fib_Size,1,Archive_Status);
		     	 set(App->Main_Information_List,MUIA_Floattext_Text,FileBuffer);
		     	 free(FileBuffer);
			}
			else
			{
			 free(ArchivePath);
			 free(ArchiveName);
			 free(ArchiveCommand);
			 free(FIB);
			 printf("Lister.c Failed To Allocate Memory\n");
		         set(App->Main_Information_List,MUIA_ShowMe,FALSE);
			 return;
			 }
		     fclose(Archive_Status);
		     remove("T:Something_Wonderful");
		    }
		    else
		    {
			 free(ArchivePath);
			 free(ArchiveName);
			 free(ArchiveCommand);
			 free(FIB);
			 printf("Lister.c Failed To Open Something WonderFUL\n");
			 set(App->Main_Information_List,MUIA_ShowMe,FALSE);
			return;
		    }
		}
		else
		{
			 free(ArchivePath);
			 free(ArchiveName);
			 free(ArchiveCommand);
			 free(FIB);
		         printf("Lister.c Failed To Lock Something WonderFUL\n");
   			 set(App->Main_Information_List,MUIA_ShowMe,FALSE);
		    return;
		}
	   } 
	   else
	   {
            set(App->Main_Information_List,MUIA_ShowMe,FALSE);
	    printf("Lister.c Failed To Allocate Main Memory\n");
	    return;
	   }
	  
	 free(ArchivePath);
	 free(ArchiveName);
	 free(ArchiveCommand);
	 free(FIB);
}
*/

void __saveds __asm InformationCode(register __a1 int *Current)
{
// BOOL fred;
// get(App->Diz_Info_Window, MUIA_Window_Open,fred);
// if(fred)
	//{
	//	set(App->Archive_Name,MUIA_Text_Contents,Base_PTR[(int)Current[0]].FileName);
         //       set(App->Archive_Path,MUIA_Text_Contents,Base_PTR[(int)Current[0]].FilePath);
	//	printf("Window Is Currently Open\n");
	//}
	//else
	//{
	// set(App->Main_List,MUIA_List_Active,(int)Current[0]);
	// set(App->Archive_Name,MUIA_Text_Contents,Base_PTR[(int)Current[0]].FileName);
	// set(App->Archive_Path,MUIA_Text_Contents,Base_PTR[(int)Current[0]].FilePath);
	// set(App->Diz_Info_Window, MUIA_Window_Open, TRUE);
//	//}
    
}
