2018-05-30 15:19:13 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/util: folderiterator.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
2018-11-11 14:42:48 -05:00
|
|
|
* Copyright (C) 2017 Retroshare Team <retroshare.project@gmail.com> *
|
2018-05-30 15:19:13 -04:00
|
|
|
* *
|
|
|
|
* This program 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 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2010-05-16 19:26:45 -04:00
|
|
|
#ifndef FOLDERITERATOR_H
|
|
|
|
#define FOLDERITERATOR_H
|
|
|
|
|
|
|
|
|
2016-07-23 22:14:43 -04:00
|
|
|
#include <stdint.h>
|
2010-05-16 19:26:45 -04:00
|
|
|
#include <iostream>
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
#include <windows.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#else
|
|
|
|
#include <dirent.h>
|
|
|
|
#endif
|
|
|
|
|
2018-10-06 19:34:05 -04:00
|
|
|
#include "util/rstime.h"
|
2010-05-16 19:26:45 -04:00
|
|
|
|
|
|
|
namespace librs { namespace util {
|
|
|
|
|
|
|
|
|
|
|
|
class FolderIterator
|
|
|
|
{
|
|
|
|
public:
|
2016-11-16 15:49:27 -05:00
|
|
|
FolderIterator(const std::string& folderName,bool allow_symlinks,bool allow_files_from_the_future = true);
|
2010-05-16 19:26:45 -04:00
|
|
|
~FolderIterator();
|
|
|
|
|
2016-07-23 22:14:43 -04:00
|
|
|
enum { TYPE_UNKNOWN = 0x00,
|
|
|
|
TYPE_FILE = 0x01,
|
|
|
|
TYPE_DIR = 0x02
|
|
|
|
};
|
2010-05-16 19:26:45 -04:00
|
|
|
|
2016-09-15 15:45:00 -04:00
|
|
|
// info about current parent directory
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t dir_modtime() const ;
|
2016-09-15 15:45:00 -04:00
|
|
|
|
|
|
|
// info about directory content
|
|
|
|
|
2016-07-23 22:14:43 -04:00
|
|
|
bool isValid() const { return validity; }
|
2010-05-16 19:26:45 -04:00
|
|
|
bool readdir();
|
2016-07-23 22:14:43 -04:00
|
|
|
void next();
|
2010-05-16 19:26:45 -04:00
|
|
|
|
|
|
|
bool closedir();
|
|
|
|
|
2016-07-23 22:14:43 -04:00
|
|
|
const std::string& file_name() ;
|
|
|
|
const std::string& file_fullpath() ;
|
|
|
|
uint64_t file_size() ;
|
2016-07-24 23:48:22 -04:00
|
|
|
uint8_t file_type() ;
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t file_modtime() ;
|
2016-07-23 22:14:43 -04:00
|
|
|
|
2010-05-16 19:26:45 -04:00
|
|
|
private:
|
2016-09-24 07:56:02 -04:00
|
|
|
bool is_open;
|
2010-05-16 19:26:45 -04:00
|
|
|
bool validity;
|
|
|
|
|
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
HANDLE handle;
|
|
|
|
bool isFirstCall;
|
|
|
|
_WIN32_FIND_DATAW fileInfo;
|
|
|
|
#else
|
|
|
|
DIR* handle;
|
2010-05-16 19:59:39 -04:00
|
|
|
struct dirent* ent;
|
2010-05-16 19:26:45 -04:00
|
|
|
#endif
|
2016-11-14 08:10:49 -05:00
|
|
|
bool updateFileInfo(bool &should_skip) ;
|
2016-07-23 22:14:43 -04:00
|
|
|
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mFileModTime ;
|
|
|
|
rstime_t mFolderModTime ;
|
2016-07-23 22:14:43 -04:00
|
|
|
uint64_t mFileSize ;
|
|
|
|
uint8_t mType ;
|
|
|
|
std::string mFileName ;
|
|
|
|
std::string mFullPath ;
|
|
|
|
std::string mFolderName ;
|
2016-11-16 15:41:32 -05:00
|
|
|
bool mAllowSymLinks;
|
2016-11-16 15:49:27 -05:00
|
|
|
bool mAllowFilesFromTheFuture;
|
2010-05-16 19:26:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} } // librs::util
|
|
|
|
|
|
|
|
|
|
|
|
#endif // FOLDERITERATOR_H
|