home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 217 / DPCS0306DVD.ISO / Toolkit / Internet / FileZilla / Server / FileZilla_Server-0.9.11.exe / source / interface / version.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-06-06  |  4.2 KB  |  128 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. #include "stdafx.h"
  20. #include "version.h"
  21.  
  22. CString GetVersionString()
  23. {
  24.     //Fill the version info
  25.     TCHAR fullpath[MAX_PATH+10];
  26.     GetModuleFileName(0, fullpath, MAX_PATH+10);
  27.     
  28.     TCHAR *str=new TCHAR[_tcslen(fullpath)+1];
  29.     strcpy(str,fullpath);
  30.     DWORD tmp=0;
  31.     DWORD len=GetFileVersionInfoSize(str,&tmp);
  32.     LPVOID pBlock=new char[len];
  33.     GetFileVersionInfo(str,0,len,pBlock);
  34.     LPVOID ptr;
  35.     UINT ptrlen;
  36.  
  37.     CString ProductName;
  38.     //Retreive the product name
  39.     
  40.     char SubBlock[50];
  41.             
  42.     // Structure used to store enumerated languages and code pages.
  43.     struct LANGANDCODEPAGE {
  44.         WORD wLanguage;
  45.         WORD wCodePage;
  46.     } *lpTranslate;
  47.  
  48.     UINT cbTranslate;
  49.             
  50.     // Read the list of languages and code pages.
  51.     if (VerQueryValue(pBlock, 
  52.                 TEXT("\\VarFileInfo\\Translation"),
  53.                 (LPVOID*)&lpTranslate,
  54.                 &cbTranslate))
  55.     {
  56.         // Read the file description for each language and code page.
  57.     
  58.         sprintf( SubBlock, 
  59.                "\\StringFileInfo\\%04x%04x\\ProductName",
  60.                lpTranslate[0].wLanguage,
  61.                lpTranslate[0].wCodePage);
  62.         // Retrieve file description for language and code page "0". 
  63.         if (VerQueryValue(pBlock, 
  64.                 SubBlock, 
  65.                 &ptr, 
  66.                     &ptrlen))
  67.         {
  68.             ProductName=(char*)ptr;
  69.         }
  70.     }
  71.     CString version;
  72.     //Format the versionstring
  73.     if (VerQueryValue(pBlock,"\\",&ptr,&ptrlen))
  74.     {
  75.         VS_FIXEDFILEINFO *fi=(VS_FIXEDFILEINFO*)ptr;
  76.         unsigned __int64 curver=(((__int64)fi->dwFileVersionMS)<<32)+fi->dwFileVersionLS;
  77.         
  78.         
  79.         if (fi->dwFileVersionMS>>16)
  80.         {
  81.             //v1.00+
  82.             if (fi->dwFileVersionLS&0xFFFF)
  83.             { //test releases
  84.                 if (fi->dwFileVersionLS>>16)
  85.                 {
  86.                     char ch='a';
  87.                     ch+=static_cast<char>(fi->dwFileVersionLS>>16)-1;
  88.                     version.Format("%s version %d.%d%c test release %d)",ProductName,fi->dwFileVersionMS>>16,fi->dwFileVersionMS&0xFFFF,ch,fi->dwFileVersionLS&0xFFFF);
  89.                 }
  90.                 else
  91.                     version.Format("%s version %d.%d test release %d",ProductName,fi->dwFileVersionMS>>16,fi->dwFileVersionMS&0xFFFF,fi->dwFileVersionLS&0xFFFF);
  92.             }
  93.             else
  94.             { //final versions
  95.                 if (fi->dwFileVersionLS>>16)
  96.                 {
  97.                     char ch='a';
  98.                     ch+=static_cast<char>(fi->dwFileVersionLS>>16)-1;
  99.                     version.Format("%s version %d.%d%c final",ProductName,fi->dwFileVersionMS>>16,fi->dwFileVersionMS&0xFFFF,ch);
  100.                 }
  101.                 else
  102.                     version.Format("%s version %d.%d final",ProductName,fi->dwFileVersionMS>>16,fi->dwFileVersionMS&0xFFFF);
  103.             }
  104.         }
  105.         else
  106.         {
  107.             //beta versions
  108.             if ((fi->dwFileVersionLS&0xFFFF)/100)
  109.                 if ((fi->dwFileVersionLS&0xFFFF) % 100)
  110.                     //test release
  111.                     version.Format("%s version 0.%d.%d%c beta test release %d",ProductName,fi->dwFileVersionMS&0xFFFF,fi->dwFileVersionLS>>16, (fi->dwFileVersionLS&0xFFFF)/100 + 'a' - 1, (fi->dwFileVersionLS&0xFFFF)%100);
  112.                 else
  113.                     //final version
  114.                     version.Format(_T("%s version 0.%d.%d%c beta"),ProductName,fi->dwFileVersionMS&0xFFFF,fi->dwFileVersionLS>>16, (fi->dwFileVersionLS&0xFFFF)/100 + 'a' - 1);
  115.             else
  116.                 if (fi->dwFileVersionLS&0xFFFF)
  117.                     //test release
  118.                     version.Format("%s version 0.%d.%d beta test release %d",ProductName,fi->dwFileVersionMS&0xFFFF,fi->dwFileVersionLS>>16,fi->dwFileVersionLS&0xFFFF);
  119.                 else
  120.                     //final version
  121.                     version.Format(_T("%s version 0.%d.%d beta"),ProductName,fi->dwFileVersionMS&0xFFFF,fi->dwFileVersionLS>>16);            
  122.         }
  123.         
  124.     }
  125.     delete [] str;
  126.     delete [] pBlock;
  127.     return version;
  128. }