controller: code cleanup

This commit is contained in:
Hylke Bons 2012-07-19 21:54:59 +02:00
parent 6d6975cb6b
commit 91c10c6cf6
3 changed files with 40 additions and 79 deletions

View file

@ -25,6 +25,10 @@ namespace SparkleShare {
public class SparkleController : SparkleControllerBase {
public SparkleController () : base ()
{
}
public override string PluginsPath {
get {
@ -33,19 +37,12 @@ namespace SparkleShare {
}
public SparkleController () : base ()
{
}
// Creates a .desktop entry in autostart folder to
// start SparkleShare automatically at login
public override void CreateStartupItem ()
{
string autostart_path = Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
"autostart"
);
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), "autostart");
string desktopfile_path = Path.Combine (autostart_path, "sparkleshare.desktop");
@ -89,10 +86,8 @@ namespace SparkleShare {
process.Start ();
process.WaitForExit ();
// ...and enable it
process.StartInfo.Arguments =
"-s /desktop/gnome/url-handlers/sparkleshare/enabled --type Boolean true";
process.StartInfo.Arguments = "-s /desktop/gnome/url-handlers/sparkleshare/enabled --type Boolean true";
process.Start ();
process.WaitForExit ();
@ -108,22 +103,16 @@ namespace SparkleShare {
public override void AddToBookmarks ()
{
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)) {
StreamReader reader = new StreamReader (bookmarks_file_path);
string bookmarks = reader.ReadToEnd ();
reader.Close ();
string bookmarks = File.ReadAllText (bookmarks_file_path);
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 {
StreamWriter writer = new StreamWriter (bookmarks_file_path);
writer.WriteLine ("file://" + SparkleConfig.DefaultConfig.FoldersPath + " SparkleShare");
writer.Close ();
File.WriteAllText (bookmarks_file_path, "file://" + FoldersPath + " SparkleShare");
}
}
@ -132,29 +121,29 @@ namespace SparkleShare {
public override bool CreateSparkleShareFolder ()
{
if (!Directory.Exists (SparkleConfig.DefaultConfig.FoldersPath)) {
Directory.CreateDirectory (SparkleConfig.DefaultConfig.FoldersPath);
SparkleHelpers.DebugInfo ("Controller", "Created '" + SparkleConfig.DefaultConfig.FoldersPath + "'");
string gvfs_command_path =
new string [] {Path.VolumeSeparatorChar.ToString (),
"usr", "bin", "gvfs-set-attribute"}.Combine ();
string gvfs_command_path = new string [] { Path.VolumeSeparatorChar.ToString (),
"usr", "bin", "gvfs-set-attribute" }.Combine ();
// Add a special icon to the SparkleShare folder
if (File.Exists (gvfs_command_path)) {
Process process = new Process ();
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = "gvfs-set-attribute";
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = "gvfs-set-attribute";
// 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.WaitForExit ();
// 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.WaitForExit ();
}
@ -168,28 +157,26 @@ namespace SparkleShare {
public override string EventLogHTML {
get {
string html_path = new string [] {Defines.PREFIX, "share",
"sparkleshare", "html", "event-log.html"}.Combine ();
string html_path = new string [] { Defines.PREFIX, "share",
"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);
html = html.Replace ("<!-- $jquery -->", jquery);
return html;
return html.Replace ("<!-- $jquery -->", jquery);
}
}
public override string DayEntryHTML {
get {
string path = new string [] {Defines.PREFIX,
"share", "sparkleshare", "html", "day-entry.html"}.Combine ();
string path = new string [] { Defines.PREFIX, "share",
"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,
"share", "sparkleshare", "html", "event-entry.html"}.Combine ();
return String.Join (Environment.NewLine, File.ReadAllLines (path));
return File.ReadAllText (path);
}
}

View file

@ -39,8 +39,7 @@ namespace SparkleShare {
public static SparkleSetup Setup;
public static SparkleAbout About;
public static string AssetsPath =
new string [] {Defines.PREFIX, "share", "sparkleshare"}.Combine ();
public static string AssetsPath = new string [] { Defines.PREFIX, "share", "sparkleshare" }.Combine ();
public SparkleUI ()

View file

@ -44,9 +44,7 @@ namespace SparkleShare {
public override string PluginsPath
{
get {
return Path.Combine (
Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location), "plugins"
);
return Path.Combine (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location), "plugins");
}
}
@ -75,9 +73,7 @@ namespace SparkleShare {
public override string EventLogHTML {
get {
string html = SparkleUIHelpers.GetHTML ("event-log.html");
html = html.Replace ("<!-- $jquery -->", SparkleUIHelpers.GetHTML ("jquery.js"));
return html;
return html.Replace ("<!-- $jquery -->", SparkleUIHelpers.GetHTML ("jquery.js"));
}
}
@ -98,10 +94,8 @@ namespace SparkleShare {
public override void CreateStartupItem ()
{
string startup_folder_path = Environment.GetFolderPath (
Environment.SpecialFolder.Startup);
string shortcut_path = Path.Combine (startup_folder_path, "SparkleShare.lnk");
string startup_folder_path = Environment.GetFolderPath (Environment.SpecialFolder.Startup);
string shortcut_path = Path.Combine (startup_folder_path, "SparkleShare.lnk");
if (File.Exists (shortcut_path))
File.Delete (shortcut_path);
@ -115,26 +109,7 @@ namespace SparkleShare {
public override void InstallProtocolHandler ()
{
/* FIXME: Need to find a way to do this without administrator privileges (or move to the installer)
// 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\"");
*/
// We ship a separate .exe for this
}
@ -180,7 +155,7 @@ namespace SparkleShare {
process.StartInfo.FileName = "explorer";
process.StartInfo.Arguments = path;
process.Start();
process.Start ();
}