Beispiel #1
0
Directory *Directory_FileSys::DoNext(Environment &env)
{
	WIN32_FIND_DATA findData;
	if (_hFind == INVALID_HANDLE_VALUE) {
		String pathName(MakePathName(false));
		if (!pathName.empty()) pathName += GetSeparator();
		pathName += "*.*";
		_hFind = ::FindFirstFile(OAL::ToNativeString(pathName.c_str()).c_str(), &findData);
		if (_hFind == INVALID_HANDLE_VALUE) return nullptr;
	} else if (!::FindNextFile(_hFind, &findData)) {
		::FindClose(_hFind);
		_hFind = INVALID_HANDLE_VALUE;
		return nullptr;
	}
	while (::strcmp(findData.cFileName, ".") == 0 ||
			::strcmp(findData.cFileName, "..") == 0) {
		if (!::FindNextFile(_hFind, &findData)) {
			::FindClose(_hFind);
			_hFind = INVALID_HANDLE_VALUE;
			return nullptr;
		}
	}
	Type type = (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)?
												TYPE_Container : TYPE_Item;
	String fileName = OAL::FromNativeString(findData.cFileName);
	return new Directory_FileSys(Directory::Reference(this), fileName.c_str(),
							type, new OAL::FileStat(fileName.c_str(), findData));
}
Beispiel #2
0
/*
** static void MakeDestFileName(char ARG_PTR *argv[], char ARG_PTR *pszDest);
**
** Create the appropriate destination file name.
**
** Arguments:  argv    - like argument to main()
**             pszDest - pointer to destination file name buffer to be filled
**                       in
**
** Returns:    void
**
** Globals:    none
*/
static VOID MakeDestFileName(CHAR ARG_PTR *argv[], CHAR ARG_PTR *pszDest)
{
   CHAR ARG_PTR *pszDestFile;

   if (nNumFileSpecs == 2 && bTargetIsDir == FALSE && bDoRename == FALSE)
      // Compress a single input file to a single output file.  N.b., we must
      // be careful to eat up the output file name command-line argument so
      // it doesn't get processed like another input file!
      STRCPY(pszDest, argv[GetNextFileArg(argv)]);
   else if (bTargetIsDir == TRUE)
   {
      // Prepend output file name with destination directory path name.
      STRCPY(pszDest, pszTargetName);

      // Isolate source file name from source file specification.
      pszDestFile = ExtractFileName(pszInFileName);

      // Add destination file name to destination directory path
      // specification.
      MakePathName(pszDest, pszDestFile);
   }
   else
      // Destination file name same as source file name.  N.b., this is an
      // error condition if (bDoRename == FALSE).
      STRCPY(pszDest, pszInFileName);
}
Beispiel #3
0
/***************************************
            FileEnum
 ***************************************/
BOOL MYRTLEXP FILE_ENUM::OpenDir( CONSTSTR path )
  {
    if ( !path ) path = "";

    oldDir = GetCurDir();
    if ( !SetCurDir(path) ) {
      SetCurDir( oldDir.Text() );
      return FALSE;
    }

    Path = GetCurDir();
    SetCurDir( oldDir.Text() );

  #if defined(__GNUC__) || defined(__QNX__)
    dir = opendir( Path.Text() );
    if ( dir == NULL || (ent=readdir(dir)) == NULL ) return FALSE;
    FPath = Path;
    FPath.Add( ent->d_name );
  #else
  #if defined(__REALDOS__) || defined(__HWIN16__)
    MemSet( &f,0,sizeof(f) );
    if ( findfirst( MakePathName(path,ALL_FILES).Text(),&f,FIO_ALLFILES ) != 0 )
      return FALSE;
    FPath = Path+f.ff_name;
  #else
  #if defined(__PROTDOS__)
    MemSet( &f,0,sizeof(f) );
    FIND *res;
    if ( (res=findfirst( MakePathName(path,ALL_FILES).Text(),FIO_ALLFILES )) == NULL )
      return FALSE;
    f = *res;
    FPath = Path+f.name;
  #else
  #if defined(__HWIN__)
    fHandle = FindFirstFile( MakePathName(path,ALL_FILES).Text(),&f );
    if ( fHandle == INVALID_HANDLE_VALUE ) return FALSE;
    FPath = Path;
    FPath.Add( f.cFileName );
  #else
  #error ERR_PLATFORM
  #endif
  #endif
  #endif
  #endif
 return TRUE;
}
Beispiel #4
0
Stream *Directory_FileSys::DoOpenStream(Environment &env, UInt32 attr)
{
	Signal &sig = env.GetSignal();
	Stream_File *pStream = new Stream_File(env);
	if (!pStream->Open(sig, MakePathName(false).c_str(), attr)) {
		return nullptr;
	}
	return pStream;
}
Beispiel #5
0
Object *Directory_FileSys::DoGetStatObj(Signal &sig)
{
	if (_pFileStat.get() == nullptr) {
		OAL::FileStat *pFileStat =
				OAL::FileStat::Generate(sig, MakePathName(false).c_str());
		if (sig.IsSignalled()) return nullptr;
		_pFileStat.reset(pFileStat);
	}
	return new Object_Stat(*_pFileStat);
}
Beispiel #6
0
Directory *Directory_MTP::DoNext(Environment &env)
{
	if (_browsePack.mtpfileHead == nullptr) {
		_browsePack.mtpfileHead = ::LIBMTP_Get_Files_And_Folders(_pDevice->GetMtpDevice(), _storageId, _itemId);
		_browsePack.mtpfile = _browsePack.mtpfileHead;
	} else {
		_browsePack.mtpfile = _browsePack.mtpfile->next;
	}
	if (_browsePack.mtpfile == nullptr) return nullptr;
	Type type = (_browsePack.mtpfile->filetype == LIBMTP_FILETYPE_FOLDER)? TYPE_Container : TYPE_Item;
	return new Directory_MTP(
		Reference(), _browsePack.mtpfile->filename, type,
		_pDevice->Reference(), _storageId, _browsePack.mtpfile->item_id,
		new Stat(MakePathName(false).c_str(), _browsePack.mtpfile));
}
Beispiel #7
0
void MYRTLEXP CTArgInit( int argc, char **argv,BOOL CaseSensitive )
  {
    DeleteArgs();
    CT_CaseSensitive = CaseSensitive;
    CT_SelfArgs      = TRUE;

    CT_argc = argc;
    CT_argv = new pchar[ CT_argc+1 ];
    int n;

    if ( StrChr(argv[0],SLASH_CHAR) == NULL )
      CT_argv[0] = StrDup( MakePathName(GetCurDir(),argv[0]).Text() );
     else
      CT_argv[0] = StrDup( argv[0] );

    for( n = 1; n < CT_argc; n++ )
      CT_argv[n] = StrDup( argv[n] );

    CT_argv[n] = NULL;
}
Beispiel #8
0
pchar MYRTLEXP CTGetArgPathName( CONSTSTR arg, CONSTSTR def, char *str, int sz )
  {  CONSTSTR m;

     if ( (m=CTArgGet(arg)) == NULL )
       StrCpy( str, MakePathName( GetStartupDir(NULL), def ).c_str(), sz );
      else {
#if defined(__HWIN32__)
       ExpandEnvironmentStrings( m, str, sz );
#else

//??Def expand on QNX

       StrCpy( str, m, sz );
#endif

       if ( !IsAbsolutePath(str) )
         StrCpy( str, MakeStartLocalPath(str).c_str(), sz );
     }

 return str;
}
Beispiel #9
0
Directory *Directory_FileSys::DoNext(Environment &env)
{
	if (_pDir == nullptr) {
		String pathName(MakePathName(false));
		String pathNameEnc = OAL::ToNativeString(pathName.c_str());
		_pDir = opendir(pathNameEnc.empty()? "." : pathNameEnc.c_str());
		if (_pDir == nullptr) return nullptr;
	}
	struct dirent *pEnt = nullptr;
	for (;;) {
		pEnt = readdir(_pDir);
		if (pEnt == nullptr) {
			closedir(_pDir);
			_pDir = nullptr;
			return nullptr;
		}
		if (::strcmp(pEnt->d_name, ".") != 0 &&
			::strcmp(pEnt->d_name, "..") != 0) break;
	}
	Type type = (pEnt->d_type == DT_DIR)? TYPE_Container : TYPE_Item;
	return new Directory_FileSys(Directory::Reference(this),
					OAL::FromNativeString(pEnt->d_name).c_str(), type, nullptr);
}