static HRESULT WINAPI PersistFile_Save(IPersistFile *pFile, LPCOLESTR pszFileName, BOOL fRemember) { HRESULT hr = S_OK; INT len; CHAR *url; InternetShortcut *This = impl_from_IPersistFile(pFile); TRACE("(%p, %s, %d)\n", pFile, debugstr_w(pszFileName), fRemember); if (pszFileName != NULL && fRemember) { LPOLESTR oldFile = This->currentFile; This->currentFile = co_strdupW(pszFileName); if (This->currentFile == NULL) { This->currentFile = oldFile; return E_OUTOFMEMORY; } CoTaskMemFree(oldFile); } if (This->url == NULL) return E_FAIL; /* Windows seems to always write: * ASCII "[InternetShortcut]" headers * ASCII names in "name=value" pairs * An ASCII (probably UTF8?) value in "URL=..." */ len = WideCharToMultiByte(CP_UTF8, 0, This->url, -1, NULL, 0, 0, 0); url = heap_alloc(len); if (url != NULL) { HANDLE file; WideCharToMultiByte(CP_UTF8, 0, This->url, -1, url, len, 0, 0); file = CreateFileW(pszFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (file != INVALID_HANDLE_VALUE) { DWORD bytesWritten; char str_header[] = "[InternetShortcut]"; char str_URL[] = "URL="; char str_eol[] = "\r\n"; WriteFile(file, str_header, lstrlenA(str_header), &bytesWritten, NULL); WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL); WriteFile(file, str_URL, lstrlenA(str_URL), &bytesWritten, NULL); WriteFile(file, url, lstrlenA(url), &bytesWritten, NULL); WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL); CloseHandle(file); if (pszFileName == NULL || fRemember) This->isDirty = FALSE; StartLinkProcessor(pszFileName); } else hr = E_FAIL; heap_free(url); } else hr = E_OUTOFMEMORY; return hr; }
static HRESULT WINAPI PersistFile_Save(IPersistFile *pFile, LPCOLESTR pszFileName, BOOL fRemember) { HRESULT hr = S_OK; INT len; CHAR *url; InternetShortcut *This = impl_from_IPersistFile(pFile); TRACE("(%p, %s, %d)\n", pFile, debugstr_w(pszFileName), fRemember); if (pszFileName != NULL && fRemember) { LPOLESTR oldFile = This->currentFile; This->currentFile = co_strdupW(pszFileName); if (This->currentFile == NULL) { This->currentFile = oldFile; return E_OUTOFMEMORY; } CoTaskMemFree(oldFile); } if (This->url == NULL) return E_FAIL; /* Windows seems to always write: * ASCII "[InternetShortcut]" headers * ASCII names in "name=value" pairs * An ASCII (probably UTF8?) value in "URL=..." */ len = WideCharToMultiByte(CP_UTF8, 0, This->url, -1, NULL, 0, 0, 0); url = heap_alloc(len); if (url != NULL) { HANDLE file; WideCharToMultiByte(CP_UTF8, 0, This->url, -1, url, len, 0, 0); file = CreateFileW(pszFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (file != INVALID_HANDLE_VALUE) { DWORD bytesWritten; char *iconfile; char str_header[] = "[InternetShortcut]"; char str_URL[] = "URL="; char str_ICONFILE[] = "ICONFILE="; char str_eol[] = "\r\n"; IPropertyStorage *pPropStgRead; PROPSPEC ps[2]; PROPVARIANT pvread[2]; ps[0].ulKind = PRSPEC_PROPID; ps[0].u.propid = PID_IS_ICONFILE; ps[1].ulKind = PRSPEC_PROPID; ps[1].u.propid = PID_IS_ICONINDEX; WriteFile(file, str_header, lstrlenA(str_header), &bytesWritten, NULL); WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL); WriteFile(file, str_URL, lstrlenA(str_URL), &bytesWritten, NULL); WriteFile(file, url, lstrlenA(url), &bytesWritten, NULL); WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL); hr = IPropertySetStorage_Open(This->property_set_storage, &FMTID_Intshcut, STGM_READ|STGM_SHARE_EXCLUSIVE, &pPropStgRead); if (SUCCEEDED(hr)) { hr = IPropertyStorage_ReadMultiple(pPropStgRead, 2, ps, pvread); if (hr == S_FALSE) { /* None of the properties are present, that's ok */ hr = S_OK; IPropertyStorage_Release(pPropStgRead); } else if (SUCCEEDED(hr)) { char indexString[50]; len = WideCharToMultiByte(CP_UTF8, 0, pvread[0].u.pwszVal, -1, NULL, 0, 0, 0); iconfile = heap_alloc(len); if (iconfile != NULL) { WideCharToMultiByte(CP_UTF8, 0, pvread[0].u.pwszVal, -1, iconfile, len, 0, 0); WriteFile(file, str_ICONFILE, lstrlenA(str_ICONFILE), &bytesWritten, NULL); WriteFile(file, iconfile, lstrlenA(iconfile), &bytesWritten, NULL); WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL); } sprintf(indexString, "ICONINDEX=%d", pvread[1].u.iVal); WriteFile(file, indexString, lstrlenA(indexString), &bytesWritten, NULL); WriteFile(file, str_eol, lstrlenA(str_eol), &bytesWritten, NULL); IPropertyStorage_Release(pPropStgRead); PropVariantClear(&pvread[0]); PropVariantClear(&pvread[1]); } else { TRACE("Unable to read properties.\n"); } } else { TRACE("Unable to get the IPropertyStorage.\n"); } CloseHandle(file); if (pszFileName == NULL || fRemember) This->isDirty = FALSE; StartLinkProcessor(pszFileName); } else hr = E_FAIL; heap_free(url); } else hr = E_OUTOFMEMORY; return hr; }