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