Back to index

lightning-sunbird  0.9+nobinonly
version.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Communicator.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corp.
00018  * Portions created by the Initial Developer are Copyright (C) 2003
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Sean Su <ssu@netscape.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "setup.h"
00039 #include "windows.h"
00040 #include "extern.h"
00041 #include "extra.h"
00042 #include "version.h"
00043 
00044 BOOL GetFileVersion(LPSTR szFile, verBlock *vbVersion)
00045 {
00046   UINT              uLen;
00047   UINT              dwLen;
00048   BOOL              bRv;
00049   DWORD             dwHandle;
00050   LPVOID            lpData;
00051   LPVOID            lpBuffer;
00052   VS_FIXEDFILEINFO  *lpBuffer2;
00053 
00054   vbVersion->ullMajor   = 0;
00055   vbVersion->ullMinor   = 0;
00056   vbVersion->ullRelease = 0;
00057   vbVersion->ullBuild   = 0;
00058   if(FileExists(szFile))
00059   {
00060     bRv    = TRUE;
00061     dwLen  = GetFileVersionInfoSize(szFile, &dwHandle);
00062     lpData = (LPVOID)malloc(sizeof(long)*dwLen);
00063     uLen   = 0;
00064 
00065     if(GetFileVersionInfo(szFile, dwHandle, dwLen, lpData) != 0)
00066     {
00067       if(VerQueryValue(lpData, "\\", &lpBuffer, &uLen) != 0)
00068       {
00069         lpBuffer2             = (VS_FIXEDFILEINFO *)lpBuffer;
00070         vbVersion->ullMajor   = HIWORD(lpBuffer2->dwFileVersionMS);
00071         vbVersion->ullMinor   = LOWORD(lpBuffer2->dwFileVersionMS);
00072         vbVersion->ullRelease = HIWORD(lpBuffer2->dwFileVersionLS);
00073         vbVersion->ullBuild   = LOWORD(lpBuffer2->dwFileVersionLS);
00074       }
00075     }
00076     free(lpData);
00077   }
00078   else
00079     /* File does not exist */
00080     bRv = FALSE;
00081 
00082   return(bRv);
00083 }
00084 
00085 void TranslateVersionStr(LPSTR szVersion, verBlock *vbVersion)
00086 {
00087   LPSTR szNum1 = NULL;
00088   LPSTR szNum2 = NULL;
00089   LPSTR szNum3 = NULL;
00090   LPSTR szNum4 = NULL;
00091 
00092   szNum1 = strtok(szVersion, ".");
00093   szNum2 = strtok(NULL,      ".");
00094   szNum3 = strtok(NULL,      ".");
00095   szNum4 = strtok(NULL,      ".");
00096 
00097   vbVersion->ullMajor   = _atoi64(szNum1);
00098   vbVersion->ullMinor   = _atoi64(szNum2);
00099   vbVersion->ullRelease = _atoi64(szNum3);
00100   vbVersion->ullBuild   = _atoi64(szNum4);
00101 }
00102 
00103 int CompareVersion(verBlock vbVersionOld, verBlock vbVersionNew)
00104 {
00105   if(vbVersionOld.ullMajor > vbVersionNew.ullMajor)
00106     return(4);
00107   else if(vbVersionOld.ullMajor < vbVersionNew.ullMajor)
00108     return(-4);
00109 
00110   if(vbVersionOld.ullMinor > vbVersionNew.ullMinor)
00111     return(3);
00112   else if(vbVersionOld.ullMinor < vbVersionNew.ullMinor)
00113     return(-3);
00114 
00115   if(vbVersionOld.ullRelease > vbVersionNew.ullRelease)
00116     return(2);
00117   else if(vbVersionOld.ullRelease < vbVersionNew.ullRelease)
00118     return(-2);
00119 
00120   if(vbVersionOld.ullBuild > vbVersionNew.ullBuild)
00121     return(1);
00122   else if(vbVersionOld.ullBuild < vbVersionNew.ullBuild)
00123     return(-1);
00124 
00125   /* the versions are all the same */
00126   return(0);
00127 }
00128