/* Does the name refer to a directory instead of a file? */
if(FileInfo -> fib_DirEntryType > 0)
{
ShowRequest(window,HailText,"Destination \"%s\" is directory, not a file.","Continue",LastFileName);
UnLock(FileLock);
goto Start;
}
else
{
/* Can we delete (overwrite) it? */
if(FileInfo -> fib_Protection & FIBF_DELETE)
{
ShowRequest(window,HailText,"File \"%s\" is protected from deletion and\ncannot be overridden.","Continue",LastFileName);
UnLock(FileLock);
goto Start;
}
else
{
/* Can we write any data to it? */
if(FileInfo -> fib_Protection & FIBF_WRITE)
{
ShowRequest(window,HailText,"File \"%s\" is not write-enabled and\ncannot be overridden.","Continue",LastFileName);
UnLock(FileLock);
goto Start;
}
}
}
/* Is there already data in the file which
* we may overwrite?
*/
if(FileInfo -> fib_Size > 0)
{
/* Ask the user what to do with the file. */
switch(ShowRequest(window,HailText,"Destination file \"%s\" already exists,\ndo you still want to save?","Override file|Append file|Abort",LastFileName))
{
/* Overwrite the file. */
case 1: break;
/* Append data to the file;
* release the filelock first.
*/
case 2: UnLock(FileLock);
FileLock = NULL;
/* Open the file for mixed read and write access. */
if(!(File = Open(FullFileName,MODE_READWRITE)))
goto OpenError;
else
{
/* Seek to the end of the file.*/
if(Seek(File,0,OFFSET_END) == -1)
{
/* Query error condition. */
Error = IoErr();
/* Close the file. */
Close(File);
/* Clear the ID to avoid confusion. */
File = NULL;
}
}
break;
/* Abort the process. */
case 0: UnLock(FileLock);
return;
}
}
}
else
Error = IoErr();
/* Unlock the filelock again. */
if(FileLock)
UnLock(FileLock);
}
else
{
Error = IoErr();
/* If unable to find the object, don't
* treat it as an error.
*/
if(Error == ERROR_OBJECT_NOT_FOUND)
Error = 0;
}
/* Display an error message. */
if(Error)
{
/* Get the AmigaDOS error message. */
if(Fault(Error,"",DummyBuffer,512))
{
ShowRequest(window,HailText,"An error occured while accessing file \"%s\":%s","Continue",LastFileName,DummyBuffer);
goto Start;
}
else
{
DisplayBeep(window -> WScreen);
return;
}
}
/* If not already open, create a new file. */
if(!File)
{
if(!(File = Open(FullFileName,MODE_NEWFILE)))
{
/* Query error condition. */
OpenError: Error = IoErr();
/* Get the AmigaDOS error message. */
if(Fault(Error,"",DummyBuffer,512))
{
ShowRequest(window,HailText,"An error occured while opening file \"%s\":%s","Continue",LastFileName,DummyBuffer);