446 |
andreas |
1 |
/*
|
|
|
2 |
* Copyright (C) 2019 to 2022 by Andreas Theofilu <andreas@theosys.at>
|
|
|
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 |
typedef struct DFILES_T
|
|
|
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 |
}DFILES_T;
|
|
|
41 |
|
|
|
42 |
class TDirectory
|
|
|
43 |
{
|
|
|
44 |
std::vector<DFILES_T> entries;
|
|
|
45 |
bool done{false};
|
|
|
46 |
std::string path;
|
|
|
47 |
bool strip{false};
|
|
|
48 |
|
|
|
49 |
public:
|
|
|
50 |
TDirectory() = default;
|
|
|
51 |
explicit TDirectory(const std::string& p) : path{p} {}
|
|
|
52 |
|
|
|
53 |
int readDir();
|
|
|
54 |
int readDir(const std::string& p);
|
|
|
55 |
int scanFiles(const std::string& filter, bool start=false);
|
|
|
56 |
size_t getNumEntries();
|
|
|
57 |
void setPath(const std::string& p) { path.assign(p); }
|
|
|
58 |
void setStripPath(bool b) { strip = b; }
|
|
|
59 |
size_t getFileSize(const std::string& f);
|
|
|
60 |
bool isFile(const std::string& f);
|
|
|
61 |
bool isDirectory(const std::string& f);
|
|
|
62 |
bool exists(const std::string& f);
|
|
|
63 |
DFILES_T getEntry(size_t pos);
|
|
|
64 |
std::string stripPath(const std::string& p, size_t idx);
|
|
|
65 |
std::string stripPath(const std::string& p, const std::string& s);
|
|
|
66 |
bool createAllPath(std::string& path, bool cut=false);
|
|
|
67 |
bool drop(const std::string& path);
|
|
|
68 |
bool dropDir(const std::string& path);
|
|
|
69 |
bool dropFile(const std::string& fname);
|
|
|
70 |
std::string getEntryWithEnd(const std::string& end);
|
|
|
71 |
std::string getEntryWithPart(const std::string& part, bool precice=true);
|
|
|
72 |
std::string getEntryWithStart(const std::string& start);
|
|
|
73 |
bool testDirectory(unsigned short att) { return (att & ATTR_DIRECTORY); }
|
|
|
74 |
bool testText(unsigned short att) { return (att & ATTR_TEXT); }
|
|
|
75 |
bool testGraphic(unsigned short att) { return (att & ATTR_GRAPHIC); }
|
|
|
76 |
bool testSound(unsigned short att) { return (att & ATTR_SOUND); }
|
|
|
77 |
bool testLink(unsigned short att) { return (att & ATTR_LINK); }
|
|
|
78 |
|
|
|
79 |
private:
|
|
|
80 |
bool checkDot(const std::string& s);
|
|
|
81 |
};
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
#endif
|