controller: code cleanup
This commit is contained in:
parent
6d6975cb6b
commit
91c10c6cf6
|
@ -25,6 +25,10 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public class SparkleController : SparkleControllerBase {
|
public class SparkleController : SparkleControllerBase {
|
||||||
|
|
||||||
|
public SparkleController () : base ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public override string PluginsPath {
|
public override string PluginsPath {
|
||||||
get {
|
get {
|
||||||
|
@ -33,19 +37,12 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SparkleController () : base ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Creates a .desktop entry in autostart folder to
|
// Creates a .desktop entry in autostart folder to
|
||||||
// start SparkleShare automatically at login
|
// start SparkleShare automatically at login
|
||||||
public override void CreateStartupItem ()
|
public override void CreateStartupItem ()
|
||||||
{
|
{
|
||||||
string autostart_path = Path.Combine (
|
string autostart_path = Path.Combine (
|
||||||
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
|
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), "autostart");
|
||||||
"autostart"
|
|
||||||
);
|
|
||||||
|
|
||||||
string desktopfile_path = Path.Combine (autostart_path, "sparkleshare.desktop");
|
string desktopfile_path = Path.Combine (autostart_path, "sparkleshare.desktop");
|
||||||
|
|
||||||
|
@ -89,10 +86,8 @@ namespace SparkleShare {
|
||||||
process.Start ();
|
process.Start ();
|
||||||
process.WaitForExit ();
|
process.WaitForExit ();
|
||||||
|
|
||||||
|
|
||||||
// ...and enable it
|
// ...and enable it
|
||||||
process.StartInfo.Arguments =
|
process.StartInfo.Arguments = "-s /desktop/gnome/url-handlers/sparkleshare/enabled --type Boolean true";
|
||||||
"-s /desktop/gnome/url-handlers/sparkleshare/enabled --type Boolean true";
|
|
||||||
|
|
||||||
process.Start ();
|
process.Start ();
|
||||||
process.WaitForExit ();
|
process.WaitForExit ();
|
||||||
|
@ -108,22 +103,16 @@ namespace SparkleShare {
|
||||||
public override void AddToBookmarks ()
|
public override void AddToBookmarks ()
|
||||||
{
|
{
|
||||||
string bookmarks_file_path = Path.Combine (SparkleConfig.DefaultConfig.HomePath, ".gtk-bookmarks");
|
string bookmarks_file_path = Path.Combine (SparkleConfig.DefaultConfig.HomePath, ".gtk-bookmarks");
|
||||||
string sparkleshare_bookmark = "file://" + SparkleConfig.DefaultConfig.FoldersPath + " SparkleShare";
|
string sparkleshare_bookmark = "file://" + FoldersPath + " SparkleShare";
|
||||||
|
|
||||||
if (File.Exists (bookmarks_file_path)) {
|
if (File.Exists (bookmarks_file_path)) {
|
||||||
StreamReader reader = new StreamReader (bookmarks_file_path);
|
string bookmarks = File.ReadAllText (bookmarks_file_path);
|
||||||
string bookmarks = reader.ReadToEnd ();
|
|
||||||
reader.Close ();
|
if (!bookmarks.Contains (sparkleshare_bookmark))
|
||||||
|
File.AppendAllText (bookmarks_file_path, "file://" + FoldersPath + " SparkleShare");
|
||||||
|
|
||||||
if (!bookmarks.Contains (sparkleshare_bookmark)) {
|
|
||||||
TextWriter writer = File.AppendText (bookmarks_file_path);
|
|
||||||
writer.WriteLine ("file://" + SparkleConfig.DefaultConfig.FoldersPath + " SparkleShare");
|
|
||||||
writer.Close ();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
StreamWriter writer = new StreamWriter (bookmarks_file_path);
|
File.WriteAllText (bookmarks_file_path, "file://" + FoldersPath + " SparkleShare");
|
||||||
writer.WriteLine ("file://" + SparkleConfig.DefaultConfig.FoldersPath + " SparkleShare");
|
|
||||||
writer.Close ();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,29 +121,29 @@ namespace SparkleShare {
|
||||||
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);
|
||||||
SparkleHelpers.DebugInfo ("Controller", "Created '" + SparkleConfig.DefaultConfig.FoldersPath + "'");
|
SparkleHelpers.DebugInfo ("Controller", "Created '" + SparkleConfig.DefaultConfig.FoldersPath + "'");
|
||||||
|
|
||||||
string gvfs_command_path =
|
string gvfs_command_path = new string [] { Path.VolumeSeparatorChar.ToString (),
|
||||||
new string [] {Path.VolumeSeparatorChar.ToString (),
|
"usr", "bin", "gvfs-set-attribute" }.Combine ();
|
||||||
"usr", "bin", "gvfs-set-attribute"}.Combine ();
|
|
||||||
|
|
||||||
// Add a special icon to the SparkleShare folder
|
// Add a special icon to the SparkleShare folder
|
||||||
if (File.Exists (gvfs_command_path)) {
|
if (File.Exists (gvfs_command_path)) {
|
||||||
Process process = new Process ();
|
Process process = new Process ();
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
process.StartInfo.FileName = "gvfs-set-attribute";
|
||||||
process.StartInfo.UseShellExecute = false;
|
|
||||||
process.StartInfo.FileName = "gvfs-set-attribute";
|
|
||||||
|
|
||||||
// Clear the custom (legacy) icon path
|
// Clear the custom (legacy) icon path
|
||||||
process.StartInfo.Arguments = "-t unset " + SparkleConfig.DefaultConfig.FoldersPath + " metadata::custom-icon";
|
process.StartInfo.Arguments = "-t unset " +
|
||||||
|
SparkleConfig.DefaultConfig.FoldersPath + " metadata::custom-icon";
|
||||||
|
|
||||||
process.Start ();
|
process.Start ();
|
||||||
process.WaitForExit ();
|
process.WaitForExit ();
|
||||||
|
|
||||||
// Give the SparkleShare folder an icon name, so that it scales
|
// Give the SparkleShare folder an icon name, so that it scales
|
||||||
process.StartInfo.Arguments = SparkleConfig.DefaultConfig.FoldersPath + " metadata::custom-icon-name 'folder-sparkleshare'";
|
process.StartInfo.Arguments = SparkleConfig.DefaultConfig.FoldersPath +
|
||||||
|
" metadata::custom-icon-name 'folder-sparkleshare'";
|
||||||
|
|
||||||
process.Start ();
|
process.Start ();
|
||||||
process.WaitForExit ();
|
process.WaitForExit ();
|
||||||
}
|
}
|
||||||
|
@ -168,28 +157,26 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public override string EventLogHTML {
|
public override string EventLogHTML {
|
||||||
get {
|
get {
|
||||||
string html_path = new string [] {Defines.PREFIX, "share",
|
string html_path = new string [] { Defines.PREFIX, "share",
|
||||||
"sparkleshare", "html", "event-log.html"}.Combine ();
|
"sparkleshare", "html", "event-log.html" }.Combine ();
|
||||||
|
|
||||||
string html = File.ReadAllText (html_path);
|
string jquery_file_path = new string [] { Defines.PREFIX, "share",
|
||||||
|
"sparkleshare", "html", "jquery.js" }.Combine ();
|
||||||
string jquery_file_path = new string [] {Defines.PREFIX, "share",
|
|
||||||
"sparkleshare", "html", "jquery.js"}.Combine ();
|
|
||||||
|
|
||||||
|
string html = File.ReadAllText (html_path);
|
||||||
string jquery = File.ReadAllText (jquery_file_path);
|
string jquery = File.ReadAllText (jquery_file_path);
|
||||||
html = html.Replace ("<!-- $jquery -->", jquery);
|
|
||||||
|
return html.Replace ("<!-- $jquery -->", jquery);
|
||||||
return html;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override string DayEntryHTML {
|
public override string DayEntryHTML {
|
||||||
get {
|
get {
|
||||||
string path = new string [] {Defines.PREFIX,
|
string path = new string [] { Defines.PREFIX, "share",
|
||||||
"share", "sparkleshare", "html", "day-entry.html"}.Combine ();
|
"sparkleshare", "html", "day-entry.html" }.Combine ();
|
||||||
|
|
||||||
return String.Join (Environment.NewLine, File.ReadAllLines (path));
|
return File.ReadAllText (path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +186,7 @@ namespace SparkleShare {
|
||||||
string path = new string [] {Defines.PREFIX,
|
string path = new string [] {Defines.PREFIX,
|
||||||
"share", "sparkleshare", "html", "event-entry.html"}.Combine ();
|
"share", "sparkleshare", "html", "event-entry.html"}.Combine ();
|
||||||
|
|
||||||
return String.Join (Environment.NewLine, File.ReadAllLines (path));
|
return File.ReadAllText (path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,7 @@ namespace SparkleShare {
|
||||||
public static SparkleSetup Setup;
|
public static SparkleSetup Setup;
|
||||||
public static SparkleAbout About;
|
public static SparkleAbout About;
|
||||||
|
|
||||||
public static string AssetsPath =
|
public static string AssetsPath = new string [] { Defines.PREFIX, "share", "sparkleshare" }.Combine ();
|
||||||
new string [] {Defines.PREFIX, "share", "sparkleshare"}.Combine ();
|
|
||||||
|
|
||||||
|
|
||||||
public SparkleUI ()
|
public SparkleUI ()
|
||||||
|
|
|
@ -44,9 +44,7 @@ namespace SparkleShare {
|
||||||
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"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,9 +73,7 @@ namespace SparkleShare {
|
||||||
public override string EventLogHTML {
|
public override string EventLogHTML {
|
||||||
get {
|
get {
|
||||||
string html = SparkleUIHelpers.GetHTML ("event-log.html");
|
string html = SparkleUIHelpers.GetHTML ("event-log.html");
|
||||||
html = html.Replace ("<!-- $jquery -->", SparkleUIHelpers.GetHTML ("jquery.js"));
|
return html.Replace ("<!-- $jquery -->", SparkleUIHelpers.GetHTML ("jquery.js"));
|
||||||
|
|
||||||
return html;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,10 +94,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public override void CreateStartupItem ()
|
public override void CreateStartupItem ()
|
||||||
{
|
{
|
||||||
string startup_folder_path = Environment.GetFolderPath (
|
string startup_folder_path = Environment.GetFolderPath (Environment.SpecialFolder.Startup);
|
||||||
Environment.SpecialFolder.Startup);
|
string shortcut_path = Path.Combine (startup_folder_path, "SparkleShare.lnk");
|
||||||
|
|
||||||
string shortcut_path = Path.Combine (startup_folder_path, "SparkleShare.lnk");
|
|
||||||
|
|
||||||
if (File.Exists (shortcut_path))
|
if (File.Exists (shortcut_path))
|
||||||
File.Delete (shortcut_path);
|
File.Delete (shortcut_path);
|
||||||
|
@ -115,26 +109,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public override void InstallProtocolHandler ()
|
public override void InstallProtocolHandler ()
|
||||||
{
|
{
|
||||||
/* FIXME: Need to find a way to do this without administrator privileges (or move to the installer)
|
// We ship a separate .exe for this
|
||||||
|
|
||||||
// Get assembly location
|
|
||||||
string location = System.Reflection.Assembly.GetExecutingAssembly ().Location;
|
|
||||||
string folder = Path.GetDirectoryName (location);
|
|
||||||
string invite_exe = Path.Combine (folder, "SparkleShareInviteOpener.exe");
|
|
||||||
|
|
||||||
// Register protocol handler as explained in
|
|
||||||
// http://msdn.microsoft.com/en-us/library/ie/aa767914(v=vs.85).aspx
|
|
||||||
string main_key = "HKEY_CLASSES_ROOT\\sparkleshare";
|
|
||||||
Registry.SetValue (main_key, "", "SparkleShare Invite Opener");
|
|
||||||
Registry.SetValue (main_key, "URL Protocol", "");
|
|
||||||
|
|
||||||
string icon_key = "HKEY_CLASSES_ROOT\\sparkleshare\\DefaultIcon";
|
|
||||||
Registry.SetValue (icon_key, "", invite_exe + ",1");
|
|
||||||
|
|
||||||
string action_key = "HKEY_CLASSES_ROOT\\sparkleshare\\shell\\open\\command";
|
|
||||||
Registry.SetValue (action_key, "", "\"" + invite_exe + "\" \"%1\"");
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,7 +155,7 @@ namespace SparkleShare {
|
||||||
process.StartInfo.FileName = "explorer";
|
process.StartInfo.FileName = "explorer";
|
||||||
process.StartInfo.Arguments = path;
|
process.StartInfo.Arguments = path;
|
||||||
|
|
||||||
process.Start();
|
process.Start ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue