|
@@ -4,10 +4,8 @@ using System.Drawing;
|
|
|
using System.Drawing.Imaging;
|
|
|
using System.IO;
|
|
|
using System.IO.Ports;
|
|
|
-using System.Linq;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Forms;
|
|
|
-using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
namespace FaceChange
|
|
@@ -17,24 +15,24 @@ namespace FaceChange
|
|
|
/// </summary>
|
|
|
public partial class SettingsWindow : Window
|
|
|
{
|
|
|
- AppContext appContext = AppContext.GetAppContext();
|
|
|
- SerialTool serialTool = SerialTool.GetSerialTool();
|
|
|
+ readonly AppContext _appContext = AppContext.GetAppContext();
|
|
|
+ readonly SerialTool _serialTool = SerialTool.GetSerialTool();
|
|
|
|
|
|
- private List<FaceInfo> faces;
|
|
|
+ private List<FaceInfo> _faces;
|
|
|
|
|
|
public SettingsWindow()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
|
|
|
- faces = appContext.FaceInfos;
|
|
|
+ _faces = _appContext.FaceInfos;
|
|
|
}
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (appContext.PortOpen)
|
|
|
+ if (_appContext.PortOpen)
|
|
|
{
|
|
|
Devices.Items.Clear();
|
|
|
- Devices.Items.Add(appContext.SerialPort.PortName);
|
|
|
+ Devices.Items.Add(_appContext.SerialPort.PortName);
|
|
|
Devices.SelectedIndex = 0;
|
|
|
Devices.IsEnabled = false;
|
|
|
Connect.Content = "断开连接";
|
|
@@ -45,31 +43,9 @@ namespace FaceChange
|
|
|
Connect.Content = "连接设备";
|
|
|
Scan_Click(null, null);
|
|
|
}
|
|
|
- // 读取配置
|
|
|
- var prop = Properties.Settings.Default.Faces;
|
|
|
- if (prop != null && !prop.Trim().Equals(""))
|
|
|
+ foreach (var face in _faces)
|
|
|
{
|
|
|
- var faceStringList = prop.Split('|').ToList();
|
|
|
- foreach (var faceString in faceStringList)
|
|
|
- {
|
|
|
- var fileName = faceString.Substring(
|
|
|
- faceString.LastIndexOf(@"\", StringComparison.Ordinal) + 1);
|
|
|
- try
|
|
|
- {
|
|
|
- faces.Add(new FaceInfo(
|
|
|
- new BitmapImage(new Uri(faceString)),
|
|
|
- fileName,
|
|
|
- faceString.Replace(fileName, @"")));
|
|
|
- }
|
|
|
- catch (Exception exception)
|
|
|
- {
|
|
|
- Console.WriteLine(exception);
|
|
|
- }
|
|
|
- }
|
|
|
- foreach (var face in faces)
|
|
|
- {
|
|
|
- ListBox.Items.Add(face);
|
|
|
- }
|
|
|
+ ListBox.Items.Add(face);
|
|
|
}
|
|
|
FaceCount.Content = ListBox.Items.Count.ToString();
|
|
|
}
|
|
@@ -77,7 +53,7 @@ namespace FaceChange
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
|
{
|
|
|
var list = new List<string>();
|
|
|
- foreach (var face in faces)
|
|
|
+ foreach (var face in _faces)
|
|
|
{
|
|
|
list.Add(face.Path + face.Name);
|
|
|
}
|
|
@@ -106,7 +82,7 @@ namespace FaceChange
|
|
|
{
|
|
|
// 清除当前串口号中的所有串口名称
|
|
|
Devices.Items.Clear();
|
|
|
- var portList = serialTool.FindPort();
|
|
|
+ var portList = _serialTool.FindPort();
|
|
|
if (portList.Count == 0)
|
|
|
{
|
|
|
System.Windows.Forms.MessageBox.Show("没有找到可用设备!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
@@ -124,16 +100,16 @@ namespace FaceChange
|
|
|
|
|
|
private void Connect_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (appContext.PortOpen)
|
|
|
+ if (_appContext.PortOpen)
|
|
|
{
|
|
|
// 关闭串口
|
|
|
- if (serialTool.ClosePort(appContext.SerialPort))
|
|
|
+ if (_serialTool.ClosePort(_appContext.SerialPort))
|
|
|
{
|
|
|
Devices.IsEnabled = true;
|
|
|
Scan.IsEnabled = true;
|
|
|
Scan_Click(null, null);
|
|
|
Connect.Content = "连接设备";
|
|
|
- appContext.SerialPort = null;
|
|
|
+ _appContext.SerialPort = null;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -150,7 +126,7 @@ namespace FaceChange
|
|
|
return;
|
|
|
}
|
|
|
// 打开串口
|
|
|
- SerialPort serialPort = serialTool.OpenPort(portName, "9600", "8", "1", "无", appContext.DataReceived);
|
|
|
+ SerialPort serialPort = _serialTool.OpenPort(portName, "9600", "8", "1", "无", _appContext.DataReceived);
|
|
|
if (serialPort == null)
|
|
|
{
|
|
|
// 打开串口失败
|
|
@@ -161,7 +137,7 @@ namespace FaceChange
|
|
|
Devices.IsEnabled = false;
|
|
|
Scan.IsEnabled = false;
|
|
|
Connect.Content = "断开连接";
|
|
|
- appContext.SerialPort = serialPort;
|
|
|
+ _appContext.SerialPort = serialPort;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -174,7 +150,7 @@ namespace FaceChange
|
|
|
System.Windows.Forms.MessageBox.Show("请先选一项!", "提示", MessageBoxButtons.OK);
|
|
|
return;
|
|
|
}
|
|
|
- faces.RemoveAt(index);
|
|
|
+ _faces.RemoveAt(index);
|
|
|
ListBox.Items.RemoveAt(index);
|
|
|
FaceCount.Content = ListBox.Items.Count.ToString();
|
|
|
}
|
|
@@ -184,7 +160,7 @@ namespace FaceChange
|
|
|
var messageBoxButtons = MessageBoxButtons.OKCancel;
|
|
|
var dr = System.Windows.Forms.MessageBox.Show("将清空列表,确定吗?", "提示", messageBoxButtons, MessageBoxIcon.Warning);
|
|
|
if (dr != System.Windows.Forms.DialogResult.OK) return;
|
|
|
- faces.Clear();
|
|
|
+ _faces.Clear();
|
|
|
ListBox.Items.Clear();
|
|
|
FaceCount.Content = ListBox.Items.Count.ToString();
|
|
|
}
|
|
@@ -210,7 +186,7 @@ namespace FaceChange
|
|
|
fileName,
|
|
|
strFileName.Replace(fileName, @""));
|
|
|
ListBox.Items.Add(faceInfo);
|
|
|
- faces.Add(faceInfo);
|
|
|
+ _faces.Add(faceInfo);
|
|
|
}
|
|
|
FaceCount.Content = ListBox.Items.Count.ToString();
|
|
|
}
|