main method: fix coding style and whitespace
This commit is contained in:
parent
e067cc30eb
commit
1a8e7925c4
|
@ -14,17 +14,18 @@
|
||||||
// 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 Mono.Unix;
|
|
||||||
using Mono.Unix.Native;
|
|
||||||
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.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using SparkleLib;
|
|
||||||
using SparkleLib.Options;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
using Mono.Unix;
|
||||||
|
using Mono.Unix.Native;
|
||||||
|
using SparkleLib;
|
||||||
|
using SparkleLib.Options;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
|
@ -44,22 +45,16 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public static void Main (string [] args)
|
public static void Main (string [] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Use translations
|
// Use translations
|
||||||
Catalog.Init (Defines.GETTEXT_PACKAGE, Defines.LOCALE_DIR);
|
Catalog.Init (Defines.GETTEXT_PACKAGE, Defines.LOCALE_DIR);
|
||||||
|
|
||||||
|
|
||||||
// Don't allow running as root
|
// Don't allow running as root
|
||||||
if (new UnixUserInfo (UnixEnvironment.UserName).UserId == 0) {
|
if (new UnixUserInfo (UnixEnvironment.UserName).UserId == 0) {
|
||||||
|
|
||||||
Console.WriteLine (_("Sorry, you can't run SparkleShare with these permissions."));
|
Console.WriteLine (_("Sorry, you can't run SparkleShare with these permissions."));
|
||||||
Console.WriteLine (_("Things would go utterly wrong."));
|
Console.WriteLine (_("Things would go utterly wrong."));
|
||||||
|
|
||||||
Environment.Exit (0);
|
Environment.Exit (0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Parse the command line options
|
// Parse the command line options
|
||||||
bool hide_ui = false;
|
bool hide_ui = false;
|
||||||
bool show_help = false;
|
bool show_help = false;
|
||||||
|
@ -71,64 +66,49 @@ namespace SparkleShare {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
p.Parse (args);
|
p.Parse (args);
|
||||||
|
|
||||||
} catch (OptionException e) {
|
} catch (OptionException e) {
|
||||||
|
|
||||||
Console.Write ("SparkleShare: ");
|
Console.Write ("SparkleShare: ");
|
||||||
Console.WriteLine (e.Message);
|
Console.WriteLine (e.Message);
|
||||||
Console.WriteLine ("Try `sparkleshare --help' for more information.");
|
Console.WriteLine ("Try `sparkleshare --help' for more information.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_help)
|
if (show_help)
|
||||||
ShowHelp (p);
|
ShowHelp (p);
|
||||||
|
|
||||||
|
|
||||||
// Load the right controller for the OS
|
// Load the right controller for the OS
|
||||||
string controller_name;
|
string controller_name;
|
||||||
switch (SparkleShare.Platform) {
|
switch (SparkleShare.Platform) {
|
||||||
|
|
||||||
case PlatformID.Unix:
|
case PlatformID.Unix:
|
||||||
SetProcessName ("sparkleshare");
|
SetProcessName ("sparkleshare");
|
||||||
controller_name = "Lin";
|
controller_name = "Lin";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PlatformID.MacOSX:
|
case PlatformID.MacOSX:
|
||||||
controller_name = "Mac";
|
controller_name = "Mac";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PlatformID.Win32NT:
|
case PlatformID.Win32NT:
|
||||||
controller_name = "Win";
|
controller_name = "Win";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
controller_name = "Lin";
|
controller_name = "Lin";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialize the controller this way so that
|
// Initialize the controller this way so that
|
||||||
// there aren't any exceptions in the OS specific UI's
|
// there aren't any exceptions in the OS specific UI's
|
||||||
Controller = (SparkleController) Activator.CreateInstance (
|
Controller = (SparkleController) Activator.CreateInstance (
|
||||||
Type.GetType ("SparkleShare.Sparkle" + controller_name + "Controller"));
|
Type.GetType ("SparkleShare.Sparkle" + controller_name + "Controller"));
|
||||||
|
|
||||||
if (Controller != null && !hide_ui) {
|
if (Controller != null && !hide_ui) {
|
||||||
|
|
||||||
UI = new SparkleUI ();
|
UI = new SparkleUI ();
|
||||||
UI.Run ();
|
UI.Run ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Prints the help output
|
// Prints the help output
|
||||||
public static void ShowHelp (OptionSet option_set)
|
public static void ShowHelp (OptionSet option_set)
|
||||||
{
|
{
|
||||||
|
|
||||||
Console.WriteLine (" ");
|
Console.WriteLine (" ");
|
||||||
Console.WriteLine (_("SparkleShare, an instant update workflow to Git."));
|
Console.WriteLine (_("SparkleShare, an instant update workflow to Git."));
|
||||||
Console.WriteLine (_("Copyright (C) 2010 Hylke Bons"));
|
Console.WriteLine (_("Copyright (C) 2010 Hylke Bons"));
|
||||||
|
@ -148,17 +128,14 @@ namespace SparkleShare {
|
||||||
|
|
||||||
option_set.WriteOptionDescriptions (Console.Out);
|
option_set.WriteOptionDescriptions (Console.Out);
|
||||||
Environment.Exit (0);
|
Environment.Exit (0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Prints the version information
|
// Prints the version information
|
||||||
public static void PrintVersion ()
|
public static void PrintVersion ()
|
||||||
{
|
{
|
||||||
|
|
||||||
Console.WriteLine (_("SparkleShare " + Defines.VERSION));
|
Console.WriteLine (_("SparkleShare " + Defines.VERSION));
|
||||||
Environment.Exit (0);
|
Environment.Exit (0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -170,22 +147,14 @@ namespace SparkleShare {
|
||||||
// Sets the Unix process name to 'sparkleshare' instead of 'mono'
|
// Sets the Unix process name to 'sparkleshare' instead of 'mono'
|
||||||
private static void SetProcessName (string name)
|
private static void SetProcessName (string name)
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (prctl (15, Encoding.ASCII.GetBytes (name + "\0"), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) != 0) {
|
if (prctl (15, Encoding.ASCII.GetBytes (name + "\0"), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) != 0) {
|
||||||
|
|
||||||
throw new ApplicationException ("Error setting process name: " +
|
throw new ApplicationException ("Error setting process name: " +
|
||||||
Mono.Unix.Native.Stdlib.GetLastError ());
|
Mono.Unix.Native.Stdlib.GetLastError ());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (EntryPointNotFoundException) {
|
} catch (EntryPointNotFoundException) {
|
||||||
|
|
||||||
Console.WriteLine ("SetProcessName: Entry point not found");
|
Console.WriteLine ("SetProcessName: Entry point not found");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -197,33 +166,21 @@ namespace SparkleShare {
|
||||||
// This fixes the PlatformID enumeration for MacOSX in Environment.OSVersion.Platform,
|
// This fixes the PlatformID enumeration for MacOSX in Environment.OSVersion.Platform,
|
||||||
// which is intentionally broken in Mono for hystorical reasons
|
// which is intentionally broken in Mono for hystorical reasons
|
||||||
static PlatformID Platform {
|
static PlatformID Platform {
|
||||||
|
|
||||||
get {
|
get {
|
||||||
|
|
||||||
IntPtr buf = IntPtr.Zero;
|
IntPtr buf = IntPtr.Zero;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
buf = Marshal.AllocHGlobal (8192);
|
buf = Marshal.AllocHGlobal (8192);
|
||||||
|
|
||||||
if (uname (buf) == 0 && Marshal.PtrToStringAnsi (buf) == "Darwin")
|
if (uname (buf) == 0 && Marshal.PtrToStringAnsi (buf) == "Darwin")
|
||||||
return PlatformID.MacOSX;
|
return PlatformID.MacOSX;
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
if (buf != IntPtr.Zero)
|
if (buf != IntPtr.Zero)
|
||||||
Marshal.FreeHGlobal (buf);
|
Marshal.FreeHGlobal (buf);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Environment.OSVersion.Platform;
|
return Environment.OSVersion.Platform;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue