SuperDesign/Source/开发辅助工具/Manager/FTP/FrmDownProg.cs

152 lines
6.7 KiB
C#
Raw Normal View History

using DiffPlex.Model;
using GameBackup3H3.DbOp;
using ryCommon;
using SuperDesign.Manager.FTP;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace .Manager.FTP
{
public partial class FrmDownProg : Form
{
public FrmDownProg()
{
InitializeComponent();
}
public List<UploadInfo> DownList { get; set; } = new List<UploadInfo>();
private void FrmDownProg_FormClosing(object sender, FormClosingEventArgs e)
{
if(e.CloseReason== CloseReason.UserClosing) { e.Cancel = true; }
}
private void FrmDownProg_Shown(object sender, EventArgs e)
{
ProgAll.Maximum = DownList.Count;
Thread th = new Thread(Start);
th.Start();
void Start()
{
var error = 0;
for (int i = 0; i < DownList.Count; i++)
{
var item = DownList[i];
FTPop.FTPWinSCP ftp = (FTPop.FTPWinSCP)FTPManger.GetFTP(item.FtpInfo, out var result);
FTPManger.FileTransferProgress += Ftp_FileTransferProgress;
this.Invoke(new Action(() =>
{
ProgAll.Value = i;
label1.Text = "正在登录FTP...";
}));
if (result == 1)
{
this.Invoke(new Action(() =>
{
label1.Text = "正在下载文件...";
}));
if (!ftp.FileExists(item.RemotePath))
{
error++;
this.Invoke(new Action(() =>
{
MessageBox.Show("远程文件不存在=>" + item.RemotePath, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}));
continue;
}
else
{
if (item.LocalPath.Length > 0)
{
var remote_fileinfo = ftp.GetFileInfo(item.RemotePath);
if (remote_fileinfo.LastWriteTime != DateTime.MinValue)
{
bool goto_next = false;
if (remote_fileinfo.LastWriteTime.ToInt64() < RyFiles.GetFileDate(item.LocalPath).LastWriteTime.ToInt64())
{
this.Invoke(new Action(() =>
{
switch (MessageBox.Show("当前本地文件的修改日期比远程服务器新,是否要替换?\r\n\r\n" + item.LocalPath, "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
{
case DialogResult.No:
error++;
goto_next = true;
break;
}
}));
}
else if (RyFiles.GetFileDate(item.LocalPath).LastWriteTime.ToInt64() == remote_fileinfo.LastWriteTime.ToInt64())
{
if (RyFiles.GetFileSize(item.LocalPath) != remote_fileinfo.Length)
{
this.Invoke(new Action(() =>
{
switch (MessageBox.Show("当前本地文件与服务器文件日期一致,但大小不一致,是否要替换?\r\n\r\n本地:" + RyFiles.GetFileSizeStr(item.LocalPath) + "=>服务器:" + RyFiles.GetFileSizeStr(remote_fileinfo.Length), "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
{
case DialogResult.No:
error++;
goto_next = true;
break;
}
}));
}
}
if (goto_next) { continue; }
}
}
}
if (ftp.Download(item.RemotePath, item.LocalPath) == 1)
{
}
else
{
this.Invoke(new Action(() =>
{
MessageBox.Show("下载失败=>" + item.RemotePath + "\r\n" + ftp.ErrorMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
error++;
}));
}
}
else
{
this.Invoke(new Action(() =>
{
MessageBox.Show("FTP登录失败=>"+item.LocalPath, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
error++;
}));
}
FTPManger.FileTransferProgress -= Ftp_FileTransferProgress;
}
this.Invoke(new Action(() =>
{
ProgAll.Value = ProgAll.Maximum;
if (error == 0)
{
DialogResult = DialogResult.OK;
}
else
{
DialogResult = DialogResult.No;
}
}));
}
}
private void Ftp_FileTransferProgress(object sender, FTPop.FileTransferProgressEventArgs e)
{
this.Invoke(new Action(() =>
{
progressBar1.Value = (e.FileProgress*100).ToInt();
}));
}
}
}