“Broken Promises” Apple Commercial

Just watched an excellent  ”Broken Promises” commercial from Apple:

How To: Check Whether String is a Valid Path String

Sometimes it’s needed to verify if given string with path is valid in terms of syntax to make sure that we can work with it (meaning it doesn’t contain symbols not allowed in path). This can be done pretty simply:

bool isValid = (path2Check.IndexOfAny(Path.GetInvalidPathChars()) == -1);

Android 2.0 is Released

Android 2.0 has arrived with plenty of new features:


More details on new features on Android Developers web site.

Converting Documents to PDF in a Minute

Convert.io is a great service for converting documents of many different types to PDF files. I’m using it when I need to read documents in MS Office 2007 format primarily.

It works really simple: just e-mail document to pdf@convert.io and wait a minute to receive PDF version.

How To: Determine What Version of .Net CF is Installed on Device

List of .Net Compact Framework versions installed on device are available in registry under:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework

This key contains a set of DWORD values with names in format X.Y.BBBB.mm that correspond to build numbers of .Net CF (build numbers can be found in Wikipedia). Each of these values can have data of 0 (installed in RAM) or 1 (installed in ROM). So to verify if specific version of .Net CF is installed we need to check if value with corresponding name exists.

Here is a method that checks for .Net CF 2  (I wrote it today to verify available .Net CF versions in setup.dll of cab installer):

BOOL IsNetCF2Installed() {
	BOOL bNetCF2Found = FALSE;

	HKEY hKey = NULL;
	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\.NETCompactFramework"), 0, KEY_READ | KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
		DWORD dwIndex = 0;
		TCHAR szName[255];
		DWORD cName = 255;
		while ((!bNetCF2Found) && (::RegEnumValue(hKey, dwIndex, szName, &cName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)) {
			if (szName[0] == '2') {
				bNetCF2Found = TRUE;
			}
			dwIndex++;
		}

		RegCloseKey(hKey);
	}

	return bNetCF2Found;
}

Updating Application That Has Custom Actions in Setup.dll

Recently I was creating installer for application that is suppose to be updated regulary. Also cab installer for this application used setup.dll to perform custom actions during install/uninstall.

Since cab installer doesn’t have “update” feature installing update is done as a sequence: uninstall_old > install_new. Calls to setup.dll will be as follows:

  1. Install_Init() from new setup.dll is called with fFirstCall=true and fPreviouslyInstalled=true.
  2. Old installation is removed. This leads to calls to  Uninstall_Init() and Uninstall_Exist() from old setup.dll (which is stored in \windows\AppMgr).
  3. Install_Init() from new setup dll is called with fFirstCall=false and fPreviouslyInstalled=false.
  4. New files are extracted by cab installer.
  5. Install_Exist() is called.

To control updating process I needed to use some kind of a marker that will be available at all of those steps.

Originally I tried to use named Mutex (mainly because it is an in-memory object), but for some reason it didn’t work as expected. So I considered key in registry and a file. Creating/removing file just to use it as a marker is not very good idea and my final solution was to use a key in registry:

#include "windows.h"
#include <string.h>

///////////////////////////////////////////////////////////
// Methods to work with marker.

void SetInstallingStartFlag() {
	HKEY hKey = NULL;
	DWORD dwDisposition;
	if (::RegCreateKeyEx(HKEY_CURRENT_USER, _T("\\SOFTWARE\\MySoftwareInstall"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) {
		::RegCloseKey(hKey);
	}
}
void RemoveInstallingStartFlag() {
	HKEY hKey = NULL;
	if (::RegOpenKeyEx(HKEY_CURRENT_USER, _T(""), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
		::RegDeleteKey(hKey, _T("\\SOFTWARE\\MySoftwareInstall"));
		::RegCloseKey(hKey);
	}
}
BOOL OpenFlagKey() {
	BOOL bOpened = FALSE;

	HKEY hKey = NULL;
	if (::RegOpenKeyEx(HKEY_CURRENT_USER, _T("\\SOFTWARE\\MySoftwareInstall"), 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
		bOpened = TRUE;
		::RegCloseKey(hKey);
	}

	return bOpened;
}
BOOL IsRemovingDuringUpdate() {
	return OpenFlagKey();
}
BOOL IsInstallingDuringUpdate() {
	return (OpenFlagKey() == FALSE);
}

TortoiseSVN and Password to SVN

TortoiseSVN does not allow save password to SVN. This forces entering it many times during the day. Fortunately there is a workaround and Ditching the Password Prompts in TortoiseSVN explains how.

What is BuildMax Property in .inf File for Cabwiz is Actually For

When installing cab file on devices that have square screens or support screen rotation (last is applicable to all devices starting from WM 2003 SE) you may receive an error message:

The program you have installed may not dispay properly because it was designed for a previous version of Windows Mobile software
“because it was designed for a previous version of Windows Mobile software” is not really correct because actually cab installer complains about screen on WM, not OS version.

To omit this error MaxBuild property declared in Vestion section of .inf file can be used. According to Microsoft:

The BuildMax value can be used to indicate that the application supports
square screens (BuildMax=0xA0000000),
screen rotation (BuildMax=0xC0000000),
or both (BuildMax=0xE0000000).

This is one of those odd things that we can found sometimes. Error message leads us to wrong direction and name of property doesn’t have any connection to what it does :)

How To: Hard Reset HTC S730

Yesterday HTC S730 that I use for development hang and after soft reset I couldn’t start it again.

So I had to perform hard reset using special key combination: holding both soft buttons press power button. At first it didn’t work. After spending couple of minutes on Internet I found that there is a trick: power button must be pressed only for a second and then released.
After very first try I successfully reset the phone :)

Creating Cab Installer for Windows Mobile Applications

I’m working on installer for Windows Mobile application. Here are some great articles I found:

I’m Tweeting

Follow

Get every new post delivered to your Inbox.