/*
 *    Filename:	Compress.m 
 *    Created :	Mon Jul  1 16:12:51 1991 
 *    Author  :	Vince DeMarco
 *		<demarco@cpsc.ucalgary.ca>
 */


/* Generated by Interface Builder */

#import <appkit/Panel.h>
#import <stdlib.h>
#import <stdio.h>
#import "Compress.h"
#import "compress.h"

@implementation Compress

- (int)compressFile:(char *)filename
{
   int status = -1;
   int return_val;

   if  ((exit_status = compress_decompress(COMPRESSS,NO_OVERWRITE,RECURSIVE,filename)) != 0){
       switch(exit_status){
	 case COMP_OKAY:
	   status = 0;
	   break;
	 case COMP_EXIST:
	   NXRunAlertPanel("Compress","File %s Doesn't Exist","Ok",NULL,NULL,filename);
	   break;
	 case COMP_BIG:
	   NXRunAlertPanel("Compress","File %s not compressed already optimal","Ok",NULL,NULL,filename);
	   break;
	 case COMP_ALREADY:
	   NXRunAlertPanel("Compress","File %s already compressed","Ok",NULL,NULL,filename);
	   break;
	 case COMP_OUTPUT:
	   NXRunAlertPanel("Compress","Can't open %s.Z","Ok",NULL,NULL,filename);
	   break;
	 case COMP_TOOLONG:
	   NXRunAlertPanel("Compress","Path %s name too long","Ok",NULL,NULL,filename);
	   break;
	 case COMP_OUTEXISTS:
	   return_val = NXRunAlertPanel("Compress","Path %s.Z already exists remove","OverWrite","Skip",NULL,filename);
	   if (return_val){
	       compress_decompress(COMPRESSS,FORCEOVERWRITE,RECURSIVE,filename);
	       status = 0;
	   }
	   break;
  	 case COMP_DIRUNREADABLE:
	   NXRunAlertPanel("Compress","Directory %s unreadable","Ok",NULL,NULL,filename);
	 default:
	   break;
       }
   }

   return(status);
}


- (int)uncompressFile:(char *)filename
{
    int status = -1;

    if ((exit_status = compress_decompress(UNCOMPRESS,NO_OVERWRITE,RECURSIVE,filename)) != 0){
       switch(exit_status){
	 case COMP_OKAY:
	   status = 0;
	   break;
	 case COMP_EXIST:
	   NXRunAlertPanel("Compress","File %s Doesn't Exist","Ok",NULL,NULL,filename);
	   break;
	 case COMP_Z:
	   NXRunAlertPanel("Compress","File %s not in compressed format","Ok",NULL,NULL,filename);
	   break;
	 case COMP_BITS:
	   NXRunAlertPanel("Compress","File %s compressed with different number of bits that i can handle","Ok",NULL,NULL,filename);
	   break;
	 case COMP_NOTCOMP:
	   NXRunAlertPanel("Compress","File %s not in compressed format","Ok",NULL,NULL,filename);
	   break;
	 case COMP_TOOLONG:
	   NXRunAlertPanel("Compress","Path %s name too long","Ok",NULL,NULL,filename);
	   break;
	 default:
	   break;
       }
    }
    return(status);
}
@end
