Exemple #1
0
void Lua_V2::FileFindFirst() {
	lua_Object extObj = lua_getparam(1);
	if (!lua_isstring(extObj)) {
		lua_pushnil();
		return;
	}

	FileFindDispose();

	const char *extension = lua_getstring(extObj);
	if (0 == strncmp(extension, "Saves/", 6))
		extension += 6;

	// _menus.lua: saveload_menu.get_file_list searches for *.gsv.
	// This avoids conflicts with grim saves.
	if (0 == strcmp(extension, "*.gsv"))
		extension = "efmi???.gsv";

	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
	g_grim->_listFiles = saveFileMan->listSavefiles(extension);
	Common::sort(g_grim->_listFiles.begin(), g_grim->_listFiles.end());
	g_grim->_listFilesIter = g_grim->_listFiles.begin();

	if (g_grim->_listFilesIter == g_grim->_listFiles.end())
		lua_pushnil();
	else
		FileFindNext();
}
static void
generateListing(TList *       const listP,
                char *        const z,
                const char *  const uri,
                TPool *       const poolP,
                const char ** const errorP,
                uint16_t *    const responseStatusP) {
    
    TFileInfo fileinfo;
    TFileFind findhandle;

    *errorP = NULL;

    if (!FileFindFirst(&findhandle, z, &fileinfo)) {
        *responseStatusP = ResponseStatusFromErrno(errno);
        xmlrpc_asprintf(errorP, "Can't read first entry in directory");
    } else {
        ListInit(listP);

        do {
            TFileInfo * fi;
            /* Files whose names start with a dot are ignored */
            /* This includes implicitly the ./ and ../ */
            if (*fileinfo.name == '.') {
                if (xmlrpc_streq(fileinfo.name, "..")) {
                    if (xmlrpc_streq(uri, "/"))
                        continue;
                } else
                    continue;
            }
            fi = (TFileInfo *)PoolAlloc(poolP, sizeof(fileinfo));
            if (fi) {
                abyss_bool success;
                memcpy(fi, &fileinfo, sizeof(fileinfo));
                success =  ListAdd(listP, fi);
                if (!success)
                    xmlrpc_asprintf(errorP, "ListAdd() failed");
            } else
                xmlrpc_asprintf(errorP, "PoolAlloc() failed.");
        } while (!*errorP && FileFindNext(&findhandle, &fileinfo));

        if (*errorP) {
            *responseStatusP = 500;
            ListFree(listP);
        }            
        FileFindClose(&findhandle);
    }
}
Exemple #3
0
int FileFindFirst (const char *pszFilter, FILEFINDSTRUCT *ffstruct, int bFindDirs)
{
	WIN32_FIND_DATA find;
#ifdef _WIN32_WCE
	wchar_t	w_str [FILENAME_LEN];
	char		str [FILENAME_LEN];
#endif
	find.dwFileAttributes = bFindDirs ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL;
	_FindFileHandle = FindFirstFile (AscToUnicode (w_str, pszFilter), &find);
	if (_FindFileHandle == INVALID_HANDLE_VALUE) 
		return 1;
	else if (bFindDirs != ((find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0))
		return FileFindNext (ffstruct, bFindDirs);
	else {
		ffstruct->size = find.nFileSizeLow;
		strcpy (ffstruct->name, (UnicodeToAsc (str, find.cFileName)));
		return 0; 
	}
}
Exemple #4
0
bool FileFindFirst(TFileFind *filefind,char *path,TFileInfo *fileinfo)
{
#ifdef _WIN32
	bool ret;
	char *p=path+strlen(path);

	*p='\\';
	*(p+1)='*';
	*(p+2)='\0';
	ret=(((*filefind)=_findfirst(path,fileinfo))!=(-1));
	*p='\0';
	return ret;
#else
	strncpy(filefind->path,path,NAME_MAX);
	filefind->path[NAME_MAX]='\0';
	if (filefind->handle=opendir(path))
		return FileFindNext(filefind,fileinfo);

	return FALSE;
#endif
}
Exemple #5
0
abyss_bool
FileFindFirst(TFileFind *  const filefind,
              const char * const path,
              TFileInfo *  const fileinfo) {
#ifdef WIN32
    abyss_bool ret;
    char *p=path+strlen(path);

    *p='\\';
    *(p+1)='*';
    *(p+2)='\0';
#ifndef __BORLANDC__
    ret=(((*filefind)=_findfirst(path,fileinfo))!=(-1));
#else
    *filefind = FindFirstFile( path, &fileinfo->data );
   ret = *filefind != NULL;
   if( ret )
   {
      LARGE_INTEGER li;
      li.LowPart = fileinfo->data.nFileSizeLow;
      li.HighPart = fileinfo->data.nFileSizeHigh;
      strcpy( fileinfo->name, fileinfo->data.cFileName );
       fileinfo->attrib = fileinfo->data.dwFileAttributes;
       fileinfo->size   = li.QuadPart;
      fileinfo->time_write = fileinfo->data.ftLastWriteTime.dwLowDateTime;
   }
#endif
    *p='\0';
    return ret;
#else  /* WIN32 */
    strncpy(filefind->path,path,NAME_MAX);
    filefind->path[NAME_MAX]='\0';
    filefind->handle=opendir(path);
    if (filefind->handle)
        return FileFindNext(filefind,fileinfo);

    return FALSE;
#endif /* WIN32 */
}
Exemple #6
0
void Lua_V2::FileFindFirst() {
	lua_Object extObj = lua_getparam(1);
	if (!lua_isstring(extObj)) {
		lua_pushnil();
		return;
	}

	FileFindDispose();

	const char *extension = lua_getstring(extObj);
	if (0 == strncmp(extension, "Saves/", 6))
		extension += 6;
	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
	g_grim->_listFiles = saveFileMan->listSavefiles(extension);
	Common::sort(g_grim->_listFiles.begin(), g_grim->_listFiles.end());
	g_grim->_listFilesIter = g_grim->_listFiles.begin();

	if (g_grim->_listFilesIter == g_grim->_listFiles.end())
		lua_pushnil();
	else
		FileFindNext();
}
Exemple #7
0
/*======================================================================
----------------------------------------------------------------------*/
static BOOL PathEmpty(CHAR *path)
   {
   BOOL result;
   EVENT info;

   ASSERT(path != NULL);

   /* Look for any files... */
   result = TRUE;
   sprintf(info.filespec, "%s/*", path);
   info.attribute = FIND_FILE;
   if (FileFindFirst(&info))
      result = FALSE;
   FileFindClose(&info);

   if (!result)
      return result;

   /* or subdirectories... */
   result = TRUE;
   sprintf(info.filespec, "%s/*", path);
   info.attribute = FIND_SUBDIR;
   if (FileFindFirst(&info))
      {
      do
         {
         if (info.filespec[0] != '.')
            {
            result = FALSE;
            break;
            }
         }
      while (FileFindNext(&info));
      }
   FileFindClose(&info);

   return result;
   }  /* end PathEmpty() */
Exemple #8
0
/*======================================================================
----------------------------------------------------------------------*/
static YD_NODE *GetYDList(H_ARCHIVE harchive,  STREAM *criteria)
	{
	EVENT info;
   YD_NODE *head = NULL;
   YD_NODE *tail = NULL;
   YD_NODE *cur,*new_node;
   int	year;
   int	day;

   InitEvent(&info);

   if (!ValidateHandle(harchive))
      {
      ArchiveLog(ARC_LOG_ERRORS, "GetYDList: ValidateHandle failed");
      return (NULL);
      }
   
	/* Look at all day directories and store them */
	sprintf(info.filespec, "%s%c*", _archive[harchive].path, PATH_DELIMITER);
	info.attribute = FIND_SUBDIR;
	if (FileFindFirst(&info)) 
		{
		do 
			{
		   /* Ignore . and .. and insist on right length! */
		   if (info.filespec[0] == '.' || strlen(info.filespec) != 7) 
		   	{
		      continue;
		   	}

		   /* Decode year and doy */
			sscanf(info.filespec, "%4d%3d", &year, &day);
		   /* Set hour, minute, and second to zeros */
		   info.yd = EncodeMSTimeDOY((INT32) year, (INT32) day, 0, 0, 0.0);
		
		   /* If earliest is specified and time is less, go around */
		   if (!UndefinedTime(criteria->time.earliest) &&
		       CompareYD(info.yd, criteria->time.earliest) < 0) 
		   	{
		      continue;
		   	}
		
		   /* If latest is specified and time is greater, go around */
		   if (!UndefinedTime(criteria->time.latest) &&
		       CompareYD(info.yd, criteria->time.latest) > 0) 
		   	{
		      continue;
		   	}
		
		   /* Otherwise, we'll save this year & day, inserting it in ordered list*/
		  	if (head == NULL)	/* if first directory, then start list*/
		  		{
		  		head = (YD_NODE*) malloc(sizeof(YD_NODE));
	  			if (head == NULL)
		  				break;
		  		tail = head;
		  		head->yd = info.yd;
				head->year = year;
				head->day = day;
				head->next = NULL;
		  		}
		  	else						/* find place to insert data */
		  		{
		  		cur = NULL;
		  		if (CompareYD(info.yd, head->yd) <= 0)
		  			{
		  			cur = (YD_NODE*) malloc(sizeof(YD_NODE));
		  			if (cur == NULL)
		  				break;
		  			cur->next = head;
					head = cur;
		  			}
		  		else if (CompareYD(info.yd, tail->yd) >= 0)
		  			{
		  			cur = (YD_NODE*) malloc(sizeof(YD_NODE));
		  			if (cur == NULL)
		  				break;
		  			tail->next = cur;
					cur->next = NULL;
					tail = cur;
		  			}
		  		else
		  			{
		  			for (cur = head; ; cur = cur->next)
		  				{
		  				if (cur->next == NULL)/*we already checked the tail*/
							break;
						if ((CompareYD(info.yd, cur->yd) >= 0) &&
					  	 (CompareYD(info.yd, cur->next->yd) <= 0))
							{
							new_node = (YD_NODE*) malloc(sizeof(YD_NODE));
			  				if (new_node == NULL)
			  					{
			  					cur = NULL;
			  					break;
			  					}
							new_node->next = cur->next;
							cur->next = new_node;
							cur = new_node;
							break;
							}
		  				}
		  			}
		  		/* If no memory to build list quit*/
		  		if (cur != NULL)
		  			{
		  			cur->yd = info.yd;
					cur->year = year;
					cur->day = day;
					}
				else
					{
					break;
					}
		  		}/*end else insert in list*/
			} while (FileFindNext(&info));
		}/* end if found first */
		FileFindClose(&info);
		return(head);
	}  /* end get_yd_list */