예제 #1
0
파일: npk.c 프로젝트: dimovich/netrix
/*
=====================
	endNpkExtract
=====================
*/
void endNpkExtract( TCHAR *szPath ) {

	if( szPath == NULL ) {
		return;
	}

	endDecompress( szPath );
}
예제 #2
0
파일: replay.c 프로젝트: dimovich/netrix
/*
=====================
	endDemo
=====================
*/
void endDemo() {
	k_system.flags &= ~SF_DEMOPLAY;

	N_FClose( ghRepFile );
	ghRepFile = INVALID_HANDLE_VALUE;

	endDecompress( gszTmpPath );

	N_Free( k_replayFig );
	k_replayFig = NULL;
	k_replayFigSize = 0;
	k_replayFigID = 0;
}
예제 #3
0
파일: sys.c 프로젝트: dimovich/netrix
/*
=====================
	loadPackResource
=====================
*/
static void loadPackResource( TCHAR *szPath ) {
	TCHAR szResPath[MAX_PATH];
	npkFileEntry_t *pFE;
	npkHeader_t npk;
	mapEntry_t *mapEntry;
	botEntry_t *botEntry;
	HANDLE hPack;
	int cnt;
	int i;
	
	__try {
		pFE = NULL;
						
		hPack = N_FOpenR( szPath );
		if( hPack == INVALID_HANDLE_VALUE ) {
			__leave;
		}
						
		//read pack header
		//
		if( ! N_FRead( hPack, &npk, sizeof( npk ) ) ) {
			__leave;
		}

		//check header
		//
		if( npk.iHeader != NPKHEADER ) {
			__leave;
		}
						
		//check CRC
		//
		if( ! npkVerifyChecksum( szPath ) ) {
			__leave;
		}
		
		//read file entry information
		//
		cnt = npk.dwFileNum;
		pFE = N_Malloc( cnt*sizeof(*pFE) );
		if( ! N_FRead( hPack, pFE, cnt*sizeof(*pFE) ) ) {
			__leave;
		}
						
		//process file entries
		for( i=0; i<cnt; i++ ) {
		
			//decompress resource, and process it
			//
			if( beginDecompress( szPath, pFE[i].dwOffset, szResPath, NULL ) ) {
				//map file
				//
				if( pFE[i].type == NPKENTRY_MAP ) {
					//load map
					//
					mapEntry = loadMapResource( szResPath );
					
					if( mapEntry ) {
						//set-up map entry
						//
						mapEntry->fe.dwFlags = FILE_PACKED;
						mapEntry->fe.pathID = k_system.cPaths-1;
						mapEntry->fe.lOffset = pFE[i].dwOffset;
						mapEntry->fe.lSize = pFE[i].dwSize;
						N_Strcpy( mapEntry->map.name, pFE[i].szIName );
					}
				}
				//bot file
				//
				else if( pFE[i].type == NPKENTRY_BOT ) {
					//load bot
					//
					botEntry = loadBotResource( szResPath );
					
					if( botEntry ) {
						//set bot entry
						//
						botEntry->fe.dwFlags = FILE_PACKED;
						botEntry->fe.pathID = k_system.cPaths-1;
						botEntry->fe.lOffset = pFE[i].dwOffset;
						botEntry->fe.lSize = pFE[i].dwSize;
						N_Strcpy( botEntry->bot.name, pFE[i].szIName );
					}
				}
			
				endDecompress( szResPath );
			}

		} //proc files

	} //try
	
	__finally {
		N_FClose( hPack );
		if( pFE ) {
			N_Free( pFE );
		}
	}
}
예제 #4
0
int main(int argc, char **argv) {
  PHASH freq = NewHash();
  int freqfid, codefid;
  int nrSource, delta;
  double clk;
  int count = 0;

  INDATA srcFile, compFile;
  
  /* Must be passed the name of a file to compress */
  if(argc < 2) {
    printf("Must give a file to compress\n");
    exit(1);
  }
  TIMESTART(clk);

  initLFIOFile(&srcFile, argv[1]);
  
  /* Read the file, 2 bytes at a time and create the frequency table */
  nrSource = 0;
  while(canFetch(&srcFile, 2)) {
    U16 wrd = fetchWordLE(&srcFile);
    nrSource += 2;
    bumpFrequency(freq, wrd);
  }
  finishIOFile(&srcFile);
  printf("Read %d bytes\n", nrSource);
  /* Open the code and frequency files */
  freqfid = CREAT("huffman.freq");
  codefid = CREAT("huffman.code");
  compressfid = CREAT("huffman.compressed");
  if(freqfid < 0 || codefid < 0 || compressfid < 0) {
    ERROR0(1, "Cannot create frequency and code files\n");
  }
  createCompressTables(freq, freqfid, codefid);
  close(freqfid); close(codefid);
  FreeHash(freq);
  
  /* Now read again and compress */
  initCompressor("huffman.code");
  initLFIOFile(&srcFile, argv[1]);
  outPoint = 0; written = 0;
  startCompress(&writeByte);
  /* Read the file, 2 bytes at a time and compress */
  while(canFetch(&srcFile, 2)) {
    U16 wrd = fetchWordLE(&srcFile);
    writeCompressedSymbol(wrd);
  }
  endCompress();
  flushOut();
  close(compressfid);
  finishIOFile(&srcFile);

  /* Now decompress and compare */
  for(count=0;count<30;count++) {
    initLFIOFile(&compFile, "huffman.compressed");
    initLFIOFile(&srcFile, argv[1]);
    startDecompress();
    delta = nrSource;
    while(delta > 0) {
      int comp = fetchCompressedSymbol(&compFile);
      int src  = fetchWordLE(&srcFile);
      if(src != comp) {
        ERROR3(-1, "Src(%04x) != Comp(%04x) (at offset %d)\n",
               src, comp, nrSource - delta);
      }
      delta -= 2;
    }
    endDecompress(&compFile);
    finishIOFile(&srcFile); finishIOFile(&compFile);
  }
  finalizeCompressor();


  TIMESTOP(clk);
  
  // sm: according to my man pages, the 'l' flag doesn't apply
  // to the 'f' format, which is always a double argument
  printf("Source %d bytes. Compressed %d bytes. Ratio: %5.2f\n",
         nrSource, written, (double)nrSource / (double)written);
  printf("Run hufftest in %8.3fms\n", clk / 1000.0);
  exit (0);
  return 0;
}