CRC32FileFingerprint failure

Just starting out? Need help? Post your questions and find answers here.
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

CRC32FileFingerprint failure

Post by doctorized »

I have downloaded some avi files to a folder. I use CRC32FileFingerprint to get the CRC code for every file. In some cases the crc returned is 0 and PB says: "[warning] The specified file does not exist." If these files are moved to another folder then crc code is returned fine. Why? The initial folder is named "M:\Completed\CSI Miami - Season 03 - HDTV". What is wrong?
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: CRC32FileFingerprint failure

Post by tinman »

doctorized wrote:I have downloaded some avi files to a folder. I use CRC32FileFingerprint to get the CRC code for every file. In some cases the crc returned is 0 and PB says: "[warning] The specified file does not exist." If these files are moved to another folder then crc code is returned fine. Why? The initial folder is named "M:\Completed\CSI Miami - Season 03 - HDTV". What is wrong?
I'm guessing here but it sounds like it could be a clash in the sharing of files between processes.

From your description it looks as if you are using a torrent to download the AVI, which I guess you will be seeding after it has downloaded. Is that correct?

If PB is trying to open the file with a sharing mode incompatible to that of the torrent application then it will not be able to open the file and you will get the "file does not exist" error. Have you tried closing the torrent application and then running the CRC32FileFingerprint?

I wouldn't assume that it's PB's fault if that turns out to be the case. It could be that the torrent application opens the file exclusively, i.e. not shared so PB (nor anything else) would ever be able to open it while the torrent application has it open. It might also only show up as a problem on files that you have finished downloading since you last started the torrent application, as it might be smart enough to open files that have completed in a shared read mode.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
happer66
User
User
Posts: 33
Joined: Tue Jan 12, 2010 12:10 pm
Location: Sweden

Re: CRC32FileFingerprint failure

Post by happer66 »

He shouldn't be able to move the files to another folder if another process has them locked though..?

You could try this code by Little John to test if they are indeed ''locked''

Code: Select all

;Original code by Little John
;http://forums.purebasic.com/english/viewtopic.php?f=5&t=44978
EnableExplicit
Define Result, TestFile$, TestPath$ = "M:\Completed\CSI Miami - Season 03 - HDTV\";GetTemporaryDirectory()
Procedure.i FileIsClosed (fileName$)
   ; returns #False if the file does not exist, or if it is opened by another process;
   ;         #True otherwise
   ;
   ; Note: By passing zero as 3rd parameter for CreateFile_(),
   ;       we request *exclusive* access to the respective file.
   ;       This fails if the file is already open.
   ; <http://msdn.microsoft.com/en-us/library/aa363858%28v=vs.85%29.aspx>
   ; <http://msdn.microsoft.com/en-us/library/aa363874%28v=vs.85%29.aspx>
   Protected handle
   
   handle = CreateFile_(@fileName$, #GENERIC_READ, 0, #Null, #OPEN_EXISTING, #FILE_ATTRIBUTE_NORMAL, #Null)
   If handle = #INVALID_HANDLE_VALUE
      ProcedureReturn #False
   Else
      CloseHandle_(handle)
      ProcedureReturn #True
   EndIf   
EndProcedure

If ExamineDirectory(0, TestPath$, "*.*")  
  While NextDirectoryEntry(0)
    If DirectoryEntryType(0) = #PB_DirectoryEntry_File
      TestFile$ = TestPath$ + DirectoryEntryName(0)
      Result = FileIsClosed(TestFile$)
      If Result = #False
        Debug "Another process has exclusive access to this file: " + TestFile$
      EndIf
    EndIf
  Wend
  FinishDirectory(0)
Else
  Debug "oops, that directory doesn't exist...."
EndIf
Image If your code isn't clean atleast make sure it's pure!
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: CRC32FileFingerprint failure

Post by tinman »

happer66 wrote:He shouldn't be able to move the files to another folder if another process has them locked though..?
True, I forgot about that.

If it's not a locking problem then it is probably something else at the filesystem level, as it still works for the file in a different path. There's no reason for CRC32FileFingerprint to fail to open a file that exists, unless that error message is incorrect.

Other things to check:
security permissions of the directory that the download is going into against the user who is executing the PB code
anti-virus/malware logs to see if access has been blocked

There was also something I remember for .CHM files, that Windows Explorer kept a flag to say that it had been downloaded from the internet and it would either block access or ask you to allow access when you tried to open it. Maybe there is something similar for AVI files?
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: CRC32FileFingerprint failure

Post by doctorized »

@ happer66: tried your code and it says "Another process has exclusive access to this file" for all the files in the directory, as I am seeding with uTorrent 3.0.
Thank you my firends for your replays!
SeregaZ
Enthusiast
Enthusiast
Posts: 628
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: CRC32FileFingerprint failure

Post by SeregaZ »

in my case CRC32FileFingerprint shows less than 0. Debug CRC32FileFingerprint("C:\Program Files\NAT\GDMS3\DSMonitor.exe") shows "-125226421" it is ok? i mean return minus it is normal?

in old 4.30PB, in droopy CRC32 shows "FFFFFFFFF889324B" it is more than 0...
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: CRC32FileFingerprint failure

Post by netmaestro »

The results are identical, CRC32FileFingerprint is returning a long.
BERESHEIT
Post Reply