Skip to content

Commit

Permalink
#26: Removed not working code from Updatemanager
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Jun 14, 2017
1 parent 0b723e9 commit 5532073
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 337 deletions.
1 change: 0 additions & 1 deletion Source/Terminals.External/Terminals.External.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
<Compile Include="Unified\Encryption\Encryptor.cs" />
<Compile Include="Unified\Encryption\EncryptTransformer.cs" />
<Compile Include="Unified\Encryption\Hash.cs" />
<Compile Include="Unified\Network\HTTP.cs" />
<Compile Include="Unified\Network\NTPClient.cs" />
<Compile Include="Unified\RSS\Collections\ExceptionCollection.cs" />
<Compile Include="Unified\RSS\Collections\RssCategoryCollection.cs" />
Expand Down
179 changes: 0 additions & 179 deletions Source/Terminals.External/Unified/Network/HTTP.cs

This file was deleted.

158 changes: 1 addition & 157 deletions Source/Terminals/Updates/UpdateManager.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
using System;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib.Zip;
using Terminals.Configuration;
using Unified;
using Unified.Network.HTTP;
using Unified.Rss;

namespace Terminals.Updates
Expand Down Expand Up @@ -37,7 +29,7 @@ private static ReleaseInfo PerformCheck(bool automaticallyUpdate)
bool autoUpdate = automaticallyUpdate; // obtain from command line arguments
if (autoUpdate)
{
DownloadLatestRelease();
// DownloadLatestRelease();
}

return downLoaded;
Expand Down Expand Up @@ -112,153 +104,5 @@ private static bool IsNewerThanCurrent(RssItem item, DateTime buildDate)
DateTime.TryParse(titleDate, out releaseDate);
return releaseDate > buildDate;
}

private static void DownloadLatestRelease()
{
try
{
String url = Settings.Instance.UpdateSource;
string contents = DownloadAsString(url);

if (!String.IsNullOrEmpty(contents))
{
TerminalsUpdates updates = (TerminalsUpdates)Serialize.DeSerializeXML(contents, typeof (TerminalsUpdates));
if (updates != null)
{
String currentMd5 = GetMd5HashFromFile("Terminals.exe");
if (currentMd5 != null)
{
//get the latest build
System.Data.DataRow row = updates.Tables[0].Rows[0];
String md5 = (row["MD5"] as string);
if (!md5.Equals(currentMd5))
{
String version = (row["version"] as String);
if (!Directory.Exists("Builds"))
Directory.CreateDirectory("Builds");

String finalFolder = @"Builds\" + version;
if (!Directory.Exists(finalFolder))
Directory.CreateDirectory(finalFolder);

String filename = String.Format("{0}.zip", version);
filename = @"Builds\" + filename;
Boolean downloaded = true;

if (!File.Exists(filename))
{
string targetUrl = row["Url"] as String;
downloaded = SaveHttpToFile(targetUrl, filename);
}

if (downloaded && File.Exists(filename))
{
//ICSharpCode.SharpZipLib.Zip.FastZipEvents evts = new ICSharpCode.SharpZipLib.Zip.FastZipEvents();
FastZip fz = new FastZip();
fz.ExtractZip(filename, finalFolder, null);

if (MessageBox.Show("A new build is available, would you like to install it now", "New Build", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
DirectoryInfo parent = FindFileInFolder(new DirectoryInfo(finalFolder), "Terminals.exe");
if (parent == null)
return;

finalFolder = parent.FullName;

File.Copy(FileLocations.CONFIG_FILENAME, Path.Combine(finalFolder, FileLocations.CONFIG_FILENAME), true);
File.Copy("Terminals.log4net.config", Path.Combine(finalFolder, "Terminals.log4net.config"), true);

String temp = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
String updaterExe = Path.Combine(temp, "TerminalsUpdater.exe");
if (File.Exists(Path.Combine(finalFolder, "TerminalsUpdater.exe")))
File.Copy(Path.Combine(finalFolder, "TerminalsUpdater.exe"), updaterExe, true);

//updaterExe = @"C:\Source\Terminals\Terminals\bin\Debug\";

if (File.Exists(updaterExe))
{
//String args = "\"" + finalFolder + "\" \"" + Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\"";
String args = String.Format("\"{0}\" \"{1}\"", finalFolder, Program.Info.Location);
System.Diagnostics.Process.Start(updaterExe, args);
Application.Exit();
}
}
}
}
}
}
}
}
catch (Exception exc)
{
Logging.Error("Failed during update.", exc);
}
}

private static bool SaveHttpToFile(string targetUrl, string filename)
{
Tuple<string, int> proxy = ResolveProxy();
return Web.SaveHTTPToFile(targetUrl, null, string.Empty, string.Empty, string.Empty,
filename, proxy.Item1, proxy.Item2, false);
}

private static string DownloadAsString(string url)
{
Tuple<string, int> proxy = ResolveProxy();
return Web.HTTPAsString(url, null, string.Empty, string.Empty,
string.Empty, proxy.Item1, proxy.Item2, false);
}

private static Tuple<string, int> ResolveProxy()
{
var settings = Settings.Instance;

if (settings.UseProxy)
return new Tuple<string, int>(settings.ProxyAddress, settings.ProxyPort);

return new Tuple<string, int>(string.Empty, 0);
}

private static DirectoryInfo FindFileInFolder(DirectoryInfo path, String filename)
{
if (path.GetFiles(filename).Length > 0)
return path;

foreach (DirectoryInfo dir in path.GetDirectories())
{
DirectoryInfo found = FindFileInFolder(dir, filename);
if (found != null)
return found;
}

return null;
}

private static string GetMd5HashFromFile(string fileName)
{
String tmpFile = fileName + ".tmp";
File.Copy(fileName, tmpFile, true);
Byte[] retVal = null;

using (FileStream file = new FileStream(tmpFile, FileMode.Open))
{
MD5 md5 = new MD5CryptoServiceProvider();
retVal = md5.ComputeHash(file);
file.Close();
}

if (retVal != null)
{
StringBuilder s = new StringBuilder();
foreach (Byte b in retVal)
{
s.Append(b.ToString("x2").ToLower());
}

return s.ToString();
}

return null;
}
}
}

0 comments on commit 5532073

Please sign in to comment.