### RySmartEditor V1.0.2501.2701 - *.[改进]FTP上传时限制300毫秒内只能刷新一次UI进度。 ### SuperDesign V3.0.2501.2701 - *.[新增]新增支持在线升级功能。 #### 项目功能->项目管理 - *.[新增]FTP上传文件列表和打包文件列表支持在软件里直接编辑。 - *.[改进]更新dll版本将比对版本号,只更新版本号更新或者更新日期更新的dll。 #### 项目功能->更新日志 - *.[新增]新增支持自动记录过的分组信息,然后可以进行选择快速插入。 - *.[新增]记录使用过的项目信息到总数据库,以方便总览。 - *.[改进]右键插入日志时直接对富文本框进行编辑,而不是替换内容,从而具备撤销功能。 - *.[改进]改进MD日志输出的样式设计。 - *.[修复]修复《确认日志覆盖》窗口里的按钮,随着窗口大小变化,按钮会错乱的BUG。 - *.[修复]修复双击日志列表显示日志时,针对本周的时间显示不正确的BUG。 - *.[修复]修复右键新增日志时,如果没有分组,插入的行可能不正确的BUG。 - *.[修复]修复设为开发日志后,鼠标指针变到文本开头的问题。 #### 网页抓取工具 - *.[新增]新增多个常用UA。 - *.[新增]切换Url时如果存在Cookie和Header时,则提示是否清空。 - *.[新增]保存记录时新增支持保存UA。 - *.[新增]Url列表支持图标展示。
284 lines
13 KiB
C#
284 lines
13 KiB
C#
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 FrmUploadProg : Form
|
|
{
|
|
public FrmUploadProg()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public List<UploadInfo> UploadList { get; set; } = new List<UploadInfo>();
|
|
private bool IsExit = false;
|
|
private void FrmTranProg_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 errormsg)
|
|
{
|
|
errormsg = "";
|
|
var ftpid = ftpinfo.Id;
|
|
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);
|
|
errormsg = ftp2.ErrorMsg;
|
|
dict_ftp[ftpid] = ftp2;
|
|
return ftp2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var ftp = new FTPop.FTPWinSCP();
|
|
ftp.FileTransferProgress += Ftp_FileTransferProgress;
|
|
result = ftp.Open(ftpinfo);
|
|
dict_ftp[ftpid] = ftp;
|
|
errormsg = ftp.ErrorMsg;
|
|
return ftp;
|
|
}
|
|
}
|
|
private void FrmTranProg_Shown(object sender, EventArgs e)
|
|
{
|
|
ProgAll.Maximum = UploadList.Count;
|
|
Thread th = new Thread(Start);
|
|
th.Start();
|
|
void Start()
|
|
{
|
|
var error = 0;
|
|
try
|
|
{
|
|
for (int i = 0; i < UploadList.Count; i++)
|
|
{
|
|
if (IsExit) { break; }
|
|
var item = UploadList[i];
|
|
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 = "正在上传文件...";
|
|
}));
|
|
var remotedir = System.IO.Path.GetDirectoryName(item.RemotePath).Replace("\\", "/");
|
|
if (!ftp.FileExists(remotedir))
|
|
{
|
|
ftp.CreateDir(remotedir);
|
|
}
|
|
else
|
|
{
|
|
if (item.LocalPath.Length > 0)
|
|
{
|
|
var remote_fileinfo = ftp.GetFileInfo(item.RemotePath);
|
|
ryCommon.sType.FileTime local_dt = null;
|
|
try
|
|
{
|
|
local_dt = RyFiles.GetFileDate(item.LocalPath);
|
|
}
|
|
catch
|
|
{
|
|
local_dt = new ryCommon.sType.FileTime();
|
|
MessageBox.Show("获取文件时间出错=>" + item.LocalPath, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
if (remote_fileinfo.LastWriteTime != DateTime.MinValue)
|
|
{
|
|
bool goto_next = false;
|
|
if (remote_fileinfo.LastWriteTime.ToInt64() > local_dt.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 (local_dt.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; }
|
|
}
|
|
}
|
|
}
|
|
var LocalPath = item.LocalPath;
|
|
var tmp_path = "";
|
|
if (LocalPath.Length == 0)
|
|
{
|
|
tmp_path = Application.StartupPath + "\\UserDb\\tmp\\FTP\\" + System.IO.Path.GetFileName(item.RemotePath);
|
|
RyFiles.WriteAllText(tmp_path, item.Content, item.Encoding);
|
|
LocalPath = tmp_path;
|
|
}
|
|
if (ftp.Upload(LocalPath, item.RemotePath) == 1)
|
|
{
|
|
ryCommon.sType.FileTime local_dt2 = null;
|
|
try
|
|
{
|
|
local_dt2 = RyFiles.GetFileDate(LocalPath);
|
|
}
|
|
catch
|
|
{
|
|
local_dt2 = new ryCommon.sType.FileTime();
|
|
MessageBox.Show("获取文件时间出错2=>" + item.LocalPath, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
item.IsSuccess = true;
|
|
item.FileWriteTime = local_dt2.LastWriteTime;
|
|
item.FileSize = RyFiles.GetFileSize(LocalPath);
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
FrmMainEditor.MainEditor.UpdateFTPFileState(item.FtpInfo.Id,
|
|
item.RemotePath,
|
|
local_dt2.LastWriteTime,
|
|
item.FileSize);
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
MessageBox.Show("上传失败=>" + (item.LocalPath.Length > 0 ? item.LocalPath : item.RemotePath) + "\r\n" + ftp.ErrorMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
error++;
|
|
}));
|
|
if (ftp.ErrorMsg.IndexOfEx("already read to the end") >= 0)
|
|
{
|
|
ftp.Close();
|
|
//ftp= (FTPop.FTPWinSCP)FTPManger.GetFTP(item.FtpInfo, out var _);
|
|
}
|
|
}
|
|
if (tmp_path.Length > 0)
|
|
RyFiles.DeleteFile(tmp_path);
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
catch(Exception ex) {
|
|
MessageBox.Show(ex.Message, "发生错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
ProgAll.Value = ProgAll.Maximum;
|
|
if (error == 0 && !IsExit)
|
|
{
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
else
|
|
{
|
|
DialogResult = DialogResult.No;
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
private DateTime dt_last = DateTime.MinValue;
|
|
private void Ftp_FileTransferProgress(object sender, FTPop.FileTransferProgressEventArgs e)
|
|
{
|
|
if (IsExit) { e.Cancel = true; }
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
try
|
|
{
|
|
if(dt_last<DateTime.Now.AddMilliseconds(-300))
|
|
{
|
|
dt_last = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
progressBar1.Value = (e.FileProgress * 100).ToInt();
|
|
}
|
|
catch { }
|
|
}));
|
|
}
|
|
|
|
private void FrmUploadProg_Load(object sender, EventArgs e)
|
|
{
|
|
if (Itrycn_Db.WinSCP_IsRunning())
|
|
{
|
|
MessageBox.Show("检测到外部FTP相关软件正在运行,可能运行不稳定。", "上传警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
public class UploadInfo
|
|
{
|
|
public FTPInfo FtpInfo { get; set; } = new FTPInfo();
|
|
public string RemotePath { get; set; } = "";
|
|
public string LocalPath { get; set; } = "";
|
|
/// <summary>
|
|
/// 当LocalPath为空时生效
|
|
/// </summary>
|
|
public string Content { get; set; } = "";
|
|
/// <summary>
|
|
/// 当LocalPath为空时生效
|
|
/// </summary>
|
|
public Encoding Encoding { get; set; } = Encoding.UTF8;
|
|
/// <summary>
|
|
/// 是否上传下载成功
|
|
/// </summary>
|
|
public bool IsSuccess { get; set; } = false;
|
|
/// <summary>
|
|
/// 上传成功后获取文件最后修改时间
|
|
/// </summary>
|
|
public DateTime FileWriteTime { get; set; } = DateTime.MinValue;
|
|
/// <summary>
|
|
/// 上传成功后返回文件大小
|
|
/// </summary>
|
|
public long FileSize { get; set; } = 0;
|
|
}
|
|
}
|