From afdcb58c8303eae89823b8af731b5ffb8661975c Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Mon, 31 May 2010 21:24:42 +0200 Subject: [PATCH] fix coding style --- SparkleShare/SparkleDialog.cs | 6 +- SparkleShare/SparkleHelpers.cs | 2 +- SparkleShare/SparklePaths.cs | 45 +++++++++++++ SparkleShare/SparkleRepo.cs | 64 +++++++++--------- SparkleShare/SparkleShare.cs | 105 ++++++++++++++++++++++++++++++ SparkleShare/SparkleStatusIcon.cs | 8 +-- SparkleShare/SparkleUI.cs | 12 ++-- SparkleShare/SparkleWindow.cs | 12 ++-- 8 files changed, 202 insertions(+), 52 deletions(-) create mode 100644 SparkleShare/SparklePaths.cs create mode 100644 SparkleShare/SparkleShare.cs diff --git a/SparkleShare/SparkleDialog.cs b/SparkleShare/SparkleDialog.cs index ccf6d889..cea05c69 100644 --- a/SparkleShare/SparkleDialog.cs +++ b/SparkleShare/SparkleDialog.cs @@ -123,7 +123,7 @@ namespace SparkleShare { new SparkleBubble (_("Syncing folder ‘") + RepoName + "’", _("SparkleShare will notify you when this is done.")); - Process Process = new Process(); + Process Process = new Process (); Process.EnableRaisingEvents = true; Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.UseShellExecute = false; @@ -152,7 +152,7 @@ namespace SparkleShare { Process.StartInfo.Arguments = SparkleHelpers.CombineMore (SparklePaths.SparklePath, RepoName); - Process.Start(); + Process.Start (); } ); @@ -185,7 +185,7 @@ namespace SparkleShare { Process.StartInfo.Arguments = SparkleHelpers.CombineMore ( SparklePaths.SparklePath, RepoName); - Process.Start(); + Process.Start (); } ); diff --git a/SparkleShare/SparkleHelpers.cs b/SparkleShare/SparkleHelpers.cs index 4f4eda57..87b11025 100644 --- a/SparkleShare/SparkleHelpers.cs +++ b/SparkleShare/SparkleHelpers.cs @@ -75,7 +75,7 @@ namespace SparkleShare { MD5 md5 = new MD5CryptoServiceProvider (); Byte[] Bytes = ASCIIEncoding.Default.GetBytes (s); Byte[] EncodedBytes = md5.ComputeHash (Bytes); - return BitConverter.ToString(EncodedBytes).ToLower ().Replace ("-", ""); + return BitConverter.ToString (EncodedBytes).ToLower ().Replace ("-", ""); } // Makes it possible to combine more than diff --git a/SparkleShare/SparklePaths.cs b/SparkleShare/SparklePaths.cs new file mode 100644 index 00000000..b7432bc7 --- /dev/null +++ b/SparkleShare/SparklePaths.cs @@ -0,0 +1,45 @@ +// SparkleShare, an instant update workflow to Git. +// Copyright (C) 2010 Hylke Bons +// +// 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 . + +using System; +using System.IO; + +namespace SparkleShare { + + public static class SparklePaths { + + public static string SparkleTmpPath = "/tmp/sparkleshare"; + + public static string HomePath = + Environment.GetEnvironmentVariable ("HOME"); + + public static string SparklePath = Path.Combine (HomePath ,"SparkleShare"); + + public static string SparkleConfigPath = + SparkleHelpers.CombineMore (HomePath, ".config", "sparkleshare"); + + public static string SparkleInstallPath = + SparkleHelpers.CombineMore ("usr", "share", "sparkleshare", + "icons", "hicolor"); + + public static string SparkleAvatarPath = + Path.Combine (SparkleConfigPath, "avatars"); + + public static string SparkleIconPath = "/usr/share/icons/hicolor"; + + } + +} diff --git a/SparkleShare/SparkleRepo.cs b/SparkleShare/SparkleRepo.cs index e0ad7175..03cb98eb 100644 --- a/SparkleShare/SparkleRepo.cs +++ b/SparkleShare/SparkleRepo.cs @@ -43,7 +43,7 @@ namespace SparkleShare { public SparkleRepo (string RepoPath) { - Process = new Process(); + Process = new Process (); Process.EnableRaisingEvents = false; Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.UseShellExecute = false; @@ -56,20 +56,20 @@ namespace SparkleShare { UserName = "Anonymous"; Process.StartInfo.FileName = "git"; Process.StartInfo.Arguments = "config --get user.name"; - Process.Start(); + Process.Start (); UserName = Process.StandardOutput.ReadToEnd ().Trim (); // Get user.email, example: "user@github.com" UserEmail = "not.set@git-scm.com"; Process.StartInfo.FileName = "git"; Process.StartInfo.Arguments = "config --get user.email"; - Process.Start(); + Process.Start (); UserEmail = Process.StandardOutput.ReadToEnd ().Trim (); // Get remote.origin.url, example: "ssh://git@github.com/user/repo" Process.StartInfo.FileName = "git"; Process.StartInfo.Arguments = "config --get remote.origin.url"; - Process.Start(); + Process.Start (); RemoteOriginUrl = Process.StandardOutput.ReadToEnd ().Trim (); // Get the repository name, example: "Project" @@ -86,7 +86,7 @@ namespace SparkleShare { // Get hash of the current commit Process.StartInfo.FileName = "git"; Process.StartInfo.Arguments = "rev-list --max-count=1 HEAD"; - Process.Start(); + Process.Start (); CurrentHash = Process.StandardOutput.ReadToEnd ().Trim (); // Watch the repository's folder @@ -94,9 +94,9 @@ namespace SparkleShare { Watcher.IncludeSubdirectories = true; Watcher.EnableRaisingEvents = true; Watcher.Filter = "*"; - Watcher.Changed += new FileSystemEventHandler(OnFileActivity); - Watcher.Created += new FileSystemEventHandler(OnFileActivity); - Watcher.Deleted += new FileSystemEventHandler(OnFileActivity); + Watcher.Changed += new FileSystemEventHandler (OnFileActivity); + Watcher.Created += new FileSystemEventHandler (OnFileActivity); + Watcher.Deleted += new FileSystemEventHandler (OnFileActivity); // Fetch remote changes every 20 seconds FetchTimer = new Timer (); @@ -105,7 +105,7 @@ namespace SparkleShare { Fetch (); }; - FetchTimer.Start(); + FetchTimer.Start (); BufferTimer = new Timer (); BufferTimer.Elapsed += delegate (object o, ElapsedEventArgs args) { @@ -132,7 +132,7 @@ namespace SparkleShare { public void OnFileActivity (object o, FileSystemEventArgs args) { WatcherChangeTypes wct = args.ChangeType; if (!ShouldIgnore (args.Name)) { - Console.WriteLine ("[Event][" + Name + "] " + wct.ToString() + + Console.WriteLine ("[Event][" + Name + "] " + wct.ToString () + " '" + args.Name + "'"); StartBufferTimer (); } @@ -155,7 +155,7 @@ namespace SparkleShare { Console.WriteLine ("[Buffer][" + Name + "] " + "Waiting for more changes..."); - BufferTimer.Start(); + BufferTimer.Start (); } else { @@ -166,7 +166,7 @@ namespace SparkleShare { FetchTimer.Start (); - BufferTimer.Start(); + BufferTimer.Start (); Console.WriteLine ("[Buffer][" + Name + "] " + "Waiting for more changes..."); } @@ -176,13 +176,13 @@ namespace SparkleShare { // Clones a remote repo public void Clone () { Process.StartInfo.Arguments = "clone " + RemoteOriginUrl; - Process.Start(); + Process.Start (); // Add a gitignore file - TextWriter Writer = new StreamWriter(LocalPath + ".gitignore"); - Writer.WriteLine("*~"); // Ignore gedit swap files - Writer.WriteLine(".*.sw?"); // Ignore vi swap files - Writer.Close(); + TextWriter Writer = new StreamWriter (LocalPath + ".gitignore"); + Writer.WriteLine ("*~"); // Ignore gedit swap files + Writer.WriteLine (".*.sw?"); // Ignore vi swap files + Writer.Close (); } // Stages the made changes @@ -190,7 +190,7 @@ namespace SparkleShare { BufferTimer.Stop (); Console.WriteLine ("[Git][" + Name + "] Staging changes..."); Process.StartInfo.Arguments = "add --all"; - Process.Start(); + Process.Start (); Process.WaitForExit (); Console.WriteLine ("[Git][" + Name + "] Changes staged."); // SparkleUI.NotificationIcon.SetSyncingState (); @@ -202,7 +202,7 @@ namespace SparkleShare { Console.WriteLine ("[Commit][" + Name + "] " + Message); Console.WriteLine ("[Git][" + Name + "] Commiting changes..."); Process.StartInfo.Arguments = "commit -m \"" + Message + "\""; - Process.Start(); + Process.Start (); Process.WaitForExit (); Console.WriteLine ("[Git][" + Name + "] Changes commited."); } @@ -213,7 +213,7 @@ namespace SparkleShare { // SparkleUI.NotificationIcon.SetSyncingState (); Console.WriteLine ("[Git][" + Name + "] Fetching changes... "); Process.StartInfo.Arguments = "fetch -v"; - Process.Start(); + Process.Start (); string Output = Process.StandardOutput.ReadToEnd ().Trim (); // TODO: This doesn't work :( Process.WaitForExit (); Console.WriteLine ("[Git][" + Name + "] Changes fetched."); @@ -231,7 +231,7 @@ namespace SparkleShare { Console.WriteLine ("[Git][" + Name + "] Rebasing fetched changes... "); Process.StartInfo.Arguments = "rebase origin"; Process.WaitForExit (); - Process.Start(); + Process.Start (); Console.WriteLine ("[Git][" + Name + "] Changes rebased."); string Output = Process.StandardOutput.ReadToEnd ().Trim (); @@ -244,7 +244,7 @@ namespace SparkleShare { Process.StartInfo.Arguments = "status"; Process.WaitForExit (); - Process.Start(); + Process.Start (); Output = Process.StandardOutput.ReadToEnd ().Trim (); foreach (string Line in Regex.Split (Output, "\n")) { @@ -257,11 +257,11 @@ namespace SparkleShare { Process.StartInfo.Arguments = "checkout --ours " + ProblemFileName; Process.WaitForExit (); - Process.Start(); + Process.Start (); DateTime DateTime = new DateTime (); string TimeStamp = - String.Format("{0:H:mm, d MMM yyyy}", DateTime); + String.Format ("{0:H:mm, d MMM yyyy}", DateTime); File.Move (ProblemFileName, ProblemFileName + " (" + UserName + " - " + @@ -270,7 +270,7 @@ namespace SparkleShare { Process.StartInfo.Arguments = "checkout --theirs " + ProblemFileName; Process.WaitForExit (); - Process.Start(); + Process.Start (); ShowEventBubble ("A mid-air collision happened!\n" + "SparkleShare made a copy of your file.", @@ -285,7 +285,7 @@ namespace SparkleShare { Process.StartInfo.Arguments = "rebase --continue"; Process.WaitForExit (); - Process.Start(); + Process.Start (); Console.WriteLine ("[Git][" + Name + "] Conflict resolved."); Push (); @@ -295,19 +295,19 @@ namespace SparkleShare { // Get the last committer e-mail Process.StartInfo.Arguments = "log --format=\"%ae\" -1"; - Process.Start(); + Process.Start (); string LastCommitEmail = Process.StandardOutput.ReadToEnd ().Trim (); // Get the last commit message Process.StartInfo.Arguments = "log --format=\"%s\" -1"; - Process.Start(); + Process.Start (); string LastCommitMessage = Process.StandardOutput.ReadToEnd ().Trim (); // Get the last commiter Process.StartInfo.Arguments = "log --format=\"%an\" -1"; - Process.Start(); + Process.Start (); string LastCommitUserName = Process.StandardOutput.ReadToEnd ().Trim (); @@ -333,7 +333,7 @@ namespace SparkleShare { public void Push () { Console.WriteLine ("[Git][" + Name + "] Pushing changes..."); Process.StartInfo.Arguments = "push"; - Process.Start(); + Process.Start (); Process.WaitForExit (); Console.WriteLine ("[Git][" + Name + "] Changes pushed."); // SparkleUI.NotificationIcon.SetIdleState (); @@ -366,7 +366,7 @@ namespace SparkleShare { int FilesDeleted = 0; Process.StartInfo.Arguments = "status"; - Process.Start(); + Process.Start (); string Output = Process.StandardOutput.ReadToEnd (); foreach (string Line in Regex.Split (Output, "\n")) { @@ -465,7 +465,7 @@ namespace SparkleShare { break; } Process.StartInfo.Arguments = LocalPath; - Process.Start(); + Process.Start (); Process.StartInfo.FileName = "git"; } ); diff --git a/SparkleShare/SparkleShare.cs b/SparkleShare/SparkleShare.cs new file mode 100644 index 00000000..cded1aed --- /dev/null +++ b/SparkleShare/SparkleShare.cs @@ -0,0 +1,105 @@ +// SparkleShare, an instant update workflow to Git. +// Copyright (C) 2010 Hylke Bons +// +// 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 . + +using Gtk; +using Mono.Unix; +using System; +using System.Diagnostics; + +namespace SparkleShare { + + // This is SparkleShare! + public class SparkleShare { + + // Short alias for the translations + public static string _ (string s) { + return Catalog.GetString (s); + } + + public static SparkleRepo [] Repositories; + public static SparkleUI SparkleUI; + + public static void Main (string [] args) { + + // Use translations + Catalog.Init ("i18n", "locale"); + + // Check if git is installed + Process Process = new Process (); + Process.StartInfo.FileName = "git"; + Process.StartInfo.RedirectStandardOutput = true; + Process.StartInfo.UseShellExecute = false; + Process.Start (); + + if (Process.StandardOutput.ReadToEnd ().IndexOf ("version") == -1) { + Console.WriteLine (_("Git wasn't found.")); + Console.WriteLine (_("You can get Git from http://git-scm.com/.")); + Environment.Exit (0); + } + + // Don't allow running as root + Process.StartInfo.FileName = "whoami"; + Process.Start (); + if (Process.StandardOutput.ReadToEnd ().Trim ().Equals ("root")) { + Console.WriteLine (_("Sorry, you can't run SparkleShare with these permissions.")); + Console.WriteLine (_("Things will go utterly wrong.")); + Environment.Exit (0); + } + + // Parse the command line arguments + bool HideUI = false; + if (args.Length > 0) { + foreach (string Argument in args) { + if (Argument.Equals ("--disable-gui") || Argument.Equals ("-d")) + HideUI = true; + if (Argument.Equals ("--help") || Argument.Equals ("-h")) { + ShowHelp (); + } + } + } + + Gtk.Application.Init (); + + SparkleUI = new SparkleUI (HideUI); + + // The main loop + Gtk.Application.Run (); + + } + + // Prints the help output + public static void ShowHelp () { + Console.WriteLine (_("SparkleShare Copyright (C) 2010 Hylke Bons")); + Console.WriteLine (" "); + Console.WriteLine (_("This program comes with ABSOLUTELY NO WARRANTY.")); + Console.WriteLine (_("This is free software, and you are welcome to redistribute it ")); + Console.WriteLine (_("under certain conditions. Please read the GNU GPLv3 for details.")); + Console.WriteLine (" "); + Console.WriteLine (_("SparkleShare syncs the ~/SparkleShare folder with remote repositories.")); + Console.WriteLine (" "); + Console.WriteLine (_("Usage: sparkleshare [start|stop|restart] [OPTION]...")); + Console.WriteLine (_("Sync SparkleShare folder with remote repositories.")); + Console.WriteLine (" "); + Console.WriteLine (_("Arguments:")); + Console.WriteLine (_("\t -d, --disable-gui\tDon't show the notification icon.")); + Console.WriteLine (_("\t -h, --help\t\tDisplay this help text.")); + Console.WriteLine (" "); + Environment.Exit (0); + } + + } + +} diff --git a/SparkleShare/SparkleStatusIcon.cs b/SparkleShare/SparkleStatusIcon.cs index e61d13c2..0d0289bc 100644 --- a/SparkleShare/SparkleStatusIcon.cs +++ b/SparkleShare/SparkleStatusIcon.cs @@ -46,14 +46,14 @@ namespace SparkleShare { Activate += delegate { - Menu Menu = new Menu(); + Menu Menu = new Menu (); MenuItem StatusItem = new MenuItem (_("Everything is up to date")); StatusItem.Sensitive = false; Menu.Add (StatusItem); Menu.Add (new SeparatorMenuItem ()); - Action FolderAction = new Action("", "SparkleShare Folder"); + Action FolderAction = new Action ("", "SparkleShare Folder"); FolderAction.IconName = "folder-sparkleshare"; FolderAction.IsImportant = true; FolderAction.Activated += delegate { @@ -67,7 +67,7 @@ namespace SparkleShare { break; } Process.StartInfo.Arguments = SparklePaths.SparklePath; - Process.Start(); + Process.Start (); }; Menu.Add (FolderAction.CreateMenuItem ()); @@ -76,7 +76,7 @@ namespace SparkleShare { int i = 0; foreach (SparkleRepo SparkleRepo in SparkleShare.Repositories) { - FolderItems [i] = new Action("", SparkleRepo.Name); + FolderItems [i] = new Action ("", SparkleRepo.Name); FolderItems [i].IconName = "folder"; FolderItems [i].IsImportant = true; FolderItems [i].Activated += CreateWindowDelegate (SparkleRepo); diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index dca53d95..70b23b8f 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -28,7 +28,7 @@ namespace SparkleShare { public SparkleUI (bool HideUI) { - Process Process = new Process(); + Process Process = new Process (); Process.EnableRaisingEvents = false; Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.UseShellExecute = false; @@ -53,7 +53,7 @@ namespace SparkleShare { "folder-sparkleshare.png"; break; } - Process.Start(); + Process.Start (); // Add the SparkleShare folder to the bookmarks switch (SparklePlatform.Name) { @@ -64,7 +64,7 @@ namespace SparkleShare { if (File.Exists (BookmarksFileName)) { TextWriter TextWriter = File.AppendText (BookmarksFileName); TextWriter.WriteLine ("file://" + SparklePath + " SparkleShare"); - TextWriter.Close(); + TextWriter.Close (); } break; @@ -100,7 +100,7 @@ namespace SparkleShare { "[synced]"; break; } - Process.Start(); + Process.Start (); } @@ -127,7 +127,7 @@ namespace SparkleShare { SparkleDialog.ShowAll (); /* Process.StartInfo.FileName = "xdg-open"; Process.StartInfo.Arguments = SparklePaths.SparklePath; - Process.Start(); + Process.Start (); */ } ); @@ -145,7 +145,7 @@ namespace SparkleShare { Watcher.EnableRaisingEvents = true; Watcher.Created += delegate (object o, FileSystemEventArgs args) { WatcherChangeTypes wct = args.ChangeType; - Console.WriteLine ("[Event][SparkleShare] " + wct.ToString() + + Console.WriteLine ("[Event][SparkleShare] " + wct.ToString () + " '" + args.Name + "'"); SparkleDialog SparkleDialog = new SparkleDialog (); SparkleDialog.ShowAll (); diff --git a/SparkleShare/SparkleWindow.cs b/SparkleShare/SparkleWindow.cs index 4f1fd724..32ab5f45 100644 --- a/SparkleShare/SparkleWindow.cs +++ b/SparkleShare/SparkleWindow.cs @@ -100,7 +100,7 @@ namespace SparkleShare { typeof (string), typeof (string)); - Process Process = new Process(); + Process Process = new Process (); Process.EnableRaisingEvents = false; Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.UseShellExecute = false; @@ -112,9 +112,9 @@ namespace SparkleShare { // We're using the snowman here to separate messages :) Process.StartInfo.Arguments = "log --format=\"%at☃%s☃%an☃%cr☃%ae\" -25"; - Process.Start(); + Process.Start (); - Output += "\n" + Process.StandardOutput.ReadToEnd().Trim (); + Output += "\n" + Process.StandardOutput.ReadToEnd ().Trim (); Output = Output.TrimStart ("\n".ToCharArray ()); string [] Lines = Regex.Split (Output, "\n"); @@ -189,7 +189,7 @@ namespace SparkleShare { Columns [2].Expand = true; Columns [1].MinWidth = 350; - LogView.CursorChanged += delegate(object o, EventArgs args) { + LogView.CursorChanged += delegate (object o, EventArgs args) { TreeModel Model; if (LogView.Selection.GetSelected (out Model, out Iter)) { SelectedEmail = (string) Model.GetValue (Iter, 4); @@ -216,9 +216,9 @@ namespace SparkleShare { Process.StartInfo.FileName = "git"; Process.StartInfo.Arguments = "log --format=\"%an☃%ae\" -50"; Process.StartInfo.WorkingDirectory = SparkleRepo.LocalPath; - Process.Start(); + Process.Start (); - string Output = Process.StandardOutput.ReadToEnd().Trim (); + string Output = Process.StandardOutput.ReadToEnd ().Trim (); string [] People = new string [50]; string [] Lines = Regex.Split (Output, "\n");