Bumping manifests a=b2g-bump
[gecko.git] / xpcom / build / FileLocation.h
blob62867d3c8d8e178363c368a45191ef4ae9c3b8c8
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
8 #include "nsString.h"
9 #include "nsCOMPtr.h"
10 #include "nsAutoPtr.h"
11 #include "nsIFile.h"
12 #include "FileUtils.h"
14 class nsZipArchive;
15 class nsZipItem;
17 namespace mozilla {
19 class FileLocation
21 public:
22 /**
23 * FileLocation is an helper to handle different kind of file locations
24 * within Gecko:
25 * - on filesystems
26 * - in archives
27 * - in archives within archives
28 * As such, it stores a path within an archive, as well as the archive
29 * path itself, or the complete file path alone when on a filesystem.
30 * When the archive is in an archive, an nsZipArchive is stored instead
31 * of a file path.
33 FileLocation();
34 ~FileLocation();
36 /**
37 * Constructor for plain files
39 explicit FileLocation(nsIFile* aFile);
41 /**
42 * Constructors for path within an archive. The archive can be given either
43 * as nsIFile or nsZipArchive.
45 FileLocation(nsIFile* aZip, const char* aPath);
47 FileLocation(nsZipArchive* aZip, const char* aPath);
49 /**
50 * Creates a new file location relative to another one.
52 FileLocation(const FileLocation& aFile, const char* aPath = nullptr);
54 /**
55 * Initialization functions corresponding to constructors
57 void Init(nsIFile* aFile);
59 void Init(nsIFile* aZip, const char* aPath);
61 void Init(nsZipArchive* aZip, const char* aPath);
63 /**
64 * Returns an URI string corresponding to the file location
66 void GetURIString(nsACString& aResult) const;
68 /**
69 * Returns the base file of the location, where base file is defined as:
70 * - The file itself when the location is on a filesystem
71 * - The archive file when the location is in an archive
72 * - The outer archive file when the location is in an archive in an archive
74 already_AddRefed<nsIFile> GetBaseFile();
76 /**
77 * Returns whether the "base file" (see GetBaseFile) is an archive
79 bool IsZip() const { return !mPath.IsEmpty(); }
81 /**
82 * Returns the path within the archive, when within an archive
84 void GetPath(nsACString& aResult) const { aResult = mPath; }
86 /**
87 * Boolean value corresponding to whether the file location is initialized
88 * or not.
90 operator bool() const { return mBaseFile || mBaseZip; }
92 /**
93 * Returns whether another FileLocation points to the same resource
95 bool Equals(const FileLocation& aFile) const;
97 /**
98 * Data associated with a FileLocation.
100 class Data
102 public:
104 * Returns the data size
106 nsresult GetSize(uint32_t* aResult);
109 * Copies the data in the given buffer
111 nsresult Copy(char* aBuf, uint32_t aLen);
112 protected:
113 friend class FileLocation;
114 nsZipItem* mItem;
115 nsRefPtr<nsZipArchive> mZip;
116 mozilla::AutoFDClose mFd;
120 * Returns the data associated with the resource pointed at by the file
121 * location.
123 nsresult GetData(Data& aData);
124 private:
125 nsCOMPtr<nsIFile> mBaseFile;
126 nsRefPtr<nsZipArchive> mBaseZip;
127 nsCString mPath;
128 }; /* class FileLocation */
130 } /* namespace mozilla */
132 #endif /* mozilla_FileLocation_h */