From bfaa142e101a53962231a105714dfdb5ba1701c8 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 3 Jul 2010 19:33:42 +0100 Subject: [PATCH] Add help for sparklediff command and make it consistent with that of sparkleshare --- SparkleDiff/SparkleDiff.cs | 59 +++++++++++++++++-- SparkleShare/SparkleShare.cs | 107 +++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 4 deletions(-) create mode 100644 SparkleShare/SparkleShare.cs diff --git a/SparkleDiff/SparkleDiff.cs b/SparkleDiff/SparkleDiff.cs index 878ee038..cef68eb7 100644 --- a/SparkleDiff/SparkleDiff.cs +++ b/SparkleDiff/SparkleDiff.cs @@ -26,11 +26,43 @@ namespace SparkleShare { public class SparkleDiff { + // Short alias for the translations + public static string _ (string s) + { + return Catalog.GetString (s); + } + public static void Main (string [] args) { + Catalog.Init (Defines.GETTEXT_PACKAGE, Defines.LOCALE_DIR); + // Check whether 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 + UnixUserInfo UnixUserInfo = new UnixUserInfo (UnixEnvironment.UserName); + if (UnixUserInfo.UserId == 0) { + Console.WriteLine (_("Sorry, you can't run SparkleShare with these permissions.")); + Console.WriteLine (_("Things would go utterly wrong.")); + Environment.Exit (0); + } + if (args.Length > 0) { + if (args [0].Equals ("--help") || args [0].Equals ("-h")) { + ShowHelp (); + Environment.Exit (0); + } string file_path = args [0]; @@ -56,6 +88,25 @@ namespace SparkleShare { } + // Prints the help output + public static void ShowHelp () + { + Console.WriteLine (_("SparkleDiff 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 (_("SparkleDiff let's you compare revisions of an image file side by side.")); + Console.WriteLine (" "); + Console.WriteLine (_("Usage: sparklediff [FILE]")); + Console.WriteLine (_("Open an image file to show its revisions")); + Console.WriteLine (" "); + Console.WriteLine (_("Arguments:")); + Console.WriteLine (_("\t -h, --help\t\tDisplay this help text.")); + Console.WriteLine (" "); + } + } @@ -223,7 +274,7 @@ namespace SparkleShare { private void SyncViewsVertically (object o, EventArgs args) { Adjustment source_adjustment = (Adjustment) o; - + if (source_adjustment == ViewLeft.ScrolledWindow.Vadjustment) ViewRight.ScrolledWindow.Vadjustment = source_adjustment; else @@ -315,7 +366,7 @@ namespace SparkleShare { public Button ButtonPrevious; public Button ButtonNext; - private int ValueCount; +// private int ValueCount; private Image Image; public RevisionView (string [] revisions) : base (false, 6) @@ -335,7 +386,7 @@ namespace SparkleShare { ButtonPrevious = new Button (image_previous); ButtonPrevious.Clicked += PreviousInComboBox; - ValueCount = 0; +// ValueCount = 0; ComboBox = ComboBox.NewText (); @@ -345,7 +396,7 @@ namespace SparkleShare { ComboBox.Active = 0; - ValueCount = revisions.Length; +// ValueCount = revisions.Length; Image image_next = new Image (); image_next.IconName = "go-next"; diff --git a/SparkleShare/SparkleShare.cs b/SparkleShare/SparkleShare.cs new file mode 100644 index 00000000..350f0bc6 --- /dev/null +++ b/SparkleShare/SparkleShare.cs @@ -0,0 +1,107 @@ +// 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 (Defines.GETTEXT_PACKAGE, Defines.LOCALE_DIR); + + // Check whether 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 + UnixUserInfo UnixUserInfo = new UnixUserInfo (UnixEnvironment.UserName); + if (UnixUserInfo.UserId == 0) { + Console.WriteLine (_("Sorry, you can't run SparkleShare with these permissions.")); + Console.WriteLine (_("Things would 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 (); + Environment.Exit (0); + } + } + } + + 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 (" "); + } + + } + +}