2018-12-03 04:35:49 +00:00
|
|
|
|
using System;
|
2019-03-20 10:02:18 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
2018-12-03 04:35:49 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2019-03-20 10:02:18 +00:00
|
|
|
|
namespace network.loki.lokinet.win32.ui
|
2018-12-03 04:35:49 +00:00
|
|
|
|
{
|
2019-03-20 10:02:18 +00:00
|
|
|
|
public partial class main_frame : Form
|
2018-12-03 04:35:49 +00:00
|
|
|
|
{
|
2019-03-20 10:02:18 +00:00
|
|
|
|
public static Process lokiNetDaemon = new Process();
|
|
|
|
|
public static bool isConnected;
|
|
|
|
|
public static string logText;
|
2019-03-25 07:14:07 +00:00
|
|
|
|
private string config_path;
|
|
|
|
|
private LogDumper ld;
|
2019-03-20 10:02:18 +00:00
|
|
|
|
|
|
|
|
|
void UpdateUI(string text)
|
|
|
|
|
{
|
|
|
|
|
this.Invoke(new MethodInvoker(delegate () { lokinetd_fd1.AppendText(text); }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public main_frame()
|
2018-12-03 04:35:49 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-03-25 07:14:07 +00:00
|
|
|
|
if (Program.platform == PlatformID.Win32NT)
|
|
|
|
|
config_path = Environment.ExpandEnvironmentVariables("%APPDATA%\\.lokinet");
|
|
|
|
|
else
|
|
|
|
|
config_path = Environment.ExpandEnvironmentVariables("%HOME%/.lokinet");
|
2019-03-20 10:02:18 +00:00
|
|
|
|
StatusLabel.Text = "Disconnected";
|
|
|
|
|
var build = ((AssemblyInformationalVersionAttribute)Assembly
|
|
|
|
|
.GetAssembly(typeof(main_frame))
|
|
|
|
|
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)[0])
|
|
|
|
|
.InformationalVersion;
|
|
|
|
|
UIVersionLabel.Text = String.Format("LokiNET version {0}", build);
|
|
|
|
|
lokinetd_fd1.Text = string.Empty;
|
|
|
|
|
logText = string.Empty;
|
2019-03-20 11:29:29 +00:00
|
|
|
|
lokiNetDaemon.OutputDataReceived += new DataReceivedEventHandler((s, ev) =>
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(ev.Data))
|
|
|
|
|
{
|
|
|
|
|
UpdateUI(ev.Data + Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-12-03 04:35:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnConfigProfile_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-03-20 10:02:18 +00:00
|
|
|
|
//MessageBox.Show("not implemented yet", "error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
|
|
|
|
UserSettingsForm f = new UserSettingsForm();
|
|
|
|
|
f.ShowDialog();
|
|
|
|
|
f.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnConnect_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string lokinetExeString;
|
|
|
|
|
|
|
|
|
|
if (Program.platform == PlatformID.Win32NT)
|
|
|
|
|
lokinetExeString = String.Format("{0}\\lokinet.exe", Directory.GetCurrentDirectory());
|
|
|
|
|
else
|
|
|
|
|
lokinetExeString = String.Format("{0}/lokinet", Directory.GetCurrentDirectory());
|
|
|
|
|
|
|
|
|
|
lokiNetDaemon.StartInfo.UseShellExecute = false;
|
|
|
|
|
lokiNetDaemon.StartInfo.RedirectStandardOutput = true;
|
|
|
|
|
//lokiNetDaemon.EnableRaisingEvents = true;
|
|
|
|
|
lokiNetDaemon.StartInfo.CreateNoWindow = true;
|
|
|
|
|
lokiNetDaemon.StartInfo.FileName = lokinetExeString;
|
|
|
|
|
lokiNetDaemon.Start();
|
|
|
|
|
lokiNetDaemon.BeginOutputReadLine();
|
|
|
|
|
btnConnect.Enabled = false;
|
2019-03-25 07:14:07 +00:00
|
|
|
|
TrayConnect.Enabled = false;
|
2019-03-20 10:02:18 +00:00
|
|
|
|
StatusLabel.Text = "Connected";
|
|
|
|
|
isConnected = true;
|
|
|
|
|
NotificationTrayIcon.Text = "LokiNET - connected";
|
|
|
|
|
btnDrop.Enabled = true;
|
2019-03-25 07:14:07 +00:00
|
|
|
|
TrayDisconnect.Enabled = true;
|
|
|
|
|
NotificationTrayIcon.ShowBalloonTip(5, "LokiNET", "Connected to network.", ToolTipIcon.Info);
|
2019-03-20 10:02:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnDrop_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
lokiNetDaemon.CancelOutputRead();
|
|
|
|
|
lokiNetDaemon.Kill();
|
|
|
|
|
btnConnect.Enabled = true;
|
2019-03-25 07:14:07 +00:00
|
|
|
|
TrayConnect.Enabled = true;
|
2019-03-20 10:02:18 +00:00
|
|
|
|
btnDrop.Enabled = false;
|
2019-03-25 07:14:07 +00:00
|
|
|
|
TrayDisconnect.Enabled = false;
|
2019-03-20 10:02:18 +00:00
|
|
|
|
StatusLabel.Text = "Disconnected";
|
|
|
|
|
NotificationTrayIcon.Text = "LokiNET - disconnected";
|
|
|
|
|
isConnected = false;
|
|
|
|
|
logText = lokinetd_fd1.Text;
|
|
|
|
|
lokinetd_fd1.Text = string.Empty;
|
2019-03-25 07:14:07 +00:00
|
|
|
|
NotificationTrayIcon.ShowBalloonTip(5, "LokiNET", "Disconnected from network.", ToolTipIcon.Info);
|
|
|
|
|
|
2019-03-20 10:02:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lokinetd_fd1_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
lokinetd_fd1.ScrollToCaret();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnHide_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
if (isConnected)
|
|
|
|
|
NotificationTrayIcon.ShowBalloonTip(5, "LokiNET", "Currently connected.", ToolTipIcon.Info);
|
|
|
|
|
else
|
|
|
|
|
NotificationTrayIcon.ShowBalloonTip(5, "LokiNET", "Currently disconnected.", ToolTipIcon.Info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NotificationTrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2019-03-25 07:14:07 +00:00
|
|
|
|
if (!Visible)
|
|
|
|
|
{
|
|
|
|
|
Show();
|
|
|
|
|
}
|
2018-12-03 04:35:49 +00:00
|
|
|
|
}
|
2019-03-20 10:38:00 +00:00
|
|
|
|
|
|
|
|
|
private void btnAbout_Click(object sender, EventArgs e)
|
2019-03-25 07:14:07 +00:00
|
|
|
|
{
|
|
|
|
|
AboutBox a = new AboutBox();
|
|
|
|
|
a.ShowDialog(this);
|
|
|
|
|
a.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveLogToFileToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (isConnected)
|
|
|
|
|
MessageBox.Show("Cannot dump log when client is running.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (logText == string.Empty)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Log is empty", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (ld == null)
|
|
|
|
|
ld = new LogDumper(logText);
|
|
|
|
|
else
|
|
|
|
|
ld.setText(logText);
|
|
|
|
|
|
|
|
|
|
ld.CreateLog(config_path);
|
|
|
|
|
MessageBox.Show(string.Format("Wrote log to {0}, previous log rotated", ld.getLogPath()), "LokiNET", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
logText = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
2019-03-20 10:38:00 +00:00
|
|
|
|
{
|
|
|
|
|
AboutBox a = new AboutBox();
|
|
|
|
|
a.ShowDialog();
|
|
|
|
|
a.Dispose();
|
|
|
|
|
}
|
2019-03-25 07:14:07 +00:00
|
|
|
|
|
|
|
|
|
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Application.Exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TrayDisconnect_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
btnDrop_Click(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TrayConnect_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
btnConnect_Click(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Show();
|
|
|
|
|
}
|
2018-12-03 04:35:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|