SuperDesign/Source/开发辅助工具/Manager/FTP/FrmUploadUpdateZipToFtp.cs
zilinsoft 30afab3ce9 ## 2025-04-24 星期四更新
### SuperDesign    V3.0.2504.2401
#### 项目功能->更新日志
- *.[新增]支持将更新日志直接更新到FTP上。
#### 网页抓取工具
- *.[修复]修复API编辑器在某些情况下因为时间戳识别错误导致报错的BUG。
2025-04-24 16:27:01 +08:00

132 lines
4.9 KiB
C#

using ExtendUI.FTPManager;
using FTPop;
using ryCommon;
using ryCommonDb;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SuperDesign.Manager.FTP
{
public partial class FrmUploadUpdateZipToFtp : Form
{
public FrmUploadUpdateZipToFtp()
{
InitializeComponent();
}
/// <summary>
/// 更新日志模式
/// </summary>
public bool UpdateLogMode { get; set; } = false;
/// <summary>
/// 更新日志
/// </summary>
public string UpdateHtml { get; set; } = "";
public string LocalPath { get; set; } = "";
public string EngName { get; set; } = "";
public int FTPId { get; set; } = 0;
public string RemoteDir { get; set; } = "";
private void BtnUploadZSB_Click(object sender, EventArgs e)
{
if (UpdateLogMode)
{
Upload(EngName + ".html_bak");
}
else
{
Upload(EngName + ".zip");
}
}
private void Upload(string filename)
{
BtnUploadZSB.Enabled = false;
BtnUploadBeta.Enabled = false;
new Thread(Start).Start();
void Start()
{
var isUpload_ok = 0;
FTPUI ftp_ui = new FTPUI(new SQLiteDataProvider(), Application.StartupPath + "\\UserDb\\Ftp.dat");
var ftp_info = ftp_ui.GetFTPInfo(FTPId);
IFTP ftp = new FTPWinSCP();
ftp.FileTransferProgress += Session_FileTransferProgress;
var opened = ftp.Open(ftp_info);
if (opened == 1)
{
if(UpdateLogMode)
{
var local_mod_file = System.IO.Path.GetDirectoryName(LocalPath) + "\\_mod.html";
var fileinfo = ftp.GetFileInfo(RemoteDir + "/_mod.html");
if(fileinfo!=null)
{
var local_dt = RyFiles.GetFileDate(local_mod_file);
if(fileinfo.LastWriteTime>local_dt.LastWriteTime)
{
if(ftp.Download(RemoteDir + "/_mod.html", local_mod_file)==1)
{
}
}
}
if(System.IO.File.Exists(local_mod_file))
{
var html= System.IO.File.ReadAllText(local_mod_file).Replace("<%content%>",UpdateHtml);
var local_html_file = System.IO.Path.GetDirectoryName(LocalPath) + "\\"+EngName+".html";
RyFiles.WriteAllText(local_html_file, html);
if (ftp.Upload(local_html_file, RemoteDir + "/" + EngName + ".html") != 1)
{
MessageBox.Show("本地目录:" + local_html_file + "\r\n远程目录:" + RemoteDir + "/" + EngName + ".html" + "\r\n" + ftp.LastError, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
if(ftp.Upload(LocalPath, RemoteDir + "/" + filename)!=1)
{
MessageBox.Show("本地目录:"+ LocalPath + "\r\n远程目录:"+ RemoteDir + "/" + filename+"\r\n"+ftp.LastError,"出错",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else { isUpload_ok = 1; }
}
else
{
MessageBox.Show("连接FTP出错=>" + ftp.LastError, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
ftp.Close();
this.Invoke(new Action(() =>
{
BtnUploadZSB.Enabled = true;
BtnUploadBeta.Enabled = true;
if(isUpload_ok==1)
{
DialogResult = DialogResult.OK;
}
}));
}
}
private void Session_FileTransferProgress(object sender, FTPop.FileTransferProgressEventArgs e)
{
this.Invoke(new Action(() =>
{
progressBar1.Value = (e.FileProgress*100).ToInt(0, 100, 100);
}));
}
private void BtnUploadBeta_Click(object sender, EventArgs e)
{
if (UpdateLogMode)
{
Upload(EngName + "_beta.html_bak");
}
else
{
Upload(EngName + "_beta.zip");
}
}
}
}