Install Windows on a UEFI device and #wpdev sdk issues

When I got the Haswell ultrabook from Intel, it had a Windows 8 x64 build. I eventually upgraded to Windows 8.1 but I faced issues when trying to hibernate / shutting it down. This seriously affected my hobbyist dev as a I tend to leave stuff open and hibernate the device.

So to solve the problem I tried to reinstall Windows 8.1 using USB key (using Windows 7 USB / DVD tool).. however the boot loader would just ignore it and revert back to boot selection screen. I eventually reinstalled the PC using Windows 8.1 Clean and refresh option and that works as advertised. But I had some issues when installing WP8 sdk.

wp8sdk

I tried in vain to install it but it wouldn’t have anything. Eventually I figured I had to do a clean install of Windows 8.1 so scouring the next, I came across this post… the tool Rufus is almost identical to stock format tool crossed with usb dvd tool :)

rufus

That worked, the UEFI bootloader finally allowed me to install using usb key however I still have the same issue with WP SDK. Turns out some certs were out of date. I again checked for root certificate update and downloaded tool from Windows Catalogue but that didn’t do much either..

so finally I reset the system date to the day I got the device.. I remember install WP SDK then and bang it installed just fine.. silly bugger

So how did I get #GDR2 for #Lumia920

I have been debating whether to pay up for Navifirm to be able to find and install GDR2 for Lumia920. I remember Andy Wilson paying up and tweeting that he couldn’t find his devices firmware there. So I decided its not worth going down XDA-developers route, instead I could just wait a bit.

Yesterday evening, Wolfgang Ziegler, tweeted that he installed #GDR2 on his device and I said.. that’s it.. bloody hell.. time to get on with it.

So like my usual cheerful self, I quickly glanced at the post, downloaded Nokia Software for Retail 3.0.8 and back.. I have an update waiting to install.. blimey.. proceed without caution :)

Didn’t I say my usual self ?

1.3 gig download, installed in 10 mins, after configuration, of course bloody backup can’t be used as by default APN isn’t set and data connection is off.. hang on.. it was working fine when I reset the Lumia925.. quick check.. damn what.. no Amber / GDR2.. how the hell..

Oh well I suppose it was intermediate update.. plug in again and bang.. NSR says another update waiting to be installed.. for the first time I actually paid attention to the update version.. bloody thing was asking me to update the same version and forcing ROM overwrite each time..

Damn you Hermit Dave.. stupid git.. never read the instructions.. RTFM.

While trying to find Nokia Software for Retail, I remember being tempted into reading How to download Nokia Firmware with Nokia Data Package Manager.
So next step.. download and install Nokia Data Package Manager.. input correct details and search.. oops latest version is same as the one shown in NSR.

Another idea.. last year when I was hacking about trying to install 7.8 on Lumia800, I downloaded another firmware, remained a few files to match the product code and then used Nokia Care Suite. Quick check.. already had latest Nokia Care Suite – installed while I was deliberating :)
back to Wolfgang Ziegler blog, downloaded the ROM for his device :) A quick rename and tried flashing with NSR and NCS.. ooops some files are missing.. nope rename wouldn’t do…

Check on XDA-Developers said you can install other ROMs.. as long as you just pick the version, start programming, select ROM and then plug the device when prompted.. did that, it said.. product codes don’t match.. Proceed ? Hell yes.. 10 mins flashing and after a few nervous minutes.. device up and running and bang.. backup worked as APN was set correctly like on Lumia925.. wohooo looks like I have GDR2.. quick check proved that to be the case :)

Job done..

Persistent Thread like behavior with #win8dev

As you might have gathered, I
* like writing bad code
* doing things that people frown upon (like writing bad code)

Ever since I started Windows 8 Development, I miss Threads in all their glory. Sure Async Task is mostly fine but its not the same. Earlier today, Arafat asked a question about truly async logging mechanism. I suggested hacking Async Task into a thread like behaviour :) – actually it just gets you a threadpool thread :)

Task.Run provides a mechanism to queue given code on a ThreadPool for parallel execution. What happens when you refuse to return the method ? well you get the ThreadPool thread as your personal bitch :)

CancellationTokenSource CancellationSource = null;
CancellationToken TaskCancellationToken;

private async void AlwaysOnLoggingAsyncTask()
{
     while (!this.TaskCancellationToken.IsCancellationRequested)
     {
          // do something.. actually do anything
          // in the sample I was mucking around with StorageFile
          // hence the async void 

          await Task.Delay(1000); // don't kill the PC by running a tight loop.
     }
}

private async void btnStart_Click(object sender, RoutedEventArgs e)
{
     CancellationSource = new CancellationTokenSource();
     this.TaskCancellationToken = CancellationSource.Token;
     Task.Run(() => this.AlwaysOnLoggingAsyncTask(), TaskCancellationToken);
}

private void btnStop_Click(object sender, RoutedEventArgs e)
{
     CancellationSource.Cancel();
}

Here’s a dummy sample logging project that incorporates this bad code :)

Update: since I was writing really bad code, I deliberately forgot to add Task.Delay. If you prefer to not write code that makes system a bit less miserable, consider adding a Task.Delay of about 1000 (1 second)

Update 2: Jarno pointed out that I am writing really really bad code – mechanism dating pre-Task era – which is correct. Old habits die hard. Well I’ve update the blog plus source :P to use Task Cancellation Token

WP7 App Piracy and how to deal with it.

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.

Single Kindle screensaver instead of disabling screensaver

Kindle’s screen (e-ink) only consumes power when it paints the screen. When it is showing something it takes 0 power. That is the reason for kindle’s 3 week battery life.

Hacking kindle to only have one screensaver works like a charm for kindle’s batter life.. lot better than disabling screensaver as it prevents screensaver code from trying to paint a different screensaver every 10 mins.

Disabling the screensaver using method i previously described in http://invokeit.wordpress.com/2011/11/21/disable-kindle-3-screensaver/ works as described.

The negative side of this (disabling the screensaver approach) is that 3G (if you have 3G kindle) and or Wifi (if you configured it) will always be on and that drains the battery like crazy.

Having done kindle screensaver hack previously i thought i’ll try this

1) Jailbreak kindle (reboot)

2) Install screensaver hack. (reboot)

3) Remove all screensavers

4) copy your favourite screensaver image

5) reboot

And there you have it. The screen switch off works like before but since there is only one screen saver, it doesn’t keep changing. The 3G / wifi are off when screensaver comes on and everyones happy

To learn how to install screen saver hack

http://wiki.mobileread.com/wiki/Kindle_Screen_Saver_Hack_for_all_2.x_and_3.x_Kindles

http://booksprung.com/free-screens

Update: After over a month of setting screensaver hack, with a very light use, i am please to say that the battery has only drained about 50%.

Update 2: Another 2 weeks and no drop in battery level. This is wicked.

Update 3: total duration betweeen charger 2+ months.

Offline tiles solution ?

As i said in my last post, i have been going around with Reflector and ISDASM. Most of the .net developers should know that Reflector is one of the best decompilers. However if you obfuscate your code even Reflector can’t do much. Thats where ISDASM comes in. ISDASM is a tool that we come across when we start programming and it shows IL for any assembly. IL is synonymous to assemly language as compared to C or C++.

Well the beauty of ISDASM is that even obfuscated code needs to be CLR understandable and anything CLR can read so can ILDASM. I tried to read IL from one of the apps i know uses offline maps but like me the devs in that app had obfuscated the code – which is understandable. I even got started on reading IL books (you know i have a very short attention span) but i decided to trust my instincts and guess what ILDASM was showing me and all i can say is that Tile Source is useless like i already discovered.

uristore based absolute uri cannot be loaded by map or possibly multi source image that is consumed by map object. What you need to do is manage the tiles yourself from the begining. no tile source needed. Based on user’s current position you load the tiles you want.

Now loading a given tile is not difficult based on coordinates however a tile is 256 x 256 pixels wide so my next problem is figuring out how many tiles to load around the current coordinate. Fortunately there is lot of info on how tile system works and i will figure it out soon.

GPS App – Reached first resistance

Over the last couple of days i have been looking into  GPS app. So far:

1) Can plot a route (not walk the route though)

2) Fetch and save the Tiles using a custom tile source so as to get handle on the url.

However i cannot use isostore based URL. I have tried direct uri, “/Shared/ShellContent/” based uri like one that works for tiles, i added randomisation so that uri caching doesn’t work. So far it only works the when getting the data from web. Once it has data, it just doesn’t paint. Surpringly no error, just the map stays black. I guess multisource image does not like isostore uri’s

I know it can be done as i have an app that does it. Infact i doubt any GPS app is using custom control.

http://social.msdn.microsoft.com/Forums/en/vemapcontroldev/thread/75bd4bc9-300a-4534-ae81-87830a366bad

Richard mentioned on the forum that he has done it for a client and that he might post the code in a month’s time. So all is not lost. If i can’t figure it out in a month -

a) i am lousy at what i do

b) i am lousy at searching

c) i can still use the solution when published.

While all the above statements are possibly true, all is not lost. I am putting my skills to good use by using .net reflector and ILDASM to figure exactly what needs to be done.