From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点
---
WPFProject/Utils/BinUtil.cs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/WPFProject/Utils/BinUtil.cs b/WPFProject/Utils/BinUtil.cs
new file mode 100644
index 0000000..264d59c
--- /dev/null
+++ b/WPFProject/Utils/BinUtil.cs
@@ -0,0 +1,58 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WPFProject.Utils
+{
+ public class BinUtil
+ {
+ /// <summary>
+ /// 鎶婂瓧绗︿覆浠ヤ簩杩涘埗瀛樺叆bin鏂囦欢涓�
+ /// </summary>
+ /// <param name="content">瀛楃鍐呭</param>
+ /// <param name="filePath">瀛樻斁璺緞</param>
+ public static void SaveStrToBin(string content, string filePath = null)
+ {
+ if (string.IsNullOrEmpty(filePath))
+ {
+ filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().FullName), "bin");
+ }
+ byte[] bytes = Convert.FromBase64String(content);
+ using (Stream stream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
+ using (BinaryWriter writer = new BinaryWriter(stream))
+ {
+ writer.Write(bytes);
+ }
+ }
+
+ /// <summary>
+ /// 浠巄in涓姞杞藉瓧绗︿覆
+ /// </summary>
+ /// <param name="content">瀛楃涓插唴瀹�</param>
+ /// <param name="filePath">bin鏂囦欢璺緞</param>
+ /// <returns>璇诲彇鏄惁鎴愬姛</returns>
+ public static bool LoadStrFromBin(ref string content, string filePath = null)
+ {
+ if (string.IsNullOrEmpty(filePath))
+ {
+ filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().FullName), "bin");
+ }
+ if (!File.Exists(filePath))
+ {
+ return false;
+ }
+ using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
+ using (BinaryReader reader = new BinaryReader(stream))
+ {
+ byte[] bytes = new byte[stream.Length];
+ reader.Read(bytes, 0, bytes.Length);
+ content = Convert.ToBase64String(bytes);
+ return true;
+ }
+ }
+ }
+}
--
Gitblit v1.9.1