moel@348
|
1 |
/*
|
moel@348
|
2 |
|
moel@348
|
3 |
This Source Code Form is subject to the terms of the Mozilla Public
|
moel@348
|
4 |
License, v. 2.0. If a copy of the MPL was not distributed with this
|
moel@348
|
5 |
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
moel@348
|
6 |
|
moel@348
|
7 |
Copyright (C) 2012 Prince Samuel <prince.samuel@gmail.com>
|
moel@348
|
8 |
|
moel@348
|
9 |
*/
|
moel@348
|
10 |
|
moel@348
|
11 |
using System;
|
moel@348
|
12 |
using System.Collections.Generic;
|
moel@348
|
13 |
using System.ComponentModel;
|
moel@348
|
14 |
using System.Data;
|
moel@348
|
15 |
using System.Drawing;
|
moel@348
|
16 |
using System.Text;
|
moel@348
|
17 |
using System.Windows.Forms;
|
moel@348
|
18 |
using System.Net;
|
moel@348
|
19 |
using System.Net.Sockets;
|
moel@348
|
20 |
using System.Diagnostics;
|
moel@348
|
21 |
|
moel@348
|
22 |
namespace OpenHardwareMonitor.GUI {
|
moel@348
|
23 |
public partial class PortForm : Form {
|
moel@348
|
24 |
private MainForm parent;
|
moel@348
|
25 |
private string localIP;
|
moel@348
|
26 |
public PortForm(MainForm m) {
|
moel@348
|
27 |
InitializeComponent();
|
moel@348
|
28 |
parent = m;
|
moel@348
|
29 |
|
moel@348
|
30 |
localIP = getLocalIP();
|
moel@348
|
31 |
}
|
moel@348
|
32 |
|
moel@348
|
33 |
private void portTextBox_TextChanged(object sender, EventArgs e) {
|
moel@348
|
34 |
|
moel@348
|
35 |
}
|
moel@348
|
36 |
|
moel@348
|
37 |
private string getLocalIP() {
|
moel@348
|
38 |
IPHostEntry host;
|
moel@348
|
39 |
string localIP = "?";
|
moel@348
|
40 |
host = Dns.GetHostEntry(Dns.GetHostName());
|
moel@348
|
41 |
foreach (IPAddress ip in host.AddressList) {
|
moel@348
|
42 |
if (ip.AddressFamily == AddressFamily.InterNetwork) {
|
moel@348
|
43 |
localIP = ip.ToString();
|
moel@348
|
44 |
}
|
moel@348
|
45 |
}
|
moel@348
|
46 |
return localIP;
|
moel@348
|
47 |
}
|
moel@348
|
48 |
|
moel@348
|
49 |
private void portNumericUpDn_ValueChanged(object sender, EventArgs e) {
|
moel@348
|
50 |
string url = "http://" + localIP + ":" + portNumericUpDn.Value + "/";
|
moel@348
|
51 |
webServerLinkLabel.Text = url;
|
moel@348
|
52 |
webServerLinkLabel.Links.Remove(webServerLinkLabel.Links[0]);
|
moel@348
|
53 |
webServerLinkLabel.Links.Add(0, webServerLinkLabel.Text.Length, url);
|
moel@348
|
54 |
}
|
moel@348
|
55 |
|
moel@348
|
56 |
private void portOKButton_Click(object sender, EventArgs e) {
|
moel@348
|
57 |
parent.Server.ListenerPort = (int)portNumericUpDn.Value;
|
moel@348
|
58 |
this.Close();
|
moel@348
|
59 |
}
|
moel@348
|
60 |
|
moel@348
|
61 |
private void portCancelButton_Click(object sender, EventArgs e) {
|
moel@348
|
62 |
this.Close();
|
moel@348
|
63 |
}
|
moel@348
|
64 |
|
moel@348
|
65 |
private void PortForm_Load(object sender, EventArgs e) {
|
moel@348
|
66 |
portNumericUpDn.Value = parent.Server.ListenerPort;
|
moel@348
|
67 |
portNumericUpDn_ValueChanged(null, null);
|
moel@348
|
68 |
}
|
moel@348
|
69 |
|
moel@348
|
70 |
private void webServerLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
|
moel@348
|
71 |
try {
|
moel@348
|
72 |
Process.Start(new ProcessStartInfo(e.Link.LinkData.ToString()));
|
moel@348
|
73 |
} catch { }
|
moel@348
|
74 |
}
|
moel@348
|
75 |
|
moel@348
|
76 |
}
|
moel@348
|
77 |
}
|