232 lines
7.7 KiB
C#
232 lines
7.7 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 INT69DB_2A.DialogForms;
|
|
using INT69DB_2A_ImageDll;
|
|
|
|
namespace INT69DB_2A.Forms
|
|
{
|
|
public partial class FormProgramUpdate : Form
|
|
{
|
|
#region Field
|
|
private FormMain m_ParentForm;
|
|
|
|
private int Check;
|
|
|
|
private string PathUSB = "";
|
|
private string PathUpdateFile = "";
|
|
private string PathRunFolder = "";
|
|
|
|
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;
|
|
|
|
this.InitializeDesign();
|
|
}
|
|
#endregion
|
|
|
|
#region Property
|
|
public FormMain ParentForm
|
|
{
|
|
get { return this.m_ParentForm; }
|
|
private set { this.m_ParentForm = value; }
|
|
}
|
|
#endregion
|
|
|
|
#region Method
|
|
private void InitializeDesign()
|
|
{
|
|
ImageDll images = new ImageDll();
|
|
|
|
if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Korean)
|
|
{
|
|
|
|
}
|
|
else if (this.ParentForm.SystemConfig.Language == DataStore.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.LanguageID.Chinese)
|
|
{
|
|
this.labelTitle.Text = "更新";
|
|
|
|
this.labelUpdateWait.Text = "请稍等...";
|
|
this.labelUpdateWait2.Text = "请勿断开USB";
|
|
this.labelUpdateRestart.Text = "关掉电源,然后在打开电源";
|
|
}
|
|
else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
private void CheckError()
|
|
{
|
|
FileInfo[] newFiles;
|
|
|
|
if (Directory.Exists("Hard Disk\\") == true)
|
|
this.PathUSB = "Hard Disk\\";
|
|
else if (Directory.Exists("하드 디스크\\") == true)
|
|
this.PathUSB = "하드 디스크\\";
|
|
else
|
|
this.PathUSB = "하드 디스크\\";
|
|
|
|
this.PathUpdateFile = this.PathUSB + "UpdateFiles\\";
|
|
|
|
DirectoryInfo info = new DirectoryInfo(this.PathUSB);
|
|
DirectoryInfo directoryFolderUpdateFiles = new DirectoryInfo(this.PathUpdateFile);
|
|
|
|
// 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.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.PathUpdateFile);
|
|
newFiles = directoryFolderUpdateFiles.GetFiles();
|
|
|
|
this.progressBarUpdateBar.Value += 20;
|
|
|
|
this.TreatmentRemoveOldFile();
|
|
this.TreatmentCopyNewFile(newFiles);
|
|
|
|
this.progressBarUpdateBar.Value += 100;
|
|
}
|
|
private void TreatmentRemoveOldFile()
|
|
{
|
|
bool removeFolderCheck = false;
|
|
FileInfo[] oldFiles, removeOldFiles;
|
|
DirectoryInfo directoryFolderRun = new DirectoryInfo(this.PathRunFolder);
|
|
DirectoryInfo directoryFolderRemove = new DirectoryInfo(this.ParentForm.PathRemoveFileFolder);
|
|
|
|
removeFolderCheck = directoryFolderRemove.Exists;
|
|
oldFiles = directoryFolderRun.GetFiles();
|
|
|
|
if (removeFolderCheck == false)
|
|
directoryFolderRemove.Create();
|
|
else
|
|
{
|
|
removeOldFiles = directoryFolderRemove.GetFiles();
|
|
|
|
if (removeOldFiles.Length >= 100)
|
|
{
|
|
foreach (FileInfo subFile in removeOldFiles)
|
|
subFile.Delete();
|
|
}
|
|
}
|
|
|
|
foreach (FileInfo subFile in oldFiles)
|
|
subFile.MoveTo(this.ParentForm.PathRemoveFileFolder + DateTime.Now.ToString("yyyyMMddHHmmss") + subFile.Name.ToString());
|
|
|
|
this.progressBarUpdateBar.Value += 20;
|
|
}
|
|
private void TreatmentCopyNewFile(FileInfo[] newFile)
|
|
{
|
|
// 새 파일 복사
|
|
foreach (FileInfo subFile in newFile)
|
|
subFile.CopyTo(this.PathRunFolder + subFile.Name.ToString());
|
|
|
|
this.progressBarUpdateBar.Value += 20;
|
|
}
|
|
|
|
public void DisplayRefresh()
|
|
{
|
|
this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormProgramUpdate;
|
|
this.CheckError();
|
|
}
|
|
#endregion
|
|
|
|
#region Override Member
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
|
|
DirectoryInfo directoryFolderUpdateFiles = new DirectoryInfo(this.PathUpdateFile);
|
|
if (directoryFolderUpdateFiles.Exists == false)
|
|
directoryFolderUpdateFiles.Create();
|
|
|
|
this.Check = 0;
|
|
this.PathUpdateFile = this.PathUSB + "UpdateFiles\\";
|
|
this.PathRunFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\";
|
|
|
|
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
|
|
}
|
|
} |