/* Generated automatically by jlpp - do not edit. */
#line 1 "io/FileInfo.jlc"
// -*- c++ -*-
/*
* Jakelib2 - General purpose C++ library
* Copyright (C) 2001 Florian Wolff (florian@donuz.de)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: FileInfo.jlc,v 1.3 2006-02-18 16:01:20 florian Exp $
*/
#include "jakelib2.h"
#include "jakelib2/io/File.h"
#include "jakelib2/io/FileInfo.h"
using namespace jakelib::lang;
using namespace jakelib::io;
JAKELIB_IMPLEMENT_CLASS("jakelib.io.FileInfo", FileInfo, Object);
JAKELIB_IMPLEMENT_ARRAY(FileInfo);
#if defined(BORLAND)
# include
# include
#elif defined(JAKELIB_WIN32API)
# include
# include
#else
# include
# include
# include
#endif
#ifdef HAVE_UNISTD_H
# include
#endif
/*****************************************************************************\
* FileInfo |
*****************************************************************************/
FileInfo::FileInfo(File* file)
{
init(file);
}
/*****************************************************************************\
* init |
*****************************************************************************/
void FileInfo::init(File* file)
{
this->file = file;
String* path = file->getPath();
_isFile = false;
_isDirectory = false;
_isSystem = false;
_isHidden = false;
//_isReadOnly = false;
_length = -1;
_aTime = 0;
_mTime = 0;
_isLink = false;
_linkDest = null;
#if defined(BORLAND)
struct ffblk ffblk;
int done = findfirst(path->latin1(), &ffblk, FA_SYSTEM|FA_DIREC|FA_RDONLY|FA_HIDDEN);
if (done == 0) {
//_isReadOnly = (ffblk.ff_attrib & FA_RDONLY) ? true : false;
_isHidden = (ffblk.ff_attrib & FA_HIDDEN) ? true : false;
_isSystem = (ffblk.ff_attrib & FA_SYSTEM) ? true : false;
_isFile = (!(ffblk.ff_attrib & FA_DIREC)) ? true : false;
_isDirectory = (ffblk.ff_attrib & FA_DIREC) ? true : false;
_length = ffblk.ff_fsize;
}
#elif defined(JAKELIB_WIN32API)
WIN32_FIND_DATA ffblk;
HANDLE hFind;
hFind = FindFirstFile(path->latin1(), &ffblk);
if (hFind != INVALID_HANDLE_VALUE) {
//_isReadOnly = (ffblk.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? true : false;
_isHidden = (ffblk.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? true : false;
_isSystem = (ffblk.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? true : false;
_isFile = (!(ffblk.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) ? true : false;
_isDirectory = (ffblk.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false;
_length = ffblk.nFileSizeLow;
_mTime = ((jlong)ffblk.ftLastWriteTime.dwLowDateTime |
((jlong)ffblk.ftLastWriteTime.dwHighDateTime << 32)) / LL(10000) - LL(11644473600000);
FindClose(hFind);
}
#else
struct stat info;
if (stat(path->latin1(), &info) == 0) {
_length = info.st_size;
_isFile = S_ISREG(info.st_mode);
_isDirectory = S_ISDIR(info.st_mode);
_aTime = (jlong) info.st_atime * LL(1000);
_mTime = (jlong) info.st_mtime * LL(1000);
if (lstat(path->latin1(), &info) == 0) {
_isLink = S_ISLNK(info.st_mode);
}
if (_isLink) {
char buf[JAKELIB_MAX_PATH + 1];
int l = ::readlink(path->latin1(), buf, JAKELIB_MAX_PATH);
if (l == -1) {
_linkDest = null;
} else {
buf[l] = '\0';
_linkDest = new String(buf);
}
}
}
#endif
}
/*****************************************************************************\
* isDirectory |
*****************************************************************************/
jboolean FileInfo::isDirectory()
{
return _isDirectory;
}
/*****************************************************************************\
* isFile |
*****************************************************************************/
jboolean FileInfo::isFile()
{
return _isFile;
}
/*****************************************************************************\
* isLink |
*****************************************************************************/
jboolean FileInfo::isLink()
{
return _isLink;
}
/*****************************************************************************\
* isSystem |
*****************************************************************************/
jboolean FileInfo::isSystem()
{
return _isSystem;
}
/*****************************************************************************\
* isHidden |
*****************************************************************************/
jboolean FileInfo::isHidden()
{
return _isHidden;
}
/*****************************************************************************\
* length |
*****************************************************************************/
jlong FileInfo::length()
{
return _length;
}
/*****************************************************************************\
* lastModified |
*****************************************************************************/
jlong FileInfo::lastModified()
{
return _mTime;
}
/*****************************************************************************\
* getFile |
*****************************************************************************/
File* FileInfo::getFile()
{
return file;
}
/*****************************************************************************\
* readlink |
*****************************************************************************/
String* FileInfo::readlink()
{
return _linkDest;
}