8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-01 05:23:03 +01:00
firebird-mirror/src/jrd/os/win32/config_root.cpp

122 lines
3.3 KiB
C++
Raw Normal View History

2002-11-03 17:26:12 +01:00
/*
* PROGRAM: Client/Server Common Code
* MODULE: config_root.cpp
* DESCRIPTION: Configuration manager (platform specific - linux/posix)
2002-11-03 17:26:12 +01:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* You may obtain a copy of the Licence at
* http://www.gnu.org/licences/lgpl.html
*
* As a special exception this file can also be included in modules
* with other source code as long as that source code has been
* released under an Open Source Initiative certificed licence.
* More information about OSI certification can be found at:
* http://www.opensource.org
*
* This module is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public Licence for more details.
*
* This module was created by members of the firebird development
* team. All individual contributions remain the Copyright (C) of
* those individuals and all rights are reserved. Contributors to
* this file are either listed below or can be obtained from a CVS
* history command.
2002-11-03 17:26:12 +01:00
*
* Created by: Mark O'Donohue <skywalker@users.sourceforge.net>
2002-11-03 17:26:12 +01:00
*
* Contributor(s):
2002-11-03 17:26:12 +01:00
*/
2002-11-14 14:40:04 +01:00
#include "firebird.h"
2002-11-03 17:26:12 +01:00
#include <windows.h>
#include "fb_types.h"
#include "fb_string.h"
#include "../jrd/os/config_root.h"
#include "../jrd/os/path_utils.h"
2003-07-15 04:43:36 +02:00
#include "../utilities/install/registry.h"
2002-11-03 17:26:12 +01:00
typedef Firebird::string string;
2002-12-06 13:04:39 +01:00
static const char *REGISTRY_KEY = "RootDirectory";
static const char *CONFIG_FILE = "firebird.conf";
2002-11-03 17:26:12 +01:00
/******************************************************************************
*
* Platform-specific root locator
*/
2002-11-17 16:46:24 +01:00
void getRootFromRegistry(TEXT *buffer, DWORD buffer_length)
{
HKEY hkey;
DWORD type;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_KEY_ROOT_CUR_VER,
0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS)
{
return;
}
2002-12-06 13:04:39 +01:00
RegQueryValueEx(hkey, REGISTRY_KEY, NULL, &type,
2002-11-17 16:46:24 +01:00
reinterpret_cast<UCHAR*>(buffer), &buffer_length);
RegCloseKey(hkey);
}
2002-11-03 17:26:12 +01:00
ConfigRoot::ConfigRoot()
{
TEXT buffer[MAXPATHLEN];
2002-11-17 16:46:24 +01:00
buffer[0] = 0;
// check the registry first
2003-03-01 17:30:55 +01:00
#if !defined(EMBEDDED)
2002-11-17 16:46:24 +01:00
getRootFromRegistry(buffer, sizeof(buffer));
2003-03-01 17:30:55 +01:00
#endif
2002-11-17 16:46:24 +01:00
if (buffer[0])
{
root_dir = buffer;
if (root_dir.rfind(PathUtils::dir_sep) != root_dir.length() - 1)
{
root_dir += PathUtils::dir_sep;
}
2002-11-17 16:46:24 +01:00
return;
}
2002-11-03 17:26:12 +01:00
// get the pathname of the running executable
GetModuleFileName(NULL, buffer, sizeof(buffer));
string bin_dir = buffer;
// get rid of the filename
int index = bin_dir.rfind(PathUtils::dir_sep);
bin_dir = bin_dir.substr(0, index);
// how should we decide to use bin_dir instead of root_dir? any ideas?
// ???
2003-03-01 17:30:55 +01:00
#if defined(EMBEDDED)
root_dir = bin_dir + PathUtils::dir_sep;
return;
#endif
2002-11-03 17:26:12 +01:00
// go to the parent directory
index = bin_dir.rfind(PathUtils::dir_sep, bin_dir.length());
root_dir = (index ? bin_dir.substr(0, index) : bin_dir) + PathUtils::dir_sep;
}
2002-12-06 13:04:39 +01:00
const char *ConfigRoot::getRootDirectory() const
2002-11-03 17:26:12 +01:00
{
2002-12-06 13:04:39 +01:00
return root_dir.c_str();
2002-11-03 17:26:12 +01:00
}
2002-12-06 13:04:39 +01:00
const char *ConfigRoot::getConfigFile() const
2002-11-03 17:26:12 +01:00
{
2002-12-06 13:04:39 +01:00
static string file = root_dir + string(CONFIG_FILE);
return file.c_str();
2002-11-03 17:26:12 +01:00
}