Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 andreas 1
/*
21 andreas 2
 * Copyright (C) 2019 to 2021 by Andreas Theofilu <andreas@theosys.at>
11 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#ifndef __DIRECTORY_H__
20
#define __DIRECTORY_H__
21
 
22
#include <string>
23
#include <vector>
24
 
25
namespace dir
26
{
27
	#define ATTR_TEXT       0x0001
28
	#define ATTR_GRAPHIC    0x0002
29
	#define ATTR_SOUND      0x0004
30
	#define ATTR_DIRECTORY  0x0008
31
	#define ATTR_LINK       0x0010
32
 
33
	struct DFILES
34
	{
35
		int count;				// Counter starting by 1
36
		size_t size;			// Size of file (directory = 0)
37
		unsigned short attr;	// Attributes (internal only)
38
		time_t date;			// The last modification date of the file/directory
39
		std::string name;		// Name of file/directory
40
	};
41
 
42
	typedef DFILES DFILES_T;
43
 
44
	class TDirectory
45
	{
46
		std::vector<DFILES_T> entries;
47
		bool done{false};
48
		std::string path;
49
		bool strip{false};
50
 
51
		public:
52
			TDirectory() = default;
53
			explicit TDirectory(const std::string& p) : path{p} {}
54
 
55
			int readDir();
56
			int readDir(const std::string& p);
57
			size_t getNumEntries();
58
			void setPath(const std::string& p) { path.assign(p); }
59
			void setStripPath(bool b) { strip = b; }
60
			size_t getFileSize(const std::string& f);
61
			bool isFile(const std::string& f);
62
			bool isDirectory(const std::string& f);
63
			bool exists(const std::string& f);
64
			DFILES_T getEntry(size_t pos);
65
			std::string stripPath(const std::string& p, size_t idx);
66
			std::string stripPath(const std::string& p, const std::string& s);
67
			bool testDirectory(unsigned short att) { return (att & ATTR_DIRECTORY); }
68
			bool testText(unsigned short att) { return (att & ATTR_TEXT); }
69
			bool testGraphic(unsigned short att) { return (att & ATTR_GRAPHIC); }
70
			bool testSound(unsigned short att) { return (att & ATTR_SOUND); }
71
			bool testLink(unsigned short att) { return (att & ATTR_LINK); }
72
 
73
		private:
74
			bool checkDot(const std::string& s);
75
	};
76
}
77
 
78
#endif