Module: wine Branch: master Commit: 9de5b114302e62f63427e4e808e61416e0955eb5 URL: http://source.winehq.org/git/wine.git/?a=commit;h=9de5b114302e62f63427e4e808...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Mon Apr 11 22:14:54 2016 +0300
ieframe: Simplify IPersist_Load, make error handling more straightforward.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/ieframe/intshcut.c | 179 +++++++++++++++++++++--------------------------- 1 file changed, 79 insertions(+), 100 deletions(-)
diff --git a/dlls/ieframe/intshcut.c b/dlls/ieframe/intshcut.c index 19b253d..385b059 100644 --- a/dlls/ieframe/intshcut.c +++ b/dlls/ieframe/intshcut.c @@ -420,135 +420,114 @@ static HRESULT WINAPI PersistFile_IsDirty(IPersistFile *pFile) return This->isDirty ? S_OK : S_FALSE; }
-/* A helper function: Allocate and fill rString. Return number of bytes read. */ -static DWORD get_profile_string(LPCWSTR lpAppName, LPCWSTR lpKeyName, +/* Returns allocated profile string and a standard return code. */ +static HRESULT get_profile_string(LPCWSTR lpAppName, LPCWSTR lpKeyName, LPCWSTR lpFileName, WCHAR **rString ) { DWORD r = 0; DWORD len = 128; WCHAR *buffer;
+ *rString = NULL; buffer = CoTaskMemAlloc(len * sizeof(*buffer)); - if (buffer != NULL) - { - r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, buffer, len, lpFileName); - while (r == len-1) - { - WCHAR *realloc_buf; + if (!buffer) + return E_OUTOFMEMORY;
- len *= 2; - realloc_buf = CoTaskMemRealloc(buffer, len * sizeof(*buffer)); - if (realloc_buf == NULL) - { - CoTaskMemFree(buffer); - *rString = NULL; - return 0; - } - buffer = realloc_buf; + r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, buffer, len, lpFileName); + while (r == len-1) + { + WCHAR *realloc_buf;
- r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, buffer, len, lpFileName); + len *= 2; + realloc_buf = CoTaskMemRealloc(buffer, len * sizeof(*buffer)); + if (realloc_buf == NULL) + { + CoTaskMemFree(buffer); + return E_OUTOFMEMORY; } + buffer = realloc_buf; + + r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, buffer, len, lpFileName); }
*rString = buffer; - return r; + return r ? S_OK : E_FAIL; }
static HRESULT WINAPI PersistFile_Load(IPersistFile *pFile, LPCOLESTR pszFileName, DWORD dwMode) { - WCHAR str_header[] = {'I','n','t','e','r','n','e','t','S','h','o','r','t','c','u','t',0}; - WCHAR str_URL[] = {'U','R','L',0}; - WCHAR str_iconfile[] = {'i','c','o','n','f','i','l','e',0}; - WCHAR str_iconindex[] = {'i','c','o','n','i','n','d','e','x',0}; + InternetShortcut *This = impl_from_IPersistFile(pFile); + static WCHAR str_header[] = {'I','n','t','e','r','n','e','t','S','h','o','r','t','c','u','t',0}; + static WCHAR str_URL[] = {'U','R','L',0}; + static WCHAR str_iconfile[] = {'i','c','o','n','f','i','l','e',0}; + static WCHAR str_iconindex[] = {'i','c','o','n','i','n','d','e','x',0}; WCHAR *filename = NULL; + WCHAR *url; HRESULT hr; - InternetShortcut *This = impl_from_IPersistFile(pFile); + IPropertyStorage *pPropStg; + WCHAR *iconfile; + WCHAR *iconindexstring; + TRACE("(%p, %s, 0x%x)\n", pFile, debugstr_w(pszFileName), dwMode); + if (dwMode != 0) FIXME("ignoring unimplemented mode 0x%x\n", dwMode); + filename = co_strdupW(pszFileName); - if (filename != NULL) - { - DWORD r; - WCHAR *url; + if (!filename) + return E_OUTOFMEMORY;
- r = get_profile_string(str_header, str_URL, pszFileName, &url); + if (FAILED(hr = get_profile_string(str_header, str_URL, pszFileName, &url))) + { + CoTaskMemFree(filename); + return hr; + }
- if (url == NULL) - { - hr = E_OUTOFMEMORY; - CoTaskMemFree(filename); - } - else if (r == 0) - { - hr = E_FAIL; - CoTaskMemFree(filename); - } - else - { - hr = S_OK; - CoTaskMemFree(This->currentFile); - This->currentFile = filename; - CoTaskMemFree(This->url); - This->url = url; - This->isDirty = FALSE; - } + CoTaskMemFree(This->currentFile); + This->currentFile = filename; + CoTaskMemFree(This->url); + This->url = url; + This->isDirty = FALSE;
- /* Now we're going to read in the iconfile and iconindex. - If we don't find them, that's not a failure case -- it's possible - that they just aren't in there. */ - if (SUCCEEDED(hr)) - { - IPropertyStorage *pPropStg; - WCHAR *iconfile; - WCHAR *iconindexstring; - hr = IPropertySetStorage_Open(This->property_set_storage, &FMTID_Intshcut, - STGM_READWRITE | STGM_SHARE_EXCLUSIVE, - &pPropStg); - - if (get_profile_string(str_header, str_iconfile, pszFileName, &iconfile)) - { - PROPSPEC ps; - PROPVARIANT pv; - ps.ulKind = PRSPEC_PROPID; - ps.u.propid = PID_IS_ICONFILE; - pv.vt = VT_LPWSTR; - pv.u.pwszVal = iconfile; - hr = IPropertyStorage_WriteMultiple(pPropStg, 1, &ps, &pv, 0); - if (FAILED(hr)) - { - TRACE("Failed to store the iconfile to our property storage. hr = 0x%x\n", hr); - } - } - CoTaskMemFree(iconfile); + /* Now we're going to read in the iconfile and iconindex. + If we don't find them, that's not a failure case -- it's possible + that they just aren't in there. */ + hr = IPropertySetStorage_Open(This->property_set_storage, &FMTID_Intshcut, + STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &pPropStg);
- if (get_profile_string(str_header, str_iconindex, pszFileName, &iconindexstring)) - { - int iconindex; - PROPSPEC ps; - PROPVARIANT pv; - char *iconindexastring = co_strdupWtoA(iconindexstring); - sscanf(iconindexastring, "%d", &iconindex); - CoTaskMemFree(iconindexastring); - ps.ulKind = PRSPEC_PROPID; - ps.u.propid = PID_IS_ICONINDEX; - pv.vt = VT_I4; - pv.u.iVal = iconindex; - hr = IPropertyStorage_WriteMultiple(pPropStg, 1, &ps, &pv, 0); - if (FAILED(hr)) - { - TRACE("Failed to store the iconindex to our property storage. hr = 0x%x\n", hr); - } - } - CoTaskMemFree(iconindexstring); + if (get_profile_string(str_header, str_iconfile, pszFileName, &iconfile) == S_OK) + { + PROPSPEC ps; + PROPVARIANT pv; + ps.ulKind = PRSPEC_PROPID; + ps.u.propid = PID_IS_ICONFILE; + pv.vt = VT_LPWSTR; + pv.u.pwszVal = iconfile; + hr = IPropertyStorage_WriteMultiple(pPropStg, 1, &ps, &pv, 0); + if (FAILED(hr)) + TRACE("Failed to store the iconfile to our property storage. hr = 0x%x\n", hr); + } + CoTaskMemFree(iconfile);
- IPropertyStorage_Release(pPropStg); - } - else - hr = E_OUTOFMEMORY; + if (get_profile_string(str_header, str_iconindex, pszFileName, &iconindexstring) == S_OK) + { + int iconindex; + PROPSPEC ps; + PROPVARIANT pv; + char *iconindexastring = co_strdupWtoA(iconindexstring); + sscanf(iconindexastring, "%d", &iconindex); + CoTaskMemFree(iconindexastring); + ps.ulKind = PRSPEC_PROPID; + ps.u.propid = PID_IS_ICONINDEX; + pv.vt = VT_I4; + pv.u.iVal = iconindex; + hr = IPropertyStorage_WriteMultiple(pPropStg, 1, &ps, &pv, 0); + if (FAILED(hr)) + TRACE("Failed to store the iconindex to our property storage. hr = 0x%x\n", hr); } - else - hr = E_OUTOFMEMORY; + CoTaskMemFree(iconindexstring); + + IPropertyStorage_Release(pPropStg); return hr; }