Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399/* * Path Functions * * Copyright 1998, 1999, 2000 Juergen Schmied * Copyright 2004 Juan Lang * Copyright 2018-2022 Katayama Hirofumi MZ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * NOTES: * * Many of these functions are in SHLWAPI.DLL also * */
#define WIN32_NO_STATUS#define _INC_WINDOWS#define COBJMACROS
#include <wine/config.h>
#include <windef.h>#include <winbase.h>#include <shlobj.h>#include <undocshell.h>#include <shlwapi.h>#include <sddl.h>#include <strsafe.h>#include <wine/debug.h>#include <wine/unicode.h>#include <assert.h>
#include <shlwapi_undoc.h>#include <shellutils.h>
#include <userenv.h>
#include "pidl.h"#include "shell32_main.h"#include "shresdef.h"
#undef _WIN32_WINNT#define _WIN32_WINNT _WIN32_WINNT_WS03
WINE_DEFAULT_DEBUG_CHANNEL(shell);
static const BOOL is_win64 = sizeof(void *) > sizeof(int);
/* FIXME: Remove this */typedef enum _NT_PRODUCT_TYPE{ NtProductWinNt = 1, NtProductLanManNt, NtProductServer} NT_PRODUCT_TYPE, *PNT_PRODUCT_TYPE;
/* FIXME: We cannot refresh the RtlGetNtProductType value before reboot. */static BOOLDoGetProductType(PNT_PRODUCT_TYPE ProductType){ HKEY hKey; LONG error; WCHAR szValue[9]; DWORD cbValue; static DWORD s_dwProductType = 0;
if (s_dwProductType != 0) { *ProductType = s_dwProductType; return TRUE; }
*ProductType = NtProductServer;
error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_READ, &hKey); if (error) return FALSE;
cbValue = sizeof(szValue); error = RegGetValueW(hKey, NULL, L"ProductType", RRF_RT_REG_SZ, NULL, (PVOID)szValue, &cbValue); if (!error) { if (lstrcmpW(szValue, L"WinNT") == 0) *ProductType = NtProductWinNt; else if (lstrcmpW(szValue, L"LanmanNT") == 0) *ProductType = NtProductLanManNt; }
s_dwProductType = *ProductType;
RegCloseKey(hKey); return TRUE;}
BOOL APIENTRY IsRemovableDrive(DWORD iDrive){ WCHAR szRoot[] = L"C:\\"; assert(L'A' + iDrive <= L'Z'); szRoot[0] = (WCHAR)(L'A' + iDrive); return GetDriveTypeW(szRoot) == DRIVE_REMOVABLE;}
/* ########## Combining and Constructing paths ##########*/
static BOOL WINAPIPathSearchOnExtensionsW( _Inout_ LPWSTR pszPath, _In_opt_ LPCWSTR *ppszDirs, _In_ BOOL bDoSearch, _In_ DWORD dwWhich){ if (*PathFindExtensionW(pszPath) != 0) return FALSE;
if (bDoSearch) return PathFindOnPathExW(pszPath, ppszDirs, dwWhich); else return PathFileExistsDefExtW(pszPath, dwWhich);}
#if (_WIN32_WINNT >= _WIN32_WINNT_WS03)static BOOL WINAPI PathIsAbsoluteW(_In_ LPCWSTR path){ return PathIsUNCW(path) || (PathGetDriveNumberW(path) != -1 && path[2] == L'\\');}
static BOOL WINAPI PathMakeAbsoluteW(_Inout_ LPWSTR path){ WCHAR path1[MAX_PATH]; DWORD cch;
if (path == NULL) return FALSE; cch = GetCurrentDirectoryW(_countof(path1), path1); if (!cch || cch > _countof(path1)) return FALSE; return (PathCombineW(path, path1, path) != NULL);}#endif
BOOL WINAPI IsLFNDriveW(LPCWSTR lpszPath);
static VOID WINAPIPathQualifyExW(_Inout_ LPWSTR pszPath, _Inout_opt_ LPCWSTR pszDir, _In_ DWORD dwFlags){ INT iDrive, cchPathLeft; WCHAR szTemp[MAX_PATH], szRoot[MAX_PATH]; PWCHAR pchTemp = szTemp, pchPath; BOOL bLFN;
TRACE("(%s,%s,0x%08x)\n", debugstr_w(pszPath), debugstr_w(pszDir), dwFlags);
/* Save pszPath path into szTemp for rebuilding the path later */ if (FAILED(StringCchCopyW(szTemp, _countof(szTemp), pszPath))) return;
/* Replace every '/' by '\' */ FixSlashesAndColonW(szTemp);
cchPathLeft = MAX_PATH;
/* Build the root-like path on pszPath, and set pchTemp */ if (!PathIsUNCW(szTemp)) { /* * Non-UNC path. * Determine and normalize the root drive. */ iDrive = PathGetDriveNumberW(szTemp); if (iDrive == -1) { /* * No drive was specified in the path. Try to find one from the * optional directory (if this fails, fall back to the one of the * Windows directory). */ if (!pszDir || FAILED(StringCchCopyW(szRoot, _countof(szRoot), pszDir))) { /* pszDir was invalid or NULL. Fall back to the * Windows directory and find its root. */ szRoot[0] = UNICODE_NULL; GetWindowsDirectoryW(szRoot, _countof(szRoot)); iDrive = PathGetDriveNumberW(szRoot); if (iDrive != -1) PathBuildRootW(szRoot, iDrive); }
if (szTemp[0] == L'\\') { PathStripToRootW(szRoot); } } else { /* * A drive is specified in the path, that can be either of the * form 'C:\xxx' or of the form 'C:xxx' (relative path). Isolate * the root part 'C:' and the rest of the path 'xxx' in pchTemp. */ PathBuildRootW(szRoot, iDrive); pchTemp += 2; if (*pchTemp == L'\\') ++pchTemp; }
bLFN = IsLFNDriveW(szRoot); if (!bLFN) { PWCHAR pch; for (pch = pchTemp; *pch != UNICODE_NULL; ++pch) {#define VALID_SHORT_PATH_CHAR_CLASSES ( \ PATH_CHAR_CLASS_DOT | \ PATH_CHAR_CLASS_BACKSLASH | \ PATH_CHAR_CLASS_COLON | \ PATH_CHAR_CLASS_OTHER_VALID \) if (!PathIsValidCharW(*pch, VALID_SHORT_PATH_CHAR_CLASSES)) { *pch = L'_'; } } }
StringCchCopyW(pszPath, MAX_PATH, szRoot); cchPathLeft -= lstrlenW(pszPath) + 1; } else /* UNC path: Begins with double backslash */ { bLFN = IsLFNDriveW(pchTemp); if (bLFN) { pszPath[2] = UNICODE_NULL; /* Cut off */ cchPathLeft -= (2 + 1); pchTemp += 2; } else { PWCHAR pchSlash = StrChrW(pszPath + 2, L'\\'); if (pchSlash) pchSlash = StrChrW(pchSlash + 1, L'\\');
if (pchSlash) { *(pchSlash + 1) = UNICODE_NULL; /* Cut off */ pchTemp += pchSlash - pszPath; cchPathLeft -= (INT)(SIZE_T)(pchSlash - pszPath) + 1; } else { bLFN = TRUE; pszPath[2] = UNICODE_NULL; /* Cut off */ cchPathLeft -= 2; pchTemp += 2; } } } /* Now pszPath is a root-like path or an empty string. */
/* Start appending the path components of szTemp to pszPath. */ while (*pchTemp && cchPathLeft > 0) { /* Collapse any .\ and ..\ parts in the path */ if (*pchTemp == L'.') { BOOL bDots = FALSE; /* '.' or '..' ? */
if (pchTemp[1] == UNICODE_NULL || pchTemp[1] == L'\\') { /* Component '.' */ bDots = TRUE; } else if (pchTemp[1] == L'.' && (pchTemp[2] == UNICODE_NULL || pchTemp[2] == L'\\')) { /* Component '..' */ PathRemoveFileSpecW(pszPath); /* Remove the last component from pszPath */ bDots = TRUE; }
/* If a '.' or '..' was encountered, skip to the next component */ if (bDots) { while (*pchTemp && *pchTemp != L'\\') { ++pchTemp; }
while (*pchTemp == L'\\') { ++pchTemp; }
continue; } }
/* Otherwise, copy the other path component */
if (!PathAddBackslashW(pszPath)) /* Append a backslash at the end */ break;
--cchPathLeft;
pchPath = &pszPath[lstrlenW(pszPath)];
if (!bLFN) /* Not LFN? */ { /* Copy MS-DOS 8.3 filename */ PWCHAR pchDot = NULL; INT ich; WCHAR szTitle[8 + 1] = L""; INT cchTitle = 0; WCHAR szDotExtension[1 + 3 + 1] = L""; INT cchDotExtension = 0;
/* Copy the component to szTitle and szDotExtension... */ while (*pchTemp && *pchTemp != L'\\') { if (*pchTemp == L'.') { pchDot = pchTemp; /* Remember the last position */
/* Clear szDotExtension */ cchDotExtension = 0; ZeroMemory(szDotExtension, sizeof(szDotExtension)); }
if (pchDot) { if (cchDotExtension < 1 + 3) szDotExtension[cchDotExtension++] = *pchTemp; } else { if (cchTitle < 8) szTitle[cchTitle++] = *pchTemp; }
++pchTemp; }
/* Add file title 'szTitle' to pchPath */ for (ich = 0; szTitle[ich] && cchPathLeft > 0; ++ich) { *pchPath++ = szTitle[ich]; --cchPathLeft; }
/* Add file extension 'szDotExtension' to pchPath */ if (pchDot) { for (ich = 0; szDotExtension[ich] && cchPathLeft > 0; ++ich) { *pchPath++ = szDotExtension[ich]; --cchPathLeft; } } } else /* LFN */ { /* Copy the component up to the next separator */ while (*pchTemp != UNICODE_NULL && *pchTemp != L'\\' && cchPathLeft > 0) { *pchPath++ = *pchTemp++; --cchPathLeft; } }
/* Skip the backslashes */ while (*pchTemp == L'\\') { ++pchTemp; }
/* Keep null-terminated */ *pchPath = UNICODE_NULL; }
/* Remove any trailing backslash */ PathRemoveBackslashW(pszPath);
if (!(dwFlags & 1)) /* Remove the trailing dot? */ { pchPath = CharPrevW(pszPath, pszPath + lstrlenW(pszPath)); if (*pchPath == L'.') *pchPath = UNICODE_NULL; }}
/************************************************************************* * PathAppend [SHELL32.36] */BOOL WINAPI PathAppendAW( LPVOID lpszPath1, LPCVOID lpszPath2){ if (SHELL_OsIsUnicode()) return PathAppendW(lpszPath1, lpszPath2); return PathAppendA(lpszPath1, lpszPath2);}
/************************************************************************* * PathGetExtensionA [internal] * * NOTES * exported by ordinal * return value points to the first char after the dot */static LPSTR PathGetExtensionA(LPCSTR lpszPath){ TRACE("(%s)\n",lpszPath);
lpszPath = PathFindExtensionA(lpszPath); return (LPSTR)(*lpszPath?(lpszPath+1):lpszPath);}
/************************************************************************* * PathGetExtensionW [internal] */static LPWSTR PathGetExtensionW(LPCWSTR lpszPath){ TRACE("(%s)\n",debugstr_w(lpszPath));
lpszPath = PathFindExtensionW(lpszPath); return (LPWSTR)(*lpszPath?(lpszPath+1):lpszPath);}
/************************************************************************* * SHPathGetExtension [SHELL32.158] */LPVOID WINAPI SHPathGetExtensionW(LPCWSTR lpszPath, DWORD void1, DWORD void2){ return PathGetExtensionW(lpszPath);}
/************************************************************************* * PathRemoveFileSpec [SHELL32.35] */BOOL WINAPI PathRemoveFileSpecAW(LPVOID lpszPath){ if (SHELL_OsIsUnicode()) return PathRemoveFileSpecW(lpszPath); return PathRemoveFileSpecA(lpszPath);}
/* Path Manipulations*/
/************************************************************************* * PathGetShortPathA [internal] */static void PathGetShortPathA(LPSTR pszPath){ CHAR path[MAX_PATH];
TRACE("%s\n", pszPath);
if (GetShortPathNameA(pszPath, path, MAX_PATH)) { lstrcpyA(pszPath, path); }}
/************************************************************************* * PathGetShortPathW [internal] */static void PathGetShortPathW(LPWSTR pszPath){ WCHAR path[MAX_PATH];
TRACE("%s\n", debugstr_w(pszPath));
if (GetShortPathNameW(pszPath, path, MAX_PATH)) { lstrcpyW(pszPath, path); }}
/************************************************************************* * PathGetShortPath [SHELL32.92] */VOID WINAPI PathGetShortPathAW(LPVOID pszPath){ if(SHELL_OsIsUnicode()) PathGetShortPathW(pszPath); PathGetShortPathA(pszPath);}
/* ########## Path Testing ##########*/
/************************************************************************* * PathIsRoot [SHELL32.29] */BOOL WINAPI PathIsRootAW(LPCVOID lpszPath){ if (SHELL_OsIsUnicode()) return PathIsRootW(lpszPath); return PathIsRootA(lpszPath);}
/************************************************************************* * PathIsExeA [internal] */static BOOL PathIsExeA (LPCSTR lpszPath){ LPCSTR lpszExtension = PathGetExtensionA(lpszPath); int i; static const char * const lpszExtensions[] = {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL };
TRACE("path=%s\n",lpszPath);
for(i=0; lpszExtensions[i]; i++) if (!lstrcmpiA(lpszExtension,lpszExtensions[i])) return TRUE;
return FALSE;}
/************************************************************************* * PathIsExeW [internal] */BOOL PathIsExeW (LPCWSTR lpszPath){ LPCWSTR lpszExtension = PathGetExtensionW(lpszPath); int i; static const WCHAR lpszExtensions[][4] = {L"exe", L"com", L"pif", L"cmd", L"bat", L"scf", L"scr", L"" };
TRACE("path=%s\n",debugstr_w(lpszPath));
for(i=0; lpszExtensions[i][0]; i++) if (!wcsicmp(lpszExtension,lpszExtensions[i])) return TRUE;
return FALSE;}
/************************************************************************* * PathIsExe [SHELL32.43] */BOOL WINAPI PathIsExeAW (LPCVOID path){ if (SHELL_OsIsUnicode()) return PathIsExeW (path); return PathIsExeA(path);}
/************************************************************************* * PathFileExists [SHELL32.45] */BOOL WINAPI PathFileExistsAW (LPCVOID lpszPath){ if (SHELL_OsIsUnicode()) return PathFileExistsW (lpszPath); return PathFileExistsA (lpszPath);}
/************************************************************************* * IsLFNDriveA [SHELL32.41] */BOOL WINAPI IsLFNDriveA(LPCSTR lpszPath){ WCHAR szBuffW[MAX_PATH], *pszW = NULL; if (lpszPath) { SHAnsiToUnicode(lpszPath, szBuffW, _countof(szBuffW)); pszW = szBuffW; } return IsLFNDriveW(pszW);}
/************************************************************************* * IsLFNDriveW [SHELL32.42] */BOOL WINAPI IsLFNDriveW(LPCWSTR lpszPath){ DWORD cchMaxFileName, iDrive; WCHAR szRoot[MAX_PATH];
if (lpszPath == NULL || lpszPath[0] == UNICODE_NULL) { szRoot[0] = 0; GetWindowsDirectoryW(szRoot, _countof(szRoot)); lpszPath = szRoot; }
if (PathIsUNCW(lpszPath)) { StringCchCopyW(szRoot, _countof(szRoot), lpszPath); PathStripToRootW(szRoot);
if (StrChrW(szRoot + 2, L'\\') == NULL) return TRUE; /* LFN */
StringCchCatW(szRoot, _countof(szRoot), L"\\"); /* Add a backslash */ } else { iDrive = ((lpszPath[0] - L'A') & 0x1F); PathBuildRootW(szRoot, iDrive);
if (!IsRemovableDrive(iDrive)) { /* FIXME: Cache correctly */ } }
#define MSDOS_8DOT3_LEN 12 /* MS-DOS 8.3 filename == length 12 */
/* GetVolumeInformation requires a root path */ if (!GetVolumeInformationW(szRoot, NULL, 0, NULL, &cchMaxFileName, NULL, NULL, 0)) { /* Don't return FALSE when GetVolumeInformationW fails. */ return TRUE; }
return cchMaxFileName > MSDOS_8DOT3_LEN;}
/************************************************************************* * IsLFNDrive [SHELL32.119] */BOOL WINAPI IsLFNDriveAW(LPCVOID lpszPath){ if (SHELL_OsIsUnicode()) return IsLFNDriveW(lpszPath); return IsLFNDriveA(lpszPath);}
/* ########## Creating Something Unique ##########*//************************************************************************* * PathMakeUniqueNameA [internal] */static BOOL PathMakeUniqueNameA( LPSTR lpszBuffer, DWORD dwBuffSize, LPCSTR lpszShortName, LPCSTR lpszLongName, LPCSTR lpszPathName){ FIXME("%p %u %s %s %s stub\n", lpszBuffer, dwBuffSize, debugstr_a(lpszShortName), debugstr_a(lpszLongName), debugstr_a(lpszPathName)); return TRUE;}
/************************************************************************* * PathMakeUniqueNameW [internal] */#ifdef __REACTOS__/* https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-pathmakeuniquename */static BOOL PathMakeUniqueNameW( _Out_ PWSTR pszUniqueName, _In_ UINT cchMax, _In_ PCWSTR pszTemplate, _In_opt_ PCWSTR pszLongPlate, /* Long template */ _In_opt_ PCWSTR pszDir){ TRACE("%p %u %s %s %s\n", pszUniqueName, cchMax, debugstr_w(pszTemplate), debugstr_w(pszLongPlate), debugstr_w(pszDir));
if (!cchMax || !pszUniqueName) return FALSE;
pszUniqueName[0] = UNICODE_NULL;
PWSTR pszDest = pszUniqueName; UINT dirLength = 0; if (pszDir) { if (StringCchCopyW(pszUniqueName, cchMax - 1, pszDir) != S_OK) return FALSE;
pszDest = PathAddBackslashW(pszUniqueName); if (!pszDest) return FALSE;
dirLength = lstrlenW(pszDir); }
PCWSTR pszTitle = pszLongPlate ? pszLongPlate : pszTemplate; PCWSTR pchDotExt, formatString = L"%d"; INT maxCount, cchTitle;
if ( !pszTitle || !IsLFNDriveW(pszDir)#if (NTDDI_VERSION < NTDDI_VISTA) || pszDir#endif ) { if (!pszTemplate) return FALSE;
pchDotExt = PathFindExtensionW(pszTemplate);
cchTitle = pchDotExt - pszTemplate; if (cchTitle > 1) { PCWSTR pch = pchDotExt - 1; while (cchTitle > 1 && (L'0' <= *pch && *pch <= L'9')) { --cchTitle; --pch; } }
#define MSDOS_8DOT3_FILENAME_TITLE_LEN 8 if (cchTitle > MSDOS_8DOT3_FILENAME_TITLE_LEN - 1) cchTitle = MSDOS_8DOT3_FILENAME_TITLE_LEN - 1;
INT extLength = lstrlenW(pchDotExt); while (cchTitle > 1 && (dirLength + cchTitle + extLength + 1 > (cchMax - 1))) --cchTitle;
if (cchTitle <= 0) maxCount = 1; else if (cchTitle == 1) maxCount = 10; else maxCount = 100;
pszTitle = pszTemplate; } else { PCWSTR openParen = StrChrW(pszTitle, L'('); if (openParen) { while (openParen) { PCWSTR pch = openParen + 1; while (*pch >= L'0' && *pch <= L'9') ++pch;
if (*pch == L')') break;
openParen = StrChrW(openParen + 1, L'('); }
if (openParen) { pchDotExt = openParen + 1; cchTitle = pchDotExt - pszTitle; } else { pchDotExt = PathFindExtensionW(pszTitle); cchTitle = pchDotExt - pszTitle; formatString = L" (%d)"; } } else { pchDotExt = PathFindExtensionW(pszTitle); cchTitle = pchDotExt - pszTitle; formatString = L" (%d)"; }
INT remainingChars = cchMax - (dirLength + cchTitle + (lstrlenW(formatString) - 2)); if (remainingChars <= 0) maxCount = 1; else if (remainingChars == 1) maxCount = 10; else if (remainingChars == 2) maxCount = 100; else maxCount = 1000; }
if (StringCchCopyNW(pszDest, cchMax - dirLength, pszTitle, cchTitle) != S_OK) return FALSE;
PWSTR pchTitle = pszDest + cchTitle; INT count; for (count = 1; count < maxCount; ++count) { WCHAR tempName[MAX_PATH]; if (StringCchPrintfW(tempName, _countof(tempName), formatString, count) != S_OK || StringCchCatW(tempName, _countof(tempName), pchDotExt) != S_OK) { return FALSE; }
if (StringCchCopyW(pchTitle, cchMax - (pchTitle - pszUniqueName), tempName) != S_OK) return FALSE;
if (!PathFileExistsW(pszUniqueName)) return TRUE; }
pszUniqueName[0] = UNICODE_NULL; return FALSE;}#elsestatic BOOL PathMakeUniqueNameW( LPWSTR lpszBuffer, DWORD dwBuffSize, LPCWSTR lpszShortName, LPCWSTR lpszLongName, LPCWSTR lpszPathName){ FIXME("%p %u %s %s %s stub\n", lpszBuffer, dwBuffSize, debugstr_w(lpszShortName), debugstr_w(lpszLongName), debugstr_w(lpszPathName)); return TRUE;}#endif
/************************************************************************* * PathMakeUniqueName [SHELL32.47] */BOOL WINAPI PathMakeUniqueNameAW( LPVOID lpszBuffer, DWORD dwBuffSize, LPCVOID lpszShortName, LPCVOID lpszLongName, LPCVOID lpszPathName){ if (SHELL_OsIsUnicode()) return PathMakeUniqueNameW(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName); return PathMakeUniqueNameA(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);}
/************************************************************************* * PathYetAnotherMakeUniqueName [SHELL32.75] */BOOL WINAPI PathYetAnotherMakeUniqueName(LPWSTR buffer, LPCWSTR path, LPCWSTR shortname, LPCWSTR longname){ WCHAR pathW[MAX_PATH], retW[MAX_PATH]; const WCHAR *file, *ext; int i = 2;
TRACE("(%p, %s, %s, %s)\n", buffer, debugstr_w(path), debugstr_w(shortname), debugstr_w(longname));
file = longname ? longname : shortname; PathCombineW(pathW, path, file); strcpyW(retW, pathW); PathRemoveExtensionW(pathW);
ext = PathFindExtensionW(file);
/* now try to make it unique */ while (PathFileExistsW(retW)) { sprintfW(retW, L"%s (%d)%s", pathW, i, ext); i++; }
strcpyW(buffer, retW); TRACE("ret - %s\n", debugstr_w(buffer));
return TRUE;}
/* ########## cleaning and resolving paths ########## */
/************************************************************************* * PathCleanupSpec [SHELL32.171] * * lpszFile is changed in place. */int WINAPI PathCleanupSpec( LPCWSTR lpszPathW, LPWSTR lpszFileW ){ int i = 0; DWORD rc = 0; int length = 0;
if (SHELL_OsIsUnicode()) { LPWSTR p = lpszFileW;
TRACE("Cleanup %s\n",debugstr_w(lpszFileW));
if (lpszPathW) length = strlenW(lpszPathW);
while (*p) { int gct = PathGetCharTypeW(*p); if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR) { lpszFileW[i]='-'; rc |= PCS_REPLACEDCHAR; } else lpszFileW[i]=*p; i++; p++; if (length + i == MAX_PATH) { rc |= PCS_FATAL | PCS_PATHTOOLONG; break; } } lpszFileW[i]=0; } else { LPSTR lpszFileA = (LPSTR)lpszFileW; LPCSTR lpszPathA = (LPCSTR)lpszPathW; LPSTR p = lpszFileA;
TRACE("Cleanup %s\n",debugstr_a(lpszFileA));
if (lpszPathA) length = strlen(lpszPathA);
while (*p) { int gct = PathGetCharTypeA(*p); if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR) { lpszFileA[i]='-'; rc |= PCS_REPLACEDCHAR; } else lpszFileA[i]=*p; i++; p++; if (length + i == MAX_PATH) { rc |= PCS_FATAL | PCS_PATHTOOLONG; break; } } lpszFileA[i]=0; } return rc;}
/************************************************************************* * PathQualifyA [SHELL32] */VOID WINAPI PathQualifyA(LPSTR pszPath){ WCHAR szPath[MAX_PATH]; TRACE("%s\n",pszPath); SHAnsiToUnicode(pszPath, szPath, _countof(szPath)); PathQualifyW(szPath); SHUnicodeToAnsi(szPath, pszPath, MAX_PATH);}
/************************************************************************* * PathQualifyW [SHELL32] */VOID WINAPI PathQualifyW(LPWSTR pszPath){ TRACE("%s\n",debugstr_w(pszPath)); PathQualifyExW(pszPath, NULL, 0);}
/************************************************************************* * PathQualify [SHELL32.49] */VOID WINAPI PathQualifyAW(LPVOID pszPath){ if (SHELL_OsIsUnicode()) PathQualifyW(pszPath); else PathQualifyA(pszPath);}
BOOL WINAPI PathResolveA(LPSTR path, LPCSTR *dirs, DWORD flags){ BOOL ret = FALSE; LPWSTR *dirsW = NULL; DWORD iDir, cDirs, cbDirs; WCHAR pathW[MAX_PATH];
TRACE("(%s,%p,0x%08x)\n", debugstr_a(path), dirs, flags);
if (dirs) { for (cDirs = 0; dirs[cDirs]; ++cDirs) ;
cbDirs = (cDirs + 1) * sizeof(LPWSTR); dirsW = SHAlloc(cbDirs); if (!dirsW) goto Cleanup;
ZeroMemory(dirsW, cbDirs); for (iDir = 0; iDir < cDirs; ++iDir) { __SHCloneStrAtoW(&dirsW[iDir], dirs[iDir]); if (dirsW[iDir] == NULL) goto Cleanup; } }
SHAnsiToUnicode(path, pathW, _countof(pathW));
ret = PathResolveW(pathW, (LPCWSTR*)dirsW, flags); if (ret) SHUnicodeToAnsi(pathW, path, MAX_PATH);
Cleanup: if (dirsW) { for (iDir = 0; iDir < cDirs; ++iDir) { SHFree(dirsW[iDir]); } SHFree(dirsW); } return ret;}
BOOL WINAPI PathResolveW(_Inout_ LPWSTR path, _Inout_opt_ LPCWSTR *dirs, _In_ DWORD flags){ DWORD dwWhich = WHICH_DEFAULT; /* The extensions to be searched */
TRACE("(%s,%p,0x%08x)\n", debugstr_w(path), dirs, flags);
if (flags & PRF_DONTFINDLNK) dwWhich &= ~WHICH_LNK; /* Don't search '.LNK' (shortcut) */
if (flags & PRF_VERIFYEXISTS) SetLastError(ERROR_FILE_NOT_FOUND); /* We set this error code at first in verification */
PathUnquoteSpacesW(path);
if (PathIsRootW(path)) /* Root path */ { if (path[0] == L'\\' && path[1] == UNICODE_NULL) /* '\' only? */ PathQualifyExW(path, ((flags & PRF_FIRSTDIRDEF) ? *dirs : NULL), 0); /* Qualify */
if (flags & PRF_VERIFYEXISTS) return PathFileExistsAndAttributesW(path, NULL); /* Check the existence */
return TRUE; }
if (PathIsFileSpecW(path)) /* Filename only */ { /* Try to find the path with program extensions applied? */ if ((flags & PRF_TRYPROGRAMEXTENSIONS) && PathSearchOnExtensionsW(path, dirs, TRUE, dwWhich)) { return TRUE; /* Found */ }
/* Try to find the filename in the directories */ if (PathFindOnPathW(path, dirs)) goto CheckAbsoluteAndFinish;
return FALSE; /* Not found */ }
if (PathIsURLW(path)) /* URL? */ return FALSE;
/* Qualify the path */ PathQualifyExW(path, ((flags & PRF_FIRSTDIRDEF) ? *dirs : NULL), 1);
TRACE("(%s)\n", debugstr_w(path));
if (!(flags & PRF_VERIFYEXISTS)) /* Don't verify the existence? */ return TRUE;
/* Try to find the path with program extensions applied? */ if (!(flags & PRF_TRYPROGRAMEXTENSIONS) || !PathSearchOnExtensionsW(path, dirs, FALSE, dwWhich)) { if (!PathFileExistsAndAttributesW(path, NULL)) return FALSE; /* Not found */ }
CheckAbsoluteAndFinish:#if (_WIN32_WINNT >= _WIN32_WINNT_WS03) if (!(flags & PRF_REQUIREABSOLUTE) || PathIsAbsoluteW(path)) return TRUE;
if (!PathMakeAbsoluteW(path)) return FALSE;
return PathFileExistsAndAttributesW(path, NULL);#else return TRUE; /* Found */#endif}
/************************************************************************* * PathResolve [SHELL32.51] */BOOL WINAPI PathResolveAW(LPVOID path, LPCVOID *paths, DWORD flags){ if (SHELL_OsIsUnicode()) return PathResolveW(path, (LPCWSTR*)paths, flags); else return PathResolveA(path, (LPCSTR*)paths, flags);}
/************************************************************************** PathProcessCommandA*/static LONG PathProcessCommandA ( LPCSTR lpszPath, LPSTR lpszBuff, DWORD dwBuffSize, DWORD dwFlags){ FIXME("%s %p 0x%04x 0x%04x stub\n", lpszPath, lpszBuff, dwBuffSize, dwFlags); if(!lpszPath) return -1; if(lpszBuff) strcpy(lpszBuff, lpszPath); return strlen(lpszPath);}
#ifndef __REACTOS__ // See ../shlexec.cpp/************************************************************************** PathProcessCommandW*/static LONG PathProcessCommandW ( LPCWSTR lpszPath, LPWSTR lpszBuff, DWORD dwBuffSize, DWORD dwFlags){ FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n", debugstr_w(lpszPath), lpszBuff, dwBuffSize, dwFlags); if(!lpszPath) return -1; if(lpszBuff) strcpyW(lpszBuff, lpszPath); return strlenW(lpszPath);}#endif
/************************************************************************** PathProcessCommand (SHELL32.653)*/LONG WINAPI PathProcessCommandAW ( LPCVOID lpszPath, LPVOID lpszBuff, DWORD dwBuffSize, DWORD dwFlags){ if (SHELL_OsIsUnicode()) return PathProcessCommandW(lpszPath, lpszBuff, dwBuffSize, dwFlags); return PathProcessCommandA(lpszPath, lpszBuff, dwBuffSize, dwFlags);}
/* ########## special ##########*/
/* !! MISSING Win2k3-compatible paths from the list below; absent from Wine !! */#ifndef __REACTOS__static const WCHAR Application_DataW[] = L"Application Data";static const WCHAR Local_Settings_Application_DataW[] = L"Local Settings\\Application Data";static const WCHAR Local_Settings_HistoryW[] = L"Local Settings\\History";static const WCHAR Local_Settings_Temporary_Internet_FilesW[] = L"Local Settings\\Temporary Internet Files";static const WCHAR MusicW[] = L"Music";static const WCHAR PicturesW[] = L"Pictures";static const WCHAR Program_FilesW[] = L"Program Files";static const WCHAR Program_Files_Common_FilesW[] = L"Program Files\\Common Files";static const WCHAR Start_Menu_ProgramsW[] = L"Start Menu\\Programs";static const WCHAR Start_Menu_Admin_ToolsW[] = L"Start Menu\\Programs\\Administrative Tools";static const WCHAR Start_Menu_StartupW[] = L"Start Menu\\Programs\\StartUp";#endif
/* Long strings that are repeated many times: keep them here */static const WCHAR szSHFolders[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";static const WCHAR szSHUserFolders[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";#ifndef __REACTOS__static const WCHAR szKnownFolderDescriptions[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FolderDescriptions";static const WCHAR szKnownFolderRedirections[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";#endif
typedef enum _CSIDL_Type { CSIDL_Type_User,#ifdef __REACTOS__ CSIDL_Type_InMyDocuments,#endif CSIDL_Type_AllUsers, CSIDL_Type_CurrVer, CSIDL_Type_Disallowed, CSIDL_Type_NonExistent, CSIDL_Type_WindowsPath, CSIDL_Type_SystemPath, CSIDL_Type_SystemX86Path,} CSIDL_Type;
/* Cannot use #if _WIN32_WINNT >= 0x0600 because _WIN32_WINNT == 0x0600 here. */#ifndef __REACTOS__#define CSIDL_CONTACTS 0x0043#define CSIDL_DOWNLOADS 0x0047#define CSIDL_LINKS 0x004d#define CSIDL_APPDATA_LOCALLOW 0x004e#define CSIDL_SAVED_GAMES 0x0062#define CSIDL_SEARCHES 0x0063#endif
typedef struct{ const KNOWNFOLDERID *id; CSIDL_Type type; LPCWSTR szValueName; LPCWSTR szDefaultPath; /* fallback string or resource ID */ INT nShell32IconIndex;} CSIDL_DATA;
static const CSIDL_DATA CSIDL_Data[] ={ { /* 0x00 - CSIDL_DESKTOP */ &FOLDERID_Desktop, CSIDL_Type_User, L"Desktop", MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY), 0 }, { /* 0x01 - CSIDL_INTERNET */ &FOLDERID_InternetFolder, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x02 - CSIDL_PROGRAMS */ &FOLDERID_Programs, CSIDL_Type_User, L"Programs", MAKEINTRESOURCEW(IDS_PROGRAMS), 0 }, { /* 0x03 - CSIDL_CONTROLS (.CPL files) */ &FOLDERID_ControlPanelFolder, CSIDL_Type_SystemPath, L"ControlPanelFolder", NULL, -IDI_SHELL_CONTROL_PANEL }, { /* 0x04 - CSIDL_PRINTERS */ &FOLDERID_PrintersFolder, CSIDL_Type_SystemPath, L"PrintersFolder", NULL, -IDI_SHELL_PRINTERS_FOLDER }, { /* 0x05 - CSIDL_PERSONAL */ &FOLDERID_Documents, CSIDL_Type_User, L"Personal", MAKEINTRESOURCEW(IDS_PERSONAL), -IDI_SHELL_MY_DOCUMENTS }, { /* 0x06 - CSIDL_FAVORITES */ &FOLDERID_Favorites, CSIDL_Type_User, L"Favorites", MAKEINTRESOURCEW(IDS_FAVORITES), -IDI_SHELL_FAVORITES }, { /* 0x07 - CSIDL_STARTUP */ &FOLDERID_Startup, CSIDL_Type_User, L"StartUp", MAKEINTRESOURCEW(IDS_STARTUP) }, { /* 0x08 - CSIDL_RECENT */ &FOLDERID_Recent, CSIDL_Type_User, L"Recent", MAKEINTRESOURCEW(IDS_RECENT), -IDI_SHELL_RECENT_DOCUMENTS }, { /* 0x09 - CSIDL_SENDTO */ &FOLDERID_SendTo, CSIDL_Type_User, L"SendTo", MAKEINTRESOURCEW(IDS_SENDTO) }, { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */ &FOLDERID_RecycleBinFolder, CSIDL_Type_Disallowed, L"RecycleBinFolder", NULL }, { /* 0x0b - CSIDL_STARTMENU */ &FOLDERID_StartMenu, CSIDL_Type_User, L"Start Menu", MAKEINTRESOURCEW(IDS_STARTMENU), -IDI_SHELL_TSKBAR_STARTMENU }, { /* 0x0c - CSIDL_MYDOCUMENTS */ &GUID_NULL, CSIDL_Type_Disallowed, /* matches WinXP--can't get its path */ NULL, NULL, -IDI_SHELL_MY_DOCUMENTS }, { /* 0x0d - CSIDL_MYMUSIC */ &FOLDERID_Music,#ifdef __REACTOS__ CSIDL_Type_InMyDocuments,#else CSIDL_Type_User,#endif L"My Music", MAKEINTRESOURCEW(IDS_MYMUSIC), -IDI_SHELL_MY_MUSIC }, { /* 0x0e - CSIDL_MYVIDEO */ &FOLDERID_Videos,#ifdef __REACTOS__ CSIDL_Type_InMyDocuments,#else CSIDL_Type_User,#endif L"My Video", MAKEINTRESOURCEW(IDS_MYVIDEO), -IDI_SHELL_MY_MOVIES }, { /* 0x0f - unassigned */ &GUID_NULL, CSIDL_Type_Disallowed, NULL, NULL, }, { /* 0x10 - CSIDL_DESKTOPDIRECTORY */ &FOLDERID_Desktop, CSIDL_Type_User, L"Desktop", MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY), 0 }, { /* 0x11 - CSIDL_DRIVES */ &FOLDERID_ComputerFolder, CSIDL_Type_Disallowed, L"MyComputerFolder", NULL, -IDI_SHELL_COMPUTER_FOLDER }, { /* 0x12 - CSIDL_NETWORK */ &FOLDERID_NetworkFolder, CSIDL_Type_Disallowed, L"NetworkPlacesFolder", NULL, -IDI_SHELL_NETWORK_FOLDER }, { /* 0x13 - CSIDL_NETHOOD */ &FOLDERID_NetHood, CSIDL_Type_User, L"NetHood", MAKEINTRESOURCEW(IDS_NETHOOD), -IDI_SHELL_NETWORK }, { /* 0x14 - CSIDL_FONTS */ &FOLDERID_Fonts, CSIDL_Type_WindowsPath, L"Fonts", L"Fonts", -IDI_SHELL_FONTS_FOLDER }, { /* 0x15 - CSIDL_TEMPLATES */ &FOLDERID_Templates, CSIDL_Type_User, L"Templates", MAKEINTRESOURCEW(IDS_TEMPLATES) }, { /* 0x16 - CSIDL_COMMON_STARTMENU */ &FOLDERID_CommonStartMenu, CSIDL_Type_AllUsers, L"Common Start Menu", MAKEINTRESOURCEW(IDS_STARTMENU), -IDI_SHELL_TSKBAR_STARTMENU }, { /* 0x17 - CSIDL_COMMON_PROGRAMS */ &FOLDERID_CommonPrograms, CSIDL_Type_AllUsers, L"Common Programs", MAKEINTRESOURCEW(IDS_PROGRAMS), 0 }, { /* 0x18 - CSIDL_COMMON_STARTUP */ &FOLDERID_CommonStartup, CSIDL_Type_AllUsers, L"Common StartUp", MAKEINTRESOURCEW(IDS_STARTUP) }, { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */ &FOLDERID_PublicDesktop, CSIDL_Type_AllUsers, L"Common Desktop", MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY), 0 }, { /* 0x1a - CSIDL_APPDATA */ &FOLDERID_RoamingAppData, CSIDL_Type_User, L"AppData", MAKEINTRESOURCEW(IDS_APPDATA) }, { /* 0x1b - CSIDL_PRINTHOOD */ &FOLDERID_PrintHood, CSIDL_Type_User, L"PrintHood", MAKEINTRESOURCEW(IDS_PRINTHOOD), -IDI_SHELL_PRINTERS_FOLDER }, { /* 0x1c - CSIDL_LOCAL_APPDATA */ &FOLDERID_LocalAppData, CSIDL_Type_User, L"Local AppData", MAKEINTRESOURCEW(IDS_LOCAL_APPDATA) }, { /* 0x1d - CSIDL_ALTSTARTUP */ &GUID_NULL, CSIDL_Type_NonExistent, NULL, NULL }, { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */ &GUID_NULL, CSIDL_Type_NonExistent, NULL, NULL }, { /* 0x1f - CSIDL_COMMON_FAVORITES */ &FOLDERID_Favorites, CSIDL_Type_AllUsers, L"Common Favorites", MAKEINTRESOURCEW(IDS_FAVORITES), -IDI_SHELL_FAVORITES }, { /* 0x20 - CSIDL_INTERNET_CACHE */ &FOLDERID_InternetCache, CSIDL_Type_User, L"Cache", MAKEINTRESOURCEW(IDS_INTERNET_CACHE) }, { /* 0x21 - CSIDL_COOKIES */ &FOLDERID_Cookies, CSIDL_Type_User, L"Cookies", MAKEINTRESOURCEW(IDS_COOKIES) }, { /* 0x22 - CSIDL_HISTORY */ &FOLDERID_History, CSIDL_Type_User, L"History", MAKEINTRESOURCEW(IDS_HISTORY) }, { /* 0x23 - CSIDL_COMMON_APPDATA */ &FOLDERID_ProgramData, CSIDL_Type_AllUsers, L"Common AppData", MAKEINTRESOURCEW(IDS_APPDATA) }, { /* 0x24 - CSIDL_WINDOWS */ &FOLDERID_Windows, CSIDL_Type_WindowsPath, L"Windows", NULL, 0 }, { /* 0x25 - CSIDL_SYSTEM */ &FOLDERID_System, CSIDL_Type_SystemPath, L"System", NULL, 0 }, { /* 0x26 - CSIDL_PROGRAM_FILES */ &FOLDERID_ProgramFiles, CSIDL_Type_CurrVer, L"ProgramFiles", MAKEINTRESOURCEW(IDS_PROGRAM_FILES), 0 }, { /* 0x27 - CSIDL_MYPICTURES */ &FOLDERID_Pictures,#ifdef __REACTOS__ CSIDL_Type_InMyDocuments,#else CSIDL_Type_User,#endif L"My Pictures", MAKEINTRESOURCEW(IDS_MYPICTURES), -IDI_SHELL_MY_PICTURES }, { /* 0x28 - CSIDL_PROFILE */ &FOLDERID_Profile, CSIDL_Type_User, NULL, NULL }, { /* 0x29 - CSIDL_SYSTEMX86 */ &FOLDERID_SystemX86, CSIDL_Type_SystemX86Path, NULL, NULL, -IDI_SHELL_SYSTEM_GEAR }, { /* 0x2a - CSIDL_PROGRAM_FILESX86 */ &FOLDERID_ProgramFilesX86, CSIDL_Type_CurrVer, L"ProgramFilesX86", L"Program Files (x86)", 0 }, { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */ &FOLDERID_ProgramFilesCommon, CSIDL_Type_CurrVer, L"ProgramFilesCommon", MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON), 0 }, { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */ &FOLDERID_ProgramFilesCommonX86, CSIDL_Type_CurrVer, L"ProgramFilesCommonX86", L"Program Files (x86)\\Common Files", 0 }, { /* 0x2d - CSIDL_COMMON_TEMPLATES */ &FOLDERID_CommonTemplates, CSIDL_Type_AllUsers, L"Common Templates", MAKEINTRESOURCEW(IDS_TEMPLATES) }, { /* 0x2e - CSIDL_COMMON_DOCUMENTS */ &FOLDERID_PublicDocuments, CSIDL_Type_AllUsers, L"Common Documents", MAKEINTRESOURCEW(IDS_PERSONAL), -IDI_SHELL_MY_DOCUMENTS }, { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */ &FOLDERID_CommonAdminTools, CSIDL_Type_AllUsers, L"Common Administrative Tools", MAKEINTRESOURCEW(IDS_ADMINTOOLS) }, { /* 0x30 - CSIDL_ADMINTOOLS */ &FOLDERID_AdminTools, CSIDL_Type_User, L"Administrative Tools", MAKEINTRESOURCEW(IDS_ADMINTOOLS) }, { /* 0x31 - CSIDL_CONNECTIONS */ &FOLDERID_ConnectionsFolder, CSIDL_Type_Disallowed, L"ConnectionsFolder", NULL, -IDI_SHELL_NETWORK_CONNECTIONS }, { /* 0x32 - unassigned */ &GUID_NULL, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x33 - unassigned */ &GUID_NULL, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x34 - unassigned */ &GUID_NULL, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x35 - CSIDL_COMMON_MUSIC */ &FOLDERID_PublicMusic, CSIDL_Type_AllUsers, L"CommonMusic", MAKEINTRESOURCEW(IDS_COMMON_MUSIC), -IDI_SHELL_MY_MUSIC }, { /* 0x36 - CSIDL_COMMON_PICTURES */ &FOLDERID_PublicPictures, CSIDL_Type_AllUsers, L"CommonPictures", MAKEINTRESOURCEW(IDS_COMMON_PICTURES), -IDI_SHELL_MY_PICTURES }, { /* 0x37 - CSIDL_COMMON_VIDEO */ &FOLDERID_PublicVideos, CSIDL_Type_AllUsers, L"CommonVideo", MAKEINTRESOURCEW(IDS_COMMON_VIDEO), -IDI_SHELL_MY_MOVIES }, { /* 0x38 - CSIDL_RESOURCES */ &FOLDERID_ResourceDir, CSIDL_Type_WindowsPath, NULL, L"Resources" }, { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */ &FOLDERID_LocalizedResourcesDir, CSIDL_Type_NonExistent, NULL, NULL }, { /* 0x3a - CSIDL_COMMON_OEM_LINKS */ &FOLDERID_CommonOEMLinks, CSIDL_Type_AllUsers, NULL, L"OEM Links" }, { /* 0x3b - CSIDL_CDBURN_AREA */ &FOLDERID_CDBurning, CSIDL_Type_User, L"CD Burning", L"Local Settings\\Application Data\\Microsoft\\CD Burning" }, { /* 0x3c unassigned */ &GUID_NULL, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x3d - CSIDL_COMPUTERSNEARME */ &GUID_NULL, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x3e - CSIDL_PROFILES */ &GUID_NULL, CSIDL_Type_Disallowed, /* oddly, this matches WinXP */ NULL, NULL },/* Cannot use #if _WIN32_WINNT >= 0x0600 because _WIN32_WINNT == 0x0600 here. */#ifndef __REACTOS__ { /* 0x3f */ &FOLDERID_AddNewPrograms, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x40 */ &FOLDERID_AppUpdates, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x41 */ &FOLDERID_ChangeRemovePrograms, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x42 */ &FOLDERID_ConflictFolder, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x43 - CSIDL_CONTACTS */ &FOLDERID_Contacts, CSIDL_Type_User, NULL, L"Contacts" }, { /* 0x44 */ &FOLDERID_DeviceMetadataStore, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x45 */ &GUID_NULL, CSIDL_Type_User, NULL, L"Documents" }, { /* 0x46 */ &FOLDERID_DocumentsLibrary, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x47 - CSIDL_DOWNLOADS */ &FOLDERID_Downloads,#ifdef __REACTOS__ CSIDL_Type_InMyDocuments,#else CSIDL_Type_User,#endif NULL, L"Downloads" }, { /* 0x48 */ &FOLDERID_Games, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x49 */ &FOLDERID_GameTasks, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x4a */ &FOLDERID_HomeGroup, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x4b */ &FOLDERID_ImplicitAppShortcuts, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x4c */ &FOLDERID_Libraries, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x4d - CSIDL_LINKS */ &FOLDERID_Links, CSIDL_Type_User, NULL, L"Links" }, { /* 0x4e - CSIDL_APPDATA_LOCALLOW */ &FOLDERID_LocalAppDataLow, CSIDL_Type_User, NULL, L"AppData\\LocalLow" }, { /* 0x4f */ &FOLDERID_MusicLibrary, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x50 */ &FOLDERID_OriginalImages, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x51 */ &FOLDERID_PhotoAlbums, CSIDL_Type_User, NULL, L"Pictures\\Slide Shows" }, { /* 0x52 */ &FOLDERID_PicturesLibrary, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x53 */ &FOLDERID_Playlists, CSIDL_Type_User, NULL, L"Music\\Playlists" }, { /* 0x54 */ &FOLDERID_ProgramFilesX64, CSIDL_Type_NonExistent, NULL, NULL }, { /* 0x55 */ &FOLDERID_ProgramFilesCommonX64, CSIDL_Type_NonExistent, NULL, NULL }, { /* 0x56 */ &FOLDERID_Public, CSIDL_Type_CurrVer, /* FIXME */ NULL, L"Users\\Public" }, { /* 0x57 */ &FOLDERID_PublicDownloads, CSIDL_Type_AllUsers, NULL, L"Downloads" }, { /* 0x58 */ &FOLDERID_PublicGameTasks, CSIDL_Type_AllUsers, NULL, L"Microsoft\\Windows\\GameExplorer" }, { /* 0x59 */ &FOLDERID_PublicLibraries, CSIDL_Type_AllUsers, NULL, L"Microsoft\\Windows\\Libraries" }, { /* 0x5a */ &FOLDERID_PublicRingtones, CSIDL_Type_AllUsers, NULL, L"Microsoft\\Windows\\Ringtones" }, { /* 0x5b */ &FOLDERID_QuickLaunch, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x5c */ &FOLDERID_RecordedTVLibrary, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x5d */ &FOLDERID_Ringtones, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x5e */ &FOLDERID_SampleMusic, CSIDL_Type_AllUsers, NULL, L"Music\\Sample Music" }, { /* 0x5f */ &FOLDERID_SamplePictures, CSIDL_Type_AllUsers, NULL, L"Pictures\\Sample Pictures" }, { /* 0x60 */ &FOLDERID_SamplePlaylists, CSIDL_Type_AllUsers, NULL, L"Music\\Sample Playlists" }, { /* 0x61 */ &FOLDERID_SampleVideos, CSIDL_Type_AllUsers, NULL, L"Videos\\Sample Videos" }, { /* 0x62 - CSIDL_SAVED_GAMES */ &FOLDERID_SavedGames, CSIDL_Type_User, NULL, L"Saved Games" }, { /* 0x63 - CSIDL_SEARCHES */ &FOLDERID_SavedSearches, CSIDL_Type_User, NULL, L"Searches" }, { /* 0x64 */ &FOLDERID_SEARCH_CSC, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x65 */ &FOLDERID_SEARCH_MAPI, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x66 */ &FOLDERID_SearchHome, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x67 */ &FOLDERID_SidebarDefaultParts, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x68 */ &FOLDERID_SidebarParts, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x69 */ &FOLDERID_SyncManagerFolder, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x6a */ &FOLDERID_SyncResultsFolder, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x6b */ &FOLDERID_SyncSetupFolder, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x6c */ &FOLDERID_UserPinned, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x6d */ &FOLDERID_UserProfiles, CSIDL_Type_CurrVer, L"Users", L"Users" }, { /* 0x6e */ &FOLDERID_UserProgramFiles, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x6f */ &FOLDERID_UserProgramFilesCommon, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }, { /* 0x70 */ &FOLDERID_UsersFiles, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x71 */ &FOLDERID_UsersLibraries, CSIDL_Type_Disallowed, NULL, NULL }, { /* 0x72 */ &FOLDERID_VideosLibrary, CSIDL_Type_Disallowed, /* FIXME */ NULL, NULL }#endif};
INT SHGetSpecialFolderID(_In_ LPCWSTR pszName){ UINT csidl;
for (csidl = 0; csidl < _countof(CSIDL_Data); ++csidl) { const CSIDL_DATA *pData = &CSIDL_Data[csidl]; if (pData->szValueName && lstrcmpiW(pszName, pData->szValueName) == 0) return csidl; }
return -1;}
INT Shell_ParseSpecialFolder(_In_ LPCWSTR pszStart, _Out_ LPWSTR *ppch, _Out_ INT *pcch){ LPCWSTR pszPath, pchBackslash; WCHAR szPath[MAX_PATH];
pchBackslash = StrChrW(pszStart, L'\\'); if (pchBackslash) { *ppch = (LPWSTR)(pchBackslash + 1); *pcch = (pchBackslash - pszStart) + 1; StrCpyNW(szPath, pszStart, min(*pcch, _countof(szPath))); pszPath = szPath; } else { *ppch = NULL; *pcch = lstrlenW(pszStart); pszPath = pszStart; }
return SHGetSpecialFolderID(pszPath);}
#ifndef __REACTOS__static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest);#elsestatic HRESULT _SHExpandEnvironmentStrings(HANDLE hToken, LPCWSTR szSrc, LPWSTR szDest, DWORD cchDest);#endif
/* Gets the value named value from the registry key * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which * is assumed to be MAX_PATH WCHARs in length. * If it exists, expands the value and writes the expanded value to * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders * Returns successful error code if the value was retrieved from the registry, * and a failure otherwise. */#ifndef __REACTOS__static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix,#elsestatic HRESULT _SHGetUserShellFolderPath(HKEY rootKey, HANDLE hToken, LPCWSTR userPrefix,#endif LPCWSTR value, LPWSTR path){ HRESULT hr; WCHAR shellFolderPath[MAX_PATH], userShellFolderPath[MAX_PATH]; LPCWSTR pShellFolderPath, pUserShellFolderPath; HKEY userShellFolderKey, shellFolderKey; DWORD dwType, dwPathLen;
TRACE("%p,%s,%s,%p\n",rootKey, debugstr_w(userPrefix), debugstr_w(value), path);
if (userPrefix) { strcpyW(shellFolderPath, userPrefix); PathAddBackslashW(shellFolderPath); strcatW(shellFolderPath, szSHFolders); pShellFolderPath = shellFolderPath; strcpyW(userShellFolderPath, userPrefix); PathAddBackslashW(userShellFolderPath); strcatW(userShellFolderPath, szSHUserFolders); pUserShellFolderPath = userShellFolderPath; } else { pUserShellFolderPath = szSHUserFolders; pShellFolderPath = szSHFolders; }
if (RegCreateKeyW(rootKey, pShellFolderPath, &shellFolderKey)) { TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath)); return E_FAIL; } if (RegCreateKeyW(rootKey, pUserShellFolderPath, &userShellFolderKey)) { TRACE("Failed to create %s\n", debugstr_w(pUserShellFolderPath)); RegCloseKey(shellFolderKey); return E_FAIL; }
dwPathLen = MAX_PATH * sizeof(WCHAR); if (!RegQueryValueExW(userShellFolderKey, value, NULL, &dwType, (LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ)) { LONG ret;
path[dwPathLen / sizeof(WCHAR)] = '\0'; if (dwType == REG_EXPAND_SZ && path[0] == '%') { WCHAR szTemp[MAX_PATH];
#ifndef __REACTOS__ _SHExpandEnvironmentStrings(path, szTemp);#else hr = _SHExpandEnvironmentStrings(hToken, path, szTemp, _countof(szTemp)); if (FAILED(hr)) goto end;#endif lstrcpynW(path, szTemp, MAX_PATH); } ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR)); if (ret != ERROR_SUCCESS) hr = HRESULT_FROM_WIN32(ret); else hr = S_OK; } else hr = E_FAIL;#ifdef __REACTOS__end:#endif RegCloseKey(shellFolderKey); RegCloseKey(userShellFolderKey); TRACE("returning 0x%08x\n", hr); return hr;}
BOOL _SHGetUserProfileDirectoryW(HANDLE hToken, LPWSTR szPath, LPDWORD lpcchPath){ BOOL result; if (!hToken) { OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken); result = GetUserProfileDirectoryW(hToken, szPath, lpcchPath); CloseHandle(hToken); } else if ((INT) hToken == -1) { result = GetDefaultUserProfileDirectoryW(szPath, lpcchPath); } else { result = GetUserProfileDirectoryW(hToken, szPath, lpcchPath); } TRACE("_SHGetUserProfileDirectoryW returning %S\n", szPath); return result;}
/* Gets a 'semi-expanded' default value of the CSIDL with index folder into * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean: * - The entry's szDefaultPath may be either a string value or an integer * resource identifier. In the latter case, the string value of the resource * is written. * - Depending on the entry's type, the path may begin with an (unexpanded) * environment variable name. The caller is responsible for expanding * environment strings if so desired. * The types that are prepended with environment variables are: * CSIDL_Type_User: %USERPROFILE% * CSIDL_Type_AllUsers: %ALLUSERSPROFILE% * CSIDL_Type_CurrVer: %SystemDrive% * (Others might make sense too, but as yet are unneeded.) */#ifndef __REACTOS__static HRESULT _SHGetDefaultValue(BYTE folder, LPWSTR pszPath)#elsestatic HRESULT _SHGetDefaultValue(HANDLE hToken, BYTE folder, LPWSTR pszPath)#endif{ HRESULT hr; WCHAR resourcePath[MAX_PATH];#ifdef __REACTOS__ NT_PRODUCT_TYPE ProductType;#endif
TRACE("0x%02x,%p\n", folder, pszPath);
if (folder >= ARRAY_SIZE(CSIDL_Data)) return E_INVALIDARG;
if (!pszPath) return E_INVALIDARG;
#ifdef __REACTOS__ if (hToken != NULL && hToken != (HANDLE)-1) { FIXME("unsupported for user other than current or default\n"); }#endif
if (!is_win64) { BOOL is_wow64;
switch (folder) { case CSIDL_PROGRAM_FILES: case CSIDL_PROGRAM_FILESX86: IsWow64Process( GetCurrentProcess(), &is_wow64 ); folder = is_wow64 ? CSIDL_PROGRAM_FILESX86 : CSIDL_PROGRAM_FILES; break; case CSIDL_PROGRAM_FILES_COMMON: case CSIDL_PROGRAM_FILES_COMMONX86: IsWow64Process( GetCurrentProcess(), &is_wow64 ); folder = is_wow64 ? CSIDL_PROGRAM_FILES_COMMONX86 : CSIDL_PROGRAM_FILES_COMMON; break; } }
switch (CSIDL_Data[folder].type) { case CSIDL_Type_User: strcpyW(pszPath, L"%USERPROFILE%"); break;#ifdef __REACTOS__ case CSIDL_Type_InMyDocuments: strcpyW(pszPath, L"%USERPROFILE%"); if (DoGetProductType(&ProductType) && ProductType == NtProductWinNt) { if (IS_INTRESOURCE(CSIDL_Data[CSIDL_MYDOCUMENTS].szDefaultPath)) { WCHAR szItem[MAX_PATH]; LoadStringW(shell32_hInstance, LOWORD(CSIDL_Data[CSIDL_MYDOCUMENTS].szDefaultPath), szItem, ARRAY_SIZE(szItem)); PathAppendW(pszPath, szItem); } else { PathAppendW(pszPath, CSIDL_Data[CSIDL_MYDOCUMENTS].szDefaultPath); } } break;#endif case CSIDL_Type_AllUsers:#ifndef __REACTOS__ strcpyW(pszPath, L"%PUBLIC%");#else strcpyW(pszPath, L"%ALLUSERSPROFILE%");#endif break; case CSIDL_Type_CurrVer: strcpyW(pszPath, L"%SystemDrive%"); break; default: ; /* no corresponding env. var, do nothing */ }
hr = S_OK; if (CSIDL_Data[folder].szDefaultPath) { if (IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath)) { if (LoadStringW(shell32_hInstance, LOWORD(CSIDL_Data[folder].szDefaultPath), resourcePath, MAX_PATH)) { PathAppendW(pszPath, resourcePath); } else { ERR("(%d,%s), LoadString failed, missing translation?\n", folder, debugstr_w(pszPath)); hr = E_FAIL; } } else { PathAppendW(pszPath, CSIDL_Data[folder].szDefaultPath); } } TRACE("returning 0x%08x\n", hr); return hr;}
/* Gets the (unexpanded) value of the folder with index folder into pszPath. * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value * can be overridden in the HKLM\\Software\\Microsoft\\Windows\\CurrentVersion key. * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in * the registry, uses _SHGetDefaultValue to get the value. */static HRESULT _SHGetCurrentVersionPath(DWORD dwFlags, BYTE folder, LPWSTR pszPath){ HRESULT hr;
TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
if (folder >= ARRAY_SIZE(CSIDL_Data)) return E_INVALIDARG; if (CSIDL_Data[folder].type != CSIDL_Type_CurrVer) return E_INVALIDARG; if (!pszPath) return E_INVALIDARG;
if (dwFlags & SHGFP_TYPE_DEFAULT)#ifndef __REACTOS__ hr = _SHGetDefaultValue(folder, pszPath);#else hr = _SHGetDefaultValue(NULL, folder, pszPath);#endif else { HKEY hKey;
if (RegCreateKeyW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion", &hKey)) hr = E_FAIL; else { DWORD dwType, dwPathLen = MAX_PATH * sizeof(WCHAR);
if (RegQueryValueExW(hKey, CSIDL_Data[folder].szValueName, NULL, &dwType, (LPBYTE)pszPath, &dwPathLen) || (dwType != REG_SZ && dwType != REG_EXPAND_SZ)) {#ifndef __REACTOS__ hr = _SHGetDefaultValue(folder, pszPath);#else hr = _SHGetDefaultValue(NULL, folder, pszPath);#endif dwType = REG_EXPAND_SZ; switch (folder) { case CSIDL_PROGRAM_FILESX86: case CSIDL_PROGRAM_FILES_COMMONX86: /* these two should never be set on 32-bit setups */ if (!is_win64) { BOOL is_wow64; IsWow64Process( GetCurrentProcess(), &is_wow64 ); if (!is_wow64) break; } /* fall through */ default: RegSetValueExW(hKey, CSIDL_Data[folder].szValueName, 0, dwType, (LPBYTE)pszPath, (strlenW(pszPath)+1)*sizeof(WCHAR)); } } else { pszPath[dwPathLen / sizeof(WCHAR)] = '\0'; hr = S_OK; } RegCloseKey(hKey); } } TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath)); return hr;}
static LPWSTR _GetUserSidStringFromToken(HANDLE Token){ char InfoBuffer[64]; PTOKEN_USER UserInfo; DWORD InfoSize; LPWSTR SidStr;
UserInfo = (PTOKEN_USER) InfoBuffer; if (! GetTokenInformation(Token, TokenUser, InfoBuffer, sizeof(InfoBuffer), &InfoSize)) { if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return NULL; UserInfo = HeapAlloc(GetProcessHeap(), 0, InfoSize); if (UserInfo == NULL) return NULL; if (! GetTokenInformation(Token, TokenUser, UserInfo, InfoSize, &InfoSize)) { HeapFree(GetProcessHeap(), 0, UserInfo); return NULL; } }
if (! ConvertSidToStringSidW(UserInfo->User.Sid, &SidStr)) SidStr = NULL;
if (UserInfo != (PTOKEN_USER) InfoBuffer) HeapFree(GetProcessHeap(), 0, UserInfo);
return SidStr;}
/* Gets the user's path (unexpanded) for the CSIDL with index folder: * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken: * - if hToken is -1, looks in HKEY_USERS\.Default * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally * calls _SHGetDefaultValue for it. */static HRESULT _SHGetUserProfilePath(HANDLE hToken, DWORD dwFlags, BYTE folder, LPWSTR pszPath){ const WCHAR *szValueName; WCHAR buffer[40]; HRESULT hr;
TRACE("%p,0x%08x,0x%02x,%p\n", hToken, dwFlags, folder, pszPath);
if (folder >= ARRAY_SIZE(CSIDL_Data)) return E_INVALIDARG;#ifdef __REACTOS__ if (CSIDL_Data[folder].type != CSIDL_Type_User && CSIDL_Data[folder].type != CSIDL_Type_InMyDocuments)#else if (CSIDL_Data[folder].type != CSIDL_Type_User)#endif { return E_INVALIDARG; } if (!pszPath) return E_INVALIDARG;
if (dwFlags & SHGFP_TYPE_DEFAULT) {#ifndef __REACTOS__ hr = _SHGetDefaultValue(folder, pszPath);#else hr = _SHGetDefaultValue(hToken, folder, pszPath);#endif } else { static const WCHAR DefaultW[] = L".Default"; LPCWSTR userPrefix = NULL; HKEY hRootKey;
if (hToken == (HANDLE)-1) { hRootKey = HKEY_USERS; userPrefix = DefaultW; } else if (hToken == NULL) hRootKey = HKEY_CURRENT_USER; else { hRootKey = HKEY_USERS; userPrefix = _GetUserSidStringFromToken(hToken); if (userPrefix == NULL) { hr = E_FAIL; goto error; } }
/* For CSIDL_Type_User we also use the GUID if no szValueName is provided */ szValueName = CSIDL_Data[folder].szValueName; if (!szValueName) { StringFromGUID2( CSIDL_Data[folder].id, buffer, 39 ); szValueName = &buffer[0]; }
#ifndef __REACTOS__ hr = _SHGetUserShellFolderPath(hRootKey, userPrefix, szValueName, pszPath); if (FAILED(hr) && hRootKey != HKEY_LOCAL_MACHINE) hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL, szValueName, pszPath); if (FAILED(hr)) hr = _SHGetDefaultValue(folder, pszPath);#else hr = _SHGetUserShellFolderPath(hRootKey, hToken, userPrefix, szValueName, pszPath); if (FAILED(hr) && hRootKey != HKEY_LOCAL_MACHINE) hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, hToken, NULL, szValueName, pszPath); if (FAILED(hr)) hr = _SHGetDefaultValue(hToken, folder, pszPath);#endif if (userPrefix != NULL && userPrefix != DefaultW) LocalFree((HLOCAL) userPrefix); }error: TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath)); return hr;}
/* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE. * If this fails, falls back to _SHGetDefaultValue. */static HRESULT _SHGetAllUsersProfilePath(DWORD dwFlags, BYTE folder, LPWSTR pszPath){ HRESULT hr;
TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
if (folder >= ARRAY_SIZE(CSIDL_Data)) return E_INVALIDARG; if (CSIDL_Data[folder].type != CSIDL_Type_AllUsers) return E_INVALIDARG; if (!pszPath) return E_INVALIDARG;
if (dwFlags & SHGFP_TYPE_DEFAULT)#ifndef __REACTOS__ hr = _SHGetDefaultValue(folder, pszPath);#else hr = _SHGetDefaultValue(NULL, folder, pszPath);#endif else {#ifndef __REACTOS__ hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,#else hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL, NULL,#endif CSIDL_Data[folder].szValueName, pszPath); if (FAILED(hr))#ifndef __REACTOS__ hr = _SHGetDefaultValue(folder, pszPath);#else hr = _SHGetDefaultValue(NULL, folder, pszPath);#endif } TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath)); return hr;}
#ifndef __REACTOS__static HRESULT _SHOpenProfilesKey(PHKEY pKey){ LONG lRet; DWORD disp;
lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", 0, NULL, 0, KEY_ALL_ACCESS, NULL, pKey, &disp); return HRESULT_FROM_WIN32(lRet);}
/* Reads the value named szValueName from the key profilesKey (assumed to be * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH * WCHARs in length. If it doesn't exist, returns szDefault (and saves * szDefault to the registry). */static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName, LPWSTR szValue, LPCWSTR szDefault){ HRESULT hr; DWORD type, dwPathLen = MAX_PATH * sizeof(WCHAR); LONG lRet;
TRACE("%p,%s,%p,%s\n", profilesKey, debugstr_w(szValueName), szValue, debugstr_w(szDefault)); lRet = RegQueryValueExW(profilesKey, szValueName, NULL, &type, (LPBYTE)szValue, &dwPathLen); if (!lRet && (type == REG_SZ || type == REG_EXPAND_SZ) && dwPathLen && *szValue) { dwPathLen /= sizeof(WCHAR); szValue[dwPathLen] = '\0'; hr = S_OK; } else { /* Missing or invalid value, set a default */ lstrcpynW(szValue, szDefault, MAX_PATH); TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName), debugstr_w(szValue)); lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ, (LPBYTE)szValue, (strlenW(szValue) + 1) * sizeof(WCHAR)); if (lRet) hr = HRESULT_FROM_WIN32(lRet); else hr = S_OK; } TRACE("returning 0x%08x (output value is %s)\n", hr, debugstr_w(szValue)); return hr;}#endif
/* Attempts to expand environment variables from szSrc into szDest, which is * assumed to be MAX_PATH characters in length. Before referring to the * environment, handles a few variables directly, because the environment * variables may not be set when this is called (as during Wine's installation * when default values are being written to the registry). * The directly handled environment variables, and their source, are: * - ALLUSERSPROFILE, USERPROFILE: reads from the registry * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its * path * If one of the directly handled environment variables is expanded, only * expands a single variable, and only in the beginning of szSrc. */#ifndef __REACTOS__static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)#elsestatic HRESULT _SHExpandEnvironmentStrings(HANDLE hToken, LPCWSTR szSrc, LPWSTR szDest, DWORD cchDest)#endif{ HRESULT hr;#ifndef __REACTOS__ WCHAR szTemp[MAX_PATH], szProfilesPrefix[MAX_PATH] = { 0 }; HKEY key = NULL;#else WCHAR szTemp[MAX_PATH];#endif
TRACE("%s, %p\n", debugstr_w(szSrc), szDest);
if (!szSrc || !szDest) return E_INVALIDARG;
/* short-circuit if there's nothing to expand */ if (szSrc[0] != '%') { strcpyW(szDest, szSrc); hr = S_OK; goto end; }#ifndef __REACTOS__ /* Get the profile prefix, we'll probably be needing it */ hr = _SHOpenProfilesKey(&key); if (SUCCEEDED(hr)) { WCHAR def_val[MAX_PATH];
/* get the system drive */ GetSystemDirectoryW(def_val, MAX_PATH); strcpyW( def_val + 3, L"Users" );
hr = _SHGetProfilesValue(key, L"ProfilesDirectory", szProfilesPrefix, def_val ); }#else hr = S_OK;#endif
*szDest = 0; strcpyW(szTemp, szSrc); while (SUCCEEDED(hr) && szTemp[0] == '%') { if (!strncmpiW(szTemp, L"%ALLUSERSPROFILE%", ARRAY_SIZE(L"%ALLUSERSPROFILE%")-1)) {#ifndef __REACTOS__ WCHAR szAllUsers[MAX_PATH];
strcpyW(szDest, szProfilesPrefix); hr = _SHGetProfilesValue(key, L"AllUsersProfile", szAllUsers, L"Public"); PathAppendW(szDest, szAllUsers);#else DWORD cchSize = cchDest; if (!GetAllUsersProfileDirectoryW(szDest, &cchSize)) goto fallback_expand;#endif PathAppendW(szDest, szTemp + ARRAY_SIZE(L"%ALLUSERSPROFILE%")-1); }#ifndef __REACTOS__ else if (!strncmpiW(szTemp, L"%PUBLIC%", ARRAY_SIZE(L"%PUBLIC%")-1)) { WCHAR szAllUsers[MAX_PATH], def_val[MAX_PATH];
GetSystemDirectoryW(def_val, MAX_PATH); strcpyW( def_val + 3, L"Users\\Public" );
hr = _SHGetProfilesValue(key, L"Public", szAllUsers, def_val); PathAppendW(szDest, szAllUsers); PathAppendW(szDest, szTemp + ARRAY_SIZE(L"%PUBLIC%")-1); }#endif else if (!strncmpiW(szTemp, L"%USERPROFILE%", ARRAY_SIZE(L"%USERPROFILE%")-1)) {#ifndef __REACTOS__ WCHAR userName[MAX_PATH]; DWORD userLen = MAX_PATH;
strcpyW(szDest, szProfilesPrefix); GetUserNameW(userName, &userLen); PathAppendW(szDest, userName);#else DWORD cchSize = cchDest; if (!_SHGetUserProfileDirectoryW(hToken, szDest, &cchSize)) goto fallback_expand;#endif PathAppendW(szDest, szTemp + ARRAY_SIZE(L"%USERPROFILE%")-1); } else if (!strncmpiW(szTemp, L"%SystemDrive%", ARRAY_SIZE(L"%SystemDrive%")-1)) {#ifndef __REACTOS__ GetSystemDirectoryW(szDest, MAX_PATH);#else if (!GetSystemDirectoryW(szDest, cchDest)) goto fallback_expand;#endif strcpyW(szDest + 3, szTemp + ARRAY_SIZE(L"%SystemDrive%")-1 + 1); } else#ifdef __REACTOS__fallback_expand:#endif {#ifndef __REACTOS__ DWORD ret = ExpandEnvironmentStringsW(szTemp, szDest, MAX_PATH);#else DWORD ret = SHExpandEnvironmentStringsForUserW(hToken, szTemp, szDest, cchDest);#endif
#ifndef __REACTOS__ if (ret > MAX_PATH)#else if (ret > cchDest)#endif hr = E_NOT_SUFFICIENT_BUFFER; else if (ret == 0) hr = HRESULT_FROM_WIN32(GetLastError()); else if (!strcmpW( szTemp, szDest )) break; /* nothing expanded */ } if (SUCCEEDED(hr)) strcpyW(szTemp, szDest); }end:#ifndef __REACTOS__ if (key) RegCloseKey(key);#endif TRACE("returning 0x%08x (input was %s, output is %s)\n", hr, debugstr_w(szSrc), debugstr_w(szDest)); return hr;}
/************************************************************************* * SHGetFolderPathW [SHELL32.@] * * Convert nFolder to path. * * RETURNS * Success: S_OK * Failure: standard HRESULT error codes. * * NOTES * Most values can be overridden in either * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders * or in the same location in HKLM. * The "Shell Folders" registry key was used in NT4 and earlier systems. * Beginning with Windows 2000, the "User Shell Folders" key is used, so * changes made to it are made to the former key too. This synchronization is * done on-demand: not until someone requests the value of one of these paths * (by calling one of the SHGet functions) is the value synchronized. * Furthermore, the HKCU paths take precedence over the HKLM paths. */HRESULT WINAPI SHGetFolderPathW( HWND hwndOwner, /* [I] owner window */ int nFolder, /* [I] CSIDL identifying the folder */ HANDLE hToken, /* [I] access token */ DWORD dwFlags, /* [I] which path to return */ LPWSTR pszPath) /* [O] converted path */{ HRESULT hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, NULL, pszPath); if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr) hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); return hr;}
HRESULT WINAPI SHGetFolderPathAndSubDirA( HWND hwndOwner, /* [I] owner window */ int nFolder, /* [I] CSIDL identifying the folder */ HANDLE hToken, /* [I] access token */ DWORD dwFlags, /* [I] which path to return */ LPCSTR pszSubPath, /* [I] sub directory of the specified folder */ LPSTR pszPath) /* [O] converted path */{ int length; HRESULT hr = S_OK; LPWSTR pszSubPathW = NULL; LPWSTR pszPathW = NULL;
TRACE("%p,%#x,%p,%#x,%s,%p\n", hwndOwner, nFolder, hToken, dwFlags, debugstr_a(pszSubPath), pszPath);
if(pszPath) { pszPathW = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR)); if(!pszPathW) { hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); goto cleanup; } } TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
/* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't * set (null), or an empty string.therefore call it without the parameter set * if pszSubPath is an empty string */ if (pszSubPath && pszSubPath[0]) { length = MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, NULL, 0); pszSubPathW = HeapAlloc(GetProcessHeap(), 0, length * sizeof(WCHAR)); if(!pszSubPathW) { hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); goto cleanup; } MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, pszSubPathW, length); }
hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, pszSubPathW, pszPathW);
if (SUCCEEDED(hr) && pszPath) WideCharToMultiByte(CP_ACP, 0, pszPathW, -1, pszPath, MAX_PATH, NULL, NULL);
cleanup: HeapFree(GetProcessHeap(), 0, pszPathW); HeapFree(GetProcessHeap(), 0, pszSubPathW); return hr;}
/************************************************************************* * SHGetFolderPathAndSubDirW [SHELL32.@] */HRESULT WINAPI SHGetFolderPathAndSubDirW( HWND hwndOwner, /* [I] owner window */ int nFolder, /* [I] CSIDL identifying the folder */ HANDLE hToken, /* [I] access token */ DWORD dwFlags, /* [I] which path to return */ LPCWSTR pszSubPath,/* [I] sub directory of the specified folder */ LPWSTR pszPath) /* [O] converted path */{ HRESULT hr; WCHAR szBuildPath[MAX_PATH], szTemp[MAX_PATH]; DWORD folder = nFolder & CSIDL_FOLDER_MASK; CSIDL_Type type; int ret; TRACE("%p,%#x,%p,%#x,%s,%p\n", hwndOwner, nFolder, hToken, dwFlags, debugstr_w(pszSubPath), pszPath);
/* Windows always NULL-terminates the resulting path regardless of success * or failure, so do so first */ if (pszPath) *pszPath = '\0';
if (folder >= ARRAY_SIZE(CSIDL_Data)) return E_INVALIDARG; if ((SHGFP_TYPE_CURRENT != dwFlags) && (SHGFP_TYPE_DEFAULT != dwFlags)) return E_INVALIDARG; szTemp[0] = 0; type = CSIDL_Data[folder].type; switch (type) { case CSIDL_Type_Disallowed: hr = E_INVALIDARG; break; case CSIDL_Type_NonExistent: hr = S_FALSE; break; case CSIDL_Type_WindowsPath: GetWindowsDirectoryW(szTemp, MAX_PATH); if (CSIDL_Data[folder].szDefaultPath && !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) && *CSIDL_Data[folder].szDefaultPath) { PathAddBackslashW(szTemp); strcatW(szTemp, CSIDL_Data[folder].szDefaultPath); } hr = S_OK; break; case CSIDL_Type_SystemPath: GetSystemDirectoryW(szTemp, MAX_PATH); if (CSIDL_Data[folder].szDefaultPath && !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) && *CSIDL_Data[folder].szDefaultPath) { PathAddBackslashW(szTemp); strcatW(szTemp, CSIDL_Data[folder].szDefaultPath); } hr = S_OK; break; case CSIDL_Type_SystemX86Path: if (!GetSystemWow64DirectoryW(szTemp, MAX_PATH)) GetSystemDirectoryW(szTemp, MAX_PATH); if (CSIDL_Data[folder].szDefaultPath && !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) && *CSIDL_Data[folder].szDefaultPath) { PathAddBackslashW(szTemp); strcatW(szTemp, CSIDL_Data[folder].szDefaultPath); } hr = S_OK; break; case CSIDL_Type_CurrVer: hr = _SHGetCurrentVersionPath(dwFlags, folder, szTemp); break; case CSIDL_Type_User:#ifdef __REACTOS__ case CSIDL_Type_InMyDocuments:#endif hr = _SHGetUserProfilePath(hToken, dwFlags, folder, szTemp); break; case CSIDL_Type_AllUsers: hr = _SHGetAllUsersProfilePath(dwFlags, folder, szTemp); break; default: FIXME("bogus type %d, please fix\n", type); hr = E_INVALIDARG; break; }
/* Expand environment strings if necessary */ if (*szTemp == '%')#ifndef __REACTOS__ hr = _SHExpandEnvironmentStrings(szTemp, szBuildPath);#else hr = _SHExpandEnvironmentStrings(hToken, szTemp, szBuildPath, _countof(szBuildPath));#endif else strcpyW(szBuildPath, szTemp);
if (FAILED(hr)) goto end;
if(pszSubPath) { /* make sure the new path does not exceed the buffer length * and remember to backslash and terminate it */ if(MAX_PATH < (lstrlenW(szBuildPath) + lstrlenW(pszSubPath) + 2)) { hr = HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE); goto end; } PathAppendW(szBuildPath, pszSubPath); PathRemoveBackslashW(szBuildPath); } /* Copy the path if it's available before we might return */ if (SUCCEEDED(hr) && pszPath) strcpyW(pszPath, szBuildPath);
/* if we don't care about existing directories we are ready */ if(nFolder & CSIDL_FLAG_DONT_VERIFY) goto end;
if (PathFileExistsW(szBuildPath)) goto end;
/* not existing but we are not allowed to create it. The return value * is verified against shell32 version 6.0. */ if (!(nFolder & CSIDL_FLAG_CREATE)) { hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); goto end; }
/* create directory/directories */ ret = SHCreateDirectoryExW(hwndOwner, szBuildPath, NULL); if (ret && ret != ERROR_ALREADY_EXISTS) { ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath)); hr = E_FAIL; goto end; }
TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath));
end:#ifdef __REACTOS__ /* create desktop.ini for custom icon */ if ((nFolder & CSIDL_FLAG_CREATE) && CSIDL_Data[folder].nShell32IconIndex) { WCHAR szIconLocation[MAX_PATH]; DWORD dwAttributes;
/* make the directory a read-only folder */ dwAttributes = GetFileAttributesW(szBuildPath); dwAttributes |= FILE_ATTRIBUTE_READONLY; SetFileAttributesW(szBuildPath, dwAttributes);
/* build the desktop.ini file path */ PathAppendW(szBuildPath, L"desktop.ini");
/* build the icon location */ StringCchPrintfW(szIconLocation, _countof(szIconLocation), L"%%SystemRoot%%\\system32\\shell32.dll,%d", CSIDL_Data[folder].nShell32IconIndex);
/* write desktop.ini */ WritePrivateProfileStringW(L".ShellClassInfo", L"IconResource", szIconLocation, szBuildPath);
/* flush! */ WritePrivateProfileStringW(NULL, NULL, NULL, szBuildPath);
/* make the desktop.ini a system and hidden file */ dwAttributes = GetFileAttributesW(szBuildPath); dwAttributes |= FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN; SetFileAttributesW(szBuildPath, dwAttributes); }#endif
TRACE("returning 0x%08x (final path is %s)\n", hr, debugstr_w(szBuildPath)); return hr;}
/************************************************************************* * SHGetFolderPathA [SHELL32.@] * * See SHGetFolderPathW. */HRESULT WINAPI SHGetFolderPathA( HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPSTR pszPath){ WCHAR szTemp[MAX_PATH]; HRESULT hr;
TRACE("%p,%d,%p,%#x,%p\n", hwndOwner, nFolder, hToken, dwFlags, pszPath);
if (pszPath) *pszPath = '\0'; hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, dwFlags, szTemp); if (SUCCEEDED(hr) && pszPath) WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL, NULL);
return hr;}
/* For each folder in folders, if its value has not been set in the registry, * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the * folder's type) to get the unexpanded value first. * Writes the unexpanded value to User Shell Folders, and queries it with * SHGetFolderPathW to force the creation of the directory if it doesn't * already exist. SHGetFolderPathW also returns the expanded value, which * this then writes to Shell Folders. */static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken, LPCWSTR szUserShellFolderPath, LPCWSTR szShellFolderPath, const UINT folders[], UINT foldersLen){ const WCHAR *szValueName; WCHAR buffer[40]; UINT i; WCHAR path[MAX_PATH]; HRESULT hr = S_OK; HKEY hUserKey = NULL, hKey = NULL; DWORD dwType, dwPathLen; LONG ret;
TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken, debugstr_w(szUserShellFolderPath), folders, foldersLen);
ret = RegCreateKeyW(hRootKey, szUserShellFolderPath, &hUserKey); if (ret) hr = HRESULT_FROM_WIN32(ret); else { ret = RegCreateKeyW(hRootKey, szShellFolderPath, &hKey); if (ret) hr = HRESULT_FROM_WIN32(ret); } for (i = 0; SUCCEEDED(hr) && i < foldersLen; i++) { dwPathLen = MAX_PATH * sizeof(WCHAR);
/* For CSIDL_Type_User we also use the GUID if no szValueName is provided */ szValueName = CSIDL_Data[folders[i]].szValueName;#ifdef __REACTOS__ if (!szValueName && (CSIDL_Data[folders[i]].type == CSIDL_Type_User || CSIDL_Data[folders[i]].type == CSIDL_Type_InMyDocuments))#else if (!szValueName && CSIDL_Data[folders[i]].type == CSIDL_Type_User)#endif { StringFromGUID2( CSIDL_Data[folders[i]].id, buffer, 39 ); szValueName = &buffer[0]; }
if (!RegQueryValueExW(hUserKey, szValueName, NULL, &dwType, (LPBYTE)path, &dwPathLen) && (dwType == REG_SZ || dwType == REG_EXPAND_SZ)) { hr = SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE, hToken, SHGFP_TYPE_CURRENT, path); } else { *path = '\0';#ifdef __REACTOS__ if (CSIDL_Data[folders[i]].type == CSIDL_Type_User || CSIDL_Data[folders[i]].type == CSIDL_Type_InMyDocuments)#else if (CSIDL_Data[folders[i]].type == CSIDL_Type_User)#endif _SHGetUserProfilePath(hToken, SHGFP_TYPE_CURRENT, folders[i], path); else if (CSIDL_Data[folders[i]].type == CSIDL_Type_AllUsers) _SHGetAllUsersProfilePath(SHGFP_TYPE_CURRENT, folders[i], path); else if (CSIDL_Data[folders[i]].type == CSIDL_Type_WindowsPath) { GetWindowsDirectoryW(path, MAX_PATH); if (CSIDL_Data[folders[i]].szDefaultPath && !IS_INTRESOURCE(CSIDL_Data[folders[i]].szDefaultPath)) { PathAddBackslashW(path); strcatW(path, CSIDL_Data[folders[i]].szDefaultPath); } } else hr = E_FAIL; if (*path) { ret = RegSetValueExW(hUserKey, szValueName, 0, REG_EXPAND_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR)); if (ret) hr = HRESULT_FROM_WIN32(ret); else { hr = SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE, hToken, SHGFP_TYPE_CURRENT, path); ret = RegSetValueExW(hKey, szValueName, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR)); if (ret) hr = HRESULT_FROM_WIN32(ret); } } } } if (hUserKey) RegCloseKey(hUserKey); if (hKey) RegCloseKey(hKey);
TRACE("returning 0x%08x\n", hr); return hr;}
static HRESULT _SHRegisterUserShellFolders(BOOL bDefault){ static const UINT folders[] = { CSIDL_PROGRAMS, CSIDL_PERSONAL, CSIDL_FAVORITES, CSIDL_APPDATA, CSIDL_STARTUP, CSIDL_RECENT, CSIDL_SENDTO, CSIDL_STARTMENU, CSIDL_MYMUSIC, CSIDL_MYVIDEO, CSIDL_DESKTOPDIRECTORY, CSIDL_NETHOOD, CSIDL_TEMPLATES, CSIDL_PRINTHOOD, CSIDL_LOCAL_APPDATA, CSIDL_INTERNET_CACHE, CSIDL_COOKIES, CSIDL_HISTORY, CSIDL_MYPICTURES, CSIDL_FONTS, CSIDL_ADMINTOOLS,/* Cannot use #if _WIN32_WINNT >= 0x0600 because _WIN32_WINNT == 0x0600 here. */#ifndef __REACTOS__ CSIDL_CONTACTS, CSIDL_DOWNLOADS, CSIDL_LINKS, CSIDL_APPDATA_LOCALLOW, CSIDL_SAVED_GAMES, CSIDL_SEARCHES#endif }; WCHAR userShellFolderPath[MAX_PATH], shellFolderPath[MAX_PATH]; LPCWSTR pUserShellFolderPath, pShellFolderPath; HRESULT hr = S_OK; HKEY hRootKey; HANDLE hToken;
TRACE("%s\n", bDefault ? "TRUE" : "FALSE"); if (bDefault) { hToken = (HANDLE)-1; hRootKey = HKEY_USERS; strcpyW(userShellFolderPath, L".Default"); PathAddBackslashW(userShellFolderPath); strcatW(userShellFolderPath, szSHUserFolders); pUserShellFolderPath = userShellFolderPath; strcpyW(shellFolderPath, L".Default"); PathAddBackslashW(shellFolderPath); strcatW(shellFolderPath, szSHFolders); pShellFolderPath = shellFolderPath; } else { hToken = NULL; hRootKey = HKEY_CURRENT_USER; pUserShellFolderPath = szSHUserFolders; pShellFolderPath = szSHFolders; }
hr = _SHRegisterFolders(hRootKey, hToken, pUserShellFolderPath, pShellFolderPath, folders, ARRAY_SIZE(folders)); TRACE("returning 0x%08x\n", hr); return hr;}
static HRESULT _SHRegisterCommonShellFolders(void){ static const UINT folders[] = { CSIDL_COMMON_STARTMENU, CSIDL_COMMON_PROGRAMS, CSIDL_COMMON_STARTUP, CSIDL_COMMON_DESKTOPDIRECTORY, CSIDL_COMMON_FAVORITES, CSIDL_COMMON_APPDATA, CSIDL_COMMON_TEMPLATES, CSIDL_COMMON_DOCUMENTS, CSIDL_COMMON_ADMINTOOLS, CSIDL_COMMON_MUSIC, CSIDL_COMMON_PICTURES, CSIDL_COMMON_VIDEO, }; HRESULT hr;
TRACE("\n"); hr = _SHRegisterFolders(HKEY_LOCAL_MACHINE, NULL, szSHUserFolders, szSHFolders, folders, ARRAY_SIZE(folders)); TRACE("returning 0x%08x\n", hr); return hr;}
/* Register the default values in the registry, as some apps seem to depend * on their presence. The set registered was taken from Windows XP. */HRESULT SHELL_RegisterShellFolders(void){ HRESULT hr;
hr = _SHRegisterUserShellFolders(TRUE); if (SUCCEEDED(hr)) hr = _SHRegisterUserShellFolders(FALSE); if (SUCCEEDED(hr)) hr = _SHRegisterCommonShellFolders(); return hr;}
/************************************************************************* * SHGetSpecialFolderPathA [SHELL32.@] */BOOL WINAPI SHGetSpecialFolderPathA ( HWND hwndOwner, LPSTR szPath, int nFolder, BOOL bCreate){ return SHGetFolderPathA(hwndOwner, nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0), NULL, 0, szPath) == S_OK;}
/************************************************************************* * SHGetSpecialFolderPathW */BOOL WINAPI SHGetSpecialFolderPathW ( HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate){ return SHGetFolderPathW(hwndOwner, nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0), NULL, 0, szPath) == S_OK;}
#ifdef __REACTOS__HRESULT SHGetFolderLocationHelper(HWND hwnd, int nFolder, REFCLSID clsid, LPITEMIDLIST *ppidl){ HRESULT hr; IShellFolder *psf; LPITEMIDLIST parent, child; EXTERN_C HRESULT SHBindToObject(IShellFolder *psf, LPCITEMIDLIST pidl, REFIID riid, void **ppvObj); *ppidl = NULL; if (FAILED(hr = SHGetFolderLocation(hwnd, nFolder, NULL, 0, &parent))) return hr; if (SUCCEEDED(hr = SHBindToObject(NULL, parent, &IID_IShellFolder, (void**)&psf))) { WCHAR clsidstr[2 + 38 + 1]; clsidstr[0] = clsidstr[1] = L':'; StringFromGUID2(clsid, clsidstr + 2, 38 + 1); hr = IShellFolder_ParseDisplayName(psf, hwnd, NULL, clsidstr, NULL, &child, NULL); if (SUCCEEDED(hr)) *ppidl = ILCombine(parent, child); IShellFolder_Release(psf); ILFree(child); } ILFree(parent); return hr;}#endif
/************************************************************************* * SHGetFolderLocation [SHELL32.@] * * Gets the folder locations from the registry and creates a pidl. * * PARAMS * hwndOwner [I] * nFolder [I] CSIDL_xxxxx * hToken [I] token representing user, or NULL for current user, or -1 for * default user * dwReserved [I] must be zero * ppidl [O] PIDL of a special folder * * RETURNS * Success: S_OK * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG * * NOTES * Creates missing reg keys and directories. * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return * virtual folders that are handled here. */HRESULT WINAPI SHGetFolderLocation( HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwReserved, LPITEMIDLIST *ppidl){ HRESULT hr = E_INVALIDARG;#ifdef __REACTOS__ WCHAR szPath[MAX_PATH];#endif
TRACE("%p 0x%08x %p 0x%08x %p\n", hwndOwner, nFolder, hToken, dwReserved, ppidl); if (!ppidl) return E_INVALIDARG; if (dwReserved) return E_INVALIDARG;
#ifdef __REACTOS__ if ((nFolder & CSIDL_FLAG_NO_ALIAS) && SHGetSpecialFolderPathW(hwndOwner, szPath, (nFolder & CSIDL_FOLDER_MASK), FALSE)) { *ppidl = ILCreateFromPathW(szPath); if (*ppidl) return S_OK; }#endif /* The virtual folders' locations are not user-dependent */ *ppidl = NULL; switch (nFolder & CSIDL_FOLDER_MASK) { case CSIDL_DESKTOP: *ppidl = _ILCreateDesktop(); break;
case CSIDL_PERSONAL: *ppidl = _ILCreateMyDocuments(); break;
case CSIDL_INTERNET: *ppidl = _ILCreateIExplore(); break;
case CSIDL_CONTROLS: *ppidl = _ILCreateControlPanel(); break;
case CSIDL_PRINTERS: *ppidl = _ILCreatePrinters(); break;
case CSIDL_BITBUCKET: *ppidl = _ILCreateBitBucket(); break;
case CSIDL_DRIVES: *ppidl = _ILCreateMyComputer(); break;
case CSIDL_NETWORK: *ppidl = _ILCreateNetwork(); break;
#ifdef __REACTOS__ case CSIDL_CONNECTIONS: hr = SHGetFolderLocationHelper(hwndOwner, CSIDL_CONTROLS, &CLSID_NetworkConnections, ppidl); break;#endif
default: { WCHAR szPath[MAX_PATH];
hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, SHGFP_TYPE_CURRENT, szPath); if (SUCCEEDED(hr)) { DWORD attributes=0;
TRACE("Value=%s\n", debugstr_w(szPath)); hr = SHILCreateFromPathW(szPath, ppidl, &attributes); } else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) { /* unlike SHGetFolderPath, SHGetFolderLocation in shell32 * version 6.0 returns E_FAIL for nonexistent paths */ hr = E_FAIL; } } } if(*ppidl) hr = S_OK;
TRACE("-- (new pidl %p)\n",*ppidl); return hr;}
/************************************************************************* * SHGetSpecialFolderLocation [SHELL32.@] * * NOTES * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent * directory. */HRESULT WINAPI SHGetSpecialFolderLocation( HWND hwndOwner, INT nFolder, LPITEMIDLIST * ppidl){ HRESULT hr = E_INVALIDARG;
TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
if (!ppidl) return E_INVALIDARG;
hr = SHGetFolderLocation(hwndOwner, nFolder, NULL, 0, ppidl); return hr;}