Changeset 1214
- Timestamp:
- 9/29/2009 11:54:51 AM (4 years ago)
- Location:
- trunk/eraser6/Eraser.Util.FileSystem
- Files:
-
- 3 edited
-
Fat32Api.cpp (modified) (4 diffs)
-
FatApi.cpp (modified) (7 diffs)
-
FatApi.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser6/Eraser.Util.FileSystem/Fat32Api.cpp
r1211 r1214 59 59 } 60 60 61 FatDirectory^ Fat32Api::LoadDirectory(unsigned cluster )61 FatDirectory^ Fat32Api::LoadDirectory(unsigned cluster, String^ name) 62 62 { 63 return gcnew Directory( cluster, this);63 return gcnew Directory(name, cluster, this); 64 64 } 65 65 … … 127 127 //Traverse the directories until we get the cluster we want. 128 128 unsigned cluster = BootSector->Fat32ParameterBlock.RootDirectoryCluster; 129 String^ parentDir = nullptr; 129 130 for each (String^ component in components) 130 131 { … … 132 133 break; 133 134 134 FatDirectory^ currentDirectory = LoadDirectory(cluster );135 FatDirectory^ currentDirectory = LoadDirectory(cluster, parentDir); 135 136 cluster = currentDirectory->GetStartCluster(component); 137 parentDir = component; 136 138 } 137 139 … … 139 141 } 140 142 141 Fat32Api::Directory::Directory(unsigned cluster, Fat32Api^ api) : FatDirectory(cluster, api) 143 Fat32Api::Directory::Directory(String^ name, unsigned cluster, Fat32Api^ api) 144 : FatDirectory(name, cluster, api) 142 145 { 143 146 } -
trunk/eraser6/Eraser.Util.FileSystem/FatApi.cpp
r1211 r1214 46 46 volumeName.Truncate(volumeName.GetLength() - 1); 47 47 VolumeHandle = gcnew SafeFileHandle(static_cast<IntPtr>(CreateFile(volumeName, 48 GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL)), 48 GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 49 FILE_FLAG_RANDOM_ACCESS, NULL)), 49 50 true); 50 51 VolumeStream = gcnew FileStream(VolumeHandle, FileAccess::Read); … … 55 56 VolumeStream->Read(bootSector, 0, sizeof(*BootSector)); 56 57 Marshal::Copy(bootSector, 0, static_cast<IntPtr>(BootSector), bootSector->Length); 58 59 //Then load the FAT 60 LoadFat(); 57 61 } 58 62 … … 80 84 FatDirectory^ FatApi::LoadDirectory(String^ directory) 81 85 { 82 return LoadDirectory(DirectoryToCluster(directory)); 86 String^ directory2 = Path::GetDirectoryName(directory); 87 return LoadDirectory(DirectoryToCluster(directory), directory2); 83 88 } 84 89 … … 145 150 } 146 151 147 FatDirectory::FatDirectory(unsigned cluster, FatApi^ api) 148 { 152 FatDirectoryEntry::FatDirectoryEntry(String^ name, FatDirectoryEntryTypes type, unsigned cluster) 153 { 154 Name = name; 155 Type = type; 149 156 Cluster = cluster; 150 Entries = gcnew Dictionary<String^, unsigned>(); 157 } 158 159 String^ FatDirectoryEntry::FullName::get() 160 { 161 String^ result = Name; 162 FatDirectoryEntry^ currentEntry = this; 163 164 while (currentEntry->Parent != nullptr) 165 { 166 currentEntry = currentEntry->Parent; 167 result = currentEntry->Name + Path::PathSeparator + result; 168 } 169 170 return result; 171 } 172 173 FatDirectory::FatDirectory(String^ name, unsigned cluster, FatApi^ api) 174 : FatDirectoryEntry(name, FatDirectoryEntryTypes::Directory, cluster) 175 { 176 Entries = gcnew Dictionary<String^, FatDirectoryEntry^>(); 151 177 Api = api; 152 178 … … 204 230 //fileName contains the correct full long file name, strip the file name of the 205 231 //invalid characters. 206 Entries->Add(gcnew String(longFileName.c_str()), GetStartCluster(*i)); 232 String^ fileName = gcnew String(longFileName.c_str()); 233 Entries->Add(fileName, gcnew FatDirectoryEntry(fileName, 234 (i->Short.Attributes & FILE_ATTRIBUTE_DIRECTORY) ? 235 FatDirectoryEntryTypes::Directory : FatDirectoryEntryTypes::File, 236 GetStartCluster(*i))); 207 237 } 208 238 } … … 232 262 } 233 263 234 Entries->Add(gcnew String(shortFileName), GetStartCluster(*i)); 264 String^ fileName = gcnew String(shortFileName); 265 Entries->Add(fileName, gcnew FatDirectoryEntry(fileName, 266 (i->Short.Attributes & FILE_ATTRIBUTE_DIRECTORY) ? 267 FatDirectoryEntryTypes::Directory : FatDirectoryEntryTypes::File, 268 GetStartCluster(*i))); 235 269 } 236 270 } … … 238 272 unsigned FatDirectory::GetStartCluster(String^ file) 239 273 { 240 return Entries[file] ;274 return Entries[file]->Cluster; 241 275 } 242 276 -
trunk/eraser6/Eraser.Util.FileSystem/FatApi.h
r1207 r1214 56 56 57 57 /// Loads the directory structure at the given cluster. 58 virtual FatDirectory^ LoadDirectory(unsigned cluster ) = 0;58 virtual FatDirectory^ LoadDirectory(unsigned cluster, String^ name) = 0; 59 59 60 60 internal: … … 120 120 }; 121 121 122 /// Represents the types of FAT directory entries. 123 public enum class FatDirectoryEntryTypes 124 { 125 File, 126 Directory 127 }; 128 129 /// Represents a FAT directory entry. 130 public ref class FatDirectoryEntry 131 { 132 public: 133 /// Constructor. 134 /// 135 /// \param[in] name The name of the entry. 136 /// \param[in] type The type of this entry. 137 /// \param[in] cluster The first cluster of the file. 138 FatDirectoryEntry(String^ name, FatDirectoryEntryTypes type, unsigned cluster); 139 140 /// Gets the name of the file or directory. 141 property String^ Name 142 { 143 String^ get() { return name; } 144 private: 145 void set(String^ value) { name = value; } 146 } 147 148 /// Gets the full path to the file or directory. 149 property String^ FullName 150 { 151 String^ get(); 152 } 153 154 /// Gets the parent directory of this entry. 155 property FatDirectory^ Parent 156 { 157 FatDirectory^ get() { return parent; } 158 private: 159 void set(FatDirectory^ value) { parent = value; } 160 } 161 162 /// Gets the type of this entry. 163 property FatDirectoryEntryTypes Type 164 { 165 FatDirectoryEntryTypes get() { return type; } 166 private: 167 void set(FatDirectoryEntryTypes value) { type = value; } 168 } 169 170 /// Gets the first cluster of this entry. 171 property unsigned Cluster 172 { 173 unsigned get() { return cluster; } 174 private: 175 void set(unsigned value) { cluster = value; } 176 } 177 178 private: 179 String^ name; 180 FatDirectory^ parent; 181 FatDirectoryEntryTypes type; 182 unsigned cluster; 183 }; 184 122 185 /// Represents a FAT directory list. 123 public ref class FatDirectory abstract 124 { 125 public: 126 /// Constructor. 127 /// 186 public ref class FatDirectory abstract : FatDirectoryEntry 187 { 188 public: 189 /// Constructor. 190 /// 191 /// \param[in] name The name of the current directory. 128 192 /// \param[in] cluster The cluster at which the directory list starts. 129 193 /// \param[in] api The FAT API object which is creating this object. 130 FatDirectory( unsigned cluster, FatApi^ api);194 FatDirectory(String^ name, unsigned cluster, FatApi^ api); 131 195 132 196 /// Gets the start cluster of the requested file within this directory. … … 135 199 /// Compacts the directory structure. 136 200 void ClearDeletedEntries(); 201 202 /// The list of files and subfolders in this directory. 203 property Collections::Generic::Dictionary<String^, FatDirectoryEntry^>^ Items 204 { 205 Collections::Generic::Dictionary<String^, FatDirectoryEntry^>^ get() 206 { 207 return Entries; 208 } 209 } 137 210 138 211 protected: … … 141 214 142 215 private: 143 unsigned Cluster;144 216 FatDirectoryFile Directory; 145 Collections::Generic::Dictionary<String^, unsigned>^ Entries;217 Collections::Generic::Dictionary<String^, FatDirectoryEntry^>^ Entries; 146 218 147 219 FatApi^ Api; … … 157 229 public: 158 230 virtual void LoadFat() override; 159 virtual FatDirectory^ LoadDirectory(unsigned cluster ) override;231 virtual FatDirectory^ LoadDirectory(unsigned cluster, String^ name) override; 160 232 161 233 internal: … … 170 242 { 171 243 public: 172 Directory( unsigned cluster, Fat32Api^ api);244 Directory(String^ name, unsigned cluster, Fat32Api^ api); 173 245 174 246 protected:
Note: See TracChangeset
for help on using the changeset viewer.
