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

Commit

Permalink
- Removed SingletonForm because of trouble with the form designer
Browse files Browse the repository at this point in the history
- Added a version check
  • Loading branch information
TheDuffman85 authored and TheDuffman85 committed Jan 14, 2015
1 parent 9968a0f commit 62b5d39
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 131 deletions.
54 changes: 54 additions & 0 deletions Synology Download Station Adapter/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
Expand All @@ -29,13 +30,16 @@ public class Adapter
private const string REG_KEY_NAME = "SynologyDownloadStationAdapter";
public static readonly string[] FILE_TYPES_ALL = new string[] { ".dlc", ".ccf", ".rsdf", ".torrent", ".nzb" };
public static readonly string[] FILE_TYPES_NO_DECRYPT = new string[] { ".torrent", ".nzb" };

private const string LASTEST_RELEASE_URL = "https://github.com/TheDuffman85/SynologyDownloadStationAdapter/releases/latest";

#endregion

#region Variables

private static HttpListener _httpListener;
private static Dictionary<string, string> _fileDownloads;
private static WebRequest _checkNewReleaseRequest;

#endregion

Expand Down Expand Up @@ -619,6 +623,56 @@ public static void OpenDownloadStation()
Process.Start("http://" + Properties.Settings.Default.Address);
}
}

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

private static void CheckNewRelease_Response(IAsyncResult result)
{
WebResponse response = _checkNewReleaseRequest.EndGetResponse(result);

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();

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 (mbResult == DialogResult.Yes)
{
Process.Start(LASTEST_RELEASE_URL);
}

}));
}
}
}
}

#endregion
}
Expand Down
5 changes: 4 additions & 1 deletion Synology Download Station Adapter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ static void Main(string[] args)
Application.SetCompatibleTextRenderingDefault(false);
Application.ApplicationExit += OnApplicationExit;

// Check for updates
Adapter.CheckUpdate();

// Start the listener
Adapter.Start();

Application.Run(frmSettings.Instance);
}
// An instance is allready running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.2.0.3")]
[assembly: AssemblyFileVersion("1.2.0.4")]
12 changes: 12 additions & 0 deletions Synology Download Station Adapter/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@
<Setting Name="SizeY" Type="System.Int32" Scope="User">
<Value Profile="(Default)">700</Value>
</Setting>
<Setting Name="CheckedVersion" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>
74 changes: 0 additions & 74 deletions Synology Download Station Adapter/SingletonForm.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@
<Compile Include="Adapter.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SingletonForm.cs">
<SubType>Form</SubType>
</Compile>
<EmbeddedResource Include="frmAddLinks.resx">
<DependentUpon>frmAddLinks.cs</DependentUpon>
</EmbeddedResource>
Expand Down
3 changes: 3 additions & 0 deletions Synology Download Station Adapter/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<setting name="SizeY" serializeAs="String">
<value>700</value>
</setting>
<setting name="CheckedVersion" serializeAs="String">
<value>0</value>
</setting>
</TheDuffman85.SynologyDownloadStationAdapter.Properties.Settings>
<SynologyDownloadStationAdapterUi.Properties.Settings>
<setting name="Address" serializeAs="String">
Expand Down
70 changes: 56 additions & 14 deletions Synology Download Station Adapter/frmAddLinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,74 @@

namespace TheDuffman85.SynologyDownloadStationAdapter
{
public partial class frmAddLinks : SingletonForm<frmAddLinks>
public partial class frmAddLinks : Form
{
#region Variable

private static object _lock = new object();
private static frmAddLinks _instance;
private bool _loading = true;

#endregion

#region Properties

/// <summary>
/// Lazy instance
/// </summary>
public static frmAddLinks Instance
{
get
{
lock (_lock)
{
if (_instance == null ||
_instance.IsDisposed)
{
_instance = new frmAddLinks();
}
}

return _instance;
}
}

#endregion

#region Constructor

public frmAddLinks()
private frmAddLinks()
{
InitializeComponent();
}

#endregion

#region Statiic Methods

public static void ShowInstance()
{
Instance.Show();
Instance.Activate();
}

#endregion

#region Methods

private void CheckClipboard()
{
if (Properties.Settings.Default.CheckClipboard)
{
if (Clipboard.ContainsText())
{
txtLinks.Text = Clipboard.GetText();
}
}
}

#endregion

#region Eventhandler

private void frmAddLinks_Load(object sender, EventArgs e)
Expand Down Expand Up @@ -72,19 +123,10 @@ private void cbClipboard_CheckedChanged(object sender, EventArgs e)

#endregion

#region Methods

private void CheckClipboard()
{
if (Properties.Settings.Default.CheckClipboard)
{
if (Clipboard.ContainsText())
{
txtLinks.Text = Clipboard.GetText();
}
}
}

#endregion

}


}
Loading

0 comments on commit 62b5d39

Please sign in to comment.