Sweden-Number/files/profile.c

687 lines
20 KiB
C
Raw Normal View History

Release 960131 Wed Jan 31 10:58:00 1996 Alexandre Julliard <julliard@sunsite.unc.edu> * [configure.in] Added --with-dll option to build libwine.so. * [controls/listbox.c] Fixed ListBoxDirectory(), DlgDirSelect() and DlgDirList(). Hopefully their behavior is correct now. * [controls/menu.c] Use SEGPTRs in ChangeMenu(), InsertMenu(), AppendMenu() and ModifyMenu() for the item data, to avoid corrupting the pointer for owner-drawn items. * [controls/static.c] Attempt to load OEM icons for SS_ICON controls. Probably not entirely correct. Don't clip the text output. * [files/directory.c] Add temp dir and Windows dir to environment. * [files/dos_fs.c] Fixed a few path handling bugs in DOSFS_GetUnixFileName(). Cache last used directory in DOSFS_FindNext() to avoid quadratic search time. * [files/drive.c] New format for drives configuration in wine.conf; allows specifying the type, label and serial number of a drive. * [files/file.c] New function FILE_OpenUnixFile to make sure we don't open a directory instead of a file. Fixed DOSFS_GetUnixFileName() check_last flag in FILE_MakeDir(). * [files/profile.c] Rewrote profile handling. Should be closer to Windows behavior now. New function PROFILE_GetWineIniString() to get a string from wine.conf. Support environment variables in wine.conf. * [loader/task.c] Fixed the order of deletion in TASK_DeleteTask() to avoid memory corruption. * [memory/global.c] Create a discarded block on GlobalAlloc() if the size is 0; thanks to John Harvey for noticing this. * [memory/local.c] LOCAL_GetHeap: make sure the pointer is valid before checking magic number. * [misc/main.c] Moved profile and registry saving to ExitWindows(), so we don't try to save them in case of a crash. * [miscemu/int21.c] INT21_GetFreeDiskSpace: try to compute the cluster size from the filesystem size instead of hard-coding it to 64. Fixed functions 0x3f and 0x40 to use _hread and _hwrite to allow reading or writing 65535 bytes (thanks to Bruce Milner for this one). * [windows/message.c] Fixed bug in linked-list handling in MSG_DeleteQueue(). Simplified SetMessageQueue(). * [wine.ini] [wine.man] Updated for new drives configuration format. Tue Jan 30 11:24:46 1996 William Magro <wmagro@tc.cornell.edu> * [controls/edit.c] Implemented ES_PASSWORD style, EM_SETPASSWORDCHAR and EM_GETPASSWORDCHAR messages. * [controls/widgets.c] Adjusted class creation flags to better match values Windows uses. * [include/windows.h] Fixed ES_NOHIDESEL typo. * [loader/ne_image.c] Added detection for zero offset in RADDR fixups. Quicken was in an infinite loop here. Mon Jan 29 20:12:22 1996 Albrecht Kleine <kleine@ak.sax.de> * [files/dos_fs.c] Bugfix: range error in month value (0..11 set to 1..12). * [windows/caret.c] Changed ROP2-mode to R2_NOTXORPEN in CARET_Callback for pulsed appearance of the caret. * [windows/mdi.c] [include/mdi.h] Changed MDITile(): added a new parameter WORD wParam for WM_MDITILE second tiling method (MDITILE_HORIZONTAL in wParam) as used in Win3.1 Sun Jan 28 14:20:00 1996 Cameron Heide <heide@ee.ualberta.ca> * [miscemu/int2f.c] Added a small bit of MSCDEX emulation. * [windows/alias.c] ALIAS_RegisterAlias was returning the hash value when it should have been returning the record number. Sat Jan 27 10:53:51 1996 Jim Peterson <jspeter@birch.ee.vt.edu> * [include/shell.h] [include/wintypes.h] Moved definition of HKEY and LPHKEY types to include/wintypes.h. Declared FONTENUMPROC in wintypes.h. * [include/windows.h] Added definition of KERNINGPAIR and LPKERNINGPAIR types. Added declarations for CopyCursor(), CopyIcon(), EnumFontFamilies(), ExtractIcon(), FatalAppExit(), FindExecutable(), GetClipCursor(), GetKerningPairs(), GetQueueStatus(), GetRasterizerCaps(), IsGDIObject(), IsMenu(), IsTask(), RegCloseKey(), RegCreateKey(), RegDeleteKey(), RegEnumKey(), RegOpenKey(), RegQueryValue(), RegSetValue(), ResetDC(), ShellExecute(), SystemParametersInfo(), and wsprintf(). * [tools/makehtml.pl] [documentation/apiw.index] New files that scan windows.h, commdlg.h, and toolhelp.h and output an HTML sorted list with optional links to www.willows.com and a tally of unimplemented APIW functions. * [objects/cursoricon.c] Added Win32 versions of CopyIcon() and CopyCursor() for use in libwine. * [win32/resource.c] [win32/winprocs.c] Added '#include "libres.h"' and explicit declarations of windows procs in order to avoid warnings. * [windows/utility.c] Added Win32 version of MulDiv() for libwine. * [*/*] [include/windows.h] Changed several function declarations to comply more strictly to the windows API (without, hopefully, altering their functionality). * [controls/menu.c] Made the return value of CheckMenuItem be the previous state of the menu item if it was found, otherwise -1 as specified in the SDK. This conflicts with the APIW specification, which says it should return TRUE if successful, otherwise FALSE. * [include/windows.h] Added obsolete WM_SIZE message wParam names for compatibility. Added WinHelp() command constants, even though they are not yet supported. * [rc/winerc.c] Tidied up transform_binary_file(). In argument checking, flattened any invalid characters specified with the prefix argument. * [library/libres.c] Made FindResource() case-insensitive when parameter 'name' is a string. Sat Jan 27 02:30 1996 Uwe Bonnes <bon@elektron.ikp.physik.th-darmstadt.de * [files/drive.c] If root "/" is given in wine.conf, use it as last resort. * [files/file.c] Report ER_AccessDenied it disk ist not writable More Debug Output * [miscemu/int21.c] Squeezed some bugs in ExtendedOpenCreateFile * [windows/winpos.c] Some windows may not be moved or resized. We are missing some structures to be exact, but the approach should help in some cases and make things worse in much fewer. Fri Jan 26 10:24:00 1996 Thomas Sandford <t.d.g.sandford@prds-grn.demon.co.uk> * [loader/pe_image.c] fixup_imports: Find builtins for Borland style entries, too Fri Jan 26 10:24:00 1996 Martin von Loewis <loewis@informatik.hu-berlin.de> * [controls/menu.c] LoadMenu: branch to Win32 for PE modules * [if1632/gdi.spec][if1632/kernel32.spec][if1632/user32.spec] DeleteObject, GetPixel, SetPixel,WritePrivateProfileStringA, WriteProfileStringA, EmptyClipboard, EnableMenuItem, EnableScrollBar, EnableWindow, InvalidateRect, SetWindowTextA, WinHelpA: new relays DrawTextA, MoveToEx, GetClientRect, InvalidateRect, LoadBitmapA/W, LoadAcceleratorsA/W, LoadMenu[Indirect]A/W, LoadStringA/W: changed to convert parameters or naming convention * [include/kernel32.h][include/wintypes.h] moved WCHAR, defined LPWSTR * [include/string32.h][win32/string32.c][include/struct32.h] New files * [loader/module.h] LoadModule: exit after returning from PE_LoadModule * [loader/pe_image.c] my_wcstombs: isascii does not work on Linux for Unicode PE_LoadImage: Handle directories * [misc/user32.c] USER32_RECT32to16, USER32_RECT16to32: new functions implemented new user32 relays * [misc/newfns.c] WIN32_WinHelpA: new function * [win32/param32.c] New file * [win32/resource.c] GetResDirEntry: added support for named entries WIN32_LoadAcceleratorsW: invoke *32 resource functions WIN32_LoadBitmapA: convert name to unicode if appropriate WIN32_ParseMenu: new function implemented new resource functions from user32.spec Wed Jan 24 18:09:00 1996 Alex Korobka <alex@phm30.pharm.sunysb.edu> * [objects/cursoricon.c] GetIconId() and LoadIconHandler() functions. * [windows/mdi.c] Better maximization support, TranslateMDISysAccel() function, misc improvements. * [windows/defwnd.c] Fix for WM_WINDOWPOSCHANGED message handler. * [windows/winpos.c] Rewrote WindowFromPoint() function. Sun Jan 21 1996 17:05:09 Marcus Meissner <msmeissn@faui01.informatik.uni-erlangen.de> * [include/toolhelp.h] [misc/toolhelp.c] Added Notify(Un)Register, but no callbacks yet. Fri Jan 19 01:43:37 1996 Victor Schneider <root@tailor.roman.org> * [Makefile.in] Added target for libwine.so.1.0. * [library/winmain.c] For WINELIBDLL, _WinMain just returns hInstance instead of calling WinMain(). * [misc/main.c] For WINELIBDLL, renamed main() to _wine_main() for calling from the stub main function. * [library/winestub.c] (new file) Provides a stub main() function for using libwine.so. Tue Jan 16 11:04:34 1996 Anand Kumria <akumria@ozemail.com.au> * [winsocket.c] Fix EPERM problem. * [global.c] Attempt to do some sanity checking in MemManInfo(). * [Changelog] Fix changelog oversight for previous entry.
1996-01-31 20:02:28 +01:00
/*
* Profile functions
*
* Copyright 1993 Miguel de Icaza
* Copyright 1996 Alexandre Julliard
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "dos_fs.h"
#include "windows.h"
#include "xmalloc.h"
#include "stddebug.h"
#include "debug.h"
typedef struct tagPROFILEKEY
{
char *name;
char *value;
struct tagPROFILEKEY *next;
} PROFILEKEY;
typedef struct tagPROFILESECTION
{
char *name;
struct tagPROFILEKEY *key;
struct tagPROFILESECTION *next;
} PROFILESECTION;
typedef struct
{
int changed;
PROFILESECTION *section;
char *dos_name;
} PROFILE;
/* Cached profile file */
static PROFILE CurProfile = { FALSE, NULL, NULL };
/* wine.ini profile content */
static PROFILESECTION *WineProfile;
#define PROFILE_MAX_LINE_LEN 1024
/* Wine profile name in $HOME directory; must begin with slash */
static const char PROFILE_WineIniName[] = "/.winerc";
/* Check for comments in profile */
#define IS_ENTRY_COMMENT(str) ((str)[0] == ';')
/***********************************************************************
* PROFILE_CopyEntry
*
* Copy the content of an entry into a buffer, removing quotes, and possibly
* translating environment variables.
*/
static void PROFILE_CopyEntry( char *buffer, const char *value, int len,
int handle_env )
{
char quote = '\0';
const char *p;
if ((*value == '\'') || (*value == '\"'))
{
if (value[1] && (value[strlen(value)-1] == *value)) quote = *value++;
}
if (!handle_env)
{
lstrcpyn( buffer, value, len );
if (quote && (len >= strlen(value))) buffer[strlen(buffer)-1] = '\0';
return;
}
for (p = value; (*p && (len > 1)); *buffer++ = *p++, len-- )
{
if ((*p == '$') && (p[1] == '{'))
{
char env_val[1024];
const char *env_p;
const char *p2 = strchr( p, '}' );
if (!p2) continue; /* ignore it */
lstrcpyn( env_val, p + 2, MIN( sizeof(env_val), (int)(p2-p)-1 ) );
if ((env_p = getenv( env_val )) != NULL)
{
lstrcpyn( buffer, env_p, len );
buffer += strlen( buffer );
len -= strlen( buffer );
}
p = p2 + 1;
}
}
*buffer = '\0';
}
/***********************************************************************
* PROFILE_Save
*
* Save a profile tree to a file.
*/
static void PROFILE_Save( FILE *file, PROFILESECTION *section )
{
PROFILEKEY *key;
for ( ; section; section = section->next)
{
if (section->name) fprintf( file, "[%s]\n", section->name );
for (key = section->key; key; key = key->next)
{
fprintf( file, "%s", key->name );
if (key->value) fprintf( file, "=%s", key->value );
fprintf( file, "\n" );
}
}
}
/***********************************************************************
* PROFILE_Free
*
* Free a profile tree.
*/
static void PROFILE_Free( PROFILESECTION *section )
{
PROFILESECTION *next_section;
PROFILEKEY *key, *next_key;
for ( ; section; section = next_section)
{
if (section->name) free( section->name );
for (key = section->key; key; key = next_key)
{
next_key = key->next;
if (key->name) free( key->name );
if (key->value) free( key->value );
free( key );
}
next_section = section->next;
free( section );
}
}
/***********************************************************************
* PROFILE_Load
*
* Load a profile tree from a file.
*/
static PROFILESECTION *PROFILE_Load( FILE *file )
{
char buffer[PROFILE_MAX_LINE_LEN];
char *p, *p2;
int line = 0;
PROFILESECTION *section, *first_section;
PROFILESECTION **prev_section;
PROFILEKEY *key, **prev_key;
first_section = (PROFILESECTION *)xmalloc( sizeof(*section) );
first_section->name = NULL;
first_section->key = NULL;
first_section->next = NULL;
prev_section = &first_section->next;
prev_key = &first_section->key;
while (fgets( buffer, PROFILE_MAX_LINE_LEN, file ))
{
line++;
p = buffer + strlen(buffer) - 1;
while ((p > buffer) && ((*p == '\n') || isspace(*p))) *p-- = '\0';
p = buffer;
while (*p && isspace(*p)) p++;
if (*p == '[') /* section start */
{
if (!(p2 = strrchr( p, ']' )))
{
fprintf( stderr, "PROFILE_Load: Invalid section header at line %d: '%s'\n",
line, p );
}
else
{
*p2 = '\0';
p++;
section = (PROFILESECTION *)xmalloc( sizeof(*section));
section->name = xstrdup( p );
section->key = NULL;
section->next = NULL;
*prev_section = section;
prev_section = &section->next;
prev_key = &section->key;
continue;
}
}
if ((p2 = strchr( p, '=' )) != NULL)
{
char *p3 = p2 - 1;
while ((p3 > p) && isspace(*p3)) *p3-- = '\0';
*p2++ = '\0';
while (*p2 && isspace(*p2)) p2++;
}
key = (PROFILEKEY *)xmalloc( sizeof(*key) );
key->name = xstrdup( p );
key->value = p2 ? xstrdup( p2 ) : NULL;
key->next = NULL;
*prev_key = key;
prev_key = &key->next;
}
if (debugging_profile)
{
fprintf( stddeb, "PROFILE_Load:\n" );
PROFILE_Save( stddeb, first_section );
fprintf( stddeb, "PROFILE_Load finished.\n" );
}
return first_section;
}
/***********************************************************************
* PROFILE_DeleteSection
*
* Delete a section from a profile tree.
*/
static BOOL PROFILE_DeleteSection( PROFILESECTION **section, const char *name )
{
while (*section)
{
if ((*section)->name && !lstrcmpi( (*section)->name, name ))
{
PROFILESECTION *to_del = *section;
*section = to_del->next;
to_del->next = NULL;
PROFILE_Free( to_del );
return TRUE;
}
section = &(*section)->next;
}
return FALSE;
}
/***********************************************************************
* PROFILE_DeleteKey
*
* Delete a key from a profile tree.
*/
static BOOL PROFILE_DeleteKey( PROFILESECTION **section,
const char *section_name, const char *key_name )
{
while (*section)
{
if ((*section)->name && !lstrcmpi( (*section)->name, section_name ))
{
PROFILEKEY **key = &(*section)->key;
while (*key)
{
if (!lstrcmpi( (*key)->name, key_name ))
{
PROFILEKEY *to_del = *key;
*key = to_del->next;
if (to_del->name) free( to_del->name );
if (to_del->value) free( to_del->value );
free( to_del );
return TRUE;
}
key = &(*key)->next;
}
}
section = &(*section)->next;
}
return FALSE;
}
/***********************************************************************
* PROFILE_Find
*
* Find a key in a profile tree, optionally creating it.
*/
static PROFILEKEY *PROFILE_Find( PROFILESECTION **section,
const char *section_name,
const char *key_name, int create )
{
while (*section)
{
if ((*section)->name && !lstrcmpi( (*section)->name, section_name ))
{
PROFILEKEY **key = &(*section)->key;
while (*key)
{
if (!lstrcmpi( (*key)->name, key_name )) return *key;
key = &(*key)->next;
}
if (!create) return NULL;
*key = (PROFILEKEY *)xmalloc( sizeof(PROFILEKEY) );
(*key)->name = xstrdup( key_name );
(*key)->value = NULL;
(*key)->next = NULL;
return *key;
}
section = &(*section)->next;
}
if (!create) return NULL;
*section = (PROFILESECTION *)xmalloc( sizeof(PROFILESECTION) );
(*section)->name = xstrdup(section_name);
(*section)->next = NULL;
(*section)->key = (PROFILEKEY *)xmalloc( sizeof(PROFILEKEY) );
(*section)->key->name = xstrdup( key_name );
(*section)->key->value = NULL;
(*section)->key->next = NULL;
return (*section)->key;
}
/***********************************************************************
* PROFILE_FlushFile
*
* Flush the current profile to disk if changed.
*/
static BOOL PROFILE_FlushFile(void)
{
char *p, buffer[MAX_PATHNAME_LEN];
const char *unix_name;
FILE *file = NULL;
if (!CurProfile.changed || !CurProfile.dos_name) return TRUE;
if (!(unix_name = DOSFS_GetUnixFileName( CurProfile.dos_name, FALSE )) ||
!(file = fopen( unix_name, "w" )))
{
/* Try to create it in $HOME/.wine */
/* FIXME: this will need a more general solution */
if ((p = getenv( "HOME" )) != NULL)
{
strcpy( buffer, p );
strcat( buffer, "/.wine/" );
p = buffer + strlen(buffer);
strcpy( p, strrchr( CurProfile.dos_name, '\\' ) + 1 );
AnsiLower( p );
file = fopen( buffer, "w" );
unix_name = buffer;
}
}
if (!file)
{
fprintf( stderr, "Warning: could not save profile file %s\n",
CurProfile.dos_name );
return FALSE;
}
dprintf_profile( stddeb, "Saving '%s' into '%s'\n",
CurProfile.dos_name, unix_name );
PROFILE_Save( file, CurProfile.section );
fclose( file );
CurProfile.changed = FALSE;
return TRUE;
}
/***********************************************************************
* PROFILE_Open
*
* Open a profile file, checking the cached file first.
*/
static BOOL PROFILE_Open( const char *filename )
{
char buffer[MAX_PATHNAME_LEN];
const char *dos_name, *unix_name;
char *newdos_name, *p;
FILE *file = NULL;
if (strchr( filename, '/' ) || strchr( filename, '\\' ) ||
strchr( filename, ':' ))
{
if (!(dos_name = DOSFS_GetDosTrueName( filename, FALSE))) return FALSE;
}
else
{
GetWindowsDirectory( buffer, sizeof(buffer) );
strcat( buffer, "\\" );
strcat( buffer, filename );
if (!(dos_name = DOSFS_GetDosTrueName( buffer, FALSE ))) return FALSE;
}
if (CurProfile.dos_name && !strcmp( dos_name, CurProfile.dos_name ))
{
dprintf_profile( stddeb, "PROFILE_Open(%s): already opened\n",
filename );
return TRUE;
}
/* Flush the previous profile */
newdos_name = xstrdup( dos_name );
PROFILE_FlushFile();
PROFILE_Free( CurProfile.section );
if (CurProfile.dos_name) free( CurProfile.dos_name );
CurProfile.section = NULL;
CurProfile.dos_name = newdos_name;
/* Try to open the profile file, first in $HOME/.wine */
/* FIXME: this will need a more general solution */
if ((p = getenv( "HOME" )) != NULL)
{
strcpy( buffer, p );
strcat( buffer, "/.wine/" );
p = buffer + strlen(buffer);
strcpy( p, strrchr( newdos_name, '\\' ) + 1 );
AnsiLower( p );
if ((file = fopen( buffer, "r" )))
dprintf_profile( stddeb, "Found it in %s\n", buffer );
}
if (!file && ((unix_name = DOSFS_GetUnixFileName( dos_name, TRUE ))))
{
if ((file = fopen( unix_name, "r" )))
dprintf_profile( stddeb, "Found it in %s\n", unix_name );
}
if (file)
{
CurProfile.section = PROFILE_Load( file );
fclose( file );
}
else
fprintf( stderr, "Warning: profile file %s not found\n", newdos_name );
dprintf_profile( stddeb, "PROFILE_Open(%s): successful\n", filename );
return TRUE;
}
/***********************************************************************
* PROFILE_GetSection
*
* Enumerate all the keys of a section.
*/
static INT PROFILE_GetSection( PROFILESECTION *section,
const char *section_name,
char *buffer, INT len, int handle_env )
{
PROFILEKEY *key;
while (section)
{
if (section->name && !lstrcmpi( section->name, section_name ))
{
for (key = section->key; key; key = key->next)
{
if (len <= 2) break;
if (IS_ENTRY_COMMENT(key->name)) continue; /* Skip comments */
PROFILE_CopyEntry( buffer, key->name, len - 1, handle_env );
len -= strlen(buffer) - 1;
buffer += strlen(buffer) + 1;
}
*buffer = '\0';
return len - 1;
}
section = section->next;
}
buffer[0] = buffer[1] = '\0';
return len - 2;
}
/***********************************************************************
* PROFILE_GetString
*
* Get a profile string.
*/
static INT PROFILE_GetString( const char *section, const char *key_name,
const char *def_val, char *buffer, INT len )
{
PROFILEKEY *key = NULL;
if (!def_val) def_val = "";
if (key_name)
{
key = PROFILE_Find( &CurProfile.section, section, key_name, FALSE );
PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val,
len, FALSE );
dprintf_profile( stddeb, "PROFILE_GetString('%s','%s','%s'): returning '%s'\n",
section, key_name, def_val, buffer );
return strlen( buffer );
}
return PROFILE_GetSection(CurProfile.section, section, buffer, len, FALSE);
}
/***********************************************************************
* PROFILE_SetString
*
* Set a profile string.
*/
static BOOL PROFILE_SetString( const char *section_name, const char *key_name,
const char *value )
{
BOOL ret;
if (!key_name) /* Delete a whole section */
{
dprintf_profile(stddeb, "PROFILE_DeleteSection('%s')\n", section_name);
ret = PROFILE_DeleteSection( &CurProfile.section, section_name );
CurProfile.changed |= ret;
return ret;
}
else if (!value) /* Delete a key */
{
dprintf_profile( stddeb, "PROFILE_DeleteKey('%s','%s')\n",
section_name, key_name );
ret = PROFILE_DeleteKey( &CurProfile.section, section_name, key_name );
CurProfile.changed |= ret;
return ret;
}
else /* Set the key value */
{
PROFILEKEY *key = PROFILE_Find( &CurProfile.section, section_name,
key_name, TRUE );
dprintf_profile( stddeb, "PROFILE_SetString('%s','%s','%s'): ",
section_name, key_name, value );
if (key->value)
{
if (!strcmp( key->value, value ))
{
dprintf_profile( stddeb, "no change needed\n" );
return TRUE; /* No change needed */
}
dprintf_profile( stddeb, "replacing '%s'\n", key->value );
free( key->value );
}
else dprintf_profile( stddeb, "creating key\n" );
key->value = xstrdup( value );
CurProfile.changed = TRUE;
return TRUE;
}
}
/***********************************************************************
* PROFILE_GetWineIniString
*
* Get a config string from the wine.ini file.
*/
int PROFILE_GetWineIniString( const char *section, const char *key_name,
const char *def, char *buffer, int len )
{
if (key_name)
{
PROFILEKEY *key = PROFILE_Find(&WineProfile, section, key_name, FALSE);
PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def,
len, TRUE );
dprintf_profile( stddeb, "PROFILE_GetWineIniString('%s','%s','%s'): returning '%s'\n",
section, key_name, def, buffer );
return strlen( buffer );
}
return PROFILE_GetSection( WineProfile, section, buffer, len, TRUE );
}
/***********************************************************************
* PROFILE_LoadWineIni
*
* Load the wine.ini file.
*/
int PROFILE_LoadWineIni(void)
{
char buffer[MAX_PATHNAME_LEN];
const char *p;
FILE *f;
if ((p = getenv( "HOME" )) != NULL)
{
lstrcpyn( buffer, p, MAX_PATHNAME_LEN - sizeof(PROFILE_WineIniName) );
strcat( buffer, PROFILE_WineIniName );
if ((f = fopen( buffer, "r" )) != NULL)
{
WineProfile = PROFILE_Load( f );
fclose( f );
return 1;
}
}
else fprintf( stderr, "Warning: could not get $HOME value for config file.\n" );
/* Try global file */
if ((f = fopen( WINE_INI_GLOBAL, "r" )) != NULL)
{
WineProfile = PROFILE_Load( f );
fclose( f );
return 1;
}
fprintf( stderr, "Can't open configuration file %s or $HOME%s\n",
WINE_INI_GLOBAL, PROFILE_WineIniName );
return 0;
}
/***********************************************************************
* GetProfileInt (KERNEL.57)
*/
UINT GetProfileInt( LPCSTR section, LPCSTR entry, INT def_val )
{
return GetPrivateProfileInt( section, entry, def_val, "win.ini" );
}
/***********************************************************************
* GetProfileString (KERNEL.58)
*/
INT GetProfileString( LPCSTR section, LPCSTR entry, LPCSTR def_val,
LPSTR buffer, INT len )
{
return GetPrivateProfileString( section, entry, def_val,
buffer, len, "win.ini" );
}
/***********************************************************************
* WriteProfileString (KERNEL.59)
*/
BOOL WriteProfileString( LPCSTR section, LPCSTR entry, LPCSTR string )
{
return WritePrivateProfileString( section, entry, string, "win.ini" );
}
/***********************************************************************
* GetPrivateProfileInt (KERNEL.127)
*/
UINT GetPrivateProfileInt( LPCSTR section, LPCSTR entry, INT def_val,
LPCSTR filename )
{
char buffer[20];
char *p;
long result;
GetPrivateProfileString( section, entry, "",
buffer, sizeof(buffer), filename );
if (!buffer[0]) return (UINT)def_val;
result = strtol( buffer, &p, 0 );
if (p == buffer) return 0; /* No digits at all */
#ifdef WINELIB32
return (UINT)result;
#else
if (result > 65535) return 65535;
if (result >= 0) return (UINT)result;
if (result < -32768) return -32768;
return (UINT)(INT)result;
#endif
}
/***********************************************************************
* GetPrivateProfileString (KERNEL.128)
*/
INT GetPrivateProfileString( LPCSTR section, LPCSTR entry, LPCSTR def_val,
LPSTR buffer, INT len, LPCSTR filename )
{
if (PROFILE_Open( filename ))
return PROFILE_GetString( section, entry, def_val, buffer, len );
lstrcpyn( buffer, def_val, len );
return strlen( buffer );
}
/***********************************************************************
* WritePrivateProfileString (KERNEL.129)
*/
BOOL WritePrivateProfileString( LPCSTR section, LPCSTR entry, LPCSTR string,
LPCSTR filename )
{
if (!PROFILE_Open( filename )) return FALSE;
if (!section) return PROFILE_FlushFile();
return PROFILE_SetString( section, entry, string );
}
/***********************************************************************
* WriteOutProfiles (KERNEL.315)
*/
void WriteOutProfiles(void)
{
PROFILE_FlushFile();
}