[Slim-Checkins] r11828 - in /branches/6.5/server/Slim/Utils: OSDetect.pm Prefs.pm

adrian at svn.slimdevices.com adrian at svn.slimdevices.com
Wed Apr 25 15:25:15 PDT 2007


Author: adrian
Date: Wed Apr 25 15:25:14 2007
New Revision: 11828

URL: http://svn.slimdevices.com?rev=11828&view=rev
Log:
Bug: N/A
Description: speculative improvement for Vista - move prefs and cache
to %ALLUSERSPROFILE%\SlimServer rather than storing under Program
Files to avoid Vista file virtualisation.

Modified:
    branches/6.5/server/Slim/Utils/OSDetect.pm
    branches/6.5/server/Slim/Utils/Prefs.pm

Modified: branches/6.5/server/Slim/Utils/OSDetect.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Utils/OSDetect.pm?rev=11828&r1=11827&r2=11828&view=diff
==============================================================================
--- branches/6.5/server/Slim/Utils/OSDetect.pm (original)
+++ branches/6.5/server/Slim/Utils/OSDetect.pm Wed Apr 25 15:25:14 2007
@@ -36,6 +36,7 @@
 
 	if ($^O =~ /Win32/) {
 		require Win32;
+		require Win32::FileSecurity;
 	}
 }
 
@@ -339,6 +340,51 @@
 	$osDetails{'osArch'} = $Config{'myarchname'};
 }
 
+
+# Return a path which is expected to be writable by all users on Vista without virtualisation
+# this should mean that the server always sees consistent versions of files under this path
+
+# NB on vista, if a normal user saves a file under C:\Program Files, this is virtualised and the
+# actual file is saved as \User\<username>\AppData\Local\VirtualStore\Program File\<rest of path>
+# This means that different users see different version of the same file.  We therefore try to avoid
+# this by not storing writable files under C:\Program Files...
+
+sub vistaWritablePath {
+	my $folder = shift;
+
+	# store files in %ALLUSERSPROFILE%\SlimServer - normally C:\ProgramData\SlimServer
+	my $root = catdir($ENV{'ALLUSERSPROFILE'}, 'SlimServer');
+	my $path = catdir($root, $folder);
+
+	return $path if -d $path;
+
+	if (! -d $root) {
+		mkdir $root;
+		_vistaOpenPath($root);
+	}
+
+	mkdir $path;
+	_vistaOpenPath($path);
+
+	return $path;
+}
+
+sub _vistaOpenPath {
+	my $path = shift;
+
+	my %perms;
+
+	Win32::FileSecurity::Get($path, \%perms);
+
+	# set file security to open for all users on system
+	# this should probably be changed to only cover locally defined users?
+	for my $uid (keys %perms) {
+		$perms{$uid} = Win32::FileSecurity::MakeMask( qw( FULL  GENERIC_ALL ) );
+	}
+			
+	Win32::FileSecurity::Set($path, \%perms);
+}
+
 1;
 
 __END__

Modified: branches/6.5/server/Slim/Utils/Prefs.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Utils/Prefs.pm?rev=11828&r1=11827&r2=11828&view=diff
==============================================================================
--- branches/6.5/server/Slim/Utils/Prefs.pm (original)
+++ branches/6.5/server/Slim/Utils/Prefs.pm Wed Apr 25 15:25:14 2007
@@ -425,6 +425,10 @@
 	} elsif ($os eq 'unix') {
 
 		$CacheDir = catdir($ENV{'HOME'},'Cache');
+
+	} elsif ($os eq 'win' && Slim::Utils::OSDetect::details->{'osName'} =~ /Vista/) {
+
+		$CacheDir = Slim::Utils::OSDetect::vistaWritablePath('Cache');
 	}
 
 	my @CacheDirs = splitdir($CacheDir);
@@ -1012,7 +1016,11 @@
 	if (Slim::Utils::OSDetect::OS() eq 'mac') {
 		$prefsPath = catdir($ENV{'HOME'}, 'Library', 'SlimDevices');
 	} elsif (Slim::Utils::OSDetect::OS() eq 'win')  {
-		$prefsPath = $Bin;
+		if (Slim::Utils::OSDetect::details->{'osName'} =~ /Vista/) {
+			$prefsPath = Slim::Utils::OSDetect::vistaWritablePath();
+		} else {
+			$prefsPath = $Bin;
+		}
 	} else {
 	 	$prefsPath = $ENV{'HOME'};
 	}



More information about the checkins mailing list