OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmUpdate.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.ComponentModel;\r
4 using System.Data;\r
5 using System.Drawing;\r
6 using System.Text;\r
7 using System.Windows.Forms;\r
8 using System.IO;\r
9 using System.Net;\r
10 \r
11 namespace Handbrake\r
12 {\r
13     public partial class frmUpdate : Form\r
14     {\r
15         public frmUpdate()\r
16         {\r
17             InitializeComponent();\r
18         }\r
19 \r
20         private void btn_update_click(object sender, EventArgs e)\r
21         {\r
22             // Try to download the contents of the update file. If sucessful then split the 2 lines and do an update check/\r
23             try\r
24             {\r
25                 String updateFile = Properties.Settings.Default.updateFile;\r
26                 WebClient client = new WebClient();\r
27                 String data = client.DownloadString(updateFile);\r
28                 String[] versionData = data.Split('\n');\r
29 \r
30                 lbl_GuiVersion.Text = versionData[0];\r
31                 lbl_cliVersion.Text = versionData[1];\r
32 \r
33                 if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion))\r
34                 {\r
35                     MessageBox.Show("A new version is available. Please visit the project website to download the update.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
36                 }\r
37             }\r
38             //else fail displaying an error message.\r
39             catch (Exception)\r
40             {\r
41 \r
42                 MessageBox.Show("Unable to check for new version at this time. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
43             }\r
44         }\r
45 \r
46         private void btn_close_Click(object sender, EventArgs e)\r
47         {\r
48             this.Close(); // Close the window\r
49         }\r
50 \r
51         private void frmUpdate_Load(object sender, EventArgs e)\r
52         {\r
53             // Set the labels with their correct values.\r
54             Version.Text = Properties.Settings.Default.GuiVersion;\r
55             cliVersion.Text = Properties.Settings.Default.CliVersion;\r
56         }\r
57     }\r
58 }