12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- using System.Text;
- namespace ShakerFile
- {
- public class ShakerStringInfo
- {
- public string ShakerName = string.Empty;
- public string ShakerSN = string.Empty;
- public byte[] TestConfig = new byte[0];
- public string ChannelNames = string.Empty;
- public void Read(IntPtr file)
- {
- int count = 0;
- int len = 0;
- WinFile.ReadFile(file, ref Unsafe.As<int, byte>(ref len), 4, out _, 0);
- count += 4;
- if (len > 0)
- {
- byte[] temp = new byte[len];
- WinFile.ReadFile(file, ref temp[0], (uint)len, out _, 0);
- ShakerName = Encoding.Default.GetString(temp);
- }
- count += len;
- len = 0;
- WinFile.ReadFile(file, ref Unsafe.As<int, byte>(ref len), 4, out _, 0);
- count += 4;
- if (len > 0)
- {
- byte[] temp = new byte[len];
- WinFile.ReadFile(file, ref temp[0], (uint)len, out _, 0);
- ShakerSN = Encoding.Default.GetString(temp);
- }
- count += len;
- len = 0;
- WinFile.ReadFile(file, ref Unsafe.As<int, byte>(ref len), 4, out _, 0); if (len > 0)
- {
- TestConfig = new byte[len];
- WinFile.ReadFile(file, ref TestConfig[0], (uint)len, out _, 0);
- }
- count += len;
- len = 0;
- WinFile.ReadFile(file, ref Unsafe.As<int, byte>(ref len), 4, out _, 0);
- if (len > 0)
- {
- byte[] temp = new byte[len];
- WinFile.ReadFile(file, ref temp[0], (uint)len, out _, 0);
- ChannelNames = Encoding.Default.GetString(temp);
- }
- count += len;
- }
- public void Write(IntPtr file, ref int count)
- {
- List<byte[]> bytes = new List<byte[]>();
- bytes.Add(Encoding.Default.GetBytes(ShakerName));
- bytes.Add(Encoding.Default.GetBytes(ShakerSN));
- bytes.Add(TestConfig);
- bytes.Add(Encoding.Default.GetBytes(ChannelNames));
- count = 0;
- for (int i = 0; i < bytes.Count; i++)
- {
- int len = bytes[i].Length;
- WinFile.WriteFile(file, ref Unsafe.As<int, byte>(ref len), 4, out _, 0);
- count += 4;
- if (len > 0)
- {
- WinFile.WriteFile(file, ref bytes[i][0], (uint)len, out _, 0);
- }
- count += len;
- }
- }
- }
- }
|