Changeset 1242
- Timestamp:
- 9/30/2009 10:10:05 AM (4 years ago)
- Location:
- trunk/eraser6/Eraser.Util.FileSystem
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser6/Eraser.Util.FileSystem/FatApi.cpp
r1239 r1242 21 21 22 22 #include <stdafx.h> 23 #include <vector> 23 24 #include <windows.h> 24 25 … … 50 51 } 51 52 52 FatApi::FatApi(VolumeInfo^ info, Stream^ stream)53 FatApi::FatApi(VolumeInfo^, Stream^ stream) 53 54 { 54 55 BootSector = new FatBootSector(); … … 96 97 } 97 98 98 std::vector<char>FatApi::GetFileContents(unsigned cluster)99 array<Byte>^ FatApi::GetFileContents(unsigned cluster) 99 100 { 100 101 if (!IsClusterAllocated(cluster)) 101 102 throw gcnew ArgumentException(L"The specified cluster is not used."); 102 103 103 std::vector<char> result;104 result.reserve(FileSize(cluster));105 array<Byte>^ buffer = gcnew array<Byte>(ClusterSizeToSize(1));104 array<Byte>^ result = gcnew array<Byte>(FileSize(cluster)); 105 const int clusterSize = ClusterSizeToSize(1); 106 int nextIndex = 0; 106 107 107 108 do 108 109 { 109 110 VolumeStream->Seek(ClusterToOffset(cluster), SeekOrigin::Begin); 110 VolumeStream->Read(buffer, 0, buffer->Length); 111 112 result.insert(result.end(), buffer->Length, 0); 113 Marshal::Copy(buffer, 0, static_cast<IntPtr>(&result.back() - buffer->Length + 1), 114 buffer->Length); 111 VolumeStream->Read(result, nextIndex, clusterSize); 112 nextIndex += clusterSize; 115 113 } 116 114 while ((cluster = GetNextCluster(cluster)) != 0xFFFFFFFF); … … 119 117 } 120 118 121 void FatApi::SetFileContents( const void* data, size_t length, unsigned cluster)119 void FatApi::SetFileContents(array<Byte>^ buffer, unsigned cluster) 122 120 { 123 121 if (!IsClusterAllocated(cluster)) 124 122 throw gcnew ArgumentException(L"The specified cluster is not used."); 125 if ( length!= FileSize(cluster))123 if (static_cast<unsigned>(buffer->Length) != FileSize(cluster)) 126 124 throw gcnew ArgumentException(L"The provided file contents will not fit in the " + 127 125 gcnew String(L"allocated file.")); 128 126 129 127 size_t clusterSize = ClusterSizeToSize(1); 130 array<Byte>^ buffer = gcnew array<Byte>(clusterSize); 131 for (size_t i = 0; i < length; i += clusterSize) 132 { 133 Marshal::Copy(static_cast<IntPtr>(reinterpret_cast<intptr_t>(static_cast<const char*>(data) + i)), 134 buffer, 0, clusterSize); 128 for (int i = 0; i < buffer->Length; i += clusterSize) 129 { 135 130 VolumeStream->Seek(ClusterToOffset(cluster), SeekOrigin::Begin); 136 VolumeStream->Write(buffer, 0, clusterSize);131 VolumeStream->Write(buffer, i, clusterSize); 137 132 cluster = GetNextCluster(cluster); 138 133 } … … 351 346 void FatDirectory::ReadDirectory() 352 347 { 353 std::vector<char>dir = Api->GetFileContents(Cluster);354 DirectorySize = dir .size()/ sizeof(::FatDirectoryEntry);348 array<Byte>^ dir = Api->GetFileContents(Cluster); 349 DirectorySize = dir->Length / sizeof(::FatDirectoryEntry); 355 350 Directory = new ::FatDirectoryEntry[DirectorySize]; 356 memcpy(Directory, &dir.front(), dir.size());351 Marshal::Copy(dir, 0, static_cast<IntPtr>(Directory), dir->Length); 357 352 358 353 ParseDirectory(); … … 361 356 void FatDirectory::WriteDirectory() 362 357 { 363 Api->SetFileContents(Directory, Api->FileSize(Cluster), Cluster); 358 array<Byte>^ buffer = gcnew array<Byte>(DirectorySize * sizeof(::FatDirectoryEntry)); 359 Marshal::Copy(static_cast<IntPtr>(Directory), buffer, 0, buffer->Length); 360 Api->SetFileContents(buffer, Cluster); 364 361 } 365 362 } -
trunk/eraser6/Eraser.Util.FileSystem/FatApi.h
r1239 r1242 22 22 #pragma once 23 23 24 #include <vector>25 24 #include "Fat.h" 26 25 … … 95 94 96 95 /// Gets the contents of the file starting at the given cluster. 97 std::vector<char>GetFileContents(unsigned cluster);96 array<Byte>^ GetFileContents(unsigned cluster); 98 97 99 98 /// Set the contents of the file starting at the given cluster. The length … … 101 100 /// 102 101 /// \param[in] buffer The data to write. 103 /// \param[in] length The amount of data to write.104 102 /// \param[in] cluster The cluster to begin writing to. 105 void SetFileContents( const void* buffer, size_t length, unsigned cluster);103 void SetFileContents(array<Byte>^ buffer, unsigned cluster); 106 104 107 105 /// Resolves a directory to the position on-disk -
trunk/eraser6/Eraser.Util.FileSystem/Stdafx.h
r1226 r1242 21 21 22 22 #pragma once 23 #include <vector> 24 23 25 #include <windows.h>
Note: See TracChangeset
for help on using the changeset viewer.
