/* * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a * aplicativos mainframe. Registro no INPI sob o nome G3270. * * Copyright (C) <2008> * * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela * Free Software Foundation. * * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para * obter mais detalhes. * * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA, 02111-1307, USA * * Este programa está nomeado como config.c e possui 389 linhas de código. * * Contatos: * * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) * licinio@bb.com.br (Licínio Luis Branco) * kraucer@bb.com.br (Kraucer Fernandes Mazuco) * */ #include #include "common.h" #include #include #ifdef WIN32 #include #define WIN_REGISTRY_ENABLED 1 #ifndef KEY_WOW64_64KEY #define KEY_WOW64_64KEY 0x0100 #endif // KEY_WOW64_64KEY #ifndef KEY_WOW64_32KEY #define KEY_WOW64_32KEY 0x0200 #endif // KEY_WOW64_64KEY #endif // WIN32 /*--[ Globals ]--------------------------------------------------------------------------------------*/ #ifdef WIN_REGISTRY_ENABLED static const gchar *registry_path = "SOFTWARE\\"; #else static GKeyFile * program_config = NULL; static const gchar * mask = "%s" G_DIR_SEPARATOR_S "%s.conf"; #endif // WIN_REGISTRY_ENABLED /*--[ Implement ]------------------------------------------------------------------------------------*/ #ifdef WIN32 gchar * get_last_error_msg(void) { LPVOID lpMsgBuf; DWORD dw = GetLastError(); gchar * ptr; gsize bytes_written; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); for(ptr=lpMsgBuf;*ptr != '\n';ptr++); *ptr = 0; ptr = g_locale_to_utf8(lpMsgBuf,strlen(lpMsgBuf)-1,NULL,&bytes_written,NULL); LocalFree(lpMsgBuf); return ptr; } #endif // WIN32 #ifdef WIN_REGISTRY_ENABLED static BOOL registry_open_key(const gchar *group, REGSAM samDesired, HKEY *hKey) { static HKEY predefined[] = { HKEY_CURRENT_USER, HKEY_USERS, HKEY_LOCAL_MACHINE }; int f; gchar * path = g_strdup_printf("%s\\%s\\%s",registry_path,g_get_application_name(),group); for(f=0;fstr); } va_start(args, first_element); for(element = first_element;element;element = va_arg(args, gchar *)) { g_string_append_c(result,G_DIR_SEPARATOR); g_string_append(result,element); } va_end(args); return g_string_free(result, FALSE); } #ifdef WIN_REGISTRY_ENABLED gboolean get_registry_handle(const gchar *group, HKEY *hKey, REGSAM samDesired) { gboolean ret; gchar * path = g_strdup_printf("%s\\%s\\%s",registry_path,g_get_application_name(),group); DWORD disp; if(RegCreateKeyEx(HKEY_CURRENT_USER,path,0,NULL,REG_OPTION_NON_VOLATILE,samDesired,NULL,hKey,&disp) == ERROR_SUCCESS) ret = TRUE; else ret = FALSE; g_free(path); return ret; } #else GKeyFile * get_application_keyfile(void) { if(!program_config) configuration_init(); return program_config; } #endif // WIN_REGISTRY_ENABLED