INT89DB_26/INT89DB_26/Forms/FormProgramUpdate.cs

231 lines
7.5 KiB
C#

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using INT89DB_26.DialogForms;
using INT89DB_26_ImageDll;
namespace INT89DB_26.Forms
{
public partial class FormProgramUpdate : Form
{
#region Field
private FormMain m_ParentForm;
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 FormProgramUpdate(FormMain parent)
{
InitializeComponent();
this.ParentForm = parent;
}
#endregion
#region Property
public FormMain ParentForm
{
get { return this.m_ParentForm; }
private set { this.m_ParentForm = value; }
}
#endregion
#region Method
private void InitializeDesign()
{
Class1 images = new Class1();
if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Korean)
{
}
else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.English)
{
this.labelTitle.Text = "Update";
this.labelUpdateWait.Text = "Wait a minute...";
this.labelUpdateWait2.Text = "Do not disconnect the USB from the body";
this.labelUpdateRestart.Text = "Turn OFF the power and then turn ON the power";
}
else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
{
this.labelTitle.Text = "更新";
this.labelUpdateWait.Text = "请稍等...";
this.labelUpdateWait2.Text = "请勿断开USB";
this.labelUpdateRestart.Text = "关掉电源,然后在打开电源";
}
else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
{
}
else
{
}
}
public void DisplayRefresh()
{
this.CheckError();
}
public void CheckError()
{
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)
{
// USB에 업데이트 파일이 없습니다
DialogFormMessage message = new DialogFormMessage(7, this.ParentForm.SystemConfig.Language, "");
message.ShowDialog();
return;
}
else
{
((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormProgramUpdate);
}
}
else
{
// USB에 업데이트 폴더가 없습니다
DialogFormMessage message = new DialogFormMessage(9, this.ParentForm.SystemConfig.Language, "");
message.ShowDialog();
return;
}
}
else
{
// USB메모리가 장착되지 않았습니다
DialogFormMessage message = new DialogFormMessage(5, this.ParentForm.SystemConfig.Language, "");
message.ShowDialog();
return;
}
}
private void ProgramUpdate()
{
FileInfo[] newFiles;
DirectoryInfo directoryFolderUpdateFiles = new DirectoryInfo(this.UpdateFilePath);
newFiles = directoryFolderUpdateFiles.GetFiles();
this.progressBarUpdateBar.Value += 20;
this.TreatmentRemoveOldFile();
this.TreatmentCopyNewFile(newFiles);
this.progressBarUpdateBar.Value += 100;
}
private void TreatmentRemoveOldFile()
{
bool removeFolderCheck = false;
FileInfo[] oldFiles;
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.progressBarUpdateBar.Value += 20;
}
private void TreatmentCopyNewFile(FileInfo[] newFile)
{
// 새 파일 복사
foreach (FileInfo subFile in newFile)
subFile.CopyTo(this.OldFilePath + subFile.Name.ToString());
this.progressBarUpdateBar.Value += 20;
}
#endregion
#region Override Member
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.InitializeDesign();
DirectoryInfo directoryFolderUpdateFiles = new DirectoryInfo(this.UpdateFilePath);
if (directoryFolderUpdateFiles.Exists == false)
directoryFolderUpdateFiles.Create();
this.Check = 0;
this.UpdateFilePath = this.USBPath + "UpdateFiles\\";
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\\";
this.timerUpdate.Interval = 1000;
this.timerUpdate.Tick += new EventHandler(timerUpdate_Tick);
this.timerUpdate.Enabled = true;
}
#endregion
#region Event Handler
private void timerUpdate_Tick(object sender, EventArgs e)
{
this.Check += 1;
if (this.Check == 3)
{
this.ParentForm.ChildFormProgramUpdate.ProgramUpdate();
}
if (this.progressBarUpdateBar.Value == 100)
{
this.labelUpdateWait.Visible = false;
this.labelUpdateWait2.Visible = false;
this.labelUpdateRestart.Visible = true;
}
}
#endregion
}
}