/*  Project Tec3270

	 SUBSYSTEM:    Tec3270.exe (Tec3270 application)
	 FILE:         alffntad.cpp
	 AUTHOR:       Alcindo Ferreira Filho

	 OVERVIEW:

    Tec3270AboutDlg  class implementation.

    COPYRIGHT:    © 1998-2007
                  Alcindo Ferreira Filho
                  <alcindo@inttec.com.br>

    LICENSE:      Tec3270_License (docs/Tec3270_License.txt)
*/
#include "alffnall.h"

ProjectRCVersion::ProjectRCVersion (TModule *module)
{
    char    appFName[255];
    char    subBlockName[255];
    DWORD   fvHandle;
    UINT    vSize;

    FVData = 0;

    module->GetModuleFileName(appFName, sizeof(appFName));
    OemToAnsi(appFName, appFName);
    DWORD dwSize = ::GetFileVersionInfoSize(appFName, &fvHandle);
    if (dwSize) {
        FVData  = (void FAR *)new char[(UINT)dwSize];
        if (::GetFileVersionInfo(appFName, fvHandle, dwSize, FVData)) {
            // Copy string to buffer so if the -dc compiler switch (Put constant strings in code segments)
            // is on VerQueryValue will work under Win16.  This works around a problem in Microsoft's ver.dll
            // which writes to the string pointed to by subBlockName.
            strcpy(subBlockName, "\\VarFileInfo\\Translation"); 
            if (!::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&TransBlock, &vSize)) {
                delete FVData;
                FVData = 0;
            } else
                // Swap the words so wsprintf will print the lang-charset in the correct format.
                *(DWORD *)TransBlock = MAKELONG(HIWORD(*(DWORD *)TransBlock), LOWORD(*(DWORD *)TransBlock));
        }
    }
}


ProjectRCVersion::~ProjectRCVersion ()
{
	 if (FVData)
		  delete [] FVData;
}


bool ProjectRCVersion::GetProductName (LPSTR &prodName)
{
	 UINT    vSize;
	 char    subBlockName[255];

	 if (FVData) {
		  wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"ProductName");
		  return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&prodName, &vSize) : false;
	 } else
		  return false;
}


bool ProjectRCVersion::GetProductVersion (LPSTR &prodVersion)
{
	 UINT    vSize;
    char    subBlockName[255];

	 if (FVData) {
		  wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"ProductVersion");
        return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&prodVersion, &vSize) : false;
	 } else
		  return false;
}


bool ProjectRCVersion::GetCopyright (LPSTR &copyright)
{
	 UINT    vSize;
    char    subBlockName[255];

	 if (FVData) {
		  wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"LegalCopyright");
		  return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&copyright, &vSize) : false;
	 } else
		  return false;
}

bool ProjectRCVersion::GetLegalTradeMarks (LPSTR &trademark)
{
	 UINT    vSize;
	 char    subBlockName[255];

	 if (FVData) {
		  wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"LegalTrademarks");
		  return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&trademark, &vSize) : false;
	 } else
		  return false;
}

bool ProjectRCVersion::GetDebug (LPSTR &debug)
{
	 UINT    vSize;
    char    subBlockName[255];

	 if (FVData) {
        wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"SpecialBuild");
		  return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&debug, &vSize) : false;
	 } else
        return false;
}


//{{Tec3270AboutDlg Implementation}}

//////////////////////////////////////////////////////////
// Tec3270AboutDlg
// ==========
// Construction/Destruction handling.
Tec3270AboutDlg::Tec3270AboutDlg (TWindow *parent, TResId resId, TModule *module)
    : ALFFDialog(parent, resId, module)
{
	 // INSERT>> Your constructor code here.
	 pMsgs = new ALFFMsgs(this);

	 // Get the static text for the value based on VERSIONINFO.
	 versionCtrl = new TStatic(this, IDC_ALFFVERSION, 255);
	 copyrightCtrl = new TStatic(this, IDC_ALFFCOPYRIGHT, 255);
	 debugCtrl = new TStatic(this, IDC_ALFFDEBUG, 255);

	 /* Get the static text for Tec3270 Remarks (17 lines ) */
	 rmks1  = new TStatic(this,IDC_ALFFREMARKS1,255);
	 rmks2  = new TStatic(this,IDC_ALFFREMARKS2,255);
	 rmks3  = new TStatic(this,IDC_ALFFREMARKS3,255);
	 rmks4  = new TStatic(this,IDC_ALFFREMARKS4,255);
	 rmks5  = new TStatic(this,IDC_ALFFREMARKS5,255);
	 rmks6  = new TStatic(this,IDC_ALFFREMARKS6,255);
	 rmks7  = new TStatic(this,IDC_ALFFREMARKS7,255);
	 rmks8  = new TStatic(this,IDC_ALFFREMARKS8,255);
	 rmks9  = new TStatic(this,IDC_ALFFREMARKS9,255);
	 rmks10 = new TStatic(this,IDC_ALFFREMARKS10,255);
	 rmks11 = new TStatic(this,IDC_ALFFREMARKS11,255);
	 rmks12 = new TStatic(this,IDC_ALFFREMARKS12,255);
	 rmks13 = new TStatic(this,IDC_ALFFREMARKS13,255);
	 rmks14 = new TStatic(this,IDC_ALFFREMARKS14,255);
	 rmks15 = new TStatic(this,IDC_ALFFREMARKS15,255);
	 rmks16 = new TStatic(this,IDC_ALFFREMARKS16,255);
	 rmks17 = new TStatic(this,IDC_ALFFREMARKS17,255);
}


Tec3270AboutDlg::~Tec3270AboutDlg ()
{
	 Destroy();

	 delete pMsgs;

	 // Get the static text for the value based on VERSIONINFO.
	 delete   versionCtrl;
	 delete   copyrightCtrl;
	 delete   debugCtrl;

	 /* Get the static text for Tec3270 Remarks (17 lines ) */
	 delete   rmks1;
	 delete   rmks2;
	 delete   rmks3;
	 delete   rmks4;
	 delete   rmks5;
	 delete   rmks6;
	 delete   rmks7;
	 delete   rmks8;
	 delete   rmks9;
	 delete   rmks10;
	 delete   rmks11;
	 delete   rmks12;
	 delete   rmks13;
	 delete   rmks14;
	 delete   rmks15;
	 delete   rmks16;
	 delete   rmks17;
}



void Tec3270AboutDlg::SetupWindow ()
{
	 LPSTR prodName = 0, prodVersion = 0, copyright = 0,
			 trademark = 0, debug = 0;

	 ALFFDialog::SetupWindow();

	 /* Load All Static Remakrs Text */
	 char remarks[255];
	 pMsgs->LoadString(IDS_ALFFREMARKS1,remarks,254);
	 rmks1->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS2,remarks,254);
	 rmks2->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS3,remarks,254);
	 rmks3->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS4,remarks,254);
	 rmks4->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS5,remarks,254);
	 rmks5->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS6,remarks,254);
	 rmks6->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS7,remarks,254);
	 rmks7->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS8,remarks,254);
	 rmks8->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS9,remarks,254);
	 rmks9->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS10,remarks,254);
	 rmks10->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS11,remarks,254);
	 rmks11->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS12,remarks,254);
	 rmks12->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS13,remarks,254);
	 rmks13->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS14,remarks,254);
	 rmks14->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS15,remarks,254);
	 rmks15->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS16,remarks,254);
	 rmks16->SetText(remarks);
	 pMsgs->LoadString(IDS_ALFFREMARKS17,remarks,254);
	 rmks17->SetText(remarks);

	 // Process the VERSIONINFO.
	 ProjectRCVersion applVersion(GetModule());

	 // Get the product name and product version strings.
	 if (applVersion.GetProductName(prodName)
		  && applVersion.GetProductVersion(prodVersion))
	  {
		/*
		 * IDC_VERSION is the product name and version number,
		 * the initial value of IDC_VERSION is
		 * the word Version (in whatever language)
		 * product name VERSION product version.
		 */
		char    buffer[255];
		buffer[0] = '\0';
		wsprintf(buffer, "%s %s", prodName, prodVersion);
		versionCtrl->SetText(buffer);
	 }

	 //Get the legal copyright string.
	 if (applVersion.GetCopyright(copyright)
		&& applVersion.GetLegalTradeMarks(trademark) )
		{
		 char    buffer[255];
		 buffer[0] = '\0';

		 wsprintf(buffer, "%s \n %s", copyright, trademark);
		 copyrightCtrl->SetText(buffer);
		}

	 // Only get the SpecialBuild text if the VERSIONINFO resource is there.
	 if (applVersion.GetDebug(debug))
		  debugCtrl->SetText(debug);
}
