/[svn]/linuxsampler/trunk/src/common/File.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/common/File.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3056 - (hide annotations) (download) (as text)
Fri Dec 16 12:57:59 2016 UTC (7 years, 4 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 4538 byte(s)
* RT Instrument Scripts: Fixed crash when using built-in script function
  "by_marks()".
* LSCP Server: Fixed client connection not being closed after network error.
* Fixed some more few compiler warnings.
* Bumped version (2.0.0.svn33).

1 iliev 1717 /***************************************************************************
2     * *
3 persson 2313 * Copyright (C) 2008 - 2012 Grigor Iliev, Benno Senoner *
4 iliev 1717 * *
5     * This program is free software; you can redistribute it and/or modify *
6     * it under the terms of the GNU General Public License as published by *
7     * the Free Software Foundation; either version 2 of the License, or *
8     * (at your option) any later version. *
9     * *
10     * This program is distributed in the hope that it will be useful, *
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13     * GNU General Public License for more details. *
14     * *
15     * You should have received a copy of the GNU General Public License *
16     * along with this program; if not, write to the Free Software *
17     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
18     * MA 02110-1301 USA *
19     ***************************************************************************/
20    
21     #ifndef LS_FILE_H
22     #define LS_FILE_H
23    
24 persson 1726 #include <memory>
25 iliev 1717 #include <string>
26     #include <vector>
27    
28     #include "Mutex.h"
29     #include <sys/stat.h>
30    
31     namespace LinuxSampler {
32    
33 schoenebeck 3056 #if __cplusplus >= 201103L && !CONFIG_NO_CPP11STL
34 persson 2840 typedef std::unique_ptr<std::vector<std::string>> FileListPtr;
35     #else
36 iliev 1717 typedef std::auto_ptr<std::vector<std::string> > FileListPtr;
37 persson 2840 #endif
38 iliev 1717
39     class File {
40     public:
41     class DirectoryWalker {
42     public:
43     virtual void DirectoryEntry(std::string Path) = 0;
44     virtual void FileEntry(std::string Path) = 0;
45     };
46    
47     File(std::string FileName);
48    
49     /**
50     * Tests whether the file exists.
51     */
52     bool Exist();
53    
54     /**
55     * Provides appropriate error message if failed to retrieve
56     * information about the specified file, in which case Exist() returns false.
57     */
58     std::string GetErrorMsg();
59    
60     /**
61     * Tests whether it's a regular file.
62     */
63     bool IsFile();
64    
65     /**
66     * Tests whether it's a directory.
67     */
68     bool IsDirectory();
69    
70     /**
71     * Returns the size of the file in bytes.
72     */
73     unsigned long GetSize();
74    
75     /**
76     * Returns the names of the regular files in the specified directory.
77     * @throws Exception If failed to list the directory content.
78     */
79     static FileListPtr GetFiles(std::string Dir);
80    
81     /**
82     * Walks through the directory tree that is located under the
83     * directory <b>Dir</b>, and calls <b>pWalker->DirectoryEntry()</b>
84     * once for each directory in the tree and <b>pWalker->FileEntry()</b>
85     * once for each file in the tree. Note that this method can be
86     * recursively invoked from within the callback functions
87     * <b>pWalker->DirectoryEntry()</b> and <b>pWalker->FileEntry()</b>.
88     * @throws Exception If the specified path is missing or is not a directory.
89     * Exception is also thrown, and the directory tree walk is stopped,
90     * if <b>pWalker->DirectoryEntry()</b> or <b>pWalker->FileEntry()</b>
91     * throws Exception.
92     */
93     static void WalkDirectoryTree(std::string Dir, DirectoryWalker* pWalker);
94 iliev 1781
95 persson 2313 static const char DirSeparator;
96     static const char PathSeparator;
97 iliev 1717
98     private:
99     bool bExist;
100     std::string ErrorMsg;
101     static Mutex DirectoryWalkerMutex;
102     static std::vector<DirectoryWalker*> DirectoryWalkers;
103     static std::string DWErrorMsg;
104    
105     struct stat Status;
106 persson 1943 #ifdef WIN32
107     static void WalkDirectoryTreeSub(std::string Dir, DirectoryWalker* pWalker);
108     #else
109 iliev 1717 static int FtwCallback(const char* fpath, const struct stat* sb, int typeflag);
110 persson 1943 #endif
111 iliev 1717 };
112     }
113    
114     #endif

  ViewVC Help
Powered by ViewVC