You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.3 KiB
C#
105 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Services;
|
|
using SevenZip;
|
|
using System.Configuration;
|
|
using System.Threading;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Diagnostics;
|
|
|
|
/// <summary>
|
|
///WebService 的摘要说明
|
|
/// </summary>
|
|
[WebService(Namespace = "http://tempuri.org/")]
|
|
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
|
|
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
|
|
// [System.Web.Script.Services.ScriptService]
|
|
public class WebService : System.Web.Services.WebService {
|
|
|
|
private static readonly string filePath = ConfigurationManager.AppSettings["Path"];
|
|
private static readonly string fileNm = ConfigurationManager.AppSettings["FileNm"];
|
|
private string zipFile = "update.zip";
|
|
private bool IsCompressionFinished = false;
|
|
public WebService () {
|
|
|
|
//如果使用设计的组件,请取消注释以下行
|
|
//InitializeComponent();
|
|
}
|
|
|
|
|
|
[WebMethod( Description="压缩文件")]
|
|
public string ZipFile()
|
|
{
|
|
|
|
string path = Server.MapPath("~");
|
|
if (IntPtr.Size == 4)
|
|
{
|
|
SevenZipCompressor.SetLibraryPath(path + "\\7z.dll");
|
|
}
|
|
else
|
|
{
|
|
SevenZipCompressor.SetLibraryPath(path + "\\7z64.dll");
|
|
}
|
|
//SevenZipCompressor.SetLibraryPath(path + "\\7z.dll");
|
|
zipFile=Guid.NewGuid().ToString()+".zip";
|
|
SevenZipCompressor Compressor = new SevenZipCompressor();
|
|
Compressor.CompressionFinished += new EventHandler<EventArgs>(cmp_CompressionFinished);
|
|
Compressor.ArchiveFormat = OutArchiveFormat.Zip;
|
|
Compressor.CompressionLevel = CompressionLevel.Normal;
|
|
Compressor.CompressDirectory(filePath, path + "\\" + zipFile);
|
|
for(int i=0;i<100000;i++)
|
|
{
|
|
if (IsCompressionFinished)
|
|
{
|
|
break;
|
|
}
|
|
|
|
Thread.Sleep(100);
|
|
|
|
}
|
|
|
|
string URL = GetRootPath() + "/" + zipFile;
|
|
return URL;
|
|
}
|
|
[WebMethod(Description = "删除已下载文件")]
|
|
public void deleteFile(string url)
|
|
{
|
|
string[] spliter={"/"};
|
|
url = url.Split(spliter, StringSplitOptions.RemoveEmptyEntries).Last();
|
|
string filePath = Server.MapPath(url);
|
|
File.Delete(filePath);
|
|
}
|
|
|
|
[WebMethod(Description = "获取文件版本号")]
|
|
public string getFileVersion()
|
|
{
|
|
FileVersionInfo VersionInfo = FileVersionInfo.GetVersionInfo(filePath + "\\" + fileNm);
|
|
|
|
return VersionInfo.FileVersion;
|
|
}
|
|
private void cmp_CompressionFinished(object sender, EventArgs e)
|
|
{
|
|
IsCompressionFinished = true;
|
|
}
|
|
public string GetRootPath()
|
|
{
|
|
|
|
|
|
string absolutePath = HttpContext.Current.Request.Url.AbsoluteUri;
|
|
string hostNameAndPort = HttpContext.Current.Request.Url.Authority;
|
|
string applicationDir = HttpContext.Current.Request.ApplicationPath;
|
|
StringBuilder sbRequestUrl = new StringBuilder();
|
|
sbRequestUrl.Append(absolutePath.Substring(0, absolutePath.IndexOf(hostNameAndPort)));
|
|
sbRequestUrl.Append(hostNameAndPort);
|
|
if (applicationDir != "/")
|
|
{
|
|
sbRequestUrl.Append(applicationDir);
|
|
}
|
|
return sbRequestUrl.ToString();
|
|
|
|
}
|
|
}
|