ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dirid.c
Go to the documentation of this file.
00001 /*
00002  * Directory id handling
00003  *
00004  * Copyright 2002 Alexandre Julliard for CodeWeavers
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "setupapi_private.h"
00022 
00023 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
00024 
00025 #define MAX_SYSTEM_DIRID DIRID_PRINTPROCESSOR
00026 #define MIN_CSIDL_DIRID 0x4000
00027 #define MAX_CSIDL_DIRID 0x403f
00028 
00029 struct user_dirid
00030 {
00031     int    id;
00032     WCHAR *str;
00033 };
00034 
00035 static int nb_user_dirids;     /* number of user dirids in use */
00036 static int alloc_user_dirids;  /* number of allocated user dirids */
00037 static struct user_dirid *user_dirids;
00038 static const WCHAR *system_dirids[MAX_SYSTEM_DIRID+1];
00039 static const WCHAR *csidl_dirids[MAX_CSIDL_DIRID-MIN_CSIDL_DIRID+1];
00040 
00041 /* retrieve the string for unknown dirids */
00042 static const WCHAR *get_unknown_dirid(void)
00043 {
00044     static WCHAR *unknown_dirid;
00045     static const WCHAR unknown_str[] = {'\\','u','n','k','n','o','w','n',0};
00046 
00047     if (!unknown_dirid)
00048     {
00049         UINT len = GetSystemDirectoryW( NULL, 0 ) + strlenW(unknown_str);
00050         if (!(unknown_dirid = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL;
00051         GetSystemDirectoryW( unknown_dirid, len );
00052         strcatW( unknown_dirid, unknown_str );
00053     }
00054     return unknown_dirid;
00055 }
00056 
00057 static const WCHAR *get_csidl_dir(DWORD csidl);
00058 
00059 /* create the string for a system dirid */
00060 static const WCHAR *create_system_dirid( int dirid )
00061 {
00062     static const WCHAR Null[]    = {0};
00063     static const WCHAR C_Root[]  = {'C',':','\\',0};
00064     static const WCHAR Drivers[] = {'\\','d','r','i','v','e','r','s',0};
00065     static const WCHAR Inf[]     = {'\\','i','n','f',0};
00066     static const WCHAR Help[]    = {'\\','h','e','l','p',0};
00067     static const WCHAR Fonts[]   = {'\\','f','o','n','t','s',0};
00068     static const WCHAR Viewers[] = {'\\','v','i','e','w','e','r','s',0};
00069     static const WCHAR System[]  = {'\\','s','y','s','t','e','m',0};
00070     static const WCHAR Spool[]   = {'\\','s','p','o','o','l',0};
00071     static const WCHAR UserProfile[] = {'U','S','E','R','P','R','O','F','I','L','E',0};
00072 
00073     WCHAR buffer[MAX_PATH+32], *str;
00074     int len;
00075 
00076     switch(dirid)
00077     {
00078     case DIRID_NULL:
00079         return Null;
00080     case DIRID_WINDOWS:
00081         GetWindowsDirectoryW( buffer, MAX_PATH );
00082         break;
00083     case DIRID_SYSTEM:
00084         GetSystemDirectoryW( buffer, MAX_PATH );
00085         break;
00086     case DIRID_DRIVERS:
00087         GetSystemDirectoryW( buffer, MAX_PATH );
00088         strcatW( buffer, Drivers );
00089         break;
00090     case DIRID_INF:
00091         GetWindowsDirectoryW( buffer, MAX_PATH );
00092         strcatW( buffer, Inf );
00093         break;
00094     case DIRID_HELP:
00095         GetWindowsDirectoryW( buffer, MAX_PATH );
00096         strcatW( buffer, Help );
00097         break;
00098     case DIRID_FONTS:
00099         GetWindowsDirectoryW( buffer, MAX_PATH );
00100         strcatW( buffer, Fonts );
00101         break;
00102     case DIRID_VIEWERS:
00103         GetSystemDirectoryW( buffer, MAX_PATH );
00104         strcatW( buffer, Viewers );
00105         break;
00106     case DIRID_APPS:
00107         return C_Root;  /* FIXME */
00108     case DIRID_SHARED:
00109         GetWindowsDirectoryW( buffer, MAX_PATH );
00110         break;
00111     case DIRID_BOOT:
00112         return C_Root;  /* FIXME */
00113     case DIRID_SYSTEM16:
00114         GetWindowsDirectoryW( buffer, MAX_PATH );
00115         strcatW( buffer, System );
00116         break;
00117     case DIRID_SPOOL:
00118     case DIRID_SPOOLDRIVERS:  /* FIXME */
00119         GetWindowsDirectoryW( buffer, MAX_PATH );
00120         strcatW( buffer, Spool );
00121         break;
00122     case DIRID_USERPROFILE:
00123         if (GetEnvironmentVariableW( UserProfile, buffer, MAX_PATH )) break;
00124         return get_csidl_dir(CSIDL_PROFILE);
00125     case DIRID_LOADER:
00126         return C_Root;  /* FIXME */
00127     case DIRID_COLOR:  /* FIXME */
00128     case DIRID_PRINTPROCESSOR:  /* FIXME */
00129     default:
00130         FIXME( "unknown dirid %d\n", dirid );
00131         return get_unknown_dirid();
00132     }
00133     len = (strlenW(buffer) + 1) * sizeof(WCHAR);
00134     if ((str = HeapAlloc( GetProcessHeap(), 0, len ))) memcpy( str, buffer, len );
00135     return str;
00136 }
00137 
00138 static const WCHAR *get_csidl_dir( DWORD csidl )
00139 {
00140     WCHAR buffer[MAX_PATH], *str;
00141     int len;
00142 
00143     if (!SHGetSpecialFolderPathW( NULL, buffer, csidl, TRUE ))
00144     {
00145         FIXME( "CSIDL %x not found\n", csidl );
00146         return get_unknown_dirid();
00147     }
00148     len = (strlenW(buffer) + 1) * sizeof(WCHAR);
00149     if ((str = HeapAlloc( GetProcessHeap(), 0, len ))) memcpy( str, buffer, len );
00150     return str;
00151 }
00152 
00153 /* retrieve the string corresponding to a dirid, or NULL if none */
00154 const WCHAR *DIRID_get_string( int dirid )
00155 {
00156     int i;
00157 
00158     if (dirid == DIRID_ABSOLUTE || dirid == DIRID_ABSOLUTE_16BIT) dirid = DIRID_NULL;
00159 
00160     if (dirid >= DIRID_USER)
00161     {
00162         for (i = 0; i < nb_user_dirids; i++)
00163             if (user_dirids[i].id == dirid) return user_dirids[i].str;
00164         WARN("user id %d not found\n", dirid );
00165         return NULL;
00166     }
00167     else if (dirid >= MIN_CSIDL_DIRID)
00168     {
00169         if (dirid > MAX_CSIDL_DIRID) return get_unknown_dirid();
00170         dirid -= MIN_CSIDL_DIRID;
00171         if (!csidl_dirids[dirid]) csidl_dirids[dirid] = get_csidl_dir( dirid );
00172         return csidl_dirids[dirid];
00173     }
00174     else
00175     {
00176         if (dirid > MAX_SYSTEM_DIRID) return get_unknown_dirid();
00177         if (!system_dirids[dirid]) system_dirids[dirid] = create_system_dirid( dirid );
00178         return system_dirids[dirid];
00179     }
00180 }
00181 
00182 /* store a user dirid string */
00183 static BOOL store_user_dirid( HINF hinf, int id, WCHAR *str )
00184 {
00185     int i;
00186 
00187     for (i = 0; i < nb_user_dirids; i++) if (user_dirids[i].id == id) break;
00188 
00189     if (i < nb_user_dirids) HeapFree( GetProcessHeap(), 0, user_dirids[i].str );
00190     else
00191     {
00192         if (nb_user_dirids >= alloc_user_dirids)
00193         {
00194             int new_size = max( 32, alloc_user_dirids * 2 );
00195 
00196         struct user_dirid *new;
00197 
00198         if (user_dirids)
00199                 new = HeapReAlloc( GetProcessHeap(), 0, user_dirids,
00200                                                   new_size * sizeof(*new) );
00201         else
00202                 new = HeapAlloc( GetProcessHeap(), 0, 
00203                                                   new_size * sizeof(*new) );
00204 
00205             if (!new) return FALSE;
00206             user_dirids = new;
00207             alloc_user_dirids = new_size;
00208         }
00209         nb_user_dirids++;
00210     }
00211     user_dirids[i].id  = id;
00212     user_dirids[i].str = str;
00213     TRACE("id %d -> %s\n", id, debugstr_w(str) );
00214     return TRUE;
00215 }
00216 
00217 
00218 /***********************************************************************
00219  *      SetupSetDirectoryIdA    (SETUPAPI.@)
00220  */
00221 BOOL WINAPI SetupSetDirectoryIdA( HINF hinf, DWORD id, PCSTR dir )
00222 {
00223     UNICODE_STRING dirW;
00224     int i;
00225 
00226     if (!id)  /* clear everything */
00227     {
00228         for (i = 0; i < nb_user_dirids; i++) HeapFree( GetProcessHeap(), 0, user_dirids[i].str );
00229         nb_user_dirids = 0;
00230         return TRUE;
00231     }
00232     if (id < DIRID_USER)
00233     {
00234         SetLastError( ERROR_INVALID_PARAMETER );
00235         return FALSE;
00236     }
00237 
00238     /* duplicate the string */
00239     if (!RtlCreateUnicodeStringFromAsciiz( &dirW, dir ))
00240     {
00241         SetLastError( ERROR_NOT_ENOUGH_MEMORY );
00242         return FALSE;
00243     }
00244     return store_user_dirid( hinf, id, dirW.Buffer );
00245 }
00246 
00247 
00248 /***********************************************************************
00249  *      SetupSetDirectoryIdW    (SETUPAPI.@)
00250  */
00251 BOOL WINAPI SetupSetDirectoryIdW( HINF hinf, DWORD id, PCWSTR dir )
00252 {
00253     int i, len;
00254     WCHAR *str;
00255 
00256     if (!id)  /* clear everything */
00257     {
00258         for (i = 0; i < nb_user_dirids; i++) HeapFree( GetProcessHeap(), 0, user_dirids[i].str );
00259         nb_user_dirids = 0;
00260         return TRUE;
00261     }
00262     if (id < DIRID_USER)
00263     {
00264         SetLastError( ERROR_INVALID_PARAMETER );
00265         return FALSE;
00266     }
00267 
00268     /* duplicate the string */
00269     len = (strlenW(dir)+1) * sizeof(WCHAR);
00270     if (!(str = HeapAlloc( GetProcessHeap(), 0, len ))) return FALSE;
00271     memcpy( str, dir, len );
00272     return store_user_dirid( hinf, id, str );
00273 }

Generated on Sun May 27 2012 04:26:12 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.