我试图做一个可以自动更新的应用程序。但它不起作用。
主要“已修补”应用程序的代码:
private void Patch()
{
using (WebClient client = new WebClient())
{
string name = "asd681648.txt";
client.DownloadFile("http://mypage/patches/" + "Graph" + ".txt", @"C:\" + name);
string text = File.ReadAllText(@"C:\" + name);
File.Delete(@"C:\" + name);
string[] version = text.Split('.');
string[] sVersion = set.ver.Split('.');
for (int i = 0; i < version.Length; i++)
{
if (int.Parse(version[i]) > int.Parse(sVersion[i]))
{
MessageBox.Show("New version will be downloaded!");
Process.Start(Environment.CurrentDirectory + "\\Patcher.exe", "Graph "+set.ver+" "+Environment.CurrentDirectory+"\\");
Application.Exit();
break;
}
}
}
}
以及“修补程序”的代码:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Deployment.Compression.Cab;
namespace Patcher
{
class Program
{
static void Main(string[] args)
{
WebClient client=new WebClient();
string name = "asd2341648.txt";
client.DownloadFile("http://mypage/patches/"+args[0]+".txt", @"C:\"+name);
string text = File.ReadAllText(@"C:\" + name);
File.Delete(@"C:\"+name);
string[] version = text.Split('.');
string[] sVersion = args[1].Split('.');
for (int i = 0; i < version.Length; i++)
{
if(int.Parse(version[i])>int.Parse(sVersion[i]))
{
break;
}
if(i==version.Length-1)
{
return;
}
}
Console.WriteLine("New version is avaliable. Downloading...");
client.DownloadFile("http://mypage/patches/patches/" + args[0]+".cab", @"C:\"+args[0]+".cab");
CabInfo cab=new CabInfo(@"C:\"+args[0]+".cab");
cab.Unpack(args[2]);
File.Delete( @"C:\"+args[0]+".cab");
}
}
}