8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 07:23:03 +01:00
firebird-mirror/src/utilities/fbcpl/fbpanel.cpp
robocop 3b70e8097a Solve several issues in the recently posted Control Panel applet:
- Cleanup.
- Adjust the #ifdef protecting headers to our style.
- Correct some C++ misuses like redundant casts and switch-case without break.
- Correct some CString and Win32 API misuses that lead either to random failures or memory leaks.
- Be consistent with bool and constness.
2005-03-20 04:35:56 +00:00

138 lines
4.4 KiB
C++

/*
* PROGRAM: Firebird 2.0 control panel applet
* MODULE: fbpanel.cpp
* DESCRIPTION: The FBPanel unit does the following things:
* - It manages the display of the icon in the
* Control Panel manager
* - It tests whether Firebird is installed
* - If Fb is installed it sets the status of items
* that can be read from the Firebird registry entries
* and launches the Applet.
*
* Everything else is handled by the fbdialog unit. This is
* not a good thing as UI stuff is integrated with management
* and diagnostic stuff. A better design for Fb 2.0 would be
* to separate everything out and share the code with the
* existing command line tools that manage services and
* installation settings.
*
* The contents of this file are subject to the Initial Developer's
* Public License Version 1.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy
* of the License here:
*
* http://www.ibphoenix.com?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing rights
* and limitations under the License.
*
* The Initial Developer of the Original Code is Paul Reeves.
*
* The Original Code is (C) 2003 Paul Reeves .
*
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
*/
#include "stdafx.h"
#include "../install/registry.h"
#include "FBPanel.h"
#include "FBDialog.h"
#include <Shlwapi.h>
LONG CFBPanel::OnInquire(UINT uAppNum, NEWCPLINFO* pInfo)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// Fill in the data
pInfo->dwSize = sizeof(NEWCPLINFO); // important
pInfo->dwFlags = 0;
pInfo->dwHelpContext = 0;
pInfo->lData = 0;
pInfo->hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON1));
strcpy(pInfo->szName, "Firebird 2.0 Server Manager");
strcpy(pInfo->szInfo, "Configure Firebird 2.0 Database Server");
strcpy(pInfo->szHelpFile, "");
return 0; // OK (don't send CPL_INQUIRE msg)
}
LONG CFBPanel::OnDblclk(HWND hwndCPl, UINT uAppNum, LONG lData)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// Create the dialog box using the parent window handle
CFBDialog dlg(CWnd::FromHandle(hwndCPl));
try {
// Check if Firebird is installed by reading the registry
HKEY hkey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_KEY_ROOT_INSTANCES, 0, KEY_QUERY_VALUE, &hkey)
== ERROR_SUCCESS)
{
char rootpath[MAX_PATH - 2];
DWORD buffer_size = sizeof(rootpath);
if (RegQueryValueEx(hkey, "DefaultInstance", NULL, NULL, LPBYTE(rootpath), &buffer_size)
== ERROR_SUCCESS)
{
PathAddBackslash(rootpath);
dlg.m_Root_Path = rootpath;
}
RegCloseKey(hkey);
dlg.m_FB_Version = "not known";
CString afilename = dlg.m_Root_Path + "bin\\gbak.exe";
buffer_size = GetFileVersionInfoSize( const_cast<char *> ((LPCTSTR) afilename), 0);
void* VersionInfo = new char [buffer_size];
void* ProductVersion = 0;
void* SpecialBuild = 0;
void* PrivateBuild = 0;
UINT ValueSize;
if ( GetFileVersionInfo( const_cast<char *> ((LPCTSTR) afilename), 0, buffer_size, VersionInfo) )
{
VerQueryValue( VersionInfo, "\\StringFileInfo\\040904E4\\ProductVersion", &ProductVersion, &ValueSize);
if (ValueSize)
{
dlg.m_FB_Version = "Version ";
dlg.m_FB_Version += (char *)ProductVersion;
}
VerQueryValue( VersionInfo, "\\StringFileInfo\\040904E4\\SpecialBuild", &SpecialBuild, &ValueSize);
if (ValueSize)
{
dlg.m_FB_Version += " ";
dlg.m_FB_Version += (char *)SpecialBuild;
}
VerQueryValue( VersionInfo, "\\StringFileInfo\\040904E4\\PrivateBuild", &PrivateBuild, &ValueSize);
if (ValueSize)
{
dlg.m_FB_Version += " ";
dlg.m_FB_Version += (char *)PrivateBuild;
}
/**/
}
delete[] VersionInfo;
// Show the dialog box
if (dlg.DoModal() != IDOK)
return 0;
}
}
catch ( ... )
{
//raise an error
dlg.MessageBox("Firebird does not appear to be installed correctly.", "Installation Error", MB_OK);
}
return 0;
}