/[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 2478 - (show annotations) (download) (as text)
Sat Oct 19 07:52:33 2013 UTC (6 years, 3 months ago) by persson
File MIME type: text/x-c++hdr
File size: 4408 byte(s)
* fixed build error on newer MinGW
* support building with older jack versions
* support building with spaces in vst sdk path

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

  ViewVC Help
Powered by ViewVC