Closed skidzo closed 6 years ago
Hi, Finalized file information is in IDBlock. For instance, if your id_file is not 'MDF' but 'UnFinMF', it is not finalised. Then flag in 'id_unf_flags' will tell you what to do to finalise the file (in mdfreader, print will appear). You can have more insight I think if you are investigating a suspicious file to open it with MDFValidator from Vector. the remove line 1220 is for specific implementation.: some people are actually embedding a mdf4 into a zip rather than using the already existing compression from spec. So to read this file, temporary uncompressed file is created. This line deals with it.
Ok, Is that probably, what could achieve what I want?
import mdfreader
from mdfreader.mdf import _open_MDF
from mdfreader.mdfinfo4 import IDBlock, UINT16
class BlockInfo(IDBlock):
def __init__(self):
super(BlockInfo,self).__init__(fid=None)
def isFinalized(self, fid):
"""
reads IDBlock id_file
"""
#self.read(fid)
fid.seek(0)
self['id_file'] = self.mdfblockreadCHAR(fid, 8)
self['id_ver'] = self.mdfblockread(fid, UINT16, 1)
fid.close()
# treatment of unfinalised file
if self['id_ver'] > 410 and 'UnFin' in self['id_file']:
return False
else:
return True
if __name__ == "__main__":
fid, _, _ = _open_MDF(fullFilePath)
bi = BlockInfo()
print(bi.isFinalized(fid))
At least this returns True, given that fullFilePath is pointing to a standard mdf file written by canape. Do you think I can listen with this on a file and wait for it is finalized and then call some event?
Hi, Yes, your code seems to be able to identify if a file is finalised. You could also cross check with flags 'id_unfi_flags'. However, I am not sure you can read your file while being written by canape under windows, you might have to investigate with OS module from python, maybe checking canape process activity...
OK, i will have to really test this in a vitrualmachine first, i will let you know if I succeed or not. Could you indicate further how to use the 'id_unfi_flags' flags properly in my example?
You could directly use IDBlock from mdfinfo4, from line 211 temp=IDBlock(fid) temp will contain a dict with id_file and id_unfi_flags keys. And there, you can see there are prints to tell you what to expect according to each bit of id_unfi_flags.
A quick test showed that it does not work this way using MDF4lib.dll 1.5.2.1, in the standard configuration of CANape 15, because it creates a tmp file which is locked for reading.
How can i find out if mdf4 file has been finalized? what is that reference to 'remove' here in that permalink? Am I confused? https://github.com/ratal/mdfreader/blob/6f5cbe685cc664532d79d524ad357cf7c8e1022f/mdfreader/mdfinfo4.py#L1220