2002-11-03 17:26:12 +01:00
|
|
|
/*
|
2003-09-26 16:18:31 +02:00
|
|
|
* 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 at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
2002-11-03 17:26:12 +01:00
|
|
|
*
|
2003-09-26 16:18:31 +02:00
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
2002-11-03 17:26:12 +01:00
|
|
|
*
|
2003-09-26 16:18:31 +02:00
|
|
|
* The Original Code was created by Dmitry Yemanov
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
2002-11-03 17:26:12 +01:00
|
|
|
*
|
2003-09-26 16:18:31 +02:00
|
|
|
* Copyright (c) 2002 Dmitry Yemanov <dimitr@users.sf.net>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* 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"
|
2003-07-15 04:43:36 +02:00
|
|
|
#include "../utilities/install/registry.h"
|
2002-11-03 17:26:12 +01:00
|
|
|
|
2004-02-08 18:08:34 +01:00
|
|
|
typedef Firebird::PathName string;
|
2002-11-03 17:26:12 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Platform-specific root locator
|
|
|
|
*/
|
2004-02-28 20:29:53 +01:00
|
|
|
namespace {
|
2002-11-03 17:26:12 +01:00
|
|
|
|
2004-02-28 20:29:53 +01:00
|
|
|
bool getRootFromRegistry(string& root)
|
2002-11-17 16:46:24 +01:00
|
|
|
{
|
|
|
|
HKEY hkey;
|
|
|
|
|
2003-10-08 11:42:23 +02:00
|
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_KEY_ROOT_INSTANCES,
|
2002-11-17 16:46:24 +01:00
|
|
|
0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS)
|
|
|
|
{
|
2004-02-28 20:29:53 +01:00
|
|
|
return false;
|
2002-11-17 16:46:24 +01:00
|
|
|
}
|
|
|
|
|
2004-02-28 20:29:53 +01:00
|
|
|
DWORD bufsize = MAXPATHLEN;
|
|
|
|
char buffer[MAXPATHLEN];
|
2004-12-06 11:17:00 +01:00
|
|
|
DWORD type;
|
2004-03-07 08:58:55 +01:00
|
|
|
const long RegRC = RegQueryValueEx(hkey, FB_DEFAULT_INSTANCE,
|
2004-02-28 20:29:53 +01:00
|
|
|
NULL, &type, reinterpret_cast<UCHAR*>(buffer), &bufsize);
|
2002-11-17 16:46:24 +01:00
|
|
|
RegCloseKey(hkey);
|
2004-02-28 20:29:53 +01:00
|
|
|
if (RegRC == ERROR_SUCCESS) {
|
|
|
|
root = buffer;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2002-11-17 16:46:24 +01:00
|
|
|
}
|
|
|
|
|
2004-06-14 01:45:02 +02:00
|
|
|
} // namespace
|
2002-11-17 16:46:24 +01:00
|
|
|
|
2004-02-28 20:29:53 +01:00
|
|
|
void ConfigRoot::osConfigRoot()
|
|
|
|
{
|
2002-11-17 16:46:24 +01:00
|
|
|
// check the registry first
|
2003-03-01 17:30:55 +01:00
|
|
|
#if !defined(EMBEDDED)
|
2004-02-28 20:29:53 +01:00
|
|
|
if (getRootFromRegistry(root_dir))
|
2002-11-17 16:46:24 +01:00
|
|
|
{
|
2004-02-28 20:29:53 +01:00
|
|
|
addSlash();
|
2002-11-17 16:46:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2004-02-28 20:29:53 +01:00
|
|
|
#endif
|
2002-11-17 16:46:24 +01:00
|
|
|
|
2002-11-03 17:26:12 +01:00
|
|
|
// get the pathname of the running executable
|
2004-02-28 20:29:53 +01:00
|
|
|
string bin_dir;
|
|
|
|
{
|
2004-03-07 08:58:55 +01:00
|
|
|
// Given the current semantics of PathName, when "buffer" goes
|
|
|
|
// out of scope, it's already bitwise copied into bin_dir.
|
2004-02-28 20:29:53 +01:00
|
|
|
char buffer[MAXPATHLEN];
|
|
|
|
GetModuleFileName(NULL, buffer, sizeof(buffer));
|
|
|
|
bin_dir = buffer;
|
|
|
|
}
|
2002-11-03 17:26:12 +01:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2004-12-06 11:17:00 +01:00
|
|
|
|