Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Missing memo file
Message
From
27/11/2002 04:53:58
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
27/11/2002 04:39:41
General information
Forum:
Visual FoxPro
Category:
FoxPro 2.x
Miscellaneous
Thread ID:
00727438
Message ID:
00727451
Views:
8
>Hi,
>
>Thanks a lot, and if corrupt how can I recover?
>By deleting the corrupt file and treating like missing file?

Of course not :) Take a backup of your .fpt and run the code below giving your fpt name as a parameter (this is one simple way - only fixes memo header,not guaranteed to recover fully everytime) :
*RepairMemo('mytable.fpt')

* RepairMemo.prg
* Simply fixes next block pointer, blocksize and filesize
Lparameters tcMemoFilename
Local handle, lnFileSize, lnNextBlockPointer, lnBlockSize, lnFirstBlock, lnCalculatedFileSize

handle=fopen(tcMemoFilename,12) && Opened readwrite
lnFileSize = fseek(handle,0,2) && Get file size
With this
	* Read header info
	lnNextBlockPointer = ReadBytes(handle, 0,4,.T.) && Stored in left-to-right format
	lnBlockSize        = ReadBytes(handle, 6,2,.T.) && Stored in left-to-right format

	* Specific to me - no blocksize setting to something other than default 0x40
	If lnBlockSize # 0x40
		WriteBytes(handle, 6,2,0x40,.T.)
		lnBlockSize=0x40
	Endif
	*

	lnFirstBlock	   = ceiling(512/lnBlockSize) && Possible min lnNextblockpointer
	lnCalculatedFileSize = lnNextBlockPointer*lnBlockSize

	* Fix if needs repair
	If !(lnFileSize >= 512 ;
			and lnNextBlockPointer >= lnFirstBlock ;
			and lnCalculatedFileSize >= lnFileSize) && Memo needs repair
		lnNextBlockPointer = max(lnNextBlockPointer, lnFirstBlock)
		lnFileSize = lnNextBlockPointer * lnBlockSize
		WriteBytes(handle, 0,4,lnNextBlockPointer,.T.) && Fix next block pointer
		=fchsize(handle, lnFileSize) && Fix filesize
	Endif
Endwith
=fclose(handle)

**************************************************************************
* ReadBytes(nHandle, nPos, nBytes[, lLR]) :
*   Reads given size of bytes at offsett specified by pos from a file opened
*   with low level functions (handle comes from that function)
**************************************************************************
FUNCTION readbytes
Lparameters tnHandle, tnPos, tnSize, tlLR
Local lcString, lnRetValue,ix
=fseek(tnHandle, tnPos,0) && Go to pos
lcString = fread(tnHandle, tnSize) && Read tnSize bytes
lnRetValue = 0
For ix=0 to tnSize-1  && Convert to a number
	lnRetValue = lnRetValue + asc(substr(lcString,ix+1)) * ;
		iif(tlLR,256^(tnSize-1-ix),256^ix)
Endfor
Return int(lnRetValue)

**************************************************************************
* WriteBytes
* Same as ReadBytes except writes to file
* 64 bits not available in this version
**************************************************************************
FUNCTION WriteBytes
Lparameters tnHandle, tnPos, tnSize, tnNumber, tlLR
Local lcString, lnLowDword, lnHighDword,ix
lcString=''
If tlLR
   For ix=tnSize-1 to 0 step -1
	lcString=lcString+chr(tnNumber/256^ix%256)
   Endfor
Else
   For ix=0 to tnSize-1
 	lcString=lcString+chr(tnNumber/256^ix%256)
   Endfor
Endif
=fseek(tnHandle, tnPos,0) && Go to pos
Return fwrite(tnHandle,lcString)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform