Files
cuetools.net/CUETools.CTDB.EACPlugin/FormSubmitParity.cs

102 lines
3.5 KiB
C#
Raw Normal View History

2011-05-26 23:19:20 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CUETools.CTDB.EACPlugin.Properties;
using System.IO;
2011-05-26 23:19:20 +00:00
namespace CUETools.CTDB.EACPlugin
{
public partial class FormSubmitParity : Form
{
private CUEToolsDB ctdb;
private int confidence, quality;
private string artist, title, agent, drivename;
private CTDBResponse resp;
2011-05-26 23:19:20 +00:00
2012-01-12 03:18:29 +00:00
public FormSubmitParity(CUEToolsDB ctdb, string agent, string drivename, int confidence, int quality, string artist, string title)
2011-05-26 23:19:20 +00:00
{
this.ctdb = ctdb;
this.confidence = confidence;
this.quality = quality;
this.artist = artist;
this.title = title;
2012-01-12 03:18:29 +00:00
this.agent = agent;
this.drivename = drivename;
this.InitializeComponent();
2011-05-26 23:19:20 +00:00
}
private void FormMetadata_Load(object sender, EventArgs e)
{
this.Icon = Resources.ctdb;
this.backgroundWorker1.RunWorkerAsync();
}
private void UploadProgress(object sender, Krystalware.UploadHelper.UploadProgressEventArgs e)
{
this.backgroundWorker1.ReportProgress((int)e.percent, e.uri);
}
2012-01-12 03:18:29 +00:00
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
this.ctdb.UploadHelper.onProgress += UploadProgress;
if (resp == null)
{
2012-01-12 03:18:29 +00:00
#if DEBUG
string server = "hq.cuetools.net";
2012-01-12 03:18:29 +00:00
#else
string server = null;
2012-01-12 03:18:29 +00:00
#endif
this.ctdb.ContactDB(server, this.agent, this.drivename, true, true, CTDBMetadataSearch.None);
this.ctdb.DoVerify();
resp = this.ctdb.Submit(this.confidence, this.quality, this.artist, this.title, null);
} else
{
var url = resp.updateurl;
resp = null;
var temp = Path.GetTempPath() + Path.GetFileName(url.Substring(url.LastIndexOf('/') + 1));
bool ok = false;
using (var stream = new FileStream(temp, FileMode.Create))
ok = this.ctdb.FetchFile(url, stream);
if (ok)
System.Diagnostics.Process.Start(temp);
}
2012-01-12 03:18:29 +00:00
this.ctdb.UploadHelper.onProgress -= UploadProgress;
}
2011-05-26 23:19:20 +00:00
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (resp != null && resp.updateurl != null)
{
DialogResult mb = MessageBox.Show(this, (resp.updatemsg ?? "") + " Do you wish to download and install it?", "An updated version of CTDB plugin is available", MessageBoxButtons.OKCancel);
if (mb == DialogResult.OK)
{
this.backgroundWorker1.RunWorkerAsync();
return;
}
}
2011-05-26 23:19:20 +00:00
this.DialogResult = DialogResult.OK;
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.progressBar1.Style = e.ProgressPercentage != 0 ? ProgressBarStyle.Continuous : ProgressBarStyle.Marquee;
this.progressBar1.Value = Math.Max(0, Math.Min(100, e.ProgressPercentage));
2012-01-17 08:04:16 +00:00
this.labelStatus.Text = e.UserState is string ? e.UserState as string : string.Empty;
2011-05-26 23:19:20 +00:00
}
2011-05-28 15:03:49 +00:00
private void FormSubmitParity_FormClosing(object sender, FormClosingEventArgs e)
{
if (this.backgroundWorker1.IsBusy)
{
e.Cancel = true;
this.progressBar1.Style = ProgressBarStyle.Marquee;
this.ctdb.CancelRequest();
}
}
2011-05-26 23:19:20 +00:00
}
}