ITC81DB_2H/ITC81DB_0H/Controls/CenterEquipment/ControlCenterEquipUpdate.cs

513 lines
22 KiB
C#
Raw Normal View History

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.IO;
using System.Text;
using System.Windows.Forms;
using SmartX;
using ITC81DB_0H.Forms;
using ITC81DB_0H.DialogForms;
using ITC81DB_0H_ImageDll;
namespace ITC81DB_0H.Controls
{
public partial class ControlCenterEquipUpdate : UserControl
{
#region Field
private FormMenu m_ParentForm;
private DataStore.Step3 UpdateStep;
private int Check;
private string USBPath = "";
private string UpdateFilePath = "";
private string OldFilePath = "";
private string RemoveFolderPath = "";
private List<string> DllName = new List<string>();
private List<long> LongOldDllFileLastWriteTime = new List<long>();
private List<long> LongNewDllFileLastWriteTime = new List<long>();
#endregion
#region Constructor
public ControlCenterEquipUpdate(FormMenu parent)
{
InitializeComponent();
this.ParentForm = parent;
this.InitializeDesign();
this.DefaultSetting();
}
#endregion
#region Property
public FormMenu ParentForm
{
get { return this.m_ParentForm; }
private set { this.m_ParentForm = value; }
}
#endregion
#region Method
public void InitializeDesign()
{
Class1 images = new Class1();
if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.English)
{
}
else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
{
}
else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Czech)
{
}
else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
{
}
else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
{
}
else
{
}
}
private void DefaultSetting()
{
this.UpdateStep = DataStore.Step3.Step1;
this.UpdateLabelStatus(this.UpdateStep, this.ParentForm.ParentForm.SystemConfig1.Language);
}
private DataStore.UpdateCheck CheckError()
{
DataStore.UpdateCheck ret = DataStore.UpdateCheck.Fail;
FileInfo[] newFiles;
if (Directory.Exists("Hard Disk\\") == true)
this.USBPath = "Hard Disk\\";
else if (Directory.Exists("하드 디스크\\") == true)
this.USBPath = "하드 디스크\\";
else
this.USBPath = "하드 디스크\\";
this.UpdateFilePath = this.USBPath + "UpdateFiles\\";
DirectoryInfo info = new DirectoryInfo(this.USBPath);
DirectoryInfo directoryFolderUpdateFiles = new DirectoryInfo(this.UpdateFilePath);
// USB 장착 유무 확인
if (info.Exists == true)
{
// USB에 UpdateFiles 유무 확인
if (directoryFolderUpdateFiles.Exists == true)
{
newFiles = directoryFolderUpdateFiles.GetFiles();
if (newFiles.Length == 0)
{
ret = DataStore.UpdateCheck.NotFile;
}
else
{
ret = DataStore.UpdateCheck.Success;
}
}
else
{
ret = DataStore.UpdateCheck.NotUpdateFolder;
}
}
else
{
ret = DataStore.UpdateCheck.NotUsbMomery;
}
return ret;
}
2020-09-22 01:11:23 +00:00
private void CheckErrorMainBoard(DialogResult result)
{
FileInfo[] newFiles;
2020-09-22 01:11:23 +00:00
bool isUpdateFile = false;
string fileName = "";
2020-09-22 01:11:23 +00:00
if (result == DialogResult.Yes)
{
if (Directory.Exists("Hard Disk\\") == true)
this.USBPath = "Hard Disk\\";
else if (Directory.Exists("하드 디스크\\") == true)
this.USBPath = "하드 디스크\\";
else
this.USBPath = "하드 디스크\\";
2020-09-22 01:11:23 +00:00
this.UpdateFilePath = this.USBPath + "UpdateFilesMain\\";
DirectoryInfo info = new DirectoryInfo(this.USBPath);
DirectoryInfo directoryFolderUpdateFiles = new DirectoryInfo(this.UpdateFilePath);
// USB 장착 유무 확인
if (info.Exists == true)
{
// USB에 UpdateFiles 유무 확인
if (directoryFolderUpdateFiles.Exists == true)
{
newFiles = directoryFolderUpdateFiles.GetFiles();
foreach (FileInfo file in newFiles)
{
fileName = file.Name.ToLower();
if (fileName == "itc81db_0h_main.int")
{
isUpdateFile = true;
this.UpdateFilePath += "itc81db_0h_main.int";
break;
}
}
if (newFiles.Length == 0 || isUpdateFile == false)
{
// USB에 업데이트 파일이 없습니다
DialogFormMessage message = new DialogFormMessage(7, this.ParentForm.ParentForm.SystemConfig1.Language);
message.ShowDialog();
return;
}
else
{
long a = 0;
byte[] byteData, version;
string sVersion = "";
FileStream fs = new FileStream(this.UpdateFilePath, FileMode.Open, FileAccess.Read);
version = new byte[8];
BinaryReader br = new BinaryReader(fs);
a = br.BaseStream.Length;
int i = int.Parse(a.ToString());
byteData = br.ReadBytes(i);
version[0] = byteData[20];
version[1] = byteData[21];
version[2] = byteData[22];
version[3] = byteData[23];
version[4] = byteData[24];
version[5] = byteData[25];
version[6] = byteData[26];
version[7] = byteData[27];
sVersion = Encoding.UTF8.GetString(version, 0, version.Length);
DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 3, this.ParentForm.ParentForm.SystemConfig1.MainBoardVersion, sVersion);
if (myDlg.ShowDialog() == DialogResult.Yes)
{
this.UpdateMainBoard();
}
else
return;
}
}
else
{
// USB에 업데이트 폴더가 없습니다
DialogFormMessage message = new DialogFormMessage(9, this.ParentForm.ParentForm.SystemConfig1.Language);
message.ShowDialog();
return;
}
}
else
{
// USB메모리가 장착되지 않았습니다
DialogFormMessage message = new DialogFormMessage(5, this.ParentForm.ParentForm.SystemConfig1.Language);
message.ShowDialog();
return;
}
}
}
2020-09-22 01:11:23 +00:00
private void ProgramUpdate()
{
FileInfo[] newFiles;
DirectoryInfo directoryFolderUpdateFiles = new DirectoryInfo(this.UpdateFilePath);
newFiles = directoryFolderUpdateFiles.GetFiles();
this.progressBarUpdate.Value += 20;
this.TreatmentRemoveOldFile();
2020-09-22 01:11:23 +00:00
this.progressBarUpdate.Value += 30;
this.TreatmentCopyNewFile(newFiles);
this.progressBarUpdate.Value += 100;
2020-09-22 01:11:23 +00:00
this.ParentForm.Enabled = false;
2020-09-22 01:11:23 +00:00
this.UpdateStep = DataStore.Step3.Step3;
this.UpdateLabelStatus(this.UpdateStep, this.ParentForm.ParentForm.SystemConfig1.Language);
}
private void TreatmentRemoveOldFile()
{
bool removeFolderCheck = false;
FileInfo[] oldFiles;
2020-09-22 01:11:23 +00:00
this.OldFilePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\";
if (this.OldFilePath.StartsWith("\\F") == true)
this.RemoveFolderPath = "Flash Disk\\RemoveFile\\";
else
this.RemoveFolderPath = "SD Card\\RemoveFile\\";
DirectoryInfo directoryFolderRun = new DirectoryInfo(this.OldFilePath);
DirectoryInfo directoryFolderRemove = new DirectoryInfo(this.RemoveFolderPath);
removeFolderCheck = directoryFolderRemove.Exists;
oldFiles = directoryFolderRun.GetFiles();
if (removeFolderCheck == false)
directoryFolderRemove.Create();
foreach (FileInfo subFile in oldFiles)
subFile.MoveTo(RemoveFolderPath + DateTime.Now.ToString("yyyyMMddHHmmss") + subFile.Name.ToString());
this.progressBarUpdate.Value += 20;
}
private void TreatmentCopyNewFile(FileInfo[] newFile)
{
// 새 파일 복사
foreach (FileInfo subFile in newFile)
subFile.CopyTo(this.OldFilePath + subFile.Name.ToString());
this.progressBarUpdate.Value += 20;
}
2020-09-22 01:11:23 +00:00
private void UpdateMainBoard()
{
long a = 0;
int count = 0, byteCount = 0;
FileStream fs = new FileStream(this.UpdateFilePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
a = br.BaseStream.Length;
byteCount = int.Parse(a.ToString());
this.ParentForm.ParentForm.UpdateForMain.ByteData = br.ReadBytes(byteCount);
count = byteCount / 100;
this.ParentForm.ParentForm.UpdateForMain.SendDataCount = count;
this.timerForMainBoard.Enabled = true;
}
public void SetProgressBarValue(int value)
{
this.progressBarUpdate.Value += value;
}
public void UpdateMainBoardFail()
{
this.labelMessage1.Text = "Update Fail!";
this.labelMessage2.Text = "Please Check your MainBoard";
}
private void UpdateLabelStatus(DataStore.Step3 step, DataStore.LanguageID language)
{
switch (step)
{
case DataStore.Step3.Step1:
#region Step1
switch (language)
{
case DataStore.LanguageID.Korean:
this.labelMessage1.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage1.Text = "USB를 본체에 삽입 하십시오";
this.labelMessage2.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage2.Text = "삽입 후 하단 'Update'버튼을 눌러주십시오";
break;
case DataStore.LanguageID.English:
this.labelMessage1.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage1.Text = "Please insert usb into the device";
this.labelMessage2.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage2.Text = "Press the bottom button after inserting";
break;
case DataStore.LanguageID.Chinese:
this.labelMessage1.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage1.Text = "请点击下端的按钮更新按钮";
this.labelMessage2.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage2.Text = "";
break;
case DataStore.LanguageID.German:
this.labelMessage1.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage1.Text = "USB nicht vom Gerät trennen";
this.labelMessage2.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage2.Text = "Drücken Sie nach dem USB-Anschluss die untere Taste";
break;
case DataStore.LanguageID.Russian:
this.labelMessage1.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage1.Text = "Пожалуйста, вставьте USB в устройство";
this.labelMessage2.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage2.Text = "Нажмите нижнюю кнопку после вставки";
break;
default:
break;
}
#endregion
break;
case DataStore.Step3.Step2:
#region Step2
switch (language)
{
case DataStore.LanguageID.Korean:
this.labelMessage1.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage1.Text = "업데이트 중...";
this.labelMessage2.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage2.Text = "USB를 본체에서 분리하지 마십시오";
break;
case DataStore.LanguageID.English:
this.labelMessage1.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage1.Text = "Updating...";
this.labelMessage2.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage2.Text = "Do not remove the USB from the device";
break;
case DataStore.LanguageID.Chinese:
this.labelMessage1.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage1.Text = "更新中...";
this.labelMessage2.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage2.Text = "请勿断开USB";
break;
case DataStore.LanguageID.German:
this.labelMessage1.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage1.Text = "Aktualisierung….";
this.labelMessage2.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage2.Text = "USB nicht vom Gerät trennen";
break;
case DataStore.LanguageID.Russian:
this.labelMessage1.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage1.Text = "Обновление...";
this.labelMessage2.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage2.Text = "Не отключайте USB";
break;
default:
break;
}
#endregion
break;
case DataStore.Step3.Step3:
#region Step3
this.labelMessage2.ForeColor = Color.Red;
switch (language)
{
case DataStore.LanguageID.Korean:
this.labelMessage1.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage1.Text = "프로그램 업데이트 완료";
this.labelMessage2.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage2.Text = "전원을 끄고 다시 켜주세요";
break;
case DataStore.LanguageID.English:
this.labelMessage1.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage1.Text = "Program update complete";
this.labelMessage2.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage2.Text = "Reset the system";
break;
case DataStore.LanguageID.Chinese:
this.labelMessage1.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage1.Text = "系统更新完成";
this.labelMessage2.Font = new Font("새굴림", 17, FontStyle.Regular);
this.labelMessage2.Text = "关掉电源,然后在打开电源";
break;
case DataStore.LanguageID.German:
this.labelMessage1.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage1.Text = "Programmaktualisierung abgeschlossen";
this.labelMessage2.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage2.Text = "Mit dem Hauptschalter aus- und einschalten";
break;
case DataStore.LanguageID.Russian:
this.labelMessage1.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage1.Text = "Обновление программы завершено";
this.labelMessage2.Font = new Font("새굴림", 12, FontStyle.Regular);
this.labelMessage2.Text = "Выключите питание и затем включите питание";
break;
default:
break;
}
#endregion
break;
default:
break;
}
this.Refresh();
}
private void ProgramUpdateCheck(DialogResult result)
{
DataStore.UpdateCheck check = DataStore.UpdateCheck.Fail;
if (result == DialogResult.Yes)
{
check = this.CheckError();
if (check == DataStore.UpdateCheck.Success)
{
2020-09-22 01:11:23 +00:00
this.buttonMainBoard.Enabled = false;
this.ButtonLCD.Enabled = false;
this.UpdateStep = DataStore.Step3.Step2;
this.UpdateLabelStatus(this.UpdateStep, this.ParentForm.ParentForm.SystemConfig1.Language);
this.ProgramUpdate();
}
else if (check == DataStore.UpdateCheck.NotUsbMomery)
{
DialogFormMessage message = new DialogFormMessage(5, this.ParentForm.ParentForm.SystemConfig1.Language);
message.ShowDialog();
}
else if (check == DataStore.UpdateCheck.NotUpdateFolder)
{
DialogFormMessage message = new DialogFormMessage(9, this.ParentForm.ParentForm.SystemConfig1.Language);
message.ShowDialog();
}
else if (check == DataStore.UpdateCheck.NotFile)
{
DialogFormMessage message = new DialogFormMessage(7, this.ParentForm.ParentForm.SystemConfig1.Language);
message.ShowDialog();
}
}
}
public void DisplayRefresh(SystemStatus status)
{
this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = DataStore.DisplayStore.EquipUpdate;
this.ParentForm.ParentForm.SetDisplayMode(DataStore.DisplayMode.Menu);
this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);
this.DefaultSetting();
}
#endregion
#region Event Handler
2020-09-22 01:11:23 +00:00
private void buttonMainBoard_Click(object sender, EventArgs e)
{
DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 3);
DialogResult dr = myDlg.ShowDialog();
myDlg.Close();
this.Refresh();
this.CheckErrorMainBoard(dr);
}
private void ButtonLCD_Click(object sender, EventArgs e)
{
DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 3);
DialogResult dr = myDlg.ShowDialog();
myDlg.Close();
this.Refresh();
this.ProgramUpdateCheck(dr);
}
2020-09-22 01:11:23 +00:00
private void timerForMainBoard_Tick(object sender, EventArgs e)
{
this.timerForMainBoard.Enabled = false;
this.ParentForm.ParentForm.SendUpdateForMain(this.ParentForm.ParentForm.UpdateForMain.ByteData);
}
#endregion
}
}