------ #### SuperDesign V3.0.2412.2001 - *.[新增]新增程序更新日志设置和自动发布功能。 - *.[修复]修复Post数据格式不正确时双击文本框会导致软件闪退的BUG。
207 lines
8.8 KiB
C#
207 lines
8.8 KiB
C#
using DiffPlex.Model;
|
|
using FTPop;
|
|
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;
|
|
using 开发辅助工具.Tools.SmartEditor;
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
namespace 开发辅助工具.Manager.FTP
|
|
{
|
|
public partial class FrmDownProg : Form
|
|
{
|
|
public FrmDownProg()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public List<UploadInfo> DownList { get; set; } = new List<UploadInfo>();
|
|
private bool IsExit = false;
|
|
private void FrmDownProg_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if(e.CloseReason== CloseReason.UserClosing && progressBar1.Value!=100)
|
|
{ IsExit = true; e.Cancel = true; }
|
|
}
|
|
private Dictionary<int, IFTP> dict_ftp = new Dictionary<int, IFTP>();
|
|
public IFTP GetFTP(FTPInfo ftpinfo, out int result, out string err_msg)
|
|
{
|
|
var ftpid = ftpinfo.Id;
|
|
err_msg = "";
|
|
if (dict_ftp.ContainsKey(ftpid))
|
|
{
|
|
var ftp = dict_ftp[ftpid];
|
|
if (ftp.IsOpen)
|
|
{
|
|
result = 1;
|
|
return ftp;
|
|
}
|
|
else
|
|
{
|
|
ftp.Close();
|
|
var ftp2 = new FTPop.FTPWinSCP();
|
|
ftp2.FileTransferProgress += Ftp_FileTransferProgress;
|
|
result = ftp2.Open(ftpinfo);
|
|
err_msg = ftp2.ErrorMsg;
|
|
dict_ftp[ftpid] = ftp2;
|
|
return ftp2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var ftp = new FTPop.FTPWinSCP();
|
|
ftp.FileTransferProgress += Ftp_FileTransferProgress;
|
|
result = ftp.Open(ftpinfo);
|
|
err_msg = ftp.ErrorMsg;
|
|
dict_ftp[ftpid] = ftp;
|
|
return ftp;
|
|
}
|
|
}
|
|
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];
|
|
if (IsExit) { break; }
|
|
FTPop.FTPWinSCP ftp = (FTPop.FTPWinSCP)GetFTP(item.FtpInfo, out var result, out var err_msg);
|
|
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 && RyFiles.FileOrDirExist(item.LocalPath))
|
|
{
|
|
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)
|
|
{
|
|
this.Invoke(new Action(() => {
|
|
FrmMainEditor.MainEditor.UpdateFileState(item.LocalPath);
|
|
}));
|
|
}
|
|
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+"\r\n"+ err_msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
error++;
|
|
}));
|
|
}
|
|
}
|
|
foreach (var item in dict_ftp)
|
|
{
|
|
item.Value.FileTransferProgress -= Ftp_FileTransferProgress;
|
|
item.Value.Close();
|
|
}
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
ProgAll.Value = ProgAll.Maximum;
|
|
if (error == 0 && !IsExit)
|
|
{
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
else
|
|
{
|
|
DialogResult = DialogResult.No;
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
|
|
private void Ftp_FileTransferProgress(object sender, FTPop.FileTransferProgressEventArgs e)
|
|
{
|
|
if (IsExit)
|
|
{
|
|
e.Cancel = IsExit;
|
|
}
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
progressBar1.Value = (e.FileProgress*100).ToInt();
|
|
}));
|
|
}
|
|
|
|
private void FrmDownProg_Load(object sender, EventArgs e)
|
|
{
|
|
if (Itrycn_Db.WinSCP_IsRunning())
|
|
{
|
|
MessageBox.Show("检测到外部FTP相关软件正在运行,可能运行不稳定。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|