[controller] SetProcessName belongs to SS main class

This commit is contained in:
Hylke Bons 2010-11-18 00:51:34 +00:00
parent ea4a77390f
commit 390c1f3bdb
3 changed files with 35 additions and 34 deletions

View file

@ -15,14 +15,11 @@
// 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;
using Mono.Unix.Native;
using SparkleLib; using SparkleLib;
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.Text;
using System.Threading; using System.Threading;
namespace SparkleShare { namespace SparkleShare {
@ -64,8 +61,6 @@ namespace SparkleShare {
public SparkleController () public SparkleController ()
{ {
SetProcessName ("sparkleshare");
InstallLauncher (); InstallLauncher ();
EnableSystemAutostart (); EnableSystemAutostart ();
@ -622,32 +617,6 @@ namespace SparkleShare {
} }
// Sets the unix process name to 'sparkleshare' instead of 'mono'
private void SetProcessName (string name)
{
try {
if (prctl (15, Encoding.ASCII.GetBytes (name + "\0"), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) != 0) {
throw new ApplicationException ("Error setting process name: " +
Mono.Unix.Native.Stdlib.GetLastError ());
}
} catch (EntryPointNotFoundException) {
Console.WriteLine ("SetProcessName: Entry point not found");
}
}
// Strange magic needed by SetProcessName
[DllImport ("libc")]
private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
// Quits the program // Quits the program
public void Quit () public void Quit ()
{ {

View file

@ -769,10 +769,10 @@ namespace SparkleShare {
// Checks to see if an email address is valid // Checks to see if an email address is valid
private bool IsValidEmail(string email) private bool IsValidEmail (string email)
{ {
Regex regex = new Regex(@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", RegexOptions.IgnoreCase); Regex regex = new Regex (@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", RegexOptions.IgnoreCase);
return regex.IsMatch (email); return regex.IsMatch (email);
} }

View file

@ -16,12 +16,15 @@
using Gtk; using Gtk;
using Mono.Unix; 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 SparkleLib; using SparkleLib;
using SparkleLib.Options; using SparkleLib.Options;
using System.Text;
namespace SparkleShare { namespace SparkleShare {
@ -42,6 +45,8 @@ namespace SparkleShare {
public static void Main (string [] args) public static void Main (string [] args)
{ {
SetProcessName ("sparkleshare");
// Use translations // Use translations
Catalog.Init (Defines.GETTEXT_PACKAGE, Defines.LOCALE_DIR); Catalog.Init (Defines.GETTEXT_PACKAGE, Defines.LOCALE_DIR);
@ -138,6 +143,33 @@ namespace SparkleShare {
} }
// Sets the unix process name to 'sparkleshare' instead of 'mono'
private static void SetProcessName (string name)
{
try {
if (prctl (15, Encoding.ASCII.GetBytes (name + "\0"), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) != 0) {
throw new ApplicationException ("Error setting process name: " +
Mono.Unix.Native.Stdlib.GetLastError ());
}
} catch (EntryPointNotFoundException) {
Console.WriteLine ("SetProcessName: Entry point not found");
}
}
// Strange magic needed by SetProcessName
[DllImport ("libc")]
private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
} }
} }