1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_FileLocation_h
6 #define mozilla_FileLocation_h
10 #include "nsAutoPtr.h"
13 #include "FileUtils.h"
24 * FileLocation is an helper to handle different kind of file locations
28 * - in archives within archives
29 * As such, it stores a path within an archive, as well as the archive
30 * path itself, or the complete file path alone when on a filesystem.
31 * When the archive is in an archive, an nsZipArchive is stored instead
37 * Constructor for plain files
39 FileLocation(nsIFile
*file
)
45 * Constructors for path within an archive. The archive can be given either
46 * as nsIFile or nsZipArchive.
48 FileLocation(nsIFile
*zip
, const char *path
)
53 FileLocation(nsZipArchive
*zip
, const char *path
)
59 * Creates a new file location relative to another one.
61 FileLocation(const FileLocation
&file
, const char *path
= NULL
);
64 * Initialization functions corresponding to constructors
66 void Init(nsIFile
*file
)
73 void Init(nsIFile
*zip
, const char *path
)
80 void Init(nsZipArchive
*zip
, const char *path
)
88 * Returns an URI string corresponding to the file location
90 void GetURIString(nsACString
&result
) const;
93 * Returns the base file of the location, where base file is defined as:
94 * - The file itself when the location is on a filesystem
95 * - The archive file when the location is in an archive
96 * - The outer archive file when the location is in an archive in an archive
98 already_AddRefed
<nsIFile
> GetBaseFile();
101 * Returns whether the "base file" (see GetBaseFile) is an archive
105 return !mPath
.IsEmpty();
109 * Returns the path within the archive, when within an archive
111 void GetPath(nsACString
&result
) const
117 * Boolean value corresponding to whether the file location is initialized
120 operator bool() const
122 return mBaseFile
|| mBaseZip
;
126 * Returns whether another FileLocation points to the same resource
128 bool Equals(const FileLocation
&file
) const;
131 * Data associated with a FileLocation.
137 * Returns the data size
139 nsresult
GetSize(uint32_t *result
);
142 * Copies the data in the given buffer
144 nsresult
Copy(char *buf
, uint32_t len
);
146 friend class FileLocation
;
148 nsRefPtr
<nsZipArchive
> mZip
;
149 mozilla::AutoFDClose mFd
;
153 * Returns the data associated with the resource pointed at by the file
156 nsresult
GetData(Data
&data
);
158 nsCOMPtr
<nsIFile
> mBaseFile
;
159 nsRefPtr
<nsZipArchive
> mBaseZip
;
161 }; /* class FileLocation */
163 } /* namespace mozilla */
165 #endif /* mozilla_FileLocation_h */