[Slim-Checkins] r11877 - /branches/6.5/platforms/win32/SlimTray.pl

mherger at svn.slimdevices.com mherger at svn.slimdevices.com
Tue May 1 14:06:10 PDT 2007


Author: mherger
Date: Tue May  1 14:06:10 2007
New Revision: 11877

URL: http://svn.slimdevices.com?rev=11877&view=rev
Log:
Bug: n/a
Description: whitespace cleanup

Modified:
    branches/6.5/platforms/win32/SlimTray.pl

Modified: branches/6.5/platforms/win32/SlimTray.pl
URL: http://svn.slimdevices.com/branches/6.5/platforms/win32/SlimTray.pl?rev=11877&r1=11876&r2=11877&view=diff
==============================================================================
--- branches/6.5/platforms/win32/SlimTray.pl (original)
+++ branches/6.5/platforms/win32/SlimTray.pl Tue May  1 14:06:10 2007
@@ -40,8 +40,10 @@
 # To avoid user confusion we therefore disable all options which are not available when running as a normal user.
 #
 # prefs and the Slimserver url are stored in a different location on Vista to avoid Vista file virtualisation.
+
 my $vista          = ((Win32::GetOSName())[0] =~ /Vista/);  # running on Vista
 my $vistaUser      = $vista && !Win32::IsAdminUser();       # running on Vista as a user (not admin) - reduce menu options
+
 my $timerSecs      = 10;
 my $ssActive       = 0;
 my $starting       = 0;
@@ -49,14 +51,17 @@
 my $checkHTTP      = 0;
 my $lastHTTPPort   = 0;
 my $stopMySQL      = 0;
+
 my %strings        = ();
 
 # Passed on the command line by Getopt::Long
 my $cliStart       = 0;
 my $cliExit        = 0;
+
 my $registryKey    = 'CUser/Software/SlimDevices/SlimServer';
 my $serviceName    = 'slimsvc';
 my $sqlServiceName = 'SlimServerMySQL';
+
 my $appExe         = File::Spec->catdir(installDir(), 'server', 'slim.exe');
 my $serverUrl      = File::Spec->catdir(writableDir(), "SlimServer Web Interface.url");
 my $prefFile       = File::Spec->catdir(writableDir(), 'slimserver.pref');
@@ -65,13 +70,15 @@
 
 # Dynamically create the popup menu based on SlimServer state
 sub PopupMenu {
-	my	@menu = ();
-	my	$type = startupType(); # = none, login, manual or auto
+	my @menu = ();
+
+	my $type = startupType(); # = none, login, manual or auto
 
 	# As a user on Vista we only allow the following as these are all a user can perform:
 	# - starting/stopping of the server if type is none, login
 	# - toggling of startup type between login and none
-	if	($ssActive) {
+
+	if ($ssActive) {
 		push @menu, [sprintf('*%s', string('OPEN_SLIMSERVER')), \&openSlimServer];
 		push @menu, ["--------"];
 		push @menu, [string('STOP_SLIMSERVER'), \&stopSlimServerMySQL] if (!$vistaUser || $type =~ /none|login/);
@@ -82,21 +89,24 @@
 	else {
 		push @menu, [string('STARTING_SLIMSERVER'), \&startSlimServer] if (!$vistaUser || $type =~ /none|login/);
 	}
-	my	$serviceString = string('RUN_AT_BOOT');
-	my	$appString     = string('RUN_AT_LOGIN');
+
+	my $serviceString = string('RUN_AT_BOOT');
+	my $appString     = string('RUN_AT_LOGIN');
 
 	# We can't modify the service while it's running
 	# So show a grayed out menu.
-	my	$setManual = undef;
-	my	$setAuto   = undef;
-	my	$setLogin  = undef;
-	if	(!$ssActive && !$starting) {
+	my $setManual = undef;
+	my $setAuto   = undef;
+	my $setLogin  = undef;
+
+	if (!$ssActive && !$starting) {
 
 		$setManual = sub { setStartupType('none') };
 		$setAuto   = sub { setStartupType('auto') };
 		$setLogin  = sub { setStartupType('login') };
 	}
-	if	($type eq 'login') {
+
+	if ($type eq 'login') {
 
 		push @menu, ["_ $serviceString", $setAuto, undef] unless $vistaUser;
 		push @menu, ["v $appString", $setManual, 1];
@@ -132,8 +142,8 @@
 	# Had problems using Getopt::Long since @ARGV isn't set.
 	# XXX There also seems to be a problem with arguments passed
 	# in. $_[0] is not the first parameter, so we use $_[1].
-	if	(scalar(@_) > 1) {
-	if	($_[1] eq '--start') {
+	if (scalar(@_) > 1) {
+		if ($_[1] eq '--start') {
 			startSlimServer();
 		}
 		elsif ($_[1] eq '--exit') {
@@ -144,10 +154,12 @@
 
 # Display tooltip based on SS state
 sub ToolTip {
-	if	($starting) {
+
+	if ($starting) {
 		return string('SLIMSERVER_STARTING');
 	}
-	if	($ssActive) {
+
+	if ($ssActive) {
 		return string('SLIMSERVER_RUNNING');
 	}
    
@@ -157,17 +169,18 @@
 # The regular (heartbeat) timer that checks the state of SlimServer
 # and modifies state variables.
 sub Timer {
-	my	$wasStarting = $starting;
+	my $wasStarting = $starting;
 
 	checkSSActive();
-	if	($starting) {
+
+	if ($starting) {
 
 		SetAnimation($timerSecs * 1000, 1000, "SlimServer", "SlimServerOff");
 
 	} elsif ($wasStarting && $ssActive && startupType() ne 'login') {
 
 		# If we were waiting for SS to start before this check, show the SS home page.
-	if	(checkForHTTP()) {
+		if (checkForHTTP()) {
 
 			Execute($serverUrl);
 
@@ -185,11 +198,14 @@
 
 	# Check if user has requested to stop SlimServer And MySQL
 	# Only try to stop MySQL service when SlimServer has stopped.
-	if	(!$ssActive && $stopMySQL) {
-	my	%status = ();
+	if (!$ssActive && $stopMySQL) {
+
+		my %status = ();
 		Win32::Service::GetStatus('', $sqlServiceName, \%status);
-	if	(scalar keys %status != 0) {
-	if	($status{'CurrentState'} == 1) {
+
+		if (scalar keys %status != 0) {
+
+			if ($status{'CurrentState'} == 1) {
 
 				# Service already stopped
 
@@ -201,10 +217,12 @@
 
 				# Service running which we can't stop
 				# Display warning, unless running as a user on Vista as we can't stop in this case
-	my	$t = 'GetStatus Failed';
+
+				my $t = 'GetStatus Failed';
 
 				Win32::Service::GetStatus('', $sqlServiceName, \%status);
-	if	(scalar keys %status != 0) {
+
+				if (scalar keys %status != 0) {
 
 					$t = "GetStatus CurrentState=$status{'CurrentState'}";
 				}
@@ -223,27 +241,31 @@
 
 	# Kill the timer, we only want to run once.
 	SetTimer(0, \&checkAndStart);
-	if	($cliExit) {
+
+	if ($cliExit) {
 		exit;
 	}
 
 	# Install the service if it isn't already.
-	my	%status = ();
+	my %status = ();
 
 	Win32::Service::GetStatus('', $serviceName, \%status);
-	if	(scalar keys %status == 0) {
+
+	if (scalar keys %status == 0) {
 
 		installService();
 	}
 
 	# Add paths if they don't exist.
-	my	$startupType = startupType();
-	if	(!$startupType) {
+	my $startupType = startupType();
+
+	if (!$startupType) {
 
 		# NB running Vista as a user means we can't read this - we hope the first run is as admin
-	my	$serviceStart = $Registry->{"LMachine/SYSTEM/CurrentControlSet/Services/$serviceName/Start"};
-	my	$cKey = $Registry->{'CUser/Software/'};
-	my	$lKey = $Registry->{'LMachine/Software/'};
+		my $serviceStart = $Registry->{"LMachine/SYSTEM/CurrentControlSet/Services/$serviceName/Start"};
+
+		my $cKey = $Registry->{'CUser/Software/'};
+		my $lKey = $Registry->{'LMachine/Software/'};
 
 		$cKey->{'SlimDevices/'} = {
 			'SlimServer/' => {
@@ -257,14 +279,15 @@
 
 	# If we're set to Start at Login, do it, but only if the process isn't
 	# already running.
-	if	(processID() == -1 && $startupType eq 'login') {
+	if (processID() == -1 && $startupType eq 'login') {
 
 		startSlimServer();
 	}
 
 	# Now see if the service happens to be up already.
 	checkSSActive();
-	if	($ssActive) {
+
+	if ($ssActive) {
 
 		SetIcon("SlimServer");
 
@@ -274,8 +297,9 @@
 	}
 
 	# Handle the command line --start flag.
-	if	($cliStart) {
-	if	(!$ssActive) {
+	if ($cliStart) {
+
+		if (!$ssActive) {
 
 			startSlimServer();
 
@@ -287,30 +311,36 @@
 
 		$cliStart = 0;
 	}
-	if	($vistaUser && !$ssActive && $startupType eq 'auto') {
+
+	if ($vistaUser && !$ssActive && $startupType eq 'auto') {
 		# running as a user on Vista so we can't start a service, fallback to running as an app
 		setStartupType('none');
 	}
 }
 
 sub checkSSActive {
-	my	$state = 'stopped';
-	if	(startupTypeIsService()) {
-	my	%status = ();
+	my $state = 'stopped';
+
+	if (startupTypeIsService()) {
+
+		my %status = ();
 
 		Win32::Service::GetStatus('', $serviceName, \%status);
-	if	($status{'CurrentState'} == 0x04) {
+
+		if ($status{'CurrentState'} == 0x04) {
 
 			$state = 'running';
 		}
 
 	} else {
-	if	(processID() != -1) {
+
+		if (processID() != -1) {
 
 			$state = 'running';
 		}
 	}
-	if	($state eq 'running') {
+
+	if ($state eq 'running') {
 
 		SetIcon("SlimServer");
 		$ssActive = 1;
@@ -324,8 +354,10 @@
 }
 
 sub startSlimServer {
-	if	(startupTypeIsService()) {
-	if	(!Win32::Service::StartService('', $serviceName)) {
+
+	if (startupTypeIsService()) {
+
+		if (!Win32::Service::StartService('', $serviceName)) {
 
 			showErrorMessage(string('START_FAILED'));
 
@@ -339,7 +371,8 @@
 
 		runBackground($appExe);
 	}
-	if	(!$ssActive) {
+
+	if (!$ssActive) {
 
 		Balloon(string('STARTING_SLIMSERVER'), "SlimServer", "", 1);
 		SetAnimation($timerSecs * 1000, 1000, "SlimServer", "SlimServerOff");
@@ -349,8 +382,10 @@
 }
 
 sub stopSlimServer {
-	if	(startupTypeIsService()) {
-	if	(!Win32::Service::StopService('', $serviceName)) {
+
+	if (startupTypeIsService()) {
+
+		if (!Win32::Service::StopService('', $serviceName)) {
 
 			showErrorMessage(string('STOP_FAILED'));
 
@@ -358,8 +393,10 @@
 		}
 
 	} else {
-	my	$pid = processID();
-	if	($pid == -1) {
+
+		my $pid = processID();
+
+		if ($pid == -1) {
 
 			showErrorMessage(string('STOP_FAILED'));
 
@@ -368,7 +405,8 @@
 
 		Win32::Process::KillProcess($pid, 1<<8);
 	}
-	if	($ssActive) {
+
+	if ($ssActive) {
 
 		Balloon(string('STOPPING_SLIMSERVER'), "SlimServer", "", 1);
 
@@ -391,16 +429,17 @@
 }
 
 sub showErrorMessage {
-	my	$message = shift;
+	my $message = shift;
 
 	MessageBox($message, "SlimServer", MB_OK | MB_ICONERROR);
 }
 
 sub startupTypeIsService {
-	my	$type = startupType();
+
+	my $type = startupType();
 
 	# These are the service types.
-	if	($type eq 'auto' || $type eq 'manual') {
+	if ($type eq 'auto' || $type eq 'manual') {
 
 		return 1;
 	}
@@ -410,22 +449,29 @@
 
 # Determine how the user wants to start SlimServer
 sub startupType {
-	my	$atBoot  = $Registry->{"$registryKey/StartAtBoot"};
-	my	$atLogin = $Registry->{"$registryKey/StartAtLogin"};
-	if	(!defined $atBoot || !defined $atLogin) {
+
+	my $atBoot  = $Registry->{"$registryKey/StartAtBoot"};
+	my $atLogin = $Registry->{"$registryKey/StartAtLogin"};
+
+	if (!defined $atBoot || !defined $atLogin) {
 		return undef;
 	}
-	if	($atLogin) {
+	
+	if ($atLogin) {
 		return 'login';
 	}
-	if	($atBoot) {
-	my	$serviceStart = $Registry->{"LMachine/SYSTEM/CurrentControlSet/Services/$serviceName/Start"};
-	if	($serviceStart) {
+
+	if ($atBoot) {
+
+		my $serviceStart = $Registry->{"LMachine/SYSTEM/CurrentControlSet/Services/$serviceName/Start"};
+
+		if ($serviceStart) {
 
 			# Start of 2 is auto, 3 is manual.
 			return oct($serviceStart) == 2 ? 'auto' : 'manual';
 		}
-	if	($vistaUser) {
+
+		if ($vistaUser) {
 			# Vista users can't read the registry key for $serviceStart - assume auto [we can't manually start the service]
 			return 'auto';
 		}
@@ -435,12 +481,14 @@
 }
 
 sub setStartupType {
-	my	$type = shift;
-	if	($type !~ /^(?:login|auto|manual|none)$/) {
+	my $type = shift;
+
+	if ($type !~ /^(?:login|auto|manual|none)$/) {
 
 		return;
 	}
-	if	($type eq 'login') {
+
+	if ($type eq 'login') {
 
 		$Registry->{"$registryKey/StartAtBoot"}  = 0;
 		$Registry->{"$registryKey/StartAtLogin"} = 1;
@@ -459,7 +507,8 @@
 
 		$Registry->{"$registryKey/StartAtBoot"}  = 1;
 		$Registry->{"$registryKey/StartAtLogin"} = 0;
-	if	($type eq 'auto') {
+
+		if ($type eq 'auto') {
 
 			setServiceAuto();
 
@@ -475,16 +524,17 @@
 
 	# Try and find it in the registry.
 	# This is a system-wide registry key.
-	my	$swKey = $Registry->{"LMachine/Software/SlimDevices/SlimServer/Path"};
-	if	(defined $swKey) {
+	my $swKey = $Registry->{"LMachine/Software/SlimDevices/SlimServer/Path"};
+
+	if (defined $swKey) {
 		return $swKey;
 	}
 
 	# Otherwise look in the standard location.
-	my	$installDir = File::Spec->catdir('C:\Program Files', 'SlimServer');
+	my $installDir = File::Spec->catdir('C:\Program Files', 'SlimServer');
 
 	# If it's not there, use the current working directory.
-	if	(!-d $installDir) {
+	if (!-d $installDir) {
 
 		$installDir = cwd();
 	}
@@ -495,7 +545,8 @@
 # Return directory for files which Slimserver can save - i.e. location of prefs file
 # This is the server dir unless we are running on Vista when it is %ALLUSERSPROFILE%\SlimServer
 sub writableDir {
-	if	($vista) {
+
+	if ($vista) {
 		return File::Spec->catdir($ENV{'ALLUSERSPROFILE'}, 'SlimServer');
 	}
 
@@ -504,14 +555,16 @@
 
 # Read pref from the server preference file - lighter weight than loading YAML
 sub getPref {
-	my	$pref = shift;
-	my	$ret;
-	if	(-r $prefFile) {
-	if	(open(PREF, $prefFile)) {
+	my $pref = shift;
+	my $ret;
+
+	if (-r $prefFile) {
+
+		if (open(PREF, $prefFile)) {
 
 			while (<PREF>) {
 				# read YAML (server) and old style prefs (installer)
-	if	(/^$pref(:| \=) (\w+)$/) {
+				if (/^$pref(:| \=) (\w+)$/) {
 					$ret = $2;
 					last;
 				}
@@ -525,8 +578,9 @@
 }
 
 sub checkForHTTP {
-	my	$httpPort = getPref('httpport') || 9000;
-	if	($lastHTTPPort ne $httpPort) {
+	my $httpPort = getPref('httpport') || 9000;
+
+	if ($lastHTTPPort ne $httpPort) {
 
 		updateSlimServerWebInterface($httpPort);
 		$lastHTTPPort = $httpPort
@@ -534,13 +588,15 @@
 
 	# Use low-level socket code. IO::Socket returns a 'Invalid Descriptor'
 	# erorr. It also sucks more memory than it should.
-	my	$raddr = '127.0.0.1';
-	my	$rport = $httpPort;
-	my	$iaddr = inet_aton($raddr);
-	my	$paddr = sockaddr_in($rport, $iaddr);
+	my $raddr = '127.0.0.1';
+	my $rport = $httpPort;
+
+	my $iaddr = inet_aton($raddr);
+	my $paddr = sockaddr_in($rport, $iaddr);
 
 	socket(SSERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
-	if	(connect(SSERVER, $paddr)) {
+
+	if (connect(SSERVER, $paddr)) {
 
 		close(SSERVER);
 		return $httpPort;
@@ -560,7 +616,7 @@
 }
 
 sub _configureService {
-	my	$type = shift;
+	my $type = shift;
 
 	Win32::Daemon::ConfigureService({
 		'machine'     => '',
@@ -570,7 +626,7 @@
 }
 
 sub installService {
-	my	$type = shift || SERVICE_DEMAND_START;
+	my $type = shift || SERVICE_DEMAND_START;
 
 	Win32::Daemon::CreateService({
 		'machine'     => '',
@@ -583,7 +639,7 @@
 }
 
 sub runBackground {
-	my	@args = @_;
+	my @args = @_;
 
 	$args[0] = Win32::GetShortPathName($args[0]);
 
@@ -598,12 +654,15 @@
 }
 
 sub processID {
-	my	$p = Win32::Process::List->new;
-	if	($p->IsError == 1) {
+
+	my $p = Win32::Process::List->new;
+
+	if ($p->IsError == 1) {
 
 		showErrorMessage("ProcessID: an error occured: " . $p->GetErrorText . " ");
 	}
-	my	$pid = ($p->GetProcessPid(qr/^slim\.exe$/))[1];
+
+	my $pid = ($p->GetProcessPid(qr/^slim\.exe$/))[1];
 
 	return $pid if defined $pid;
 	return -1;
@@ -614,8 +673,9 @@
 #  One parameter the new port number
 
 sub updateSlimServerWebInterface {
-	my	$port = shift;
-	if	(open(URLFILE, ">:crlf", $serverUrl)) {
+	my $port = shift;
+
+	if (open(URLFILE, ">:crlf", $serverUrl)) {
 
 		print URLFILE "[InternetShortcut]\nURL=http://127.0.0.1:$port\n";
 		close URLFILE;
@@ -628,14 +688,14 @@
 
 # return localised version of string token
 sub string {
-	my	$name = shift;
+	my $name = shift;
 	$strings{ $name }->{ $language } || $strings{ 'EN' } || "Bad string $name";
 }
 
 sub loadStrings {
-	my	$string     = '';
-	my	$language   = '';
-	my	$stringname = '';
+	my $string     = '';
+	my $language   = '';
+	my $stringname = '';
 
 	LINE: while (my $line = <DATA>) {
 
@@ -643,7 +703,8 @@
 		
 		next if $line =~ /^#/;
 		next if $line !~ /\S/;
-	if	($line =~ /^(\S+)$/) {
+
+		if ($line =~ /^(\S+)$/) {
 
 			$stringname = $1;
 			$string = '';



More information about the checkins mailing list