Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Profile functions |
| 3 | * |
| 4 | * Copyright 1993 Miguel de Icaza |
| 5 | * Copyright 1996 Alexandre Julliard |
| 6 | */ |
| 7 | |
| 8 | #include <ctype.h> |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 9 | #include <errno.h> |
Alexandre Julliard | 73be8d1 | 2000-12-06 20:25:11 +0000 | [diff] [blame] | 10 | #include <fcntl.h> |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 11 | #include <stdlib.h> |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 12 | #include <string.h> |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 13 | #include <stdio.h> |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 14 | #include <sys/stat.h> |
Alexandre Julliard | 647876e | 2000-01-25 01:35:01 +0000 | [diff] [blame] | 15 | #include <sys/types.h> |
| 16 | #include <pwd.h> |
| 17 | #include <unistd.h> |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 18 | |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 19 | #include "windef.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 20 | #include "winbase.h" |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 21 | #include "winnls.h" |
Marcus Meissner | 9b4fcf7 | 1999-12-04 04:19:55 +0000 | [diff] [blame] | 22 | #include "winerror.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 23 | #include "wine/winbase16.h" |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 24 | #include "winreg.h" |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 25 | #include "file.h" |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 26 | #include "heap.h" |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 27 | #include "debugtools.h" |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 28 | #include "options.h" |
Alexandre Julliard | 37e9503 | 2001-07-19 00:39:09 +0000 | [diff] [blame] | 29 | #include "wine/server.h" |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 30 | |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 31 | DEFAULT_DEBUG_CHANNEL(profile); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 32 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 33 | typedef struct tagPROFILEKEY |
| 34 | { |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 35 | char *value; |
| 36 | struct tagPROFILEKEY *next; |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 37 | char name[1]; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 38 | } PROFILEKEY; |
| 39 | |
| 40 | typedef struct tagPROFILESECTION |
| 41 | { |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 42 | struct tagPROFILEKEY *key; |
| 43 | struct tagPROFILESECTION *next; |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 44 | char name[1]; |
| 45 | } PROFILESECTION; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 46 | |
| 47 | |
| 48 | typedef struct |
| 49 | { |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 50 | BOOL changed; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 51 | PROFILESECTION *section; |
| 52 | char *dos_name; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 53 | char *unix_name; |
| 54 | char *filename; |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 55 | time_t mtime; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 56 | } PROFILE; |
| 57 | |
| 58 | |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 59 | #define N_CACHED_PROFILES 10 |
| 60 | |
| 61 | /* Cached profile files */ |
| 62 | static PROFILE *MRUProfile[N_CACHED_PROFILES]={NULL}; |
| 63 | |
| 64 | #define CurProfile (MRUProfile[0]) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 65 | |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 66 | /* wine.ini config file registry root */ |
| 67 | static HKEY wine_profile_key; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 68 | |
| 69 | #define PROFILE_MAX_LINE_LEN 1024 |
| 70 | |
| 71 | /* Wine profile name in $HOME directory; must begin with slash */ |
| 72 | static const char PROFILE_WineIniName[] = "/.winerc"; |
| 73 | |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 74 | /* Wine profile: the profile file being used */ |
| 75 | static char PROFILE_WineIniUsed[MAX_PATHNAME_LEN] = ""; |
| 76 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 77 | /* Check for comments in profile */ |
| 78 | #define IS_ENTRY_COMMENT(str) ((str)[0] == ';') |
| 79 | |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 80 | static const WCHAR wininiW[] = { 'w','i','n','.','i','n','i',0 }; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 81 | |
Alexandre Julliard | 301df6b | 2001-08-16 18:12:56 +0000 | [diff] [blame] | 82 | static CRITICAL_SECTION PROFILE_CritSect = CRITICAL_SECTION_INIT("PROFILE_CritSect"); |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 83 | |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 84 | static const char hex[16] = "0123456789ABCDEF"; |
Alexandre Julliard | 647876e | 2000-01-25 01:35:01 +0000 | [diff] [blame] | 85 | |
| 86 | /*********************************************************************** |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 87 | * PROFILE_CopyEntry |
| 88 | * |
| 89 | * Copy the content of an entry into a buffer, removing quotes, and possibly |
| 90 | * translating environment variables. |
| 91 | */ |
| 92 | static void PROFILE_CopyEntry( char *buffer, const char *value, int len, |
| 93 | int handle_env ) |
| 94 | { |
| 95 | char quote = '\0'; |
| 96 | const char *p; |
| 97 | |
Dmitry Timoshkov | fdc78a3 | 2000-12-19 19:37:03 +0000 | [diff] [blame] | 98 | if(!buffer) return; |
| 99 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 100 | if ((*value == '\'') || (*value == '\"')) |
| 101 | { |
| 102 | if (value[1] && (value[strlen(value)-1] == *value)) quote = *value++; |
| 103 | } |
| 104 | |
| 105 | if (!handle_env) |
| 106 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 107 | lstrcpynA( buffer, value, len ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 108 | if (quote && (len >= strlen(value))) buffer[strlen(buffer)-1] = '\0'; |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | for (p = value; (*p && (len > 1)); *buffer++ = *p++, len-- ) |
| 113 | { |
| 114 | if ((*p == '$') && (p[1] == '{')) |
| 115 | { |
| 116 | char env_val[1024]; |
| 117 | const char *env_p; |
| 118 | const char *p2 = strchr( p, '}' ); |
| 119 | if (!p2) continue; /* ignore it */ |
Francois Gouget | 6d77d3a | 2000-03-25 21:44:35 +0000 | [diff] [blame] | 120 | lstrcpynA(env_val, p + 2, min( sizeof(env_val), (int)(p2-p)-1 )); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 121 | if ((env_p = getenv( env_val )) != NULL) |
| 122 | { |
Francois Gouget | 09a1783 | 2001-05-07 18:11:57 +0000 | [diff] [blame] | 123 | int buffer_len; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 124 | lstrcpynA( buffer, env_p, len ); |
Francois Gouget | 09a1783 | 2001-05-07 18:11:57 +0000 | [diff] [blame] | 125 | buffer_len = strlen( buffer ); |
| 126 | buffer += buffer_len; |
| 127 | len -= buffer_len; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 128 | } |
| 129 | p = p2 + 1; |
| 130 | } |
| 131 | } |
Eric Pouech | f54c95f | 1999-10-31 17:32:57 +0000 | [diff] [blame] | 132 | if (quote && (len > 1)) buffer--; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 133 | *buffer = '\0'; |
| 134 | } |
| 135 | |
| 136 | |
| 137 | /*********************************************************************** |
| 138 | * PROFILE_Save |
| 139 | * |
| 140 | * Save a profile tree to a file. |
| 141 | */ |
| 142 | static void PROFILE_Save( FILE *file, PROFILESECTION *section ) |
| 143 | { |
| 144 | PROFILEKEY *key; |
| 145 | |
| 146 | for ( ; section; section = section->next) |
| 147 | { |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 148 | if (section->name) fprintf( file, "\r\n[%s]\r\n", section->name ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 149 | for (key = section->key; key; key = key->next) |
| 150 | { |
| 151 | fprintf( file, "%s", key->name ); |
| 152 | if (key->value) fprintf( file, "=%s", key->value ); |
Alexandre Julliard | 7d654eb | 1996-02-25 11:36:22 +0000 | [diff] [blame] | 153 | fprintf( file, "\r\n" ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | |
| 159 | /*********************************************************************** |
| 160 | * PROFILE_Free |
| 161 | * |
| 162 | * Free a profile tree. |
| 163 | */ |
| 164 | static void PROFILE_Free( PROFILESECTION *section ) |
| 165 | { |
| 166 | PROFILESECTION *next_section; |
| 167 | PROFILEKEY *key, *next_key; |
| 168 | |
| 169 | for ( ; section; section = next_section) |
| 170 | { |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 171 | for (key = section->key; key; key = next_key) |
| 172 | { |
| 173 | next_key = key->next; |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 174 | if (key->value) HeapFree( GetProcessHeap(), 0, key->value ); |
| 175 | HeapFree( GetProcessHeap(), 0, key ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 176 | } |
| 177 | next_section = section->next; |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 178 | HeapFree( GetProcessHeap(), 0, section ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 182 | static inline int PROFILE_isspace(char c) |
| 183 | { |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 184 | if (isspace(c)) return 1; |
| 185 | if (c=='\r' || c==0x1a) return 1; |
| 186 | /* CR and ^Z (DOS EOF) are spaces too (found on CD-ROMs) */ |
| 187 | return 0; |
| 188 | } |
| 189 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 190 | |
| 191 | /*********************************************************************** |
| 192 | * PROFILE_Load |
| 193 | * |
| 194 | * Load a profile tree from a file. |
| 195 | */ |
| 196 | static PROFILESECTION *PROFILE_Load( FILE *file ) |
| 197 | { |
| 198 | char buffer[PROFILE_MAX_LINE_LEN]; |
| 199 | char *p, *p2; |
| 200 | int line = 0; |
| 201 | PROFILESECTION *section, *first_section; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 202 | PROFILESECTION **next_section; |
| 203 | PROFILEKEY *key, *prev_key, **next_key; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 204 | |
Dimitrie O. Paun | abdbced | 2000-04-29 14:20:28 +0000 | [diff] [blame] | 205 | first_section = HeapAlloc( GetProcessHeap(), 0, sizeof(*section) ); |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 206 | if(first_section == NULL) return NULL; |
| 207 | first_section->name[0] = 0; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 208 | first_section->key = NULL; |
| 209 | first_section->next = NULL; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 210 | next_section = &first_section->next; |
| 211 | next_key = &first_section->key; |
| 212 | prev_key = NULL; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 213 | |
| 214 | while (fgets( buffer, PROFILE_MAX_LINE_LEN, file )) |
| 215 | { |
| 216 | line++; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 217 | p = buffer; |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 218 | while (*p && PROFILE_isspace(*p)) p++; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 219 | if (*p == '[') /* section start */ |
| 220 | { |
| 221 | if (!(p2 = strrchr( p, ']' ))) |
| 222 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 223 | WARN("Invalid section header at line %d: '%s'\n", |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 224 | line, p ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 225 | } |
| 226 | else |
| 227 | { |
| 228 | *p2 = '\0'; |
| 229 | p++; |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 230 | if (!(section = HeapAlloc( GetProcessHeap(), 0, sizeof(*section) + strlen(p) ))) |
| 231 | break; |
| 232 | strcpy( section->name, p ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 233 | section->key = NULL; |
| 234 | section->next = NULL; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 235 | *next_section = section; |
| 236 | next_section = §ion->next; |
| 237 | next_key = §ion->key; |
| 238 | prev_key = NULL; |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 239 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 240 | TRACE("New section: '%s'\n",section->name); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 241 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 242 | continue; |
| 243 | } |
| 244 | } |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 245 | |
| 246 | p2=p+strlen(p) - 1; |
| 247 | while ((p2 > p) && ((*p2 == '\n') || PROFILE_isspace(*p2))) *p2--='\0'; |
| 248 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 249 | if ((p2 = strchr( p, '=' )) != NULL) |
| 250 | { |
| 251 | char *p3 = p2 - 1; |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 252 | while ((p3 > p) && PROFILE_isspace(*p3)) *p3-- = '\0'; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 253 | *p2++ = '\0'; |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 254 | while (*p2 && PROFILE_isspace(*p2)) p2++; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 255 | } |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 256 | |
| 257 | if(*p || !prev_key || *prev_key->name) |
Dimitrie O. Paun | abdbced | 2000-04-29 14:20:28 +0000 | [diff] [blame] | 258 | { |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 259 | if (!(key = HeapAlloc( GetProcessHeap(), 0, sizeof(*key) + strlen(p) ))) break; |
| 260 | strcpy( key->name, p ); |
| 261 | if (p2) |
| 262 | { |
| 263 | key->value = HeapAlloc( GetProcessHeap(), 0, strlen(p2)+1 ); |
| 264 | strcpy( key->value, p2 ); |
| 265 | } |
| 266 | else key->value = NULL; |
| 267 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 268 | key->next = NULL; |
| 269 | *next_key = key; |
| 270 | next_key = &key->next; |
| 271 | prev_key = key; |
| 272 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 273 | TRACE("New key: name='%s', value='%s'\n",key->name,key->value?key->value:"(none)"); |
Dimitrie O. Paun | abdbced | 2000-04-29 14:20:28 +0000 | [diff] [blame] | 274 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 275 | } |
| 276 | return first_section; |
| 277 | } |
| 278 | |
Alexandre Julliard | 73be8d1 | 2000-12-06 20:25:11 +0000 | [diff] [blame] | 279 | /* convert the .winerc file to the new format */ |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 280 | static void convert_config( FILE *in, const char *output_name ) |
Alexandre Julliard | 73be8d1 | 2000-12-06 20:25:11 +0000 | [diff] [blame] | 281 | { |
| 282 | char buffer[PROFILE_MAX_LINE_LEN]; |
| 283 | char *p, *p2; |
| 284 | FILE *out; |
| 285 | |
| 286 | /* create the output file, only if it doesn't exist already */ |
| 287 | int fd = open( output_name, O_WRONLY|O_CREAT|O_EXCL, 0666 ); |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 288 | if (fd == -1) |
| 289 | { |
| 290 | MESSAGE( "Could not create new config file '%s': %s\n", output_name, strerror(errno) ); |
| 291 | ExitProcess(1); |
| 292 | } |
Alexandre Julliard | 73be8d1 | 2000-12-06 20:25:11 +0000 | [diff] [blame] | 293 | |
| 294 | out = fdopen( fd, "w" ); |
| 295 | fprintf( out, "WINE REGISTRY Version 2\n" ); |
| 296 | fprintf( out, ";; All keys relative to \\\\Machine\\\\Software\\\\Wine\\\\Wine\\\\Config\n\n" ); |
| 297 | while (fgets( buffer, PROFILE_MAX_LINE_LEN, in )) |
| 298 | { |
| 299 | if (buffer[strlen(buffer)-1] == '\n') buffer[strlen(buffer)-1] = 0; |
| 300 | p = buffer; |
| 301 | while (*p && PROFILE_isspace(*p)) p++; |
| 302 | if (*p == '[') /* section start */ |
| 303 | { |
| 304 | if ((p2 = strrchr( p, ']' ))) |
| 305 | { |
| 306 | *p2 = '\0'; |
| 307 | p++; |
| 308 | fprintf( out, "[%s]\n", p ); |
| 309 | } |
| 310 | continue; |
| 311 | } |
| 312 | |
| 313 | if (*p == ';' || *p == '#') |
| 314 | { |
| 315 | fprintf( out, "%s\n", p ); |
| 316 | continue; |
| 317 | } |
| 318 | |
| 319 | p2=p+strlen(p) - 1; |
| 320 | while ((p2 > p) && ((*p2 == '\n') || PROFILE_isspace(*p2))) *p2--='\0'; |
| 321 | |
| 322 | if ((p2 = strchr( p, '=' )) != NULL) |
| 323 | { |
| 324 | char *p3 = p2 - 1; |
| 325 | while ((p3 > p) && PROFILE_isspace(*p3)) *p3-- = '\0'; |
| 326 | *p2++ = '\0'; |
| 327 | while (*p2 && PROFILE_isspace(*p2)) p2++; |
| 328 | } |
| 329 | |
| 330 | if (!*p) |
| 331 | { |
| 332 | fprintf( out, "\n" ); |
| 333 | continue; |
| 334 | } |
| 335 | fputc( '"', out ); |
| 336 | while (*p) |
| 337 | { |
| 338 | if (*p == '\\') fputc( '\\', out ); |
| 339 | fputc( *p, out ); |
| 340 | p++; |
| 341 | } |
| 342 | fprintf( out, "\" = \"" ); |
Alexandre Julliard | 550ba5b | 2001-01-05 22:23:37 +0000 | [diff] [blame] | 343 | if (p2) |
Alexandre Julliard | 73be8d1 | 2000-12-06 20:25:11 +0000 | [diff] [blame] | 344 | { |
Alexandre Julliard | 550ba5b | 2001-01-05 22:23:37 +0000 | [diff] [blame] | 345 | while (*p2) |
| 346 | { |
| 347 | if (*p2 == '\\') fputc( '\\', out ); |
| 348 | fputc( *p2, out ); |
| 349 | p2++; |
| 350 | } |
Alexandre Julliard | 73be8d1 | 2000-12-06 20:25:11 +0000 | [diff] [blame] | 351 | } |
| 352 | fprintf( out, "\"\n" ); |
| 353 | } |
| 354 | fclose( out ); |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | |
| 358 | /*********************************************************************** |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 359 | * PROFILE_DeleteSection |
| 360 | * |
| 361 | * Delete a section from a profile tree. |
| 362 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 363 | static BOOL PROFILE_DeleteSection( PROFILESECTION **section, LPCSTR name ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 364 | { |
| 365 | while (*section) |
| 366 | { |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 367 | if ((*section)->name[0] && !strcasecmp( (*section)->name, name )) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 368 | { |
| 369 | PROFILESECTION *to_del = *section; |
| 370 | *section = to_del->next; |
| 371 | to_del->next = NULL; |
| 372 | PROFILE_Free( to_del ); |
| 373 | return TRUE; |
| 374 | } |
| 375 | section = &(*section)->next; |
| 376 | } |
| 377 | return FALSE; |
| 378 | } |
| 379 | |
| 380 | |
| 381 | /*********************************************************************** |
| 382 | * PROFILE_DeleteKey |
| 383 | * |
| 384 | * Delete a key from a profile tree. |
| 385 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 386 | static BOOL PROFILE_DeleteKey( PROFILESECTION **section, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 387 | LPCSTR section_name, LPCSTR key_name ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 388 | { |
| 389 | while (*section) |
| 390 | { |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 391 | if ((*section)->name[0] && !strcasecmp( (*section)->name, section_name )) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 392 | { |
| 393 | PROFILEKEY **key = &(*section)->key; |
| 394 | while (*key) |
| 395 | { |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 396 | if (!strcasecmp( (*key)->name, key_name )) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 397 | { |
| 398 | PROFILEKEY *to_del = *key; |
| 399 | *key = to_del->next; |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 400 | if (to_del->value) HeapFree( GetProcessHeap(), 0, to_del->value); |
| 401 | HeapFree( GetProcessHeap(), 0, to_del ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 402 | return TRUE; |
| 403 | } |
| 404 | key = &(*key)->next; |
| 405 | } |
| 406 | } |
| 407 | section = &(*section)->next; |
| 408 | } |
| 409 | return FALSE; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | /*********************************************************************** |
Uwe Bonnes | d88fbb7 | 2000-06-20 20:48:46 +0000 | [diff] [blame] | 414 | * PROFILE_DeleteAllKeys |
| 415 | * |
| 416 | * Delete all keys from a profile tree. |
| 417 | */ |
| 418 | void PROFILE_DeleteAllKeys( LPCSTR section_name) |
| 419 | { |
| 420 | PROFILESECTION **section= &CurProfile->section; |
| 421 | while (*section) |
| 422 | { |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 423 | if ((*section)->name[0] && !strcasecmp( (*section)->name, section_name )) |
Uwe Bonnes | d88fbb7 | 2000-06-20 20:48:46 +0000 | [diff] [blame] | 424 | { |
| 425 | PROFILEKEY **key = &(*section)->key; |
| 426 | while (*key) |
| 427 | { |
| 428 | PROFILEKEY *to_del = *key; |
| 429 | *key = to_del->next; |
Uwe Bonnes | d88fbb7 | 2000-06-20 20:48:46 +0000 | [diff] [blame] | 430 | if (to_del->value) HeapFree( GetProcessHeap(), 0, to_del->value); |
| 431 | HeapFree( GetProcessHeap(), 0, to_del ); |
| 432 | CurProfile->changed =TRUE; |
| 433 | } |
| 434 | } |
| 435 | section = &(*section)->next; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | |
| 440 | /*********************************************************************** |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 441 | * PROFILE_Find |
| 442 | * |
| 443 | * Find a key in a profile tree, optionally creating it. |
| 444 | */ |
| 445 | static PROFILEKEY *PROFILE_Find( PROFILESECTION **section, |
| 446 | const char *section_name, |
| 447 | const char *key_name, int create ) |
| 448 | { |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 449 | const char *p; |
| 450 | int seclen, keylen; |
| 451 | |
| 452 | while (PROFILE_isspace(*section_name)) section_name++; |
| 453 | p = section_name + strlen(section_name) - 1; |
| 454 | while ((p > section_name) && PROFILE_isspace(*p)) p--; |
| 455 | seclen = p - section_name + 1; |
| 456 | |
| 457 | while (PROFILE_isspace(*key_name)) key_name++; |
| 458 | p = key_name + strlen(key_name) - 1; |
| 459 | while ((p > key_name) && PROFILE_isspace(*p)) p--; |
| 460 | keylen = p - key_name + 1; |
| 461 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 462 | while (*section) |
| 463 | { |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 464 | if ( ((*section)->name[0]) |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 465 | && (!(strncasecmp( (*section)->name, section_name, seclen ))) |
| 466 | && (((*section)->name)[seclen] == '\0') ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 467 | { |
| 468 | PROFILEKEY **key = &(*section)->key; |
| 469 | while (*key) |
| 470 | { |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 471 | if ( (!(strncasecmp( (*key)->name, key_name, keylen ))) |
| 472 | && (((*key)->name)[keylen] == '\0') ) |
| 473 | return *key; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 474 | key = &(*key)->next; |
| 475 | } |
| 476 | if (!create) return NULL; |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 477 | if (!(*key = HeapAlloc( GetProcessHeap(), 0, sizeof(PROFILEKEY) + strlen(key_name) ))) |
| 478 | return NULL; |
| 479 | strcpy( (*key)->name, key_name ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 480 | (*key)->value = NULL; |
| 481 | (*key)->next = NULL; |
| 482 | return *key; |
| 483 | } |
| 484 | section = &(*section)->next; |
| 485 | } |
| 486 | if (!create) return NULL; |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 487 | *section = HeapAlloc( GetProcessHeap(), 0, sizeof(PROFILESECTION) + strlen(section_name) ); |
Dimitrie O. Paun | abdbced | 2000-04-29 14:20:28 +0000 | [diff] [blame] | 488 | if(*section == NULL) return NULL; |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 489 | strcpy( (*section)->name, section_name ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 490 | (*section)->next = NULL; |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 491 | if (!((*section)->key = HeapAlloc( GetProcessHeap(), 0, |
| 492 | sizeof(PROFILEKEY) + strlen(key_name) ))) |
Dimitrie O. Paun | abdbced | 2000-04-29 14:20:28 +0000 | [diff] [blame] | 493 | { |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 494 | HeapFree(GetProcessHeap(), 0, *section); |
| 495 | return NULL; |
Dimitrie O. Paun | abdbced | 2000-04-29 14:20:28 +0000 | [diff] [blame] | 496 | } |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 497 | strcpy( (*section)->key->name, key_name ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 498 | (*section)->key->value = NULL; |
| 499 | (*section)->key->next = NULL; |
| 500 | return (*section)->key; |
| 501 | } |
| 502 | |
| 503 | |
| 504 | /*********************************************************************** |
| 505 | * PROFILE_FlushFile |
| 506 | * |
| 507 | * Flush the current profile to disk if changed. |
| 508 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 509 | static BOOL PROFILE_FlushFile(void) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 510 | { |
| 511 | char *p, buffer[MAX_PATHNAME_LEN]; |
| 512 | const char *unix_name; |
| 513 | FILE *file = NULL; |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 514 | struct stat buf; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 515 | |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 516 | if(!CurProfile) |
| 517 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 518 | WARN("No current profile!\n"); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 519 | return FALSE; |
| 520 | } |
| 521 | |
| 522 | if (!CurProfile->changed || !CurProfile->dos_name) return TRUE; |
| 523 | if (!(unix_name = CurProfile->unix_name) || !(file = fopen(unix_name, "w"))) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 524 | { |
| 525 | /* Try to create it in $HOME/.wine */ |
| 526 | /* FIXME: this will need a more general solution */ |
Alexandre Julliard | de1d5ad | 2000-04-06 20:36:17 +0000 | [diff] [blame] | 527 | strcpy( buffer, get_config_dir() ); |
Alexandre Julliard | 647876e | 2000-01-25 01:35:01 +0000 | [diff] [blame] | 528 | p = buffer + strlen(buffer); |
| 529 | *p++ = '/'; |
| 530 | strcpy( p, strrchr( CurProfile->dos_name, '\\' ) + 1 ); |
Alexandre Julliard | dcd247e | 2000-08-14 17:39:15 +0000 | [diff] [blame] | 531 | _strlwr( p ); |
Alexandre Julliard | 647876e | 2000-01-25 01:35:01 +0000 | [diff] [blame] | 532 | file = fopen( buffer, "w" ); |
| 533 | unix_name = buffer; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | if (!file) |
| 537 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 538 | WARN("could not save profile file %s\n", CurProfile->dos_name); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 539 | return FALSE; |
| 540 | } |
| 541 | |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 542 | TRACE("Saving '%s' into '%s'\n", CurProfile->dos_name, unix_name ); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 543 | PROFILE_Save( file, CurProfile->section ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 544 | fclose( file ); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 545 | CurProfile->changed = FALSE; |
| 546 | if(!stat(unix_name,&buf)) |
| 547 | CurProfile->mtime=buf.st_mtime; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 548 | return TRUE; |
| 549 | } |
| 550 | |
| 551 | |
| 552 | /*********************************************************************** |
Alexandre Julliard | e61b792 | 1999-07-31 19:24:11 +0000 | [diff] [blame] | 553 | * PROFILE_ReleaseFile |
| 554 | * |
| 555 | * Flush the current profile to disk and remove it from the cache. |
| 556 | */ |
| 557 | static void PROFILE_ReleaseFile(void) |
| 558 | { |
| 559 | PROFILE_FlushFile(); |
| 560 | PROFILE_Free( CurProfile->section ); |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 561 | if (CurProfile->dos_name) HeapFree( GetProcessHeap(), 0, CurProfile->dos_name ); |
| 562 | if (CurProfile->unix_name) HeapFree( GetProcessHeap(), 0, CurProfile->unix_name ); |
| 563 | if (CurProfile->filename) HeapFree( GetProcessHeap(), 0, CurProfile->filename ); |
Alexandre Julliard | e61b792 | 1999-07-31 19:24:11 +0000 | [diff] [blame] | 564 | CurProfile->changed = FALSE; |
| 565 | CurProfile->section = NULL; |
| 566 | CurProfile->dos_name = NULL; |
| 567 | CurProfile->unix_name = NULL; |
| 568 | CurProfile->filename = NULL; |
| 569 | CurProfile->mtime = 0; |
| 570 | } |
| 571 | |
| 572 | |
| 573 | /*********************************************************************** |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 574 | * PROFILE_Open |
| 575 | * |
| 576 | * Open a profile file, checking the cached file first. |
| 577 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 578 | static BOOL PROFILE_Open( LPCSTR filename ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 579 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 580 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 581 | char buffer[MAX_PATHNAME_LEN]; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 582 | char *newdos_name, *p; |
| 583 | FILE *file = NULL; |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 584 | int i,j; |
| 585 | struct stat buf; |
| 586 | PROFILE *tempProfile; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 587 | |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 588 | /* First time around */ |
| 589 | |
| 590 | if(!CurProfile) |
| 591 | for(i=0;i<N_CACHED_PROFILES;i++) |
| 592 | { |
Dimitrie O. Paun | abdbced | 2000-04-29 14:20:28 +0000 | [diff] [blame] | 593 | MRUProfile[i]=HeapAlloc( GetProcessHeap(), 0, sizeof(PROFILE) ); |
| 594 | if(MRUProfile[i] == NULL) break; |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 595 | MRUProfile[i]->changed=FALSE; |
| 596 | MRUProfile[i]->section=NULL; |
| 597 | MRUProfile[i]->dos_name=NULL; |
| 598 | MRUProfile[i]->unix_name=NULL; |
| 599 | MRUProfile[i]->filename=NULL; |
| 600 | MRUProfile[i]->mtime=0; |
| 601 | } |
| 602 | |
| 603 | /* Check for a match */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 604 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 605 | if (strchr( filename, '/' ) || strchr( filename, '\\' ) || |
| 606 | strchr( filename, ':' )) |
| 607 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 608 | if (!DOSFS_GetFullName( filename, FALSE, &full_name )) return FALSE; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 609 | } |
| 610 | else |
| 611 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 612 | GetWindowsDirectoryA( buffer, sizeof(buffer) ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 613 | strcat( buffer, "\\" ); |
| 614 | strcat( buffer, filename ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 615 | if (!DOSFS_GetFullName( buffer, FALSE, &full_name )) return FALSE; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 616 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 617 | |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 618 | for(i=0;i<N_CACHED_PROFILES;i++) |
| 619 | { |
| 620 | if ((MRUProfile[i]->filename && !strcmp( filename, MRUProfile[i]->filename )) || |
| 621 | (MRUProfile[i]->dos_name && !strcmp( full_name.short_name, MRUProfile[i]->dos_name ))) |
| 622 | { |
| 623 | if(i) |
| 624 | { |
| 625 | PROFILE_FlushFile(); |
| 626 | tempProfile=MRUProfile[i]; |
| 627 | for(j=i;j>0;j--) |
| 628 | MRUProfile[j]=MRUProfile[j-1]; |
| 629 | CurProfile=tempProfile; |
| 630 | } |
| 631 | if(!stat(CurProfile->unix_name,&buf) && CurProfile->mtime==buf.st_mtime) |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 632 | TRACE("(%s): already opened (mru=%d)\n", |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 633 | filename, i ); |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 634 | else |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 635 | TRACE("(%s): already opened, needs refreshing (mru=%d)\n", |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 636 | filename, i ); |
| 637 | return TRUE; |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
Andreas Mohr | 87bff28 | 1999-11-21 02:03:03 +0000 | [diff] [blame] | 641 | /* Flush the old current profile */ |
| 642 | PROFILE_FlushFile(); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 643 | |
Andreas Mohr | 87bff28 | 1999-11-21 02:03:03 +0000 | [diff] [blame] | 644 | /* Make the oldest profile the current one only in order to get rid of it */ |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 645 | if(i==N_CACHED_PROFILES) |
| 646 | { |
| 647 | tempProfile=MRUProfile[N_CACHED_PROFILES-1]; |
| 648 | for(i=N_CACHED_PROFILES-1;i>0;i--) |
| 649 | MRUProfile[i]=MRUProfile[i-1]; |
| 650 | CurProfile=tempProfile; |
| 651 | } |
Alexandre Julliard | e61b792 | 1999-07-31 19:24:11 +0000 | [diff] [blame] | 652 | if(CurProfile->filename) PROFILE_ReleaseFile(); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 653 | |
Andreas Mohr | 87bff28 | 1999-11-21 02:03:03 +0000 | [diff] [blame] | 654 | /* OK, now that CurProfile is definitely free we assign it our new file */ |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 655 | newdos_name = HeapAlloc( GetProcessHeap(), 0, strlen(full_name.short_name)+1 ); |
| 656 | strcpy( newdos_name, full_name.short_name ); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 657 | CurProfile->dos_name = newdos_name; |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 658 | CurProfile->filename = HeapAlloc( GetProcessHeap(), 0, strlen(filename)+1 ); |
| 659 | strcpy( CurProfile->filename, filename ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 660 | |
| 661 | /* Try to open the profile file, first in $HOME/.wine */ |
| 662 | |
| 663 | /* FIXME: this will need a more general solution */ |
Alexandre Julliard | de1d5ad | 2000-04-06 20:36:17 +0000 | [diff] [blame] | 664 | strcpy( buffer, get_config_dir() ); |
Alexandre Julliard | 647876e | 2000-01-25 01:35:01 +0000 | [diff] [blame] | 665 | p = buffer + strlen(buffer); |
| 666 | *p++ = '/'; |
| 667 | strcpy( p, strrchr( newdos_name, '\\' ) + 1 ); |
Alexandre Julliard | dcd247e | 2000-08-14 17:39:15 +0000 | [diff] [blame] | 668 | _strlwr( p ); |
Alexandre Julliard | 647876e | 2000-01-25 01:35:01 +0000 | [diff] [blame] | 669 | if ((file = fopen( buffer, "r" ))) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 670 | { |
Alexandre Julliard | 647876e | 2000-01-25 01:35:01 +0000 | [diff] [blame] | 671 | TRACE("(%s): found it in %s\n", |
| 672 | filename, buffer ); |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 673 | CurProfile->unix_name = HeapAlloc( GetProcessHeap(), 0, strlen(buffer)+1 ); |
| 674 | strcpy( CurProfile->unix_name, buffer ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 677 | if (!file) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 678 | { |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 679 | CurProfile->unix_name = HeapAlloc( GetProcessHeap(), 0, strlen(full_name.long_name)+1 ); |
| 680 | strcpy( CurProfile->unix_name, full_name.long_name ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 681 | if ((file = fopen( full_name.long_name, "r" ))) |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 682 | TRACE("(%s): found it in %s\n", |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 683 | filename, full_name.long_name ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | if (file) |
| 687 | { |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 688 | CurProfile->section = PROFILE_Load( file ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 689 | fclose( file ); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 690 | if(!stat(CurProfile->unix_name,&buf)) |
| 691 | CurProfile->mtime=buf.st_mtime; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 692 | } |
| 693 | else |
Alexandre Julliard | d1ce8b2 | 1996-09-02 16:46:30 +0000 | [diff] [blame] | 694 | { |
| 695 | /* Does not exist yet, we will create it in PROFILE_FlushFile */ |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 696 | WARN("profile file %s not found\n", newdos_name ); |
Alexandre Julliard | d1ce8b2 | 1996-09-02 16:46:30 +0000 | [diff] [blame] | 697 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 698 | return TRUE; |
| 699 | } |
| 700 | |
| 701 | |
| 702 | /*********************************************************************** |
| 703 | * PROFILE_GetSection |
| 704 | * |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 705 | * Returns all keys of a section. |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 706 | * If return_values is TRUE, also include the corresponding values. |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 707 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 708 | static INT PROFILE_GetSection( PROFILESECTION *section, LPCSTR section_name, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 709 | LPSTR buffer, UINT len, BOOL handle_env, |
| 710 | BOOL return_values ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 711 | { |
| 712 | PROFILEKEY *key; |
Dmitry Timoshkov | fdc78a3 | 2000-12-19 19:37:03 +0000 | [diff] [blame] | 713 | |
| 714 | if(!buffer) return 0; |
| 715 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 716 | while (section) |
| 717 | { |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 718 | if (section->name[0] && !strcasecmp( section->name, section_name )) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 719 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 720 | UINT oldlen = len; |
Alexandre Julliard | 9416aba | 1999-01-26 17:29:49 +0000 | [diff] [blame] | 721 | for (key = section->key; key; key = key->next) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 722 | { |
| 723 | if (len <= 2) break; |
Alexandre Julliard | 9416aba | 1999-01-26 17:29:49 +0000 | [diff] [blame] | 724 | if (!*key->name) continue; /* Skip empty lines */ |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 725 | if (IS_ENTRY_COMMENT(key->name)) continue; /* Skip comments */ |
| 726 | PROFILE_CopyEntry( buffer, key->name, len - 1, handle_env ); |
Alexandre Julliard | 0c126c7 | 1996-02-18 18:44:41 +0000 | [diff] [blame] | 727 | len -= strlen(buffer) + 1; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 728 | buffer += strlen(buffer) + 1; |
Marcus Meissner | ee6ea51 | 2001-06-06 21:03:40 +0000 | [diff] [blame] | 729 | if (len < 2) |
| 730 | break; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 731 | if (return_values && key->value) { |
| 732 | buffer[-1] = '='; |
| 733 | PROFILE_CopyEntry ( buffer, |
| 734 | key->value, len - 1, handle_env ); |
| 735 | len -= strlen(buffer) + 1; |
| 736 | buffer += strlen(buffer) + 1; |
| 737 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 738 | } |
| 739 | *buffer = '\0'; |
Marcus Meissner | acfae0c | 1999-05-08 18:29:10 +0000 | [diff] [blame] | 740 | if (len <= 1) |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 741 | /*If either lpszSection or lpszKey is NULL and the supplied |
| 742 | destination buffer is too small to hold all the strings, |
| 743 | the last string is truncated and followed by two null characters. |
| 744 | In this case, the return value is equal to cchReturnBuffer |
| 745 | minus two. */ |
| 746 | { |
| 747 | buffer[-1] = '\0'; |
| 748 | return oldlen - 2; |
| 749 | } |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 750 | return oldlen - len; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 751 | } |
| 752 | section = section->next; |
| 753 | } |
| 754 | buffer[0] = buffer[1] = '\0'; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 755 | return 0; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 758 | /* See GetPrivateProfileSectionNamesA for documentation */ |
Andreas Mohr | adfeec9 | 1999-05-22 16:04:57 +0000 | [diff] [blame] | 759 | static INT PROFILE_GetSectionNames( LPSTR buffer, UINT len ) |
| 760 | { |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 761 | LPSTR buf; |
| 762 | UINT f,l; |
Andreas Mohr | adfeec9 | 1999-05-22 16:04:57 +0000 | [diff] [blame] | 763 | PROFILESECTION *section; |
| 764 | |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 765 | if (!buffer || !len) |
| 766 | return 0; |
| 767 | if (len==1) { |
| 768 | *buffer='\0'; |
| 769 | return 0; |
| 770 | } |
Dmitry Timoshkov | fdc78a3 | 2000-12-19 19:37:03 +0000 | [diff] [blame] | 771 | |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 772 | f=len-1; |
| 773 | buf=buffer; |
| 774 | section = CurProfile->section; |
| 775 | while ((section!=NULL)) { |
| 776 | if (section->name[0]) { |
| 777 | l = strlen(section->name)+1; |
| 778 | if (l > f) { |
| 779 | if (f>0) { |
| 780 | strncpy(buf, section->name, f-1); |
| 781 | buf += f-1; |
| 782 | *buf++='\0'; |
| 783 | } |
| 784 | *buf='\0'; |
| 785 | return len-2; |
| 786 | } |
| 787 | strcpy(buf, section->name); |
| 788 | buf += l; |
| 789 | f -= l; |
| 790 | } |
| 791 | section = section->next; |
| 792 | } |
| 793 | *buf='\0'; |
Andreas Mohr | adfeec9 | 1999-05-22 16:04:57 +0000 | [diff] [blame] | 794 | return buf-buffer; |
| 795 | } |
| 796 | |
| 797 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 798 | /*********************************************************************** |
| 799 | * PROFILE_GetString |
| 800 | * |
| 801 | * Get a profile string. |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 802 | * |
| 803 | * Tests with GetPrivateProfileString16, W95a, |
| 804 | * with filled buffer ("****...") and section "set1" and key_name "1" valid: |
| 805 | * section key_name def_val res buffer |
| 806 | * "set1" "1" "x" 43 [data] |
| 807 | * "set1" "1 " "x" 43 [data] (!) |
| 808 | * "set1" " 1 "' "x" 43 [data] (!) |
| 809 | * "set1" "" "x" 1 "x" |
| 810 | * "set1" "" "x " 1 "x" (!) |
| 811 | * "set1" "" " x " 3 " x" (!) |
| 812 | * "set1" NULL "x" 6 "1\02\03\0\0" |
| 813 | * "set1" "" "x" 1 "x" |
| 814 | * NULL "1" "x" 0 "" (!) |
| 815 | * "" "1" "x" 1 "x" |
| 816 | * NULL NULL "" 0 "" |
| 817 | * |
| 818 | * |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 819 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 820 | static INT PROFILE_GetString( LPCSTR section, LPCSTR key_name, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 821 | LPCSTR def_val, LPSTR buffer, UINT len ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 822 | { |
| 823 | PROFILEKEY *key = NULL; |
| 824 | |
Dmitry Timoshkov | fdc78a3 | 2000-12-19 19:37:03 +0000 | [diff] [blame] | 825 | if(!buffer) return 0; |
| 826 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 827 | if (!def_val) def_val = ""; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 828 | if (key_name && key_name[0]) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 829 | { |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 830 | key = PROFILE_Find( &CurProfile->section, section, key_name, FALSE ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 831 | PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val, |
| 832 | len, FALSE ); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 833 | TRACE("('%s','%s','%s'): returning '%s'\n", |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 834 | section, key_name, def_val, buffer ); |
| 835 | return strlen( buffer ); |
| 836 | } |
Uwe Bonnes | b2ccbb2 | 2000-03-04 19:03:15 +0000 | [diff] [blame] | 837 | if (key_name && !(key_name[0])) |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 838 | /* Win95 returns 0 on keyname "". Tested with Likse32 bon 000227 */ |
Uwe Bonnes | b2ccbb2 | 2000-03-04 19:03:15 +0000 | [diff] [blame] | 839 | return 0; |
Andreas Mohr | adfeec9 | 1999-05-22 16:04:57 +0000 | [diff] [blame] | 840 | if (section && section[0]) |
| 841 | return PROFILE_GetSection(CurProfile->section, section, buffer, len, |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 842 | FALSE, FALSE); |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 843 | buffer[0] = '\0'; |
| 844 | return 0; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | |
| 848 | /*********************************************************************** |
| 849 | * PROFILE_SetString |
| 850 | * |
| 851 | * Set a profile string. |
| 852 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 853 | static BOOL PROFILE_SetString( LPCSTR section_name, LPCSTR key_name, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 854 | LPCSTR value ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 855 | { |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 856 | if (!key_name) /* Delete a whole section */ |
| 857 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 858 | TRACE("('%s')\n", section_name); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 859 | CurProfile->changed |= PROFILE_DeleteSection( &CurProfile->section, |
| 860 | section_name ); |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 861 | return TRUE; /* Even if PROFILE_DeleteSection() has failed, |
| 862 | this is not an error on application's level.*/ |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 863 | } |
| 864 | else if (!value) /* Delete a key */ |
| 865 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 866 | TRACE("('%s','%s')\n", |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 867 | section_name, key_name ); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 868 | CurProfile->changed |= PROFILE_DeleteKey( &CurProfile->section, |
| 869 | section_name, key_name ); |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 870 | return TRUE; /* same error handling as above */ |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 871 | } |
| 872 | else /* Set the key value */ |
| 873 | { |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 874 | PROFILEKEY *key = PROFILE_Find( &CurProfile->section, section_name, |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 875 | key_name, TRUE ); |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 876 | TRACE("('%s','%s','%s'): \n", |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 877 | section_name, key_name, value ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 878 | if (!key) return FALSE; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 879 | if (key->value) |
| 880 | { |
Marcus Meissner | a6ae555 | 2000-06-13 01:06:22 +0000 | [diff] [blame] | 881 | /* strip the leading spaces. We can safely strip \n\r and |
| 882 | * friends too, they should not happen here anyway. */ |
| 883 | while (PROFILE_isspace(*value)) value++; |
| 884 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 885 | if (!strcmp( key->value, value )) |
| 886 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 887 | TRACE(" no change needed\n" ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 888 | return TRUE; /* No change needed */ |
| 889 | } |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 890 | TRACE(" replacing '%s'\n", key->value ); |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 891 | HeapFree( GetProcessHeap(), 0, key->value ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 892 | } |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 893 | else TRACE(" creating key\n" ); |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 894 | key->value = HeapAlloc( GetProcessHeap(), 0, strlen(value)+1 ); |
| 895 | strcpy( key->value, value ); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 896 | CurProfile->changed = TRUE; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 897 | } |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 898 | return TRUE; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | |
| 902 | /*********************************************************************** |
| 903 | * PROFILE_GetWineIniString |
| 904 | * |
| 905 | * Get a config string from the wine.ini file. |
| 906 | */ |
| 907 | int PROFILE_GetWineIniString( const char *section, const char *key_name, |
| 908 | const char *def, char *buffer, int len ) |
| 909 | { |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 910 | char tmp[PROFILE_MAX_LINE_LEN]; |
| 911 | HKEY hkey; |
| 912 | DWORD err; |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 913 | |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 914 | if (!(err = RegOpenKeyA( wine_profile_key, section, &hkey ))) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 915 | { |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 916 | DWORD type; |
| 917 | DWORD count = sizeof(tmp); |
| 918 | err = RegQueryValueExA( hkey, key_name, 0, &type, tmp, &count ); |
| 919 | RegCloseKey( hkey ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 920 | } |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 921 | PROFILE_CopyEntry( buffer, err ? def : tmp, len, TRUE ); |
| 922 | TRACE( "('%s','%s','%s'): returning '%s'\n", section, key_name, def, buffer ); |
| 923 | return strlen(buffer); |
| 924 | } |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 925 | |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 926 | |
| 927 | /*********************************************************************** |
| 928 | * PROFILE_EnumWineIniString |
| 929 | * |
| 930 | * Get a config string from the wine.ini file. |
| 931 | */ |
| 932 | BOOL PROFILE_EnumWineIniString( const char *section, int index, |
| 933 | char *name, int name_len, char *buffer, int len ) |
| 934 | { |
| 935 | char tmp[PROFILE_MAX_LINE_LEN]; |
| 936 | HKEY hkey; |
| 937 | DWORD err, type; |
| 938 | DWORD count = sizeof(tmp); |
| 939 | |
| 940 | if (RegOpenKeyA( wine_profile_key, section, &hkey )) return FALSE; |
| 941 | err = RegEnumValueA( hkey, index, name, (DWORD*)&name_len, NULL, &type, tmp, &count ); |
| 942 | RegCloseKey( hkey ); |
| 943 | if (!err) |
| 944 | { |
| 945 | PROFILE_CopyEntry( buffer, tmp, len, TRUE ); |
| 946 | TRACE( "('%s',%d): returning '%s'='%s'\n", section, index, name, buffer ); |
| 947 | } |
| 948 | return !err; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | |
| 952 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 953 | * PROFILE_GetWineIniInt |
| 954 | * |
| 955 | * Get a config integer from the wine.ini file. |
| 956 | */ |
| 957 | int PROFILE_GetWineIniInt( const char *section, const char *key_name, int def ) |
| 958 | { |
| 959 | char buffer[20]; |
| 960 | char *p; |
| 961 | long result; |
| 962 | |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 963 | PROFILE_GetWineIniString( section, key_name, "", buffer, sizeof(buffer) ); |
| 964 | if (!buffer[0]) return def; |
| 965 | result = strtol( buffer, &p, 0 ); |
| 966 | return (p == buffer) ? 0 /* No digits at all */ : (int)result; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | |
| 970 | /****************************************************************************** |
| 971 | * |
| 972 | * int PROFILE_GetWineIniBool( |
| 973 | * char const *section, |
| 974 | * char const *key_name, |
| 975 | * int def ) |
| 976 | * |
| 977 | * Reads a boolean value from the wine.ini file. This function attempts to |
| 978 | * be user-friendly by accepting 'n', 'N' (no), 'f', 'F' (false), or '0' |
| 979 | * (zero) for false, 'y', 'Y' (yes), 't', 'T' (true), or '1' (one) for |
| 980 | * true. Anything else results in the return of the default value. |
| 981 | * |
| 982 | * This function uses 1 to indicate true, and 0 for false. You can check |
| 983 | * for existence by setting def to something other than 0 or 1 and |
| 984 | * examining the return value. |
| 985 | */ |
| 986 | int PROFILE_GetWineIniBool( |
| 987 | char const *section, |
| 988 | char const *key_name, |
| 989 | int def ) |
| 990 | { |
| 991 | char key_value[2]; |
| 992 | int retval; |
| 993 | |
| 994 | PROFILE_GetWineIniString(section, key_name, "~", key_value, 2); |
| 995 | |
| 996 | switch(key_value[0]) { |
| 997 | case 'n': |
| 998 | case 'N': |
| 999 | case 'f': |
| 1000 | case 'F': |
| 1001 | case '0': |
| 1002 | retval = 0; |
| 1003 | break; |
| 1004 | |
| 1005 | case 'y': |
| 1006 | case 'Y': |
| 1007 | case 't': |
| 1008 | case 'T': |
| 1009 | case '1': |
| 1010 | retval = 1; |
| 1011 | break; |
| 1012 | |
| 1013 | default: |
| 1014 | retval = def; |
| 1015 | } |
| 1016 | |
Francois Gouget | e76218d | 2001-05-09 17:31:31 +0000 | [diff] [blame] | 1017 | TRACE("(\"%s\", \"%s\", %s), [%c], ret %s.\n", section, key_name, |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1018 | def ? "TRUE" : "FALSE", key_value[0], |
| 1019 | retval ? "TRUE" : "FALSE"); |
| 1020 | |
| 1021 | return retval; |
| 1022 | } |
| 1023 | |
| 1024 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 1025 | /*********************************************************************** |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1026 | * PROFILE_LoadWineIni |
| 1027 | * |
Chris Morgan | 4a3d508 | 2001-01-10 22:57:34 +0000 | [diff] [blame] | 1028 | * Load the old .winerc file. |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1029 | */ |
| 1030 | int PROFILE_LoadWineIni(void) |
| 1031 | { |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 1032 | OBJECT_ATTRIBUTES attr; |
| 1033 | UNICODE_STRING nameW; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1034 | char buffer[MAX_PATHNAME_LEN]; |
| 1035 | const char *p; |
| 1036 | FILE *f; |
Eric Pouech | 0521a54 | 2000-02-20 13:39:42 +0000 | [diff] [blame] | 1037 | HKEY hKeySW; |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 1038 | DWORD disp; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1039 | |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 1040 | attr.Length = sizeof(attr); |
| 1041 | attr.RootDirectory = 0; |
| 1042 | attr.ObjectName = &nameW; |
| 1043 | attr.Attributes = 0; |
| 1044 | attr.SecurityDescriptor = NULL; |
| 1045 | attr.SecurityQualityOfService = NULL; |
| 1046 | |
Alexandre Julliard | 86ff8c0 | 2000-04-13 16:10:20 +0000 | [diff] [blame] | 1047 | /* make sure HKLM\\Software\\Wine\\Wine exists as non-volatile key */ |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 1048 | if (!RtlCreateUnicodeStringFromAsciiz( &nameW, "Machine\\Software\\Wine\\Wine" ) || |
| 1049 | NtCreateKey( &hKeySW, KEY_ALL_ACCESS, &attr, 0, NULL, 0, &disp )) |
Eric Pouech | 0521a54 | 2000-02-20 13:39:42 +0000 | [diff] [blame] | 1050 | { |
| 1051 | ERR("Cannot create config registry key\n" ); |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 1052 | ExitProcess( 1 ); |
Eric Pouech | 0521a54 | 2000-02-20 13:39:42 +0000 | [diff] [blame] | 1053 | } |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 1054 | RtlFreeUnicodeString( &nameW ); |
| 1055 | NtClose( hKeySW ); |
| 1056 | |
| 1057 | if (!RtlCreateUnicodeStringFromAsciiz( &nameW, "Machine\\Software\\Wine\\Wine\\Config" ) || |
| 1058 | NtCreateKey( &wine_profile_key, KEY_ALL_ACCESS, &attr, 0, |
| 1059 | NULL, REG_OPTION_VOLATILE, &disp )) |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 1060 | { |
| 1061 | ERR("Cannot create config registry key\n" ); |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 1062 | ExitProcess( 1 ); |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 1063 | } |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 1064 | RtlFreeUnicodeString( &nameW ); |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1065 | |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 1066 | if (!CLIENT_IsBootThread()) return 1; /* already loaded */ |
| 1067 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1068 | if ((p = getenv( "HOME" )) != NULL) |
| 1069 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1070 | lstrcpynA(buffer, p, MAX_PATHNAME_LEN - sizeof(PROFILE_WineIniName)); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1071 | strcat( buffer, PROFILE_WineIniName ); |
| 1072 | if ((f = fopen( buffer, "r" )) != NULL) |
| 1073 | { |
Francois Gouget | baa9bf9 | 1999-12-27 05:24:06 +0000 | [diff] [blame] | 1074 | lstrcpynA(PROFILE_WineIniUsed,buffer,MAX_PATHNAME_LEN); |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 1075 | goto found; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1076 | } |
| 1077 | } |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1078 | else WARN("could not get $HOME value for config file.\n" ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1079 | |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 1080 | if (disp == REG_OPENED_EXISTING_KEY) return 1; /* loaded by the server */ |
| 1081 | |
Chris Morgan | 4a3d508 | 2001-01-10 22:57:34 +0000 | [diff] [blame] | 1082 | MESSAGE( "Can't open configuration file %s/config\n",get_config_dir() ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1083 | return 0; |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 1084 | |
| 1085 | found: |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 1086 | |
| 1087 | if (disp == REG_OPENED_EXISTING_KEY) |
| 1088 | { |
Chris Morgan | 4a3d508 | 2001-01-10 22:57:34 +0000 | [diff] [blame] | 1089 | MESSAGE( "Warning: configuration loaded by the server from '%s/config',\n" |
| 1090 | " file '%s' was ignored.\n", get_config_dir(), PROFILE_WineIniUsed ); |
Alexandre Julliard | 6c8d917 | 2000-08-26 04:40:07 +0000 | [diff] [blame] | 1091 | fclose( f ); |
| 1092 | return 1; |
| 1093 | } |
| 1094 | |
Alexandre Julliard | 73be8d1 | 2000-12-06 20:25:11 +0000 | [diff] [blame] | 1095 | /* convert to the new format */ |
| 1096 | sprintf( buffer, "%s/config", get_config_dir() ); |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 1097 | convert_config( f, buffer ); |
Alexandre Julliard | 00377a7 | 2000-02-19 20:50:00 +0000 | [diff] [blame] | 1098 | fclose( f ); |
Alexandre Julliard | 9515336 | 2001-03-23 19:13:23 +0000 | [diff] [blame] | 1099 | |
| 1100 | MESSAGE( "The '%s' configuration file has been converted\n" |
| 1101 | "to the new format and saved as '%s'.\n", PROFILE_WineIniUsed, buffer ); |
| 1102 | MESSAGE( "You should verify that the contents of the new file are correct,\n" |
| 1103 | "and then remove the old one and restart Wine.\n" ); |
| 1104 | ExitProcess(0); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 1108 | /*********************************************************************** |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1109 | * PROFILE_UsageWineIni |
| 1110 | * |
| 1111 | * Explain the wine.ini file to those who don't read documentation. |
| 1112 | * Keep below one screenful in length so that error messages above are |
| 1113 | * noticed. |
| 1114 | */ |
| 1115 | void PROFILE_UsageWineIni(void) |
| 1116 | { |
Alexandre Julliard | 359f497e | 1999-07-04 16:02:24 +0000 | [diff] [blame] | 1117 | MESSAGE("Perhaps you have not properly edited or created " |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1118 | "your Wine configuration file.\n"); |
Gerard Patel | 151023d | 2001-01-22 19:27:06 +0000 | [diff] [blame] | 1119 | MESSAGE("This is '%s/config'\n", get_config_dir()); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1120 | /* RTFM, so to say */ |
| 1121 | } |
| 1122 | |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 1123 | /*********************************************************************** |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 1124 | * PROFILE_GetStringItem |
| 1125 | * |
| 1126 | * Convenience function that turns a string 'xxx, yyy, zzz' into |
| 1127 | * the 'xxx\0 yyy, zzz' and returns a pointer to the 'yyy, zzz'. |
| 1128 | */ |
| 1129 | char* PROFILE_GetStringItem( char* start ) |
| 1130 | { |
| 1131 | char* lpchX, *lpch; |
| 1132 | |
| 1133 | for (lpchX = start, lpch = NULL; *lpchX != '\0'; lpchX++ ) |
| 1134 | { |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 1135 | if( *lpchX == ',' ) |
| 1136 | { |
| 1137 | if( lpch ) *lpch = '\0'; else *lpchX = '\0'; |
| 1138 | while( *(++lpchX) ) |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1139 | if( !PROFILE_isspace(*lpchX) ) return lpchX; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 1140 | } |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 1141 | else if( PROFILE_isspace( *lpchX ) && !lpch ) lpch = lpchX; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1142 | else lpch = NULL; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 1143 | } |
| 1144 | if( lpch ) *lpch = '\0'; |
| 1145 | return NULL; |
| 1146 | } |
| 1147 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1148 | /********************* API functions **********************************/ |
| 1149 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1150 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1151 | * GetProfileInt (KERNEL.57) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1152 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1153 | UINT16 WINAPI GetProfileInt16( LPCSTR section, LPCSTR entry, INT16 def_val ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1154 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1155 | return GetPrivateProfileInt16( section, entry, def_val, "win.ini" ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | |
| 1159 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1160 | * GetProfileIntA (KERNEL32.@) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1161 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1162 | UINT WINAPI GetProfileIntA( LPCSTR section, LPCSTR entry, INT def_val ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1163 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1164 | return GetPrivateProfileIntA( section, entry, def_val, "win.ini" ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1168 | * GetProfileIntW (KERNEL32.@) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1169 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1170 | UINT WINAPI GetProfileIntW( LPCWSTR section, LPCWSTR entry, INT def_val ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1171 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1172 | return GetPrivateProfileIntW( section, entry, def_val, wininiW ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1175 | /* |
Lionel Ulmer | f89722d | 2001-07-20 17:55:39 +0000 | [diff] [blame] | 1176 | * if allow_section_name_copy is TRUE, allow the copying : |
| 1177 | * - of Section names if 'section' is NULL |
| 1178 | * - of Keys in a Section if 'entry' is NULL |
| 1179 | * (see MSDN doc for GetPrivateProfileString) |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1180 | */ |
| 1181 | static int PROFILE_GetPrivateProfileString( LPCSTR section, LPCSTR entry, |
| 1182 | LPCSTR def_val, LPSTR buffer, |
| 1183 | UINT16 len, LPCSTR filename, |
Lionel Ulmer | f89722d | 2001-07-20 17:55:39 +0000 | [diff] [blame] | 1184 | BOOL allow_section_name_copy ) |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1185 | { |
| 1186 | int ret; |
| 1187 | LPSTR pDefVal = NULL; |
| 1188 | |
| 1189 | if (!filename) |
| 1190 | filename = "win.ini"; |
| 1191 | |
| 1192 | /* strip any trailing ' ' of def_val. */ |
| 1193 | if (def_val) |
| 1194 | { |
| 1195 | LPSTR p = (LPSTR)&def_val[strlen(def_val)]; /* even "" works ! */ |
| 1196 | |
| 1197 | while (p > def_val) |
| 1198 | { |
| 1199 | p--; |
| 1200 | if ((*p) != ' ') |
| 1201 | break; |
| 1202 | } |
| 1203 | if (*p == ' ') /* ouch, contained trailing ' ' */ |
| 1204 | { |
| 1205 | int len = (int)p - (int)def_val; |
| 1206 | pDefVal = HeapAlloc(GetProcessHeap(), 0, len + 1); |
| 1207 | strncpy(pDefVal, def_val, len); |
| 1208 | pDefVal[len] = '\0'; |
| 1209 | } |
| 1210 | } |
| 1211 | if (!pDefVal) |
| 1212 | pDefVal = (LPSTR)def_val; |
| 1213 | |
| 1214 | EnterCriticalSection( &PROFILE_CritSect ); |
| 1215 | |
| 1216 | if (PROFILE_Open( filename )) { |
Lionel Ulmer | f89722d | 2001-07-20 17:55:39 +0000 | [diff] [blame] | 1217 | if ((allow_section_name_copy) && (section == NULL)) |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1218 | ret = PROFILE_GetSectionNames(buffer, len); |
| 1219 | else |
Lionel Ulmer | f89722d | 2001-07-20 17:55:39 +0000 | [diff] [blame] | 1220 | /* PROFILE_GetString already handles the 'entry == NULL' case */ |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1221 | ret = PROFILE_GetString( section, entry, pDefVal, buffer, len ); |
| 1222 | } else { |
| 1223 | lstrcpynA( buffer, pDefVal, len ); |
| 1224 | ret = strlen( buffer ); |
| 1225 | } |
| 1226 | |
| 1227 | LeaveCriticalSection( &PROFILE_CritSect ); |
| 1228 | |
| 1229 | if (pDefVal != def_val) /* allocated */ |
| 1230 | HeapFree(GetProcessHeap(), 0, pDefVal); |
| 1231 | |
| 1232 | return ret; |
| 1233 | } |
| 1234 | |
| 1235 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1236 | * GetPrivateProfileString (KERNEL.128) |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1237 | */ |
| 1238 | INT16 WINAPI GetPrivateProfileString16( LPCSTR section, LPCSTR entry, |
| 1239 | LPCSTR def_val, LPSTR buffer, |
| 1240 | UINT16 len, LPCSTR filename ) |
| 1241 | { |
| 1242 | return PROFILE_GetPrivateProfileString( section, entry, def_val, |
| 1243 | buffer, len, filename, FALSE ); |
| 1244 | } |
| 1245 | |
| 1246 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1247 | * GetPrivateProfileStringA (KERNEL32.@) |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1248 | */ |
| 1249 | INT WINAPI GetPrivateProfileStringA( LPCSTR section, LPCSTR entry, |
| 1250 | LPCSTR def_val, LPSTR buffer, |
| 1251 | UINT len, LPCSTR filename ) |
| 1252 | { |
| 1253 | return PROFILE_GetPrivateProfileString( section, entry, def_val, |
| 1254 | buffer, len, filename, TRUE ); |
| 1255 | } |
| 1256 | |
| 1257 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1258 | * GetPrivateProfileStringW (KERNEL32.@) |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1259 | */ |
| 1260 | INT WINAPI GetPrivateProfileStringW( LPCWSTR section, LPCWSTR entry, |
| 1261 | LPCWSTR def_val, LPWSTR buffer, |
| 1262 | UINT len, LPCWSTR filename ) |
| 1263 | { |
| 1264 | LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section ); |
| 1265 | LPSTR entryA = HEAP_strdupWtoA( GetProcessHeap(), 0, entry ); |
| 1266 | LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); |
| 1267 | LPSTR def_valA = HEAP_strdupWtoA( GetProcessHeap(), 0, def_val ); |
| 1268 | LPSTR bufferA = HeapAlloc( GetProcessHeap(), 0, len ); |
| 1269 | INT ret = GetPrivateProfileStringA( sectionA, entryA, def_valA, |
| 1270 | bufferA, len, filenameA ); |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 1271 | if (len > 0 && !MultiByteToWideChar( CP_ACP, 0, bufferA, -1, buffer, len )) |
| 1272 | buffer[len-1] = 0; |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1273 | HeapFree( GetProcessHeap(), 0, sectionA ); |
| 1274 | HeapFree( GetProcessHeap(), 0, entryA ); |
| 1275 | HeapFree( GetProcessHeap(), 0, filenameA ); |
| 1276 | HeapFree( GetProcessHeap(), 0, def_valA ); |
| 1277 | HeapFree( GetProcessHeap(), 0, bufferA); |
| 1278 | return ret; |
| 1279 | } |
| 1280 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1281 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1282 | * GetProfileString (KERNEL.58) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1283 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1284 | INT16 WINAPI GetProfileString16( LPCSTR section, LPCSTR entry, LPCSTR def_val, |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1285 | LPSTR buffer, UINT16 len ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1286 | { |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1287 | return PROFILE_GetPrivateProfileString( section, entry, def_val, |
| 1288 | buffer, len, "win.ini", FALSE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1292 | * GetProfileStringA (KERNEL32.@) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1293 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1294 | INT WINAPI GetProfileStringA( LPCSTR section, LPCSTR entry, LPCSTR def_val, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1295 | LPSTR buffer, UINT len ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1296 | { |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1297 | return PROFILE_GetPrivateProfileString( section, entry, def_val, |
| 1298 | buffer, len, "win.ini", TRUE ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1302 | * GetProfileStringW (KERNEL32.@) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1303 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1304 | INT WINAPI GetProfileStringW( LPCWSTR section, LPCWSTR entry, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1305 | LPCWSTR def_val, LPWSTR buffer, UINT len ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1306 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1307 | return GetPrivateProfileStringW( section, entry, def_val, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1308 | buffer, len, wininiW ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1311 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1312 | * WriteProfileString (KERNEL.59) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1313 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1314 | BOOL16 WINAPI WriteProfileString16( LPCSTR section, LPCSTR entry, |
| 1315 | LPCSTR string ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1316 | { |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1317 | return WritePrivateProfileString16( section, entry, string, "win.ini" ); |
| 1318 | } |
| 1319 | |
| 1320 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1321 | * WriteProfileStringA (KERNEL32.@) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1322 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1323 | BOOL WINAPI WriteProfileStringA( LPCSTR section, LPCSTR entry, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1324 | LPCSTR string ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1325 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1326 | return WritePrivateProfileStringA( section, entry, string, "win.ini" ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1330 | * WriteProfileStringW (KERNEL32.@) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1331 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1332 | BOOL WINAPI WriteProfileStringW( LPCWSTR section, LPCWSTR entry, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1333 | LPCWSTR string ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1334 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1335 | return WritePrivateProfileStringW( section, entry, string, wininiW ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | |
| 1339 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1340 | * GetPrivateProfileInt (KERNEL.127) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1341 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1342 | UINT16 WINAPI GetPrivateProfileInt16( LPCSTR section, LPCSTR entry, |
| 1343 | INT16 def_val, LPCSTR filename ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1344 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1345 | long result=(long)GetPrivateProfileIntA(section,entry,def_val,filename); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1346 | |
| 1347 | if (result > 65535) return 65535; |
| 1348 | if (result >= 0) return (UINT16)result; |
| 1349 | if (result < -32768) return -32768; |
| 1350 | return (UINT16)(INT16)result; |
| 1351 | } |
| 1352 | |
| 1353 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1354 | * GetPrivateProfileIntA (KERNEL32.@) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1355 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1356 | UINT WINAPI GetPrivateProfileIntA( LPCSTR section, LPCSTR entry, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1357 | INT def_val, LPCSTR filename ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1358 | { |
| 1359 | char buffer[20]; |
| 1360 | char *p; |
| 1361 | long result; |
| 1362 | |
Andreas Mohr | 3ac104f | 2000-09-29 21:04:44 +0000 | [diff] [blame] | 1363 | PROFILE_GetPrivateProfileString( section, entry, "", |
| 1364 | buffer, sizeof(buffer), filename, FALSE ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1365 | if (!buffer[0]) return (UINT)def_val; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1366 | result = strtol( buffer, &p, 0 ); |
| 1367 | if (p == buffer) return 0; /* No digits at all */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1368 | return (UINT)result; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1371 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1372 | * GetPrivateProfileIntW (KERNEL32.@) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1373 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1374 | UINT WINAPI GetPrivateProfileIntW( LPCWSTR section, LPCWSTR entry, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1375 | INT def_val, LPCWSTR filename ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1376 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1377 | LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section ); |
| 1378 | LPSTR entryA = HEAP_strdupWtoA( GetProcessHeap(), 0, entry ); |
| 1379 | LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1380 | UINT res = GetPrivateProfileIntA(sectionA, entryA, def_val, filenameA); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1381 | HeapFree( GetProcessHeap(), 0, sectionA ); |
| 1382 | HeapFree( GetProcessHeap(), 0, filenameA ); |
| 1383 | HeapFree( GetProcessHeap(), 0, entryA ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1384 | return res; |
| 1385 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1386 | |
| 1387 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1388 | * GetPrivateProfileSection (KERNEL.418) |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1389 | */ |
| 1390 | INT16 WINAPI GetPrivateProfileSection16( LPCSTR section, LPSTR buffer, |
| 1391 | UINT16 len, LPCSTR filename ) |
| 1392 | { |
| 1393 | return GetPrivateProfileSectionA( section, buffer, len, filename ); |
| 1394 | } |
| 1395 | |
| 1396 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1397 | * GetPrivateProfileSectionA (KERNEL32.@) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1398 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1399 | INT WINAPI GetPrivateProfileSectionA( LPCSTR section, LPSTR buffer, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1400 | DWORD len, LPCSTR filename ) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1401 | { |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1402 | int ret = 0; |
| 1403 | |
| 1404 | EnterCriticalSection( &PROFILE_CritSect ); |
| 1405 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1406 | if (PROFILE_Open( filename )) |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1407 | ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, |
| 1408 | FALSE, TRUE); |
| 1409 | |
| 1410 | LeaveCriticalSection( &PROFILE_CritSect ); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1411 | |
Marcus Meissner | 264360f | 1999-05-08 10:02:05 +0000 | [diff] [blame] | 1412 | return ret; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1413 | } |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1414 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1415 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1416 | * GetPrivateProfileSectionW (KERNEL32.@) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1417 | */ |
| 1418 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1419 | INT WINAPI GetPrivateProfileSectionW (LPCWSTR section, LPWSTR buffer, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1420 | DWORD len, LPCWSTR filename ) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1421 | |
| 1422 | { |
| 1423 | LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section ); |
| 1424 | LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); |
| 1425 | LPSTR bufferA = HeapAlloc( GetProcessHeap(), 0, len ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1426 | INT ret = GetPrivateProfileSectionA( sectionA, bufferA, len, |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1427 | filenameA ); |
Marcus Meissner | 264360f | 1999-05-08 10:02:05 +0000 | [diff] [blame] | 1428 | MultiByteToWideChar(CP_ACP,0,bufferA,ret,buffer,len); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1429 | HeapFree( GetProcessHeap(), 0, sectionA ); |
| 1430 | HeapFree( GetProcessHeap(), 0, filenameA ); |
| 1431 | HeapFree( GetProcessHeap(), 0, bufferA); |
| 1432 | return ret; |
| 1433 | } |
| 1434 | |
| 1435 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1436 | * GetProfileSection (KERNEL.419) |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1437 | */ |
| 1438 | INT16 WINAPI GetProfileSection16( LPCSTR section, LPSTR buffer, UINT16 len ) |
| 1439 | { |
| 1440 | return GetPrivateProfileSection16( section, buffer, len, "win.ini" ); |
| 1441 | } |
| 1442 | |
| 1443 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1444 | * GetProfileSectionA (KERNEL32.@) |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1445 | */ |
| 1446 | INT WINAPI GetProfileSectionA( LPCSTR section, LPSTR buffer, DWORD len ) |
| 1447 | { |
| 1448 | return GetPrivateProfileSectionA( section, buffer, len, "win.ini" ); |
| 1449 | } |
| 1450 | |
| 1451 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 1452 | * GetProfileSectionW (KERNEL32.@) |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1453 | */ |
| 1454 | INT WINAPI GetProfileSectionW( LPCWSTR section, LPWSTR buffer, DWORD len ) |
| 1455 | { |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1456 | return GetPrivateProfileSectionW( section, buffer, len, wininiW ); |
| 1457 | } |
| 1458 | |
| 1459 | |
| 1460 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1461 | * WritePrivateProfileString (KERNEL.129) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1462 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1463 | BOOL16 WINAPI WritePrivateProfileString16( LPCSTR section, LPCSTR entry, |
| 1464 | LPCSTR string, LPCSTR filename ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1465 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1466 | return WritePrivateProfileStringA(section,entry,string,filename); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1470 | * WritePrivateProfileStringA (KERNEL32.@) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1471 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1472 | BOOL WINAPI WritePrivateProfileStringA( LPCSTR section, LPCSTR entry, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1473 | LPCSTR string, LPCSTR filename ) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1474 | { |
Alexandre Julliard | e61b792 | 1999-07-31 19:24:11 +0000 | [diff] [blame] | 1475 | BOOL ret = FALSE; |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1476 | |
| 1477 | EnterCriticalSection( &PROFILE_CritSect ); |
| 1478 | |
Alexandre Julliard | e61b792 | 1999-07-31 19:24:11 +0000 | [diff] [blame] | 1479 | if (PROFILE_Open( filename )) |
| 1480 | { |
| 1481 | if (!section && !entry && !string) |
| 1482 | PROFILE_ReleaseFile(); /* always return FALSE in this case */ |
| 1483 | else |
| 1484 | ret = PROFILE_SetString( section, entry, string ); |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | LeaveCriticalSection( &PROFILE_CritSect ); |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1488 | return ret; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1491 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1492 | * WritePrivateProfileStringW (KERNEL32.@) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1493 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1494 | BOOL WINAPI WritePrivateProfileStringW( LPCWSTR section, LPCWSTR entry, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1495 | LPCWSTR string, LPCWSTR filename ) |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1496 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1497 | LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section ); |
| 1498 | LPSTR entryA = HEAP_strdupWtoA( GetProcessHeap(), 0, entry ); |
| 1499 | LPSTR stringA = HEAP_strdupWtoA( GetProcessHeap(), 0, string ); |
| 1500 | LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1501 | BOOL res = WritePrivateProfileStringA( sectionA, entryA, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1502 | stringA, filenameA ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1503 | HeapFree( GetProcessHeap(), 0, sectionA ); |
| 1504 | HeapFree( GetProcessHeap(), 0, entryA ); |
| 1505 | HeapFree( GetProcessHeap(), 0, stringA ); |
| 1506 | HeapFree( GetProcessHeap(), 0, filenameA ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1507 | return res; |
| 1508 | } |
| 1509 | |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1510 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1511 | * WritePrivateProfileSection (KERNEL.416) |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1512 | */ |
| 1513 | BOOL16 WINAPI WritePrivateProfileSection16( LPCSTR section, |
| 1514 | LPCSTR string, LPCSTR filename ) |
| 1515 | { |
| 1516 | return WritePrivateProfileSectionA( section, string, filename ); |
| 1517 | } |
| 1518 | |
| 1519 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 1520 | * WritePrivateProfileSectionA (KERNEL32.@) |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1521 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1522 | BOOL WINAPI WritePrivateProfileSectionA( LPCSTR section, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1523 | LPCSTR string, LPCSTR filename ) |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1524 | { |
Rein Klazes | 7458be0 | 2000-01-05 01:42:51 +0000 | [diff] [blame] | 1525 | BOOL ret = FALSE; |
| 1526 | LPSTR p ; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1527 | |
Rein Klazes | 7458be0 | 2000-01-05 01:42:51 +0000 | [diff] [blame] | 1528 | EnterCriticalSection( &PROFILE_CritSect ); |
| 1529 | |
| 1530 | if (PROFILE_Open( filename )) { |
Marcus Meissner | 25e7403 | 2000-11-26 22:36:19 +0000 | [diff] [blame] | 1531 | if (!section && !string) |
Rein Klazes | 7458be0 | 2000-01-05 01:42:51 +0000 | [diff] [blame] | 1532 | PROFILE_ReleaseFile(); /* always return FALSE in this case */ |
Uwe Bonnes | d88fbb7 | 2000-06-20 20:48:46 +0000 | [diff] [blame] | 1533 | else if (!string) /* delete the named section*/ |
| 1534 | ret = PROFILE_SetString(section,NULL,NULL); |
Rein Klazes | 7458be0 | 2000-01-05 01:42:51 +0000 | [diff] [blame] | 1535 | else { |
Uwe Bonnes | d88fbb7 | 2000-06-20 20:48:46 +0000 | [diff] [blame] | 1536 | PROFILE_DeleteAllKeys(section); |
| 1537 | ret = TRUE; |
| 1538 | while(*string) { |
Alexandre Julliard | 5f728ca | 2001-07-24 21:45:22 +0000 | [diff] [blame] | 1539 | LPSTR buf = HeapAlloc( GetProcessHeap(), 0, strlen(string)+1 ); |
| 1540 | strcpy( buf, string ); |
Rein Klazes | 7458be0 | 2000-01-05 01:42:51 +0000 | [diff] [blame] | 1541 | if((p=strchr( buf, '='))){ |
| 1542 | *p='\0'; |
| 1543 | ret = PROFILE_SetString( section, buf, p+1 ); |
| 1544 | |
| 1545 | } |
| 1546 | HeapFree( GetProcessHeap(), 0, buf ); |
| 1547 | string += strlen(string)+1; |
| 1548 | } |
| 1549 | |
| 1550 | } |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1551 | } |
Rein Klazes | 7458be0 | 2000-01-05 01:42:51 +0000 | [diff] [blame] | 1552 | |
| 1553 | LeaveCriticalSection( &PROFILE_CritSect ); |
| 1554 | return ret; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1557 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 1558 | * WritePrivateProfileSectionW (KERNEL32.@) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1559 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1560 | BOOL WINAPI WritePrivateProfileSectionW( LPCWSTR section, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1561 | LPCWSTR string, LPCWSTR filename) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1562 | |
| 1563 | { |
| 1564 | LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section ); |
| 1565 | LPSTR stringA = HEAP_strdupWtoA( GetProcessHeap(), 0, string ); |
| 1566 | LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1567 | BOOL res = WritePrivateProfileSectionA( sectionA, stringA, filenameA ); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1568 | HeapFree( GetProcessHeap(), 0, sectionA ); |
| 1569 | HeapFree( GetProcessHeap(), 0, stringA ); |
| 1570 | HeapFree( GetProcessHeap(), 0, filenameA ); |
| 1571 | return res; |
| 1572 | } |
| 1573 | |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1574 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1575 | * WriteProfileSection (KERNEL.417) |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1576 | */ |
| 1577 | BOOL16 WINAPI WriteProfileSection16( LPCSTR section, LPCSTR keys_n_values) |
| 1578 | { |
| 1579 | return WritePrivateProfileSection16( section, keys_n_values, "win.ini"); |
| 1580 | } |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1581 | |
| 1582 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1583 | * WriteProfileSectionA (KERNEL32.@) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1584 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1585 | BOOL WINAPI WriteProfileSectionA( LPCSTR section, LPCSTR keys_n_values) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1586 | |
| 1587 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1588 | return WritePrivateProfileSectionA( section, keys_n_values, "win.ini"); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1592 | * WriteProfileSectionW (KERNEL32.@) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1593 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1594 | BOOL WINAPI WriteProfileSectionW( LPCWSTR section, LPCWSTR keys_n_values) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1595 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1596 | return (WritePrivateProfileSectionW (section,keys_n_values, wininiW)); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1600 | * GetPrivateProfileSectionNames (KERNEL.143) |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1601 | */ |
| 1602 | WORD WINAPI GetPrivateProfileSectionNames16( LPSTR buffer, WORD size, |
| 1603 | LPCSTR filename ) |
| 1604 | { |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 1605 | return GetPrivateProfileSectionNamesA(buffer,size,filename); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1606 | } |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1607 | |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1608 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1609 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1610 | * GetProfileSectionNames (KERNEL.142) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1611 | */ |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 1612 | WORD WINAPI GetProfileSectionNames16(LPSTR buffer, WORD size) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1613 | |
| 1614 | { |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 1615 | return GetPrivateProfileSectionNamesA(buffer,size,"win.ini"); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | |
| 1619 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1620 | * GetPrivateProfileSectionNamesA (KERNEL32.@) |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 1621 | * |
| 1622 | * Returns the section names contained in the specified file. |
| 1623 | * FIXME: Where do we find this file when the path is relative? |
| 1624 | * The section names are returned as a list of strings with an extra |
| 1625 | * '\0' to mark the end of the list. Except for that the behavior |
| 1626 | * depends on the Windows version. |
| 1627 | * |
| 1628 | * Win95: |
| 1629 | * - if the buffer is 0 or 1 character long then it is as if it was of |
| 1630 | * infinite length. |
| 1631 | * - otherwise, if the buffer is to small only the section names that fit |
| 1632 | * are returned. |
| 1633 | * - note that this means if the buffer was to small to return even just |
| 1634 | * the first section name then a single '\0' will be returned. |
| 1635 | * - the return value is the number of characters written in the buffer, |
| 1636 | * except if the buffer was too smal in which case len-2 is returned |
| 1637 | * |
| 1638 | * Win2000: |
| 1639 | * - if the buffer is 0, 1 or 2 characters long then it is filled with |
| 1640 | * '\0' and the return value is 0 |
| 1641 | * - otherwise if the buffer is too small then the first section name that |
| 1642 | * does not fit is truncated so that the string list can be terminated |
| 1643 | * correctly (double '\0') |
| 1644 | * - the return value is the number of characters written in the buffer |
| 1645 | * except for the trailing '\0'. If the buffer is too small, then the |
| 1646 | * return value is len-2 |
| 1647 | * - Win2000 has a bug that triggers when the section names and the |
| 1648 | * trailing '\0' fit exactly in the buffer. In that case the trailing |
| 1649 | * '\0' is missing. |
| 1650 | * |
| 1651 | * Wine implements the observed Win2000 behavior (except for the bug). |
| 1652 | * |
| 1653 | * Note that when the buffer is big enough then the return value may be any |
| 1654 | * value between 1 and len-1 (or len in Win95), including len-2. |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1655 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1656 | DWORD WINAPI GetPrivateProfileSectionNamesA( LPSTR buffer, DWORD size, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1657 | LPCSTR filename) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1658 | |
| 1659 | { |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 1660 | DWORD ret = 0; |
| 1661 | |
| 1662 | EnterCriticalSection( &PROFILE_CritSect ); |
| 1663 | |
| 1664 | if (PROFILE_Open( filename )) |
| 1665 | ret = PROFILE_GetSectionNames(buffer, size); |
| 1666 | |
| 1667 | LeaveCriticalSection( &PROFILE_CritSect ); |
| 1668 | |
| 1669 | return ret; |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | |
| 1673 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1674 | * GetPrivateProfileSectionNamesW (KERNEL32.@) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1675 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1676 | DWORD WINAPI GetPrivateProfileSectionNamesW( LPWSTR buffer, DWORD size, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1677 | LPCWSTR filename) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1678 | |
| 1679 | { |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 1680 | LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); |
| 1681 | LPSTR bufferA = HeapAlloc( GetProcessHeap(), 0, size); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1682 | |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 1683 | INT ret = GetPrivateProfileSectionNamesA(bufferA, size, filenameA); |
| 1684 | if (size > 0 && !MultiByteToWideChar( CP_ACP, 0, bufferA, -1, buffer, size )) |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 1685 | buffer[size-1] = 0; |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 1686 | HeapFree( GetProcessHeap(), 0, bufferA); |
| 1687 | HeapFree( GetProcessHeap(), 0, filenameA ); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1688 | |
Francois Gouget | 19b05e5 | 2001-08-28 18:39:26 +0000 | [diff] [blame] | 1689 | return ret; |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1692 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1693 | * GetPrivateProfileStruct (KERNEL.407) |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1694 | */ |
| 1695 | BOOL16 WINAPI GetPrivateProfileStruct16(LPCSTR section, LPCSTR key, |
| 1696 | LPVOID buf, UINT16 len, LPCSTR filename) |
| 1697 | { |
| 1698 | return GetPrivateProfileStructA( section, key, buf, len, filename ); |
| 1699 | } |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1700 | |
| 1701 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1702 | * GetPrivateProfileStructA (KERNEL32.@) |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 1703 | * |
| 1704 | * Should match Win95's behaviour pretty much |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1705 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1706 | BOOL WINAPI GetPrivateProfileStructA (LPCSTR section, LPCSTR key, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1707 | LPVOID buf, UINT len, LPCSTR filename) |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1708 | { |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1709 | BOOL ret = FALSE; |
| 1710 | |
| 1711 | EnterCriticalSection( &PROFILE_CritSect ); |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1712 | |
| 1713 | if (PROFILE_Open( filename )) { |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1714 | PROFILEKEY *k = PROFILE_Find ( &CurProfile->section, section, key, FALSE); |
| 1715 | if (k) { |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 1716 | TRACE("value (at %p): '%s'\n", k->value, k->value); |
| 1717 | if (((strlen(k->value) - 2) / 2) == len) |
| 1718 | { |
| 1719 | LPSTR end, p; |
| 1720 | BOOL valid = TRUE; |
| 1721 | CHAR c; |
| 1722 | DWORD chksum = 0; |
| 1723 | |
| 1724 | end = k->value + strlen(k->value); /* -> '\0' */ |
| 1725 | /* check for invalid chars in ASCII coded hex string */ |
| 1726 | for (p=k->value; p < end; p++) |
| 1727 | { |
| 1728 | if (!isxdigit(*p)) |
| 1729 | { |
| 1730 | WARN("invalid char '%c' in file '%s'->'[%s]'->'%s' !\n", |
| 1731 | *p, filename, section, key); |
| 1732 | valid = FALSE; |
| 1733 | break; |
| 1734 | } |
| 1735 | } |
| 1736 | if (valid) |
| 1737 | { |
| 1738 | BOOL highnibble = TRUE; |
| 1739 | BYTE b = 0, val; |
| 1740 | LPBYTE binbuf = (LPBYTE)buf; |
| 1741 | |
| 1742 | end -= 2; /* don't include checksum in output data */ |
| 1743 | /* translate ASCII hex format into binary data */ |
| 1744 | for (p=k->value; p < end; p++) |
| 1745 | { |
| 1746 | c = toupper(*p); |
| 1747 | val = (c > '9') ? |
| 1748 | (c - 'A' + 10) : (c - '0'); |
| 1749 | |
| 1750 | if (highnibble) |
| 1751 | b = val << 4; |
| 1752 | else |
| 1753 | { |
| 1754 | b += val; |
| 1755 | *binbuf++ = b; /* feed binary data into output */ |
| 1756 | chksum += b; /* calculate checksum */ |
| 1757 | } |
| 1758 | highnibble ^= 1; /* toggle */ |
| 1759 | } |
| 1760 | /* retrieve stored checksum value */ |
| 1761 | c = toupper(*p++); |
| 1762 | b = ( (c > '9') ? (c - 'A' + 10) : (c - '0') ) << 4; |
| 1763 | c = toupper(*p); |
| 1764 | b += (c > '9') ? (c - 'A' + 10) : (c - '0'); |
| 1765 | if (b == (chksum & 0xff)) /* checksums match ? */ |
| 1766 | ret = TRUE; |
| 1767 | } |
| 1768 | } |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1769 | } |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1770 | } |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1771 | LeaveCriticalSection( &PROFILE_CritSect ); |
| 1772 | |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 1773 | return ret; |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1776 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1777 | * GetPrivateProfileStructW (KERNEL32.@) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1778 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1779 | BOOL WINAPI GetPrivateProfileStructW (LPCWSTR section, LPCWSTR key, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1780 | LPVOID buffer, UINT len, LPCWSTR filename) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1781 | { |
| 1782 | LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section ); |
| 1783 | LPSTR keyA = HEAP_strdupWtoA( GetProcessHeap(), 0, key); |
| 1784 | LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); |
| 1785 | LPSTR bufferA = HeapAlloc( GetProcessHeap(), 0, len ); |
| 1786 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1787 | INT ret = GetPrivateProfileStructA( sectionA, keyA, bufferA, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1788 | len, filenameA ); |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 1789 | if (len > 0 && !MultiByteToWideChar( CP_ACP, 0, bufferA, -1, buffer, len )) |
| 1790 | ((LPWSTR)buffer)[len-1] = 0; |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1791 | HeapFree( GetProcessHeap(), 0, bufferA); |
| 1792 | HeapFree( GetProcessHeap(), 0, sectionA ); |
| 1793 | HeapFree( GetProcessHeap(), 0, keyA ); |
| 1794 | HeapFree( GetProcessHeap(), 0, filenameA ); |
| 1795 | |
| 1796 | return ret; |
| 1797 | } |
| 1798 | |
| 1799 | |
| 1800 | |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1801 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 1802 | * WritePrivateProfileStruct (KERNEL.406) |
Ulrich Weigand | 8228bd6 | 1999-04-22 09:56:09 +0000 | [diff] [blame] | 1803 | */ |
| 1804 | BOOL16 WINAPI WritePrivateProfileStruct16 (LPCSTR section, LPCSTR key, |
| 1805 | LPVOID buf, UINT16 bufsize, LPCSTR filename) |
| 1806 | { |
| 1807 | return WritePrivateProfileStructA( section, key, buf, bufsize, filename ); |
| 1808 | } |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1809 | |
| 1810 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1811 | * WritePrivateProfileStructA (KERNEL32.@) |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1812 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1813 | BOOL WINAPI WritePrivateProfileStructA (LPCSTR section, LPCSTR key, |
Alexandre Julliard | e61b792 | 1999-07-31 19:24:11 +0000 | [diff] [blame] | 1814 | LPVOID buf, UINT bufsize, LPCSTR filename) |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1815 | { |
Alexandre Julliard | e61b792 | 1999-07-31 19:24:11 +0000 | [diff] [blame] | 1816 | BOOL ret = FALSE; |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 1817 | LPBYTE binbuf; |
| 1818 | LPSTR outstring, p; |
| 1819 | DWORD sum = 0; |
Alexandre Julliard | e61b792 | 1999-07-31 19:24:11 +0000 | [diff] [blame] | 1820 | |
| 1821 | if (!section && !key && !buf) /* flush the cache */ |
| 1822 | return WritePrivateProfileStringA( NULL, NULL, NULL, filename ); |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1823 | |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 1824 | /* allocate string buffer for hex chars + checksum hex char + '\0' */ |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 1825 | outstring = HeapAlloc( GetProcessHeap(), 0, bufsize*2 + 2 + 1); |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 1826 | p = outstring; |
| 1827 | for (binbuf = (LPBYTE)buf; binbuf < (LPBYTE)buf+bufsize; binbuf++) { |
| 1828 | *p++ = hex[*binbuf >> 4]; |
| 1829 | *p++ = hex[*binbuf & 0xf]; |
| 1830 | sum += *binbuf; |
| 1831 | } |
| 1832 | /* checksum is sum & 0xff */ |
| 1833 | *p++ = hex[(sum & 0xf0) >> 4]; |
| 1834 | *p++ = hex[sum & 0xf]; |
| 1835 | *p++ = '\0'; |
| 1836 | |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1837 | EnterCriticalSection( &PROFILE_CritSect ); |
| 1838 | |
Alexandre Julliard | e61b792 | 1999-07-31 19:24:11 +0000 | [diff] [blame] | 1839 | if (PROFILE_Open( filename )) |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 1840 | ret = PROFILE_SetString( section, key, outstring ); |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1841 | |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1842 | LeaveCriticalSection( &PROFILE_CritSect ); |
| 1843 | |
Alexandre Julliard | 90476d6 | 2000-02-16 22:47:24 +0000 | [diff] [blame] | 1844 | HeapFree( GetProcessHeap(), 0, outstring ); |
Andreas Mohr | 17b1f46 | 2000-01-30 21:15:14 +0000 | [diff] [blame] | 1845 | |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1846 | return ret; |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1849 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 1850 | * WritePrivateProfileStructW (KERNEL32.@) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1851 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1852 | BOOL WINAPI WritePrivateProfileStructW (LPCWSTR section, LPCWSTR key, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1853 | LPVOID buf, UINT bufsize, LPCWSTR filename) |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1854 | { |
| 1855 | LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section ); |
| 1856 | LPSTR keyA = HEAP_strdupWtoA( GetProcessHeap(), 0, key); |
| 1857 | LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1858 | INT ret = WritePrivateProfileStructA( sectionA, keyA, buf, bufsize, |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1859 | filenameA ); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1860 | HeapFree( GetProcessHeap(), 0, sectionA ); |
| 1861 | HeapFree( GetProcessHeap(), 0, keyA ); |
| 1862 | HeapFree( GetProcessHeap(), 0, filenameA ); |
| 1863 | |
| 1864 | return ret; |
| 1865 | } |
| 1866 | |
Alexandre Julliard | ebfc0fe | 1998-06-28 18:40:26 +0000 | [diff] [blame] | 1867 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1868 | /*********************************************************************** |
| 1869 | * WriteOutProfiles (KERNEL.315) |
| 1870 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1871 | void WINAPI WriteOutProfiles16(void) |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1872 | { |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1873 | EnterCriticalSection( &PROFILE_CritSect ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1874 | PROFILE_FlushFile(); |
Eric Pouech | ed15575 | 1999-03-25 13:24:08 +0000 | [diff] [blame] | 1875 | LeaveCriticalSection( &PROFILE_CritSect ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 1876 | } |
Marcus Meissner | 9b4fcf7 | 1999-12-04 04:19:55 +0000 | [diff] [blame] | 1877 | |
| 1878 | /*********************************************************************** |
Patrik Stridvall | 044855c | 2001-07-11 18:56:41 +0000 | [diff] [blame] | 1879 | * CloseProfileUserMapping (KERNEL32.@) |
Marcus Meissner | 9b4fcf7 | 1999-12-04 04:19:55 +0000 | [diff] [blame] | 1880 | */ |
| 1881 | BOOL WINAPI CloseProfileUserMapping(void) { |
| 1882 | FIXME("(), stub!\n"); |
| 1883 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 1884 | return FALSE; |
| 1885 | } |