You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BirdyFlash.Lib {
|
|
public class DeviceE2PContents {
|
|
public DeviceInfo deviceInfo;
|
|
public List<byte> data;
|
|
public DeviceE2PContents() {
|
|
|
|
}
|
|
public bool writeAsFile(E2PFileFormat fileFormat, string filePath) {
|
|
if (fileFormat == E2PFileFormat.Binary) {
|
|
System.IO.File.WriteAllBytes(filePath, this.data.ToArray());
|
|
return true;
|
|
}
|
|
if (fileFormat == E2PFileFormat.HEXText) {
|
|
string hexText = string.Join("\n",
|
|
BitConverter.ToString(this.data.ToArray()).Replace('-',' ').Split(3*32)
|
|
);
|
|
System.IO.File.WriteAllBytes(filePath, Encoding.ASCII.GetBytes(hexText));
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public static string getFileExtension(DeviceInfo deviceInfo) {
|
|
return deviceInfo.model[0].ToString().ToLower() + deviceInfo.model.ToString().Substring(1) + ".rev2";
|
|
}
|
|
|
|
public void readFromFile(E2PFileFormat fileFormat, string filePath) {
|
|
if (fileFormat == E2PFileFormat.Binary) {
|
|
this.data = new List<byte>(System.IO.File.ReadAllBytes(filePath));
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
public enum E2PFileFormat {
|
|
TPLOriginal = 0,
|
|
Binary = 1,
|
|
HEXText = 2
|
|
}
|
|
}
|