3 Commits

  1. 8
      Apewer.Windows/WinForm/MenuItem.cs
  2. 5
      Apewer/BytesUtility.cs
  3. 9
      Apewer/StorageUtility.cs

8
Apewer.Windows/WinForm/MenuItem.cs

@ -37,6 +37,14 @@ namespace Apewer.WinForm
Action = action; Action = action;
} }
/// <summary>创建可点击的文本菜单项。</summary>
public MenuItem(string text, Action<MenuItem> action, object data)
{
Text = text;
Action = action;
Data = data;
}
} }
} }

5
Apewer/BytesUtility.cs

@ -165,7 +165,7 @@ namespace Apewer
#region Text #region Text
/// <summary>将字节数组转换为十六进制文本。</summary>
/// <summary>将字节数组转换为十六进制文本(小写)。</summary>
public static string ToHex(this byte[] bytes) public static string ToHex(this byte[] bytes)
{ {
int length = bytes.Length; int length = bytes.Length;
@ -185,6 +185,9 @@ namespace Apewer
/// <summary>将十六进制文本转换为字节数组。</summary> /// <summary>将十六进制文本转换为字节数组。</summary>
public static byte[] FromHex(this string hex) public static byte[] FromHex(this string hex)
{ {
if (string.IsNullOrEmpty(hex)) return Empty;
hex = hex.Replace(" ", "").Replace("-", "");
if (string.IsNullOrEmpty(hex) || hex.Length < 2) return Empty; if (string.IsNullOrEmpty(hex) || hex.Length < 2) return Empty;
if (hex.Length % 2 != 0) return Empty; if (hex.Length % 2 != 0) return Empty;

9
Apewer/StorageUtility.cs

@ -437,6 +437,9 @@ namespace Apewer
{ {
try try
{ {
var dir = Path.GetDirectoryName(path);
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
File.WriteAllBytes(path, TextUtility.Bom); File.WriteAllBytes(path, TextUtility.Bom);
return true; return true;
} }
@ -451,6 +454,9 @@ namespace Apewer
var success = false; var success = false;
try try
{ {
var dir = Path.GetDirectoryName(path);
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
var write1 = BytesUtility.Write(file, TextUtility.Bom); var write1 = BytesUtility.Write(file, TextUtility.Bom);
if (write1 == TextUtility.Bom.Length) if (write1 == TextUtility.Bom.Length)
{ {
@ -474,6 +480,9 @@ namespace Apewer
{ {
try try
{ {
var dir = Path.GetDirectoryName(path);
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
File.WriteAllBytes(path, bytes); File.WriteAllBytes(path, bytes);
return true; return true;
} }

Loading…
Cancel
Save