sbFileUtils.h
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 #ifndef SBFILEUTILS_H_
26 #define SBFILEUTILS_H_
27 
28 #include <nsCOMPtr.h>
29 #include <nsCRT.h>
30 #include <nsIFile.h>
31 #include <nsIInputStream.h>
32 #include <nsIOutputStream.h>
33 #include <nsStringGlue.h>
34 #include <sbMemoryUtils.h>
35 
36 class nsIInputStream;
37 class nsIOutputStream;
38 class nsIURI;
39 
43 nsresult sbOpenInputStream(nsAString const & aPath, nsIInputStream ** aStream);
44 
48 nsresult sbOpenInputStream(nsIURI * aURI, nsIInputStream ** aStream);
49 
53 nsresult sbOpenInputStream(nsIFile * aFile, nsIInputStream ** aStream);
54 
58 nsresult sbOpenOutputStream(nsIFile * aFile, nsIOutputStream ** aStream);
59 
63 nsresult sbOpenOutputStream(nsAString const & aPath,
64  nsIOutputStream ** aStream);
68 nsresult sbReadFile(nsIFile * aFile, nsACString &aBuffer);
69 
73 nsresult
74 sbConsumeStream(nsIInputStream *aSource, PRUint32 aMaxCount,
75  nsACString &aBuffer);
76 
84 nsresult sbNewFileURI(nsIFile* aFile,
85  nsIURI** aURI);
86 
96 void RemoveBadFileNameCharacters(nsAString& aFileName,
97  PRBool aAllPlatforms);
98 
99 
100 //
101 // Auto-disposal class wrappers.
102 //
103 // sbAutoInputStream Wrapper to auto-close an input stream.
104 // sbAutoOutputStream Wrapper to auto-close an output stream.
105 // sbAutoRemoveFile Warpper to auto-remove an nsIFile.
106 //
107 
108 SB_AUTO_NULL_CLASS(sbAutoInputStream,
109  nsCOMPtr<nsIInputStream>,
110  mValue->Close());
111 SB_AUTO_NULL_CLASS(sbAutoOutputStream,
112  nsCOMPtr<nsIOutputStream>,
113  mValue->Close());
114 SB_AUTO_NULL_CLASS(sbAutoRemoveFile,
115  nsCOMPtr<nsIFile>,
116  mValue->Remove(PR_FALSE));
117 
118 
119 //
120 // Default file and directory permissions.
121 //
122 
123 #define SB_DEFAULT_FILE_PERMISSIONS 0644
124 #define SB_DEFAULT_DIRECTORY_PERMISSIONS 0755
125 
126 
127 //
128 // Bad file name characters.
129 //
130 // SB_FILE_BAD_CHARACTERS Bad file name characters, including file path
131 // separators.
132 // SB_FILE_BAD_CHARACTERS_ALL_PLATFORMS
133 // Bad file name characters for all platforms,
134 // including file path separators for all
135 // platforms.
136 //
137 
138 #define SB_FILE_BAD_CHARACTERS FILE_ILLEGAL_CHARACTERS FILE_PATH_SEPARATOR
139 #define SB_FILE_BAD_CHARACTERS_ALL_PLATFORMS CONTROL_CHARACTERS "/\\:*?\"<>|"
140 
141 #endif /* SBFILEUTILS_H_ */
142 
_updateCookies aPath
SB_AUTO_NULL_CLASS(sbAutoInputStream, nsCOMPtr< nsIInputStream >, mValue->Close())
nsresult sbConsumeStream(nsIInputStream *aSource, PRUint32 aMaxCount, nsACString &aBuffer)
nsresult sbOpenOutputStream(nsIFile *aFile, nsIOutputStream **aStream)
nsresult sbNewFileURI(nsIFile *aFile, nsIURI **aURI)
nsresult sbOpenInputStream(nsAString const &aPath, nsIInputStream **aStream)
Definition: sbFileUtils.cpp:47
nsresult sbReadFile(nsIFile *aFile, nsACString &aBuffer)
void RemoveBadFileNameCharacters(nsAString &aFileName, PRBool aAllPlatforms)