public static Image CreateImage(IImageable stream, String path, ImageCallback callback) {
			ulong BLOCK_SIZE = 1024 * 1024; // Write 1MB at a time
			BinaryWriter bw = new BinaryWriter(System.IO.File.OpenWrite(path));
			ulong offset = 0;
			while (offset < stream.StreamLength) {
				ulong read = Math.Min(BLOCK_SIZE, stream.StreamLength - offset);
				bw.Write(stream.GetBytes(offset, read));
				callback(offset, stream.StreamLength);
				offset += read;
			}
			bw.Close();
			callback(stream.StreamLength, stream.StreamLength);

			Image result = new Image();
			result.Path = path;
			result.Name = System.IO.Path.GetFileNameWithoutExtension(path);
			result.Attributes = stream.GetAttributes();
			if (stream is IPhysicalDisk) {
				result.StorageType = StorageType.PhysicalDisk;
			} else if (stream is PhysicalDiskPartition) {
				result.StorageType = StorageType.PhysicalDiskPartition;
			} else {
				result.StorageType = StorageType.PhysicalDiskRange;
			}
			result.LoadFileSystem();
			return result;
		}
示例#2
0
        public static Image CreateImage(IImageable stream, String path, ImageCallback callback)
        {
            ulong        BLOCK_SIZE = 1024 * 1024;      // Write 1MB at a time
            BinaryWriter bw         = new BinaryWriter(System.IO.File.OpenWrite(path));
            ulong        offset     = 0;

            while (offset < stream.StreamLength)
            {
                ulong read = Math.Min(BLOCK_SIZE, stream.StreamLength - offset);
                bw.Write(stream.GetBytes(offset, read));
                callback(offset, stream.StreamLength);
                offset += read;
            }
            bw.Close();
            callback(stream.StreamLength, stream.StreamLength);

            Image result = new Image();

            result.Path       = path;
            result.Name       = System.IO.Path.GetFileNameWithoutExtension(path);
            result.Attributes = stream.GetAttributes();
            if (stream is IPhysicalDisk)
            {
                result.StorageType = StorageType.PhysicalDisk;
            }
            else if (stream is PhysicalDiskPartition)
            {
                result.StorageType = StorageType.PhysicalDiskPartition;
            }
            else
            {
                result.StorageType = StorageType.PhysicalDiskRange;
            }
            result.LoadFileSystem();
            return(result);
        }