自動更新ができるアプリケーションを試してみました。しかし、それは機能していません。
メインの「パッチ適用済み」アプリのコード:
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");
}
}
}