128 lines
4.8 KiB
C#
128 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Publish
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void btnSelect_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnPack_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//var dir = "..\\AllBase\\BaseClass.cs";
|
|
var dir = "BaseClass.cs";
|
|
string baseClassStr = File.ReadAllText(dir);
|
|
var mainPath = baseClassStr.Substring(baseClassStr.IndexOf("MainPath = \"") + "MainPath = \"".Length);
|
|
mainPath = mainPath.Split('\"')[0];
|
|
var versionCount = baseClassStr.Substring(baseClassStr.IndexOf("VersionCount = ") + "VersionCount = ".Length);
|
|
versionCount = versionCount.Split(';')[0];
|
|
int version = Convert.ToInt32(versionCount);
|
|
|
|
List<string> filePathLst = new List<string>();
|
|
string destinationZip = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Update" + mainPath + version + ".zip";
|
|
foreach (var item in this.lstFile.Items)
|
|
{
|
|
filePathLst.Add(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + item.ToString());
|
|
}
|
|
using (ZipArchive zip = ZipFile.Open(destinationZip, ZipArchiveMode.Create))
|
|
{
|
|
foreach (string filePath in filePathLst)
|
|
{
|
|
zip.CreateEntryFromFile(filePath, Path.GetFileName(filePath), CompressionLevel.Optimal);
|
|
}
|
|
}
|
|
MessageBox.Show("打包成功!");
|
|
this.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void btnSelectOrder_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnPackOrder_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var mainPath = "";
|
|
////var dir = "..\\AllBase\\BaseClass.cs";
|
|
//var dir = "BaseClass.cs";
|
|
//string baseClassStr = File.ReadAllText(dir);
|
|
////var mainPath = baseClassStr.Substring(baseClassStr.IndexOf("MainPath = \"") + "MainPath = \"".Length);
|
|
////mainPath = mainPath.Split('\"')[0];
|
|
//var versionCount = baseClassStr.Substring(baseClassStr.IndexOf("VersionCount = ") + "VersionCount = ".Length);
|
|
//versionCount = versionCount.Split(';')[0];
|
|
//int version = Convert.ToInt32(versionCount);
|
|
|
|
var files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory);
|
|
int version = 100;
|
|
foreach (var file in files)
|
|
{
|
|
var fileName = file.Split('\\').LastOrDefault();
|
|
if (fileName.StartsWith("WxFindOrderUpdate"))
|
|
{
|
|
var versionTmp = fileName.Replace(".zip", "").Replace("WxFindOrderUpdate", "");
|
|
try
|
|
{
|
|
if (Convert.ToInt32(versionTmp) > version)
|
|
version = Convert.ToInt32(versionTmp);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
}
|
|
version += 1;
|
|
while (version.ToString().Contains("4"))
|
|
{
|
|
version++;
|
|
}
|
|
|
|
List<string> filePathLst = new List<string>();
|
|
string destinationZip = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "WxFindOrderUpdate" + mainPath + version + ".zip";
|
|
foreach (var item in this.lstOrderFile.Items)
|
|
{
|
|
filePathLst.Add(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + item.ToString());
|
|
}
|
|
using (ZipArchive zip = ZipFile.Open(destinationZip, ZipArchiveMode.Create))
|
|
{
|
|
foreach (string filePath in filePathLst)
|
|
{
|
|
zip.CreateEntryFromFile(filePath, Path.GetFileName(filePath), CompressionLevel.Optimal);
|
|
}
|
|
}
|
|
MessageBox.Show("打包成功!");
|
|
this.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|