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

Commit

Permalink
Version 1.4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDuffman85 committed Apr 12, 2015
1 parent d373996 commit 7836a7b
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 48 deletions.
28 changes: 23 additions & 5 deletions Synology Download Station Adapter/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,15 @@ public static bool AddLinksToDownloadStation(DecrypterBase decrypter)
public static bool AddLinksToDownloadStation(List<string> links)
{
DownloadStation ds = null;

try
{
ds = new DownloadStation(new Uri("http://" + Properties.Settings.Default.Address), Properties.Settings.Default.Username, Encoding.UTF8.GetString(Convert.FromBase64String(Properties.Settings.Default.Password)));
UriBuilder uriBuilder = new UriBuilder(Properties.Settings.Default.Address)
{
Scheme = Uri.UriSchemeHttp
};

ds = new DownloadStation(uriBuilder.Uri, Properties.Settings.Default.Username, Encoding.UTF8.GetString(Convert.FromBase64String(Properties.Settings.Default.Password)));

// Login to Download Station
if (ds.Login())
Expand Down Expand Up @@ -622,7 +627,12 @@ public static bool AddFileToDownloadStation(string path)

try
{
ds = new DownloadStation(new Uri("http://" + Properties.Settings.Default.Address), Properties.Settings.Default.Username, Encoding.UTF8.GetString(Convert.FromBase64String(Properties.Settings.Default.Password)));
UriBuilder uriBuilder = new UriBuilder(Properties.Settings.Default.Address)
{
Scheme = Uri.UriSchemeHttp
};

ds = new DownloadStation(uriBuilder.Uri, Properties.Settings.Default.Username, Encoding.UTF8.GetString(Convert.FromBase64String(Properties.Settings.Default.Password)));

if (File.Exists(path))
{
Expand Down Expand Up @@ -745,8 +755,16 @@ public static void OpenDownloadStation()
else
#endif
{

Process.Start("http://" + Properties.Settings.Default.Address);
UriBuilder uriBuilder = new UriBuilder(Properties.Settings.Default.Address);

// ToDo

if (string.IsNullOrEmpty(uriBuilder.Scheme))
{
uriBuilder.Scheme = Uri.UriSchemeHttp;
}

Process.Start(uriBuilder.Uri.ToString());
}
}

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.3.0.1")]
[assembly: AssemblyFileVersion("1.4.0.0")]

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 @@ -3,7 +3,7 @@
<Profiles />
<Settings>
<Setting Name="Address" Type="System.String" Scope="User">
<Value Profile="(Default)">diskstation:5000</Value>
<Value Profile="(Default)">http://diskstation:5000</Value>
</Setting>
<Setting Name="Username" Type="System.String" Scope="User">
<Value Profile="(Default)">admin</Value>
Expand All @@ -20,7 +20,7 @@
<Setting Name="ApplicationEnabled" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="ApplicationUrl" Type="System.String" Scope="User">
<Setting Name="ApplicationPath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="SizeX" Type="System.Int32" Scope="User">
Expand Down
4 changes: 2 additions & 2 deletions Synology Download Station Adapter/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><userSettings>
<TheDuffman85.SynologyDownloadStationAdapter.Properties.Settings>
<setting name="Address" serializeAs="String">
<value>diskstation:5000</value>
<value>http://diskstation:5000</value>
</setting>
<setting name="Username" serializeAs="String">
<value>admin</value>
Expand All @@ -26,7 +26,7 @@
<setting name="ApplicationEnabled" serializeAs="String">
<value>False</value>
</setting>
<setting name="ApplicationUrl" serializeAs="String">
<setting name="ApplicationPath" serializeAs="String">
<value />
</setting>
<setting name="SizeX" serializeAs="String">
Expand Down
14 changes: 6 additions & 8 deletions Synology Download Station Adapter/frmAddLinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,13 @@ private void btnAdd_Click(object sender, EventArgs e)
{
this.Visible = false;
Clipboard.Clear();

frmSettings.Instance.Invoke((MethodInvoker)(() =>
new Task(() =>
{
// Run on UI thread
new Task(() => { Adapter.AddLinksToDownloadStation(txtLinks.Lines.ToList()); }).Start();
}
));

this.Close();
Adapter.AddLinksToDownloadStation(txtLinks.Lines.ToList());
this.Invoke((MethodInvoker)(() => { this.Close(); }));
}).Start();
}

private void btnCancel_Click(object sender, EventArgs e)
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 @@ -111,7 +111,7 @@ protected void NewIntance()
private void frmDownloadStation_Load(object sender, EventArgs e)
{
webControl.DocumentReady += webControl_DocumentReady;
webControl.Source = new Uri(Properties.Settings.Default.ApplicationUrl);
webControl.Source = new Uri(new Uri(Properties.Settings.Default.Address), Properties.Settings.Default.ApplicationPath);
}

private void frmDownloadStation_ResizeEnd(object sender, EventArgs e)
Expand Down
26 changes: 14 additions & 12 deletions Synology Download Station Adapter/frmSettings.Designer.cs

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

98 changes: 85 additions & 13 deletions Synology Download Station Adapter/frmSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private frmSettings()
cbAutostart.Visible = false;
lblApplicationUrl.Visible = false;
cbApplicationEnabled.Visible = false;
txtApplicationUrl.Visible = false;
txtApplicationPath.Visible = false;

cbShowDecryptedLinks.Top = cbShowDecryptedLinks.Top - 23;
cbIgnoreHoster.Top = cbIgnoreHoster.Top - 46;
Expand All @@ -116,7 +116,31 @@ private frmSettings()
lblVersion.Text = lblVersion.Text + " (Mono)";
#endif


#region Upgrade Settings

bool upgraded = false;
Uri address;

if (!Uri.TryCreate(Properties.Settings.Default.Address, UriKind.Absolute, out address) ||
(address != null && address.Scheme != Uri.UriSchemeHttp && address.Scheme != Uri.UriSchemeHttps))
{
Properties.Settings.Default.Address = "http://" + Properties.Settings.Default.Address;
upgraded = true;
}

if (Properties.Settings.Default.ApplicationEnabled &&
string.IsNullOrEmpty(Properties.Settings.Default.ApplicationPath))
{
Properties.Settings.Default.ApplicationPath = "/download/index.cgi";
upgraded = true;
}

if (upgraded)
{
Properties.Settings.Default.Save();
}

#endregion

InitBookmarks();
}
Expand Down Expand Up @@ -227,7 +251,7 @@ private void btnSave_Click(object sender, EventArgs e)
Properties.Settings.Default.Password = Convert.ToBase64String(Encoding.UTF8.GetBytes(txtPassword.Text));
#if !__MonoCS__
Properties.Settings.Default.ApplicationEnabled = cbApplicationEnabled.Checked;
Properties.Settings.Default.ApplicationUrl = txtApplicationUrl.Text;
Properties.Settings.Default.ApplicationPath = txtApplicationPath.Text;
#endif
Properties.Settings.Default.ShowDecryptedLinks = cbShowDecryptedLinks.Checked;
Properties.Settings.Default.IgnoreHoster = cbIgnoreHoster.Checked;
Expand Down Expand Up @@ -258,7 +282,7 @@ private void frmSettings_VisibleChanged(object sender, EventArgs e)
txtPassword.Text = Encoding.UTF8.GetString(Convert.FromBase64String(Properties.Settings.Default.Password));
#if !__MonoCS__
cbApplicationEnabled.Checked = Properties.Settings.Default.ApplicationEnabled;
txtApplicationUrl.Text = Properties.Settings.Default.ApplicationUrl;
txtApplicationPath.Text = Properties.Settings.Default.ApplicationPath;
#endif
cbShowDecryptedLinks.Checked = Properties.Settings.Default.ShowDecryptedLinks;
cbIgnoreHoster.Checked = Properties.Settings.Default.IgnoreHoster;
Expand All @@ -278,24 +302,72 @@ private void btnFileAssociation_Click(object sender, EventArgs e)
}


private void cbApplicationUrl_CheckedChanged(object sender, EventArgs e)
private void cbApplicationPath_CheckedChanged(object sender, EventArgs e)
{
#if !__MonoCS__
if (!cbApplicationEnabled.Checked)
{
txtApplicationUrl.Enabled = false;
txtApplicationUrl.Text = string.Empty;
txtApplicationPath.Enabled = false;
txtApplicationPath.Text = string.Empty;
}
else
{
txtApplicationUrl.Enabled = true;
if (string.IsNullOrEmpty(txtApplicationUrl.Text))
txtApplicationPath.Enabled = true;
if (string.IsNullOrEmpty(txtApplicationPath.Text))
{
txtApplicationUrl.Text = "http://" + txtAddress.Text + "/download/index.cgi";
txtApplicationPath.Text = "/download/index.cgi";
}
}
#endif
}
}

private void txtAddress_Validating(object sender, CancelEventArgs e)
{
Uri address;
DialogResult result = System.Windows.Forms.DialogResult.None;

if (!Uri.TryCreate(txtAddress.Text, UriKind.Absolute, out address))
{
result = MessageBox.Show("Please enter a valid uri. eg.: http://diskstation:5000", "Settings", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
}
else
{
if (address.Scheme != Uri.UriSchemeHttp &&
address.Scheme != Uri.UriSchemeHttps)
{
result = MessageBox.Show("The protocol has to be http or https.", "Settings", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
}
}

if (result == System.Windows.Forms.DialogResult.OK)
{
e.Cancel = true;
}
else if (result == System.Windows.Forms.DialogResult.Cancel)
{
txtAddress.Text = Properties.Settings.Default.Address;
}
}

private void txtApplicationPath_Validating(object sender, CancelEventArgs e)
{
Uri path;
DialogResult result = System.Windows.Forms.DialogResult.None;

if (!Uri.TryCreate(txtApplicationPath.Text, UriKind.Relative, out path))
{
result = MessageBox.Show("Please enter a relative uri. eg.: /download/index.cgi", "Settings", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
}

if (result == System.Windows.Forms.DialogResult.OK)
{
e.Cancel = true;
}
else if (result == System.Windows.Forms.DialogResult.Cancel)
{
txtApplicationPath.Text = Properties.Settings.Default.ApplicationPath;
}
}

private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
Expand Down Expand Up @@ -417,8 +489,8 @@ private void bookmarkToolStripMenuItem_Click(object sender, EventArgs e)
}

#endregion

#endregion
#endregion

}
}

0 comments on commit 7836a7b

Please sign in to comment.