using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace Attendance.Common
{
public struct TemplateDataStruct //608
{
public ushort TemplateSize;
public ushort PIN;
public byte FingerID;
public byte Valid;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 602)]
public byte[] Template;
}
public class USB_TemplateData
{
public static List<TemplateDataStruct> ReadFromUSB()
{
List<TemplateDataStruct> rtn = null;
int size = 608;
//Find usb driver
string filename = @"C:/Documents and Settings/cs44689/Desktop/u2/u2/template.dat";
//foreach (System.IO.DriveInfo di in System.IO.DriveInfo.GetDrives())
//{
// if (di.DriveType == DriveType.Removable && di.IsReady)
// {
// if (System.IO.File.Exists(di.RootDirectory.FullName + "user.dat"))
// {
// filename = di.RootDirectory.FullName + "user.dat";
// break;
// }
// }
//}
if (filename.Length > 0)
{
rtn = new List<TemplateDataStruct>();
using (FileStream fs = File.Open(filename, FileMode.Open))
{
System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
byte[] buf = new byte[fs.Length];
br.Read(buf, 0, (int)fs.Length);
for (int i = 0; i < buf.Length; i = (i + 1) * size)
{
IntPtr ptr = Marshal.AllocHGlobal(size);
Marshal.Copy(buf, i, ptr, size);
TemplateDataStruct ud = (TemplateDataStruct)Marshal.PtrToStructure(ptr, typeof(TemplateDataStruct));
rtn.Add(ud);
}
br.Close();
}
}
return rtn;
}
}
}