Silverlight Version
One nifty utility that I've been using for a long time but never got around to publishing is a Silverlight version detector which will tell you the full version that you have installed on your machine. It really isn't that hard to do, but the nice thing about this one is that I've been using it on Silverlight versions way back to before 1.0 was released and the product was still called WPF/E.
I primarily use this code for times when someone calls me up with a problem along the lines of 'something is running wacky on my machine'. It's much easier to just point them to a URL than to list the steps needed to find their version other ways.
Please note that this code is *not* the way that you're supposed to check whether the user has a version installed or not, that's what IsVersionSupported is for. The reason for this is that everyone seems to add bugs when trying to roll their own version detection code, so in the interest of making sure that your code continues to work through future updates, please use IsVersionSupported.
To use IsVersionSupported: Application.Current.Host.IsVersionSupported("2.0.31005.0");
3 Comments:
Pete,
Hi, I watched your PDC 2008 WPF demo featuring a UI for Twitter. You showed an update to your application done by Celso Gomes. Is there any chance of making this a download on your blog? I just thought it was amazing how he used styling and animation to alter your cool application. I think this application would be a good one to study :-)
Chris
Hello, i found your Silverlight Version detector via Google... and found out that Google Chrome is using the bruteforce method to crack the version of SL.
it takes about 3 seconds to bruteforce, so my questions is: Why didn't you use Binary Search?
is the speed of O(Log(N)) instead of O(N)...
alternatively, one could store the existing versions from Wikipedia (or Microsoft) and simply test the ~12 version...
Thanks - nice script !!
new time: 500 msec
old time: 15000 msec
30 times faster :D
Here is the upgrade:
// outside detectSilverlightVersion():
function BinarySearch(control, versionNumbers, indx, min, max) {
if (max < min)
return -1; // not found
if (min == max)
return min;
versionNumbers[indx] = Math.ceil(min + ((max - min) / 2))
var isSupported = control.IsVersionSupported(buildVersionString(versionNumbers))
if (!isSupported)
return BinarySearch(control, versionNumbers, indx, min, versionNumbers[indx] - 1)
else if (isSupported)
return BinarySearch(control, versionNumbers, indx, versionNumbers[indx], max)
else
return -1; // not found
}
buildVersionString = function(versionNumbers) {
var versionString = "";
for (var l = 0; l < versionNumbers.length; ++l) {
versionString += versionNumbers[l];
if (l != versionNumbers.length - 1)
versionString += ".";
}
return versionString;
}
// inside detectSilverlightVersion():
var versionNumbers = [0, 0, 0, 0];
versionNumbers[0] = BinarySearch(control, versionNumbers, 0, 0, 20);
versionNumbers[1] = BinarySearch(control, versionNumbers, 1, 0, 20);
versionNumbers[2] = BinarySearch(control, versionNumbers, 2, 0, 100000);
versionNumbers[3] = BinarySearch(control, versionNumbers, 3, 0, 20);
silverlightVersion = buildVersionString(versionNumbers);
Post a Comment
<< Home