home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 217 / DPCS0306DVD.ISO / Toolkit / Internet / FileZilla / Server / FileZilla_Server-0.9.11.exe / source / version.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-06-06  |  4.1 KB  |  126 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. CStdString 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.     CStdString 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.     CStdString version;
  72.     //Format the versionstring
  73.     if (VerQueryValue(pBlock,"\\",&ptr,&ptrlen))
  74.     {
  75.         VS_FIXEDFILEINFO *fi=(VS_FIXEDFILEINFO*)ptr;
  76.         
  77.         if (fi->dwFileVersionMS>>16)
  78.         {
  79.             //v1.00+
  80.             if (fi->dwFileVersionLS&0xFFFF)
  81.             { //test releases
  82.                 if (fi->dwFileVersionLS>>16)
  83.                 {
  84.                     char ch='a';
  85.                     ch+=static_cast<char>(fi->dwFileVersionLS>>16)-1;
  86.                     version.Format("%s version %d.%d%c test release %d)",ProductName,fi->dwFileVersionMS>>16,fi->dwFileVersionMS&0xFFFF,ch,fi->dwFileVersionLS&0xFFFF);
  87.                 }
  88.                 else
  89.                     version.Format("%s version %d.%d test release %d",ProductName,fi->dwFileVersionMS>>16,fi->dwFileVersionMS&0xFFFF,fi->dwFileVersionLS&0xFFFF);
  90.             }
  91.             else
  92.             { //final versions
  93.                 if (fi->dwFileVersionLS>>16)
  94.                 {
  95.                     char ch='a';
  96.                     ch+=static_cast<char>(fi->dwFileVersionLS>>16)-1;
  97.                     version.Format("%s version %d.%d%c final",ProductName,fi->dwFileVersionMS>>16,fi->dwFileVersionMS&0xFFFF,ch);
  98.                 }
  99.                 else
  100.                     version.Format("%s version %d.%d final",ProductName,fi->dwFileVersionMS>>16,fi->dwFileVersionMS&0xFFFF);
  101.             }
  102.         }
  103.         else
  104.         {
  105.             //beta versions
  106.             if ((fi->dwFileVersionLS&0xFFFF)/100)
  107.                 if ((fi->dwFileVersionLS&0xFFFF) % 100)
  108.                     //test release
  109.                     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);
  110.                 else
  111.                     //final version
  112.                     version.Format(_T("%s version 0.%d.%d%c beta"),ProductName,fi->dwFileVersionMS&0xFFFF,fi->dwFileVersionLS>>16, (fi->dwFileVersionLS&0xFFFF)/100 + 'a' - 1);
  113.             else
  114.                 if (fi->dwFileVersionLS&0xFFFF)
  115.                     //test release
  116.                     version.Format("%s version 0.%d.%d beta test release %d",ProductName,fi->dwFileVersionMS&0xFFFF,fi->dwFileVersionLS>>16,fi->dwFileVersionLS&0xFFFF);
  117.                 else
  118.                     //final version
  119.                     version.Format(_T("%s version 0.%d.%d beta"),ProductName,fi->dwFileVersionMS&0xFFFF,fi->dwFileVersionLS>>16);
  120.         }
  121.         
  122.     }
  123.     delete [] str;
  124.     delete [] pBlock;
  125.     return version;
  126. }