windows: clean up controller
This commit is contained in:
parent
196a3902c3
commit
ba6e058fec
|
@ -1,39 +0,0 @@
|
||||||
// SparkleShare, an instant update workflow to Git.
|
|
||||||
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using Notifications;
|
|
||||||
|
|
||||||
namespace SparkleShare {
|
|
||||||
|
|
||||||
public class SparkleBubble : Notification {
|
|
||||||
|
|
||||||
public SparkleBubble (string title, string subtext) : base (title, subtext)
|
|
||||||
{
|
|
||||||
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer ();
|
|
||||||
timer.Tick += delegate { this.Close (); };
|
|
||||||
timer.Interval = 4500;
|
|
||||||
timer.Start ();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checks whether the system allows adding buttons to a notification,
|
|
||||||
// prevents error messages in Ubuntu.
|
|
||||||
new public void AddAction (string action, string label, ActionHandler handler)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SparkleShare, an instant update workflow to Git.
|
// SparkleShare, a collaboration and sharing tool.
|
||||||
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
@ -8,51 +8,58 @@
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful,
|
// This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using System.Reflection;
|
|
||||||
using SparkleLib;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Windows.Forms;
|
using System.Threading;
|
||||||
|
|
||||||
using CefSharp;
|
using CefSharp;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
using SparkleLib;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
public class SparkleController : SparkleControllerBase {
|
public class SparkleController : SparkleControllerBase {
|
||||||
private int sshAgentPid;
|
|
||||||
|
private int ssh_agent_pid;
|
||||||
|
|
||||||
|
|
||||||
|
public SparkleController () : base ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public override string PluginsPath
|
public override string PluginsPath
|
||||||
{
|
{
|
||||||
get
|
get {
|
||||||
{
|
return Path.Combine (
|
||||||
return Path.Combine (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location), "plugins");
|
Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location),
|
||||||
|
"plugins"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SparkleController () : base ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Initialize ()
|
public override void Initialize ()
|
||||||
{
|
{
|
||||||
Settings settings = new Settings ();
|
Settings settings = new Settings ();
|
||||||
BrowserSettings browserSettings = new BrowserSettings ();
|
BrowserSettings browser_settings = new BrowserSettings ();
|
||||||
|
|
||||||
if (!CEF.Initialize (settings, browserSettings)) {
|
if (!CEF.Initialize (settings, browser_settings)) {
|
||||||
Console.WriteLine ("Couldn't initialise CEF");
|
Console.WriteLine ("Could not initialise CEF");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,32 +71,31 @@ namespace SparkleShare {
|
||||||
|
|
||||||
// Add msysgit to path, as we cannot asume it is added to the path
|
// Add msysgit to path, as we cannot asume it is added to the path
|
||||||
// Asume it is installed in @"<exec dir>\msysgit\bin"
|
// Asume it is installed in @"<exec dir>\msysgit\bin"
|
||||||
string ExecutableDir = Path.GetDirectoryName(Application.ExecutablePath);
|
string executable_dir = Path.GetDirectoryName (Application.ExecutablePath);
|
||||||
string MSysGit = Path.Combine(ExecutableDir, "msysgit");
|
string msysgit = Path.Combine (executable_dir, "msysgit");
|
||||||
|
|
||||||
string newPath = MSysGit + @"\bin" + ";"
|
string new_PATH = msysgit + @"\bin" + ";" +
|
||||||
+ MSysGit + @"\mingw\bin" + ";"
|
msysgit + @"\mingw\bin" + ";" +
|
||||||
+ MSysGit + @"\cmd" + ";"
|
msysgit + @"\cmd" + ";" +
|
||||||
+ System.Environment.ExpandEnvironmentVariables ("%PATH%");
|
Environment.ExpandEnvironmentVariables ("%PATH%");
|
||||||
System.Environment.SetEnvironmentVariable ("PATH", newPath);
|
|
||||||
System.Environment.SetEnvironmentVariable ("PLINK_PROTOCOL", "ssh");
|
|
||||||
|
|
||||||
if (String.IsNullOrEmpty (System.Environment.GetEnvironmentVariable ("HOME")))
|
Environment.SetEnvironmentVariable ("PATH", new_PATH);
|
||||||
System.Environment.SetEnvironmentVariable ("HOME", Environment.ExpandEnvironmentVariables ("%HOMEDRIVE%%HOMEPATH%"));
|
Environment.SetEnvironmentVariable ("PLINK_PROTOCOL", "ssh");
|
||||||
|
|
||||||
StartSshAgent ();
|
if (string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("HOME")))
|
||||||
|
Environment.SetEnvironmentVariable ("HOME",
|
||||||
|
Environment.ExpandEnvironmentVariables ("%HOMEDRIVE%%HOMEPATH%"));
|
||||||
|
|
||||||
|
StartSSH ();
|
||||||
base.Initialize ();
|
base.Initialize ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override string EventLogHTML
|
public override string EventLogHTML
|
||||||
{
|
{
|
||||||
get
|
get {
|
||||||
{
|
|
||||||
string html = Properties.Resources.event_log_html;
|
string html = Properties.Resources.event_log_html;
|
||||||
|
|
||||||
html = html.Replace ("<!-- $jquery-url -->", "application://sparkleshare/jquery.js");
|
html = html.Replace ("<!-- $jquery-url -->", "application://sparkleshare/jquery.js");
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,8 +103,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public override string DayEntryHTML
|
public override string DayEntryHTML
|
||||||
{
|
{
|
||||||
get
|
get {
|
||||||
{
|
|
||||||
return Properties.Resources.day_entry_html;
|
return Properties.Resources.day_entry_html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,130 +111,142 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public override string EventEntryHTML
|
public override string EventEntryHTML
|
||||||
{
|
{
|
||||||
get
|
get {
|
||||||
{
|
|
||||||
return Properties.Resources.event_entry_html;
|
return Properties.Resources.event_entry_html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Creates a .desktop entry in autostart folder to
|
|
||||||
// start SparkleShare automatically at login
|
|
||||||
public override void CreateStartupItem ()
|
public override void CreateStartupItem ()
|
||||||
{
|
{
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override void InstallProtocolHandler()
|
public override void InstallProtocolHandler()
|
||||||
{
|
{
|
||||||
// Get assembly location
|
// Get assembly location
|
||||||
string location = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
string location = System.Reflection.Assembly.GetExecutingAssembly ().Location;
|
||||||
string folder = Path.GetDirectoryName(location);
|
string folder = Path.GetDirectoryName (location);
|
||||||
string inviteExe = Path.Combine(folder, "SparkleShareInviteOpen.exe");
|
string invite_exe = Path.Combine (folder, "SparkleShareInviteOpener.exe");
|
||||||
|
|
||||||
// Register protocol handler as explained in
|
// Register protocol handler as explained in
|
||||||
// http://msdn.microsoft.com/en-us/library/ie/aa767914(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/ie/aa767914(v=vs.85).aspx
|
||||||
string mainKey = "HKEY_CLASSES_ROOT\\sparkleshare";
|
string main_key = "HKEY_CLASSES_ROOT\\sparkleshare";
|
||||||
Registry.SetValue(mainKey, "", "SparkleShare Invites");
|
Registry.SetValue (main_key, "", "SparkleShare Invite Opener");
|
||||||
Registry.SetValue(mainKey, "URL Protocol", "");
|
Registry.SetValue (main_key, "URL Protocol", "");
|
||||||
|
|
||||||
string iconKey = "HKEY_CLASSES_ROOT\\sparkleshare\\DefaultIcon";
|
string icon_key = "HKEY_CLASSES_ROOT\\sparkleshare\\DefaultIcon";
|
||||||
Registry.SetValue(iconKey, "", inviteExe + ",1");
|
Registry.SetValue (icon_key, "", invite_exe + ",1");
|
||||||
|
|
||||||
string actionKey = "HKEY_CLASSES_ROOT\\sparkleshare\\shell\\open\\command";
|
string action_key = "HKEY_CLASSES_ROOT\\sparkleshare\\shell\\open\\command";
|
||||||
Registry.SetValue(actionKey, "", "\"" + inviteExe + "\" \"%1\"");
|
Registry.SetValue (action_key, "", "\"" + invite_exe + "\" \"%1\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Adds the SparkleShare folder to the user's
|
|
||||||
// list of bookmarked places
|
|
||||||
public override void AddToBookmarks ()
|
public override void AddToBookmarks ()
|
||||||
{
|
{
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Creates the SparkleShare folder in the user's home folder
|
|
||||||
public override bool CreateSparkleShareFolder ()
|
public override bool CreateSparkleShareFolder ()
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(SparkleConfig.DefaultConfig.FoldersPath))
|
if (!Directory.Exists(SparkleConfig.DefaultConfig.FoldersPath) {
|
||||||
{
|
|
||||||
Directory.CreateDirectory(SparkleConfig.DefaultConfig.FoldersPath);
|
Directory.CreateDirectory(SparkleConfig.DefaultConfig.FoldersPath);
|
||||||
Directory.CreateDirectory(SparkleConfig.DefaultConfig.TmpPath);
|
Directory.CreateDirectory(SparkleConfig.DefaultConfig.TmpPath);
|
||||||
SparkleHelpers.DebugInfo("Config", "Created '" + SparkleConfig.DefaultConfig.FoldersPath + "'");
|
|
||||||
|
SparkleHelpers.DebugInfo("Config", "Created \"" +
|
||||||
|
SparkleConfig.DefaultConfig.FoldersPath + "\"");
|
||||||
|
|
||||||
|
// TODO: Set a custom SparkleShare folder icon
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OpenFile(string url)
|
|
||||||
{
|
|
||||||
Process process = new Process();
|
|
||||||
process.StartInfo.Arguments = "\"" + url + "\"";
|
|
||||||
process.StartInfo.FileName = "start";
|
|
||||||
|
|
||||||
process.Start();
|
public override void OpenFile (string url)
|
||||||
|
{
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.FileName = "start";
|
||||||
|
process.StartInfo.Arguments = "\"" + url + "\"";
|
||||||
|
|
||||||
|
process.Start ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override void OpenSparkleShareFolder (string subfolder)
|
public override void OpenSparkleShareFolder (string subfolder)
|
||||||
{
|
{
|
||||||
Process process = new Process();
|
Process process = new Process ();
|
||||||
process.StartInfo.Arguments = ",/root," + SparkleHelpers.CombineMore(SparkleConfig.DefaultConfig.FoldersPath, subfolder);
|
process.StartInfo.FileName = "explorer";
|
||||||
process.StartInfo.FileName = "explorer";
|
process.StartInfo.Arguments = ",/root," +
|
||||||
|
Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, subfolder);
|
||||||
|
|
||||||
process.Start();
|
process.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override void Quit ()
|
public override void Quit ()
|
||||||
{
|
{
|
||||||
KillSshAgent ();
|
StopSSH ();
|
||||||
base.Quit ();
|
base.Quit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartSshAgent ()
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty (System.Environment.GetEnvironmentVariable ("SSH_AUTH_SOCK"))) {
|
|
||||||
|
|
||||||
Process process = new Process ();
|
private void StartSSH ()
|
||||||
process.StartInfo.FileName = "ssh-agent";
|
{
|
||||||
process.StartInfo.UseShellExecute = false;
|
string auth_sock = Environment.GetEnvironmentVariable ("SSH_AUTH_SOCK");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty (auth_sock)) {
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.FileName = "ssh-agent";
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
|
||||||
process.Start ();
|
process.Start ();
|
||||||
|
|
||||||
string Output = process.StandardOutput.ReadToEnd ();
|
string output = process.StandardOutput.ReadToEnd ();
|
||||||
process.WaitForExit ();
|
process.WaitForExit ();
|
||||||
|
|
||||||
Match AuthSock = new Regex (@"SSH_AUTH_SOCK=([^;\n\r]*)").Match (Output);
|
Match auth_sock_match = new Regex (@"SSH_AUTH_SOCK=([^;\n\r]*)").Match (output);
|
||||||
if (AuthSock.Success) {
|
|
||||||
System.Environment.SetEnvironmentVariable ("SSH_AUTH_SOCK", AuthSock.Groups[1].Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Match AgentPid = new Regex (@"SSH_AGENT_PID=([^;\n\r]*)").Match (Output);
|
if (auth_sock_match.Success)
|
||||||
if (AgentPid.Success) {
|
Environment.SetEnvironmentVariable ("SSH_AUTH_SOCK",
|
||||||
Int32.TryParse (AgentPid.Groups [1].Value, out sshAgentPid);
|
auth_sock_match.Groups [1].Value);
|
||||||
System.Environment.SetEnvironmentVariable ("SSH_AGENT_PID", AgentPid.Groups[1].Value);
|
|
||||||
SparkleHelpers.DebugInfo ("SSH", "ssh-agent started, PID=" + AgentPid.Groups[1].Value);
|
Match ssh_pid_match = new Regex (@"SSH_AGENT_PID=([^;\n\r]*)").Match (output);
|
||||||
}
|
|
||||||
else {
|
if (ssh_pid_match.Success) {
|
||||||
SparkleHelpers.DebugInfo ("SSH", "ssh-agent started, PID=unknown");
|
string ssh_pid = ssh_pid_match.Groups [1].Value;
|
||||||
|
|
||||||
|
Int32.TryParse (ssh_pid, out this.ssh_agent_pid);
|
||||||
|
Environment.SetEnvironmentVariable ("SSH_AGENT_PID", ssh_pid);
|
||||||
|
|
||||||
|
SparkleHelpers.DebugInfo ("Controller",
|
||||||
|
"ssh-agent started, PID=" + ssh_pid);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SparkleHelpers.DebugInfo ("Controller", "ssh-agent started, PID=unknown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void KillSshAgent ()
|
|
||||||
|
private void StopSSH ()
|
||||||
{
|
{
|
||||||
if (sshAgentPid != 0) {
|
if (ssh_agent_pid != 0) {
|
||||||
// Kill the SSH_AGENT that we started
|
|
||||||
try {
|
try {
|
||||||
Process.GetProcessById (sshAgentPid).Kill ();
|
Process.GetProcessById (this.ssh_agent_pid).Kill ();
|
||||||
|
|
||||||
} catch (ArgumentException) {
|
} catch (ArgumentException) {
|
||||||
SparkleHelpers.DebugInfo ("SSH", "Could not kill the ssh-agent, because the process wasn't running");
|
SparkleHelpers.DebugInfo ("SSH",
|
||||||
|
"Could not stop SSH: the process isn't running");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue