|
#1
|
||||
|
||||
|
Compare File Versions - String to Number Problems
I am trying to compare which file version of my software is installed to what the latest version out is so I can let True Update send the appropriate incremental patch to the user. It seems so simple, but for some reason my code does not return the expected values.
I would expect that the code below would trim the "1." from the left of the g_InstalledVersion string and the ".0.0" from the right of that string leaving me with a string containing the value "10". I do the same with my 1.11.0.0 string and then convert both of those strings to numbers to perform my arithmetic. I am expecting to have a final result of 1 stored in my versions_difference variable because 11 - 10 = 1, but it doesn't happen. It's failing somewhere with the String.TrimRight and String.TrimLeft function and I have no clue why. I'm sure this is really simple, but I just can't figure out what is going wrong. Does anyone have any ideas? Attached is my code with some debugging dialog messages I've commented out. Code:
g_InstalledVersion = "1.10.0.0";
--Dialog.Message("g_InstalledVersion", g_InstalledVersion);
g_TargetVersion = "1.11.0.0";
--Dialog.Message("g_TargetVersion", g_TargetVersion);
trim_InstalledVersion = String.TrimRight(g_InstalledVersion, ".0.0");
--Dialog.Message("trim_InstalledVersion", trim_InstalledVersion);
trim_InstalledVersion2 = String.TrimLeft(trim_InstalledVersion, "1.");
--Dialog.Message("trim_InstalledVersion2", trim_InstalledVersion2);
trim_TargetVersion = String.TrimRight(g_TargetVersion, ".0.0");
--Dialog.Message("trim_TargetVersion", trim_TargetVersion);
trim_TargetVersion2 = String.TrimLeft(trim_TargetVersion, "1.");
--Dialog.Message("trim_TargetVersion2", trim_TargetVersion2);
short_InstalledVersion = String.ToNumber(trim_InstalledVersion2);
--Dialog.Message("short_InstalledVersion", short_InstalledVersion);
short_TargetVersion = String.ToNumber(trim_TargetVersion2);
--Dialog.Message("short_TargetVersion", short_TargetVersion);
versions_difference = (short_TargetVersion - short_InstalledVersion);
Dialog.Message("versions_difference", versions_difference);
Thanks for any help anyone can offer!
Last edited by Dnixon; 01-10-2008 at 06:00 PM. Reason: For further clarification |
|
#2
|
||||
|
||||
|
I figured it out
![]() I found out about the bug with the string.trimRight / string.trimLeft function and rewrote the code as follows. Works great for determining which incremental patch to deliver to the user. g_installedVersion could be a registry key value that is set when you install the software. True Update can request that key and set it to the g_installedVersion variable at runtime. g_targetVersion is coded in the server script in your True Update code. Code:
g_installedVersion = "1.1.0.0";
t_installedVersion = String.Replace(g_installedVersion, ".0.0", "", false);
t1_installedVersion = String.Replace(t_installedVersion, "1.", "", false);
g_targetVersion = "1.4.0.0";
t_targetVersion = String.Replace(g_targetVersion, ".0.0", "", false);
t1_targetVersion = String.Replace(t_targetVersion, "1.", "", false);
i_version = (t1_targetVersion - t1_installedVersion);
if i_version == 1 then
-- Where do you want to download the installer/patch file from and to?
g_SourceURL = "www.whatever.com/incrementalPatch1.exe";
g_PatchFileDest = SessionVar.Expand("%SourceFolder%\\Patches\\incrementalPatch1.exe");
else if specific_version == 2 then
-- Where do you want to download the installer/patch file from and to?
g_SourceURL = "www.whatever.com/incrementalPatch2.exe";
g_PatchFileDest = SessionVar.Expand("%SourceFolder%\\Patches\\incrementalPatch2.exe");
else
-- Where do you want to download the installer/patch file from and to?
g_SourceURL = "www.whatever.com/incrementalPatch3.exe";
g_PatchFileDest = SessionVar.Expand("%SourceFolder%\\Patches\\incrementalPatch3.exe");
end
end
Last edited by Dnixon; 01-11-2008 at 09:10 AM. Reason: to further clarify |
|
#3
|
||||
|
||||
|
I am not aware of any current bugs with the String functions. Would you be able to post your findings?
Thanks for your time Adam Kapilik |
|
#4
|
||||
|
||||
|
If I remember correctly, it just doesn't work. I found some other threads where people said there was a bug with the function. Here's the string I had to begin with:
"1.1.0.0" I wanted to remove the ".0.0" from the right and the "1." from the left so I would just have a number: "1". Well it didn't actually trim the characters when the code was executed. |
|
#5
|
||||
|
||||
|
Hi Dnixon,
Remember that the second parameter passed to String.TrimLeft() and String.TrimRight() are the characters to trim not the string to trim. So in this example: Code:
trimmed = String.TrimRight("1.10.0.0", "0.");
Code:
1.1 So in your example when you trim ".0.0" from the right, and "1." from the left, you are actually trimming all of the characters from the string. I hope this helps.
__________________
MSI Factory The Next Generation Intelligent Setup Builder |
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Jukebox Enhancements | Zylo | AutoPlay Media Studio 6.0 | 2 | 01-13-2007 08:39 PM |
| Reading Install Path From Registry | Staggan | Visual Patch 2.0 | 33 | 05-04-2006 11:31 AM |
| Hey guys... having problems writing to a text file | CelticDragon | AutoPlay Media Studio 4.0 | 1 | 08-11-2003 10:31 AM |
| Mac autostart function??? | Protocol | AutoPlay Media Studio 4.0 | 21 | 06-26-2003 11:25 AM |
| INFO: Tips for Debugging Action Lists in AutoPlay Media Studio 4.0 | Support | AutoPlay Media Studio 4.0 Examples | 0 | 10-03-2002 09:38 AM |
All times are GMT -6. The time now is 02:46 AM.









Linear Mode

