After getting a Windows XP Virtual PC up and running I was able to test my last project’s update feature in XP…and it didn’t work. From those of you who have Vista like me know that the user profile is no longer under Documents and Settings, but Users.
My original code didn’t take into account spaces in the file path, so when a user on XP tried to update the app, it would try to copy itself to “C:\documents” and fail. Since I’d already distributed the previous version, I couldn’t go about fixing it without also creating a tool to replace copies that were on computers already. So I oped for hacking it in the newest version.
Since the file path was given to the updated app when it runs, I simply needed to make my update code smarter….sort of, smarter may be to generous. I simply looped through the arguments until I hit one that ended with “.exe” and then used the result as the path to update to. Below is the code, which in future version will probably be commented out.
if (!System.IO.File.Exists(hargs["update_path"].ToString()))
{
int i = Array.FindIndex(args, (delegate(string s) { if (s.ToLower() == "-update") { return true; } return false; })) + 1;
string[] path = new string[0];
for (i = i; i < args.Length; i++)
{
Array.Resize(ref path, path.Length + 1);
path[path.Length - 1] = args[i];
if (args[i].EndsWith(".exe"))
{
hargs["update_path"] = string.Join(" ", path);
break;
}
}
}

