-
Notifications
You must be signed in to change notification settings - Fork 0
/
CRC.PRG
73 lines (68 loc) · 2.94 KB
/
CRC.PRG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
procedure CRCTEST
COMPRESS( 'compr.exe',"compr.cpr" ) && Compress TEST file
unCOMPRESS( 'compr.exe',"compr.cpr" ) && Compress TEST file
UNCOMPRESS( 'compr.CPr', 'compr.EXT' ) && Extract TEST file
COMPRESS( 'compr.exe',"compr.cpr" ) && Compress TEST file
unCOMPRESS( 'compr.cpr',"compr.ext" ) && Compress TEST file
return
*/
FUNCTION COMPRESS(infile,outfile)
LOCAL Ret_Mess:=.T.
PRIVATE IS_COMPRESS:=.T.,inhandle,outhandle,FileLen:=0,FilePos:=0
inhandle=fopen(infile,0) && Open file
FileLen:=Fseek(InHandle,0,2)
Fseek(InHandle,0)
if ( inhandle == -1 ) && Error opening file ??
al_box({"Žè¨¡ª ®âªàëâ¨ï "+infile})
Ret_Mess:=.F.
else
outhandle = fcreate( outfile ) && Create file
? "€à娢 æ¨ï "+alltrim(upper(token(infile,'\')))+" "+;
space(15-len(alltrim(upper(token(infile,'\')))))
&& ‚맮¢ äãªæ¨¨ 'C' á à §¬¥à®¬ á«®¢ àï ¨ ⨯®¬ ª®¬¯à¥áᨨ
&& ˆá¯®«ì§ã¥âáï á«®¢ àì 4K ¨ ASCII ª®¬¯à¥áá¨ï.
pk_implode(4096 , 1)
?? " Ok."
fclose( inhandle ) && Close files
fclose( outhandle )
endif
return Ret_Mess
FUNCTION UNCOMPRESS(infile, outfile)
LOCAL Ret_Mess:=.T.
PRIVATE IS_COMPRESS:=.F.,inhandle,outhandle,WorkStep:=0,FileLen:=0,FilePos:=0
inhandle = fopen( infile, 0 ) && Open file
FileLen:=Fseek(InHandle,0,2)
Fseek(InHandle,0)
if ( inhandle == -1 )
al_box({"Žè¨¡ª ®âªàëâ¨ï "+infile})
Ret_Mess:=.F.
else
outhandle = fcreate( outfile ) && Create file
?? " § à娢 æ¨ï "+alltrim(upper(token(outfile,"\")))+" "+;
space(15-len(alltrim(upper(token(outfile,"\")))))
pk_explode()
?? if(WorkStep#0," Ok.",' ” ©« ¥ ï¥âáï à娢ë¬.')
fclose( inhandle ) && Close files
fclose( outhandle )
endif
return Ret_Mess
FUNCTION R_DATA
private buff, bytesread, size,row:=row(),col:=col()
FilePos:=if((FilePos+4096)<=FileLen,FilePos+4096,FileLen)
@ row,col say if(is_compress,str(round(FilePos*100/FileLen,0),3,0)+"% ","")
@ row,col say ""
size = pk_getsize() && Š®«¨ç¥á⢮ ¡ ©â®¢ ¤«ï ç⥨ï
buff = space( size ) && ®«ã票¥ ¢à¥¬¥®£® ¡ãä¥à
bytesread = fread( inhandle, @buff, size ) && ç⥨¥ ¤ ëå ¨§ ä ©«
pk_setbuf( @buff, bytesread ) && ª®¯¨à®¢ ¨¥ ᮤ¥à¦¨¬®£® ¡ãä¥à
return bytesread
FUNCTION W_DATA
Local GetBuf:="",GetSize:=0,row:=row(),col:=col()
GetBuf:=pk_getbuf(); GetSize:=pk_getsize()
fwrite( outhandle, GetBuf, GetSize) && ‡ ¯¨áì ¤¨áª
FilePos:=if((FilePos+GetSize)>=FileLen,FileLen,FilePos+4096)
@ row, col say if(.not.is_compress,str(round(FilePos*100/FileLen,0),3,0)+"%","")
@ row, col say ""
WorkStep:=if(.not.is_compress,WorkStep+1,0)
return .t.