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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2313 - (show annotations) (download) (as text)
Sun Feb 12 11:32:43 2012 UTC (12 years, 2 months ago) by persson
File MIME type: text/x-c++hdr
File size: 4429 byte(s)
* bugfix: LADSPA_PATH was not evaluated correctly when containing
  multiple paths (#165)

1 /***************************************************************************
2 * *
3 * Copyright (C) 2008 - 2012 Grigor Iliev, Benno Senoner *
4 * *
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 #include <memory>
25 #include <string>
26 #include <vector>
27
28 #include "Mutex.h"
29 #ifndef WIN32
30 #include <sys/stat.h>
31 #endif
32
33 namespace LinuxSampler {
34
35 typedef std::auto_ptr<std::vector<std::string> > FileListPtr;
36
37 class File {
38 public:
39 class DirectoryWalker {
40 public:
41 virtual void DirectoryEntry(std::string Path) = 0;
42 virtual void FileEntry(std::string Path) = 0;
43 };
44
45 File(std::string FileName);
46
47 /**
48 * Tests whether the file exists.
49 */
50 bool Exist();
51
52 /**
53 * Provides appropriate error message if failed to retrieve
54 * information about the specified file, in which case Exist() returns false.
55 */
56 std::string GetErrorMsg();
57
58 /**
59 * Tests whether it's a regular file.
60 */
61 bool IsFile();
62
63 /**
64 * Tests whether it's a directory.
65 */
66 bool IsDirectory();
67
68 /**
69 * Returns the size of the file in bytes.
70 */
71 unsigned long GetSize();
72
73 /**
74 * Returns the names of the regular files in the specified directory.
75 * @throws Exception If failed to list the directory content.
76 */
77 static FileListPtr GetFiles(std::string Dir);
78
79 /**
80 * Walks through the directory tree that is located under the
81 * directory <b>Dir</b>, and calls <b>pWalker->DirectoryEntry()</b>
82 * once for each directory in the tree and <b>pWalker->FileEntry()</b>
83 * once for each file in the tree. Note that this method can be
84 * recursively invoked from within the callback functions
85 * <b>pWalker->DirectoryEntry()</b> and <b>pWalker->FileEntry()</b>.
86 * @throws Exception If the specified path is missing or is not a directory.
87 * Exception is also thrown, and the directory tree walk is stopped,
88 * if <b>pWalker->DirectoryEntry()</b> or <b>pWalker->FileEntry()</b>
89 * throws Exception.
90 */
91 static void WalkDirectoryTree(std::string Dir, DirectoryWalker* pWalker);
92
93 static const char DirSeparator;
94 static const char PathSeparator;
95
96 private:
97 bool bExist;
98 std::string ErrorMsg;
99 static Mutex DirectoryWalkerMutex;
100 static std::vector<DirectoryWalker*> DirectoryWalkers;
101 static std::string DWErrorMsg;
102
103 struct stat Status;
104 #ifdef WIN32
105 static void WalkDirectoryTreeSub(std::string Dir, DirectoryWalker* pWalker);
106 #else
107 static int FtwCallback(const char* fpath, const struct stat* sb, int typeflag);
108 #endif
109 };
110 }
111
112 #endif

  ViewVC Help
Powered by ViewVC