Lets assume that you had a wicked idea and that you spent some time writing an app for your beloved Windows Phone. It got publish and you were very excited about it – however a quick search on the net showed that it was available for download from various hosting sites.
This has happened to me more than once. It happened with Sliding Keyboard 1.1 in June 2011 and with Cool Camera 1.0 last week. So what do you do ? You write to the sites saying that this is your stuff and that its being hosted illegally – some times you might get a response at other times you are just ignored.
Well lets deal with it. Most apps provide a trial mechanism. It is a must unless you can think of a really good reason for not allowing trial. Most of my apps have a trial mode download – which is a fully functional download except it shows adverts and is limited to certain usage.
I tend to define a static boolean property called IsTrial. I use this property as there’s no sense in constant lookups (plus license does not change while app is active)
var license = new Microsoft.Phone.Marketplace.LicenseInformation();
IsTrial = license.IsTrial();
This simple piece of code will check license set (if you downloaded the app from Marketplace). However, sideloaded xap’s return true as there is no license attached. Don’t loose your faith just yet.. There’s still something you can do.
While the app is submitted to microsoft for testing, microsoft packages a file called WMAppPRHeader.xml. The beauty of this file is that if the xap contains this file, it can only be installed with marketplace installer. So what your all the xap hosting sites do ? they remove this file and repackage the xap. Do you see where i am going ? Yes, you check for this file. If you can’t find this file, it means that your xap was sideloaded. so we modify the above code to:
try
{
XDocument doc = XDocument.Load("WMAppPRHeader.xml");
var license = new Microsoft.Phone.Marketplace.LicenseInformation();
IsTrial = license.IsTrial();
}
catch
{
IsTrial = true;
}
we try to load the file, if we can load it, it was installed through marketplace mechanism and we can use IsTrial to determine whether the app is in Trial or not. If it was sideloaded, we set it to Trial by catching the FileNotFoundException.
So you silently convert your app to Trial mode and manage the sideloaded app as if you would for Trial, display ads and restrict the user like you would otherwise. You can even display a Buy now message in your app’s about page 🙂
BTW – don’t go about trying to add junk to file name and then trying to clean up later so make it harder. Compilers are smart and they will see the redundant chars and strip it out. What you should however do is always Obfuscate your code. As long as you do a bit of extra work, the ones who pirate your app will have a hard time as obfuscation can rename functions / encrypt strings in addition to doing a lot more.