Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: Doobrey on January 04, 2006, 08:23:03 PM

Title: Stopping "Insert Volume.." requesters with Lock()
Post by: Doobrey on January 04, 2006, 08:23:03 PM
 Is there an easy way to check that a file/dir exists without having that annoying "Please insert volume:blah blah" requester ?

 Or am I stuck having to LockDosList() and traverse the list to see if the volume exists ,and only then do a Lock() (not forgetting the UnlockDosList() after !!) ?


Title: Re: Stopping "Insert Volume.." requesters with Lock()
Post by: Piru on January 04, 2006, 08:38:33 PM
@Doobrey
Quote
Is there an easy way to check that a file/dir exists without having that annoying "Please insert volume:blah blah" requester ?

Code: [Select]

#include <dos/dos.h>
#include <dos/dosextens.h>

#include <proto/exec.h>
#include <proto/dos.h>

BPTR LockQuiet(const char *name, LONG mode)
{
  struct Process *self = (APTR) FindTask(NULL);
  APTR oldwinptr;
  BPTR lock;

  oldwinptr = self->pr_WindowPtr;
  self->pr_WindowPtr = (APTR) -1;

  lock = Lock(name, mode);

  self->pr_WindowPtr = oldwinptr;

  return lock;
}


To test existance:
Code: [Select]

BPTR exists;

exists = LockQuiet("some:path/to/object", ACTION_READ);
if (exists)
{
  UnLock(exists);

  /* object exists */
}
else
{
  /* object doesn't exist */
}


Quote
Or am I stuck having to LockDosList() and traverse the list to see if the volume exists ,and only then do a Lock() (not forgetting the UnlockDosList() after !!) ?

No. That would break anyway: You must not Lock() while holding lock of the doslist.
Title: Re: Stopping "Insert Volume.." requesters with Lock()
Post by: Doobrey on January 04, 2006, 08:47:00 PM
Thanks Piru, nice and simple...just what I needed.

Quote

You must not Lock() while holding lock of the doslist.


Ooops.. I meant LockDosList(), check for volume, UnlockDosList() then Lock()... honest guv ;-)