Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDuffman85 authored and TheDuffman85 committed Jan 14, 2015
1 parent 62b5d39 commit aa76d91
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 38 deletions.
85 changes: 49 additions & 36 deletions Synology Download Station Adapter/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class Adapter

private static HttpListener _httpListener;
private static Dictionary<string, string> _fileDownloads;
private static WebRequest _checkNewReleaseRequest;
//private static WebRequest _checkNewReleaseRequest;
private static System.Timers.Timer _checkNewReleaseTimer;

#endregion

Expand Down Expand Up @@ -68,6 +69,11 @@ public static void Start()

_fileDownloads = new Dictionary<string, string>();

_checkNewReleaseTimer = new System.Timers.Timer();
_checkNewReleaseTimer.Elapsed +=_checkNewReleaseTimer_Elapsed;
_checkNewReleaseTimer.Interval = 43200000; // Every 12 hours
_checkNewReleaseTimer.Start() ;

try
{
_httpListener.Start();
Expand Down Expand Up @@ -96,6 +102,11 @@ public static void Start()

}

private static void _checkNewReleaseTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
CheckUpdateAsync();
}

/// <remarks>
/// Based on code created by bennyborn
/// https://github.com/bennyborn/ClickNLoadDecrypt/
Expand Down Expand Up @@ -623,57 +634,59 @@ public static void OpenDownloadStation()
Process.Start("http://" + Properties.Settings.Default.Address);
}
}
public static void CheckUpdate()

public static void CheckUpdateAsync()
{
try
{
_checkNewReleaseRequest = WebRequest.Create(LASTEST_RELEASE_URL);
_checkNewReleaseRequest.BeginGetResponse(new AsyncCallback(CheckNewRelease_Response), null);
}
catch
{
// Throw no error here
}
new Task(() => { CheckUpdate(); }).Start();
}

private static void CheckNewRelease_Response(IAsyncResult result)
private static void CheckUpdate()
{
WebResponse response = _checkNewReleaseRequest.EndGetResponse(result);
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(LASTEST_RELEASE_URL);
request.Referer = "http://SynologyDownloadStationAdapte.update";

if (response != null &&
WebResponse response = request.GetResponse();

if (response != null &&
response.ResponseUri.Segments != null &&
response.ResponseUri.Segments.Length > 0)
{
int gitVersion = 0;
int currentVersion = 0;
string gitVersionStr = response.ResponseUri.Segments.Last();
string currentVersionStr = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;

if (int.TryParse(gitVersionStr.Replace(".", ""), out gitVersion) &&
int.TryParse(currentVersionStr.Replace(".", ""), out currentVersion))
{
if (gitVersion > Properties.Settings.Default.CheckedVersion &&
gitVersion > currentVersion)
{
Properties.Settings.Default.CheckedVersion = gitVersion;
Properties.Settings.Default.Save();
int gitVersion = 0;
int currentVersion = 0;
string gitVersionStr = response.ResponseUri.Segments.Last();
string currentVersionStr = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;

frmSettings.Instance.BeginInvoke(new MethodInvoker(delegate
{
DialogResult mbResult = MessageBox.Show(frmSettings.Instance, "There is a new version available. Do you want to download it now?", "Synology Download Station Adapter", MessageBoxButtons.YesNo);
if (int.TryParse(gitVersionStr.Replace(".", ""), out gitVersion) &&
int.TryParse(currentVersionStr.Replace(".", ""), out currentVersion))
{
if (gitVersion > Properties.Settings.Default.CheckedVersion &&
gitVersion > currentVersion)
{
Properties.Settings.Default.CheckedVersion = gitVersion;
Properties.Settings.Default.Save();

if (mbResult == DialogResult.Yes)
frmSettings.Instance.BeginInvoke(new MethodInvoker(delegate
{
Process.Start(LASTEST_RELEASE_URL);
}
DialogResult mbResult = MessageBox.Show(frmSettings.Instance, "There is a new version available. Do you want to download it now?", "Synology Download Station Adapter", MessageBoxButtons.YesNo);

if (mbResult == DialogResult.Yes)
{
Process.Start(LASTEST_RELEASE_URL);
}

}));
}));
}
}
}
}
catch
{
// Throw no error here
}
}

#endregion
}
}
2 changes: 1 addition & 1 deletion Synology Download Station Adapter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void Main(string[] args)
Application.ApplicationExit += OnApplicationExit;

// Check for updates
Adapter.CheckUpdate();
Adapter.CheckUpdateAsync();

// Start the listener
Adapter.Start();
Expand Down
2 changes: 1 addition & 1 deletion Synology Download Station Adapter/frmDownloadStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static frmDownloadStation Instance
if (_instance == null ||
_instance.IsDisposed)
{

_instance = new frmDownloadStation();
}
}

Expand Down

0 comments on commit aa76d91

Please sign in to comment.