Accessing Cordova Config Info From JavaScript Without Plugins

I wanted to access the current build number for analytics, but there seemed to be no easy way to get at the info that Cordova puts into the plist file (Xcode) and AndroidManifest.xml (Android Studio).

My solution is to copy those to files into the www folder at build time and then load them with AJAX. It means adding the following line in the iOS project in ios/cordova/lib/copy-www-build-step.js, somewhere near the end:

shell.cp('-f', path.join(path.dirname(PROJECT_FILE_PATH), path.basename(PROJECT_FILE_PATH, '.xcodeproj'), '*.plist'), dstWwwDir);

As part of the build process, this copies the plist file into the root web directory as it’s deployed onto the device (meaning there are no changes to the source filesystem). So if it doesn’t seem to work, write some kind of check to see if the file actually gets copied.

Then in Android Studio, inside build.gradle for the app module, right before the line that starts android {:

task copyFiles(type: Copy) {
description = 'copying some file(s)....'
from "../app/AndroidManifest.xml"
into '../app/src/main/assets/www/'
}
preBuild.dependsOn copyFiles

Unlike the Xcode version, this copies AndroidManifest.xml into the www root directory before it’s deployed to the device, so the file will appear inside the www directory. It’s overwritten each time in case there are any changes.

Then inside JavaScript, to access data within those files I used jQuery to parse AndroidManifest.xml and a library called Plist Parser to make iOS just as easy. Plist Parser turns the annoyingly structured file into a JSON object that’s trivial to navigate through.

The JavaScript code, assuming there’s a check for platform somewhere else, is below. I mainly wanted CFBundleVersion (iOS) and android:versionCode (Android), but you can access anything else in the file too:

if (platform == 'android') {
$.ajax({
url: 'AndroidManifest.xml',
dataType: 'text',
success: function (response) {
var xml = $(jQuery.parseXML(response));
var root = xml.find('manifest');
if (root) {
if (root.attr('android:versionCode')) {
var app_version = root.attr('android:versionCode');
}
if (root.attr('package')) {
var app_id = root.attr('package');
}
}
},
error: function (response) {
//Will have to do without data from plist file
}
});
} else if (platform == 'ios') {
$.ajax({
url: '[your plist filename]',
dataType: 'text',
success: function (xmlString) {
var plist = PlistParser.parse(xmlString);
if (plist) {
if (plist['CFBundleVersion']) {
var app_version = plist['CFBundleVersion'];
}
if (plist['CFBundleVersion']) {
var app_id = plist['CFBundleIdentifier'];
}
}
resolve();
},
error: function (response) {
//Will have to do without data from plist file
}
});
}

I’ve yet to see whether running cordova build ios or cordova build android overwrites the build process changes or not.

How to find Firefox easily in Task Manager

Often I need to kill firefox.exe so I’ve identified this simple way of finding it without having to sort alphabetically and scroll all the way down through reams of pointless, resource-sapping Windows processes (which are no doubt running “just in case” to shave 1 microsecond off an app I use every once 3 years… acrotray.exe, you know who you are). Anyway, here it is:

  • Open task manager
  • Sort by memory usage
  • It’s the stupid bloated fat memory leaking process at the top (but double-check it’s not photoshop.exe)
  • Kill kill kill

Hopefully this will be useful to someone else who also has their system ground to a halt just because they’ve left their browser on the same 40k static page for more than an hour.

Fixing incorrect awgina.dll version remotely

I’ve recently installed PCAnywhere and, getting home, tried to remote desktop to my PC. Except I couldn’t because apparently I had an “incompatible version of awgina.dll”. I should also contact my network adminstrator for the latest version because obviously whoever that is is bound to have different versions just left around the place.

Anyway, Googling for awgina.dll brought back some useful results and it was indeed PCAnywhere’s fault, but unfortunately all the fixes involved going into the registry. If you can’t log on, that’s quite hard.

But this link was more helpful as apparently awgina.dll had overridden msgina.dll. So, I switched myself into hack mode and did this:

  • Connected over the network to c:\windows\system32
  • Renamed the old awgina.dll, just in case. (I’m not a cowboy, you know!)
  • Copied msgina.dll and rename it to awgina.dll
  • Voila! Connection worked fine.

I’ll see tomorrow whether there are any adverse effects on PCAnywhere, but being able to work remotely is much more important anyway.

Accessing Experts Exchange without paying

It seems that Experts Exchange is now making people pay for accessing content generated by their users. I’m sure it was inevitable but it’s very underhand to build up a free knowledge base and then make people pay for what will often be content they’ve contributed to.

It’s even more underhand that they have to let the content remain accessible to Google otherwise they won’t come up top for searches any more. But that’s where there’s a route around the subscription system. In easy steps:

  1. Search for something useful in Google e.g. “javascript baseHfef”.
  2. See a possibly useful result from Experts Exchange.
  3. View the version that’s in Google’s cache e.g. results for “javascript baseHref”

Maybe they’ll think of a way around that sometime, but in the meantime if they want their content in Google then it’s got to be accessible.

MSN Live Messenger hack: remove ads

I posted once about a tool to remove ads from MSN Messenger 7 and I’ve just upgraded to MSN Live Messenger. So, a quick Google later, and I found an application to do the same (and more). I must admit I didn’t understand all the options, but I’ve gotten rid of the ads so that’s all that counts. The app is called A-patch.

A-patch for MSN Live Messenger

Install multiple versions of IE on your PC

This useful app allows you to run different versions of Internet Explorer on the same Windows install, which sounds pretty clever and indeed it is. A simple download and install and it seems to do exactly what it promises. Now why can’t Microsoft provide that kind of functionality, I wonder?

I also tried the IE7 standalone install but I can’t tell how successful that’s been yet. IE7 started up just fine, but the first dropdown I tried to interact with throw a ‘popup blocked’ error. Could be a glitch but I can live with it for now.

Install multiple versions of IE on your PC

Standalone IE7

Autorun an executable from a USB key in Windows XP

After much Googling, reading, hacking, downloading applications and generally fiddling about, we finally got a USB key to put up the correct autorun prompt when you put the key in the port. i.e. put the application you want to run at the top, and not list a load of files and folders to open. It is:

In autorun.inf you want:

[autorun]
action=My presentation
icon=icon_file.ico
open=executable_fil.exe

And that seemed to do it. Maybe everyone knows how to do this already and just didn’t tell me, but it definitely didn’t work without the ‘action’ line. Okay, the executable still has to be picked from the list of actions, but it appears at the top so it’s fairly obvious.

Renaming a Windows 2003 server/Exchange 2003 domain

After managing to successfully get my Exchange data back yesterday, I realised that I wanted to give the domain a different name. Of course, being Microsoft it isn’t as simple as just right clicking and renaming something. No, renaming an Active Directory domain is quite a task.

I found some help on Microsoft Technet and after a certain amount of coaxing and fudging it seemed to do the trick.

Recovering an Exchange edb database

The server with our Exchange 2003 database on it died. It didn’t seem to be the hard drive but the server itself – the power just wouldn’t come back on. So, I had to set up Exchange on a new server and then plug the old hard drive in and try and pursuade it to use the old database files as the new message store. Active Directory was running on the same machine so there was no user information stored anywhere else either.

My method seems to have worked, and this (in outline) is the steps I took. You’re definitely taking a risk doing this, and I’m sure there’s a more robust way, so make sure you’ve got backups of the world and his dog before you start any of this.

  1. Make sure Exchange, and Active Directory, is all working fine on the new machine.
  2. Stop the Exchange store service
  3. Go into Exchange System Manager -> Servers -> [Your server] -> Storage Group and dismount the mailbox store.
  4. Rename the MDBDATA folder in your new Exchange directory
  5. Copy the old MDBDATA folder that you want to restore from in
  6. Run the first few steps on the knowledge base article How to recover the information store on Exchange 2000 Server or Exchange Server 2003 in a single site. I only got to step 5 before I couldn’t stop dabbling myself.
  7. Set up users in the new Active Directory structure matching the old users
  8. Go into Exchange System Manager -> Servers -> [Your server] -> Storage Group and right click on the Mailbox Store and select ‘Properties’.
  9. Select the ‘Database’ tab and tick ‘This database can be overwritten by a restore’
  10. Mount the Store (right click on it)

This should mount without any errors. If you’re still getting problems, go back to the knowledge base article and follow it through again.

Next is getting all your data back, and here’s where I went well and truly off-piste:

  1. Create Active Directory users matching the people who’s mailboxes you need to restore. Don’t accept the option to create an Exchange mailbox.
  2. Go into Exchange System Manager -> Tools -> Mailbox Recovery Center and right click to add the mailbox store.
  3. You should see a list of old mailboxes come up in the right hand panel, with little ‘X’s next to them. Right click on each one in turn and ‘Find Match’ and then ‘Reconnect’.
  4. Hopefully, that’ll do it!

Before trying any of that you may like to take the photo below, demonstrating my accredited drive mounting techniques, as a warning as to how I tend to approach these things.

Exchange drive recovery