File size: 2,952 Bytes
e26fba6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
using System;
using System.Collections.Generic;
using System.Text;
using Ionic.Zip;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Linq;
namespace MovieTube.Setup.Updater
{
class Program
{
private static List<string> Files = new List<string>
{
"MovieTube.exe",
"MovieTube.Client.Scraper.dll",
"MovieTube.UpService.exe",
"AxInterop.WMPLib.dll",
"Interop.WMPLib.dll",
"pref.db",
"MovieTube.exe.config"
};
private static string ZipFileName = "MovieTube.zip";
private static string ZipDestinationPath;
static void Main(string[] args)
{
try
{
ZipDestinationPath = Path.Combine(Application.StartupPath, "..\\..\\..\\MovieFinder.Web\\App_Data\\MovieTube.zip");
var configPath = Path.Combine(Application.StartupPath, "..\\..\\..\\MovieFinder.Web\\Web.config");
Version version;
if (!IsVersionChanged(out version))
return;
if (File.Exists(ZipFileName))
File.Delete(ZipFileName);
using (var zip = new ZipFile())
{
foreach (var f in Files)
zip.AddFile(f, "");
zip.Save(ZipFileName);
File.Copy(ZipFileName, ZipDestinationPath, true);
}
var doc = XDocument.Load(configPath);
var elem = doc.Root.Descendants("add").Where(x => (string)x.Attribute("key") == "AppVersion").Single().Attribute("value");
elem.Value = version.ToString();
doc.Save(configPath);
MessageBox.Show("New version updated");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private static bool IsVersionChanged(out Version newVersion)
{
var version = AssemblyName.GetAssemblyName(Path.Combine(Application.StartupPath, Files[0])).Version;
newVersion = version;
if (!File.Exists(ZipDestinationPath))
return true;
var temp = Path.Combine(Application.StartupPath, "Temp");
if (Directory.Exists(temp))
Directory.Delete(temp, true);
Directory.CreateDirectory(temp);
using (ZipFile zip1 = ZipFile.Read(ZipDestinationPath))
{
zip1.ExtractAll(temp, ExtractExistingFileAction.OverwriteSilently);
}
var fPath = Path.Combine(temp, Files[0]);
version = AssemblyName.GetAssemblyName(fPath).Version;
return version != newVersion;
}
}
}
|