/[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 1943 - (hide annotations) (download) (as text)
Tue Jul 14 18:25:11 2009 UTC (14 years, 8 months ago) by persson
File MIME type: text/x-c++hdr
File size: 4378 byte(s)
* fixed instrument database recursive import, which was broken on
  Windows

1 iliev 1717 /***************************************************************************
2     * *
3 persson 1943 * Copyright (C) 2008 - 2009 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 persson 1943 #ifndef WIN32
30 iliev 1717 #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 iliev 1781
93 iliev 1717 static char DirSeparator;
94    
95     private:
96     bool bExist;
97     std::string ErrorMsg;
98     static Mutex DirectoryWalkerMutex;
99     static std::vector<DirectoryWalker*> DirectoryWalkers;
100     static std::string DWErrorMsg;
101    
102     struct stat Status;
103 persson 1943 #ifdef WIN32
104     static void WalkDirectoryTreeSub(std::string Dir, DirectoryWalker* pWalker);
105     #else
106 iliev 1717 static int FtwCallback(const char* fpath, const struct stat* sb, int typeflag);
107 persson 1943 #endif
108 iliev 1717 };
109     }
110    
111     #endif

  ViewVC Help
Powered by ViewVC