237 lines
		
	
	
		
			6.5 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			237 lines
		
	
	
		
			6.5 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
//
 | 
						|
// ATTROS2.CPP
 | 
						|
//
 | 
						|
//  Source file for ArchiveLib 2.0
 | 
						|
//
 | 
						|
//  Copyright (c) Greenleaf Software, Inc. 1994-1996
 | 
						|
//  All Rights Reserved
 | 
						|
//
 | 
						|
// CONTENTS
 | 
						|
//
 | 
						|
//  ALFile::ReadAttributesFromFileSys()
 | 
						|
//  ALFile::WriteAttributesToFileSys()
 | 
						|
//
 | 
						|
// DESCRIPTION
 | 
						|
//
 | 
						|
//  These two files provide system-dependent functionality for ALFile.
 | 
						|
//  It takes different code to set the attributes for files depending
 | 
						|
//  on which O/S you are targetting.
 | 
						|
//
 | 
						|
// REVISION HISTORY
 | 
						|
//
 | 
						|
//   February 14, 1996  2.0A : New release
 | 
						|
 | 
						|
#include "arclib.h"
 | 
						|
#if !defined( AL_IBM )
 | 
						|
#pragma hdrstop
 | 
						|
#endif
 | 
						|
 | 
						|
#define INCL_DOSFILEMGR
 | 
						|
#include <os2.h>
 | 
						|
#include <io.h>
 | 
						|
#include <time.h>
 | 
						|
#include "filestor.h"
 | 
						|
#include "fileattr.h"
 | 
						|
 | 
						|
//
 | 
						|
// NAME
 | 
						|
//
 | 
						|
//  ALFile::ReadAttributesFromFileSys()
 | 
						|
//
 | 
						|
// PLATFORMS/ENVIRONMENTS
 | 
						|
//
 | 
						|
//  OS/2
 | 
						|
//  C++
 | 
						|
//
 | 
						|
// SHORT DESCRIPTION
 | 
						|
//
 | 
						|
//  Read in the attributes of a file under OS/2.
 | 
						|
//
 | 
						|
// C++ SYNOPSIS
 | 
						|
//
 | 
						|
//  #include "arclib.h"
 | 
						|
//  #include "filestor.h"
 | 
						|
//
 | 
						|
//  int ALFile::ReadAttributesFromFileSys();
 | 
						|
//
 | 
						|
// C SYNOPSIS
 | 
						|
//
 | 
						|
//  None, this internal protected function has no C version.
 | 
						|
//
 | 
						|
// VB SYNOPSIS
 | 
						|
//
 | 
						|
//  None, this internal protected function has no VB version.
 | 
						|
//
 | 
						|
// DELPHI SYNOPSIS
 | 
						|
//
 | 
						|
//  None, this internal protected function has no Delphi version.
 | 
						|
//
 | 
						|
// ARGUMENTS
 | 
						|
//
 | 
						|
//  None.
 | 
						|
//
 | 
						|
// DESCRIPTION
 | 
						|
//
 | 
						|
//  When an ALFile object is opened, we have to read the file attributes.
 | 
						|
//  This is an O/S dependent function, but I don't want to have too many
 | 
						|
//  #ifdefs, so I package it in a separate directory that gets compiled
 | 
						|
//  in an environment dependent fashion.  This particular file gets
 | 
						|
//  compiled for any library that's using the OS/2 file system.
 | 
						|
//
 | 
						|
//  All this function has to do is call the DosQueryFileInfo() function,
 | 
						|
//  then translate the returned bits into the appropriate internal attribute
 | 
						|
//  bits.  Note that we don't try to translate any extended bits beyond
 | 
						|
//  those in DOS compatiblity mode.  If there is extra stuff that goes with
 | 
						|
//  the HPFS, for example, we aren't paying any attention to it.
 | 
						|
//
 | 
						|
// RETURNS
 | 
						|
//
 | 
						|
//  AL_SUCCESS or AL_CANT_OPEN_FILE.
 | 
						|
//
 | 
						|
// EXAMPLE
 | 
						|
//
 | 
						|
// SEE ALSO
 | 
						|
//
 | 
						|
// REVISION HISTORY
 | 
						|
//
 | 
						|
//   February 14, 1996  2.0A : New release.
 | 
						|
//
 | 
						|
 | 
						|
int AL_PROTO
 | 
						|
ALFile::ReadAttributesFromFileSys()  /* Tag protected function */
 | 
						|
{
 | 
						|
    FILESTATUS3 InfoBuf;
 | 
						|
    APIRET rc;
 | 
						|
    rc = DosQueryFileInfo( miHandle,
 | 
						|
                           FIL_STANDARD,
 | 
						|
                           (PVOID) &InfoBuf,
 | 
						|
                           sizeof( InfoBuf ) );
 | 
						|
    if ( rc != 0 )
 | 
						|
        return mStatus.SetError( AL_CANT_OPEN_FILE,
 | 
						|
                                 "Couldn't get file attribute "
 | 
						|
                                 "information for %s.  errno = %d.",
 | 
						|
                                 mName.GetName(),
 | 
						|
                                 rc );
 | 
						|
    mAttributes.miUnixBitsPresent = 0;
 | 
						|
    mAttributes.miReadOnly = ( InfoBuf.attrFile & FILE_READONLY ) != 0;
 | 
						|
    mAttributes.miSystem = ( InfoBuf.attrFile & FILE_SYSTEM ) != 0;
 | 
						|
    mAttributes.miHidden = ( InfoBuf.attrFile & FILE_HIDDEN ) != 0;
 | 
						|
    mAttributes.miArchive = ( InfoBuf.attrFile & FILE_ARCHIVED ) != 0;
 | 
						|
    return AL_SUCCESS;
 | 
						|
}
 | 
						|
 | 
						|
//
 | 
						|
// NAME
 | 
						|
//
 | 
						|
//  ALFile::WriteAttributesToFileSys()
 | 
						|
//
 | 
						|
// PLATFORMS/ENVIRONMENTS
 | 
						|
//
 | 
						|
//  OS/2
 | 
						|
//  C++
 | 
						|
//
 | 
						|
// SHORT DESCRIPTION
 | 
						|
//
 | 
						|
//  Set the attributes of a file under OS/2.
 | 
						|
//
 | 
						|
// C++ SYNOPSIS
 | 
						|
//
 | 
						|
//  #include "arclib.h"
 | 
						|
//  #include "filestor.h"
 | 
						|
//
 | 
						|
//  int ALFile::WriteAttributesToFileSys();
 | 
						|
//
 | 
						|
// C SYNOPSIS
 | 
						|
//
 | 
						|
//  None, this internal protected function has no C version.
 | 
						|
//
 | 
						|
// VB SYNOPSIS
 | 
						|
//
 | 
						|
//  None, this internal protected function has no VB version.
 | 
						|
//
 | 
						|
// DELPHI SYNOPSIS
 | 
						|
//
 | 
						|
//  None, this internal protected function has no Delphi version.
 | 
						|
//
 | 
						|
// ARGUMENTS
 | 
						|
//
 | 
						|
//  None.
 | 
						|
//
 | 
						|
// DESCRIPTION
 | 
						|
//
 | 
						|
//  When an ALFile object is closed, we have to set the file attributes.
 | 
						|
//  This is an O/S dependent function, but I don't want to have too many
 | 
						|
//  #ifdefs, so I package it in a separate directory that gets compiled
 | 
						|
//  in an environment dependent fashion.  This particular file gets
 | 
						|
//  compiled for any library that's using the OS/2 file system.
 | 
						|
//
 | 
						|
//  This function calls DosSetPathInfo() to set both the time and date
 | 
						|
//  stamp for the given file.  This differs somewhat from the NT and
 | 
						|
//  DOS versions of the function, which only set the attributes.
 | 
						|
//
 | 
						|
// RETURNS
 | 
						|
//
 | 
						|
//  Nothing.
 | 
						|
//
 | 
						|
// EXAMPLE
 | 
						|
//
 | 
						|
// SEE ALSO
 | 
						|
//
 | 
						|
// REVISION HISTORY
 | 
						|
//
 | 
						|
//   February 14, 1996  2.0A : New release.
 | 
						|
//
 | 
						|
 | 
						|
void AL_PROTO
 | 
						|
ALFile::WriteAttributesToFileSys()  /* Tag protected function */
 | 
						|
{
 | 
						|
    FILESTATUS3 InfoBuf;
 | 
						|
    DosQueryPathInfo( (PSZ)(char*)mName,
 | 
						|
                      FIL_STANDARD,
 | 
						|
                      (PVOID) &InfoBuf,
 | 
						|
                      sizeof( InfoBuf ) );
 | 
						|
    if ( mAttributes.miReadOnly )
 | 
						|
        InfoBuf.attrFile |= FILE_READONLY;
 | 
						|
    else
 | 
						|
        InfoBuf.attrFile &= ~FILE_READONLY;
 | 
						|
    if ( mAttributes.miSystem )
 | 
						|
        InfoBuf.attrFile |= FILE_SYSTEM;
 | 
						|
    else
 | 
						|
        InfoBuf.attrFile &= ~FILE_SYSTEM;
 | 
						|
    if ( mAttributes.miHidden )
 | 
						|
        InfoBuf.attrFile |= FILE_HIDDEN;
 | 
						|
    else
 | 
						|
        InfoBuf.attrFile &= ~FILE_HIDDEN;
 | 
						|
    if ( mAttributes.miArchive )
 | 
						|
        InfoBuf.attrFile |= FILE_ARCHIVED;
 | 
						|
    else
 | 
						|
        InfoBuf.attrFile &= ~FILE_ARCHIVED;
 | 
						|
 | 
						|
    struct tm tblock;
 | 
						|
    mTimeDate.GetTimeDate( &tblock );
 | 
						|
    InfoBuf.ftimeCreation.hours = tblock.tm_hour;
 | 
						|
    InfoBuf.ftimeCreation.minutes = tblock.tm_min;
 | 
						|
    InfoBuf.ftimeCreation.twosecs = tblock.tm_sec / 2;
 | 
						|
    InfoBuf.ftimeLastAccess.hours = tblock.tm_hour;
 | 
						|
    InfoBuf.ftimeLastAccess.minutes = tblock.tm_min;
 | 
						|
    InfoBuf.ftimeLastAccess.twosecs = tblock.tm_sec / 2;
 | 
						|
    InfoBuf.ftimeLastWrite.hours = tblock.tm_hour;
 | 
						|
    InfoBuf.ftimeLastWrite.minutes = tblock.tm_min;
 | 
						|
    InfoBuf.ftimeLastWrite.twosecs = tblock.tm_sec / 2;
 | 
						|
    InfoBuf.fdateCreation.day = tblock.tm_mday;
 | 
						|
    InfoBuf.fdateCreation.month = tblock.tm_mon + 1;
 | 
						|
    InfoBuf.fdateCreation.year = tblock.tm_year + 1900 - 1980;
 | 
						|
    InfoBuf.fdateLastAccess.day = tblock.tm_mday;
 | 
						|
    InfoBuf.fdateLastAccess.month = tblock.tm_mon + 1;
 | 
						|
    InfoBuf.fdateLastAccess.year = tblock.tm_year + 1900 - 1980;
 | 
						|
    InfoBuf.fdateLastWrite.day = tblock.tm_mday;
 | 
						|
    InfoBuf.fdateLastWrite.month = tblock.tm_mon + 1;
 | 
						|
    InfoBuf.fdateLastWrite.year = tblock.tm_year + 1900 -1980;
 | 
						|
    DosSetPathInfo( (PSZ)(char*)mName,
 | 
						|
                    FIL_STANDARD,
 | 
						|
                    (PVOID) &InfoBuf,
 | 
						|
                    sizeof( InfoBuf ),
 | 
						|
                    0L );
 | 
						|
}
 | 
						|
 |