10-14-2011, 07:57 AM
hi, i have problems with reading from the file ".restore", sometimes the read are correct but sometimes are corrupt, possibly the file it's open by cat but my code do this:
public static OclRestoreData Deserialize(string fileName)
{
File.Copy(fileName, fileName + "Cp", true);
OclRestoreData rData = new OclRestoreData();
FileInfo dataFile = new FileInfo(fileName + "Cp");
FileStream stream = null;
try
{
stream = dataFile.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
rData = null;
return rData;
}
finally
{
if (stream != null)
{
stream.Close();
//file is not locked
byte[] bytes = File.ReadAllBytes(fileName + "Cp");
int cursor = 0;
// Reading version_bin
rData.version_bin = BitConverter.ToUInt32(bytes, cursor);
cursor += 4;
and the rest of the reading... any idea???
public static OclRestoreData Deserialize(string fileName)
{
File.Copy(fileName, fileName + "Cp", true);
OclRestoreData rData = new OclRestoreData();
FileInfo dataFile = new FileInfo(fileName + "Cp");
FileStream stream = null;
try
{
stream = dataFile.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
rData = null;
return rData;
}
finally
{
if (stream != null)
{
stream.Close();
//file is not locked
byte[] bytes = File.ReadAllBytes(fileName + "Cp");
int cursor = 0;
// Reading version_bin
rData.version_bin = BitConverter.ToUInt32(bytes, cursor);
cursor += 4;
and the rest of the reading... any idea???