-
/* $Id: appwiz.c 29364 2007-10-02 23:34:00Z janderwald $
*
* PROJECT: ReactOS Software Control Panel
* FILE: dll/cpl/appwiz/createlink.c
* PURPOSE: ReactOS Software Control Panel
- * PROGRAMMER: Johannes Anderwald
+ * PROGRAMMER: Gero Kuehn (reactos.filter@gkware.com)
+ * Dmitry Chapyshev (lentind@yandex.ru)
+ * Johannes Anderwald
+ * UPDATE HISTORY:
+ * 06-17-2004 Created
*/
-#include <windows.h>
-#include <commctrl.h>
-#include <cpl.h>
-#include <prsht.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <tchar.h>
-#include <process.h>
-#include <shlobj.h>
-#include <objbase.h>
-#include <shobjidl.h>
-#include <shlguid.h>
-#include <stdio.h>
-#include "resource.h"
#include "appwiz.h"
+BOOL
+IsShortcut(HKEY hKey)
+{
+ WCHAR Value[10];
+ DWORD Size;
+ DWORD Type;
+
+ Size = sizeof(Value);
+ if (RegQueryValueExW(hKey, L"IsShortcut", NULL, &Type, (LPBYTE)Value, &Size) != ERROR_SUCCESS)
+ return FALSE;
+
+ if (Type != REG_SZ)
+ return FALSE;
+
+ return (wcsicmp(Value, L"yes") == 0);
+}
+
+BOOL
+IsExtensionAShortcut(LPWSTR lpExtension)
+{
+ HKEY hKey;
+ WCHAR Buffer[100];
+ DWORD Size;
+ DWORD Type;
+
+ if (RegOpenKeyExW(HKEY_CLASSES_ROOT, lpExtension, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
+ return FALSE;
+
+ if (IsShortcut(hKey))
+ {
+ RegCloseKey(hKey);
+ return TRUE;
+ }
+
+ Size = sizeof(Buffer);
+ if (RegQueryValueEx(hKey, NULL, NULL, &Type, (LPBYTE)Buffer, &Size) != ERROR_SUCCESS || Type != REG_SZ)
+ {
+ RegCloseKey(hKey);
+ return FALSE;
+ }
+
+ RegCloseKey(hKey);
-BOOL
+ if (RegOpenKeyExW(HKEY_CLASSES_ROOT, Buffer, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
+ return FALSE;
+
+ if (IsShortcut(hKey))
+ {
+ RegCloseKey(hKey);
+ return TRUE;
+ }
+
+ RegCloseKey(hKey);
+ return FALSE;
+}
+
+BOOL
CreateShortcut(PCREATE_LINK_CONTEXT pContext)
{
- IShellLinkW *pShellLink;
+ IShellLinkW *pShellLink, *pSourceShellLink;
IPersistFile *pPersistFile;
HRESULT hr;
+ WCHAR Path[MAX_PATH];
+ LPWSTR lpExtension;
+
+ /* get the extension */
+ lpExtension = wcsrchr(pContext->szTarget, '.');
+
+ if (IsExtensionAShortcut(lpExtension))
+ {
+ hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_ALL, &IID_IShellLink, (void**)&pSourceShellLink);
+
+ if (hr != S_OK)
+ return FALSE;
+
+ hr = pSourceShellLink->lpVtbl->QueryInterface(pSourceShellLink, &IID_IPersistFile, (void**)&pPersistFile);
+ if (hr != S_OK)
+ {
+ pSourceShellLink->lpVtbl->Release(pSourceShellLink);
+ return FALSE;
+ }
+
+ hr = pPersistFile->lpVtbl->Load(pPersistFile, (LPCOLESTR)pContext->szTarget, STGM_READ);
+ pPersistFile->lpVtbl->Release(pPersistFile);
+
+ if (hr != S_OK)
+ {
+ pSourceShellLink->lpVtbl->Release(pSourceShellLink);
+ return FALSE;
+ }
+
+ hr = pSourceShellLink->lpVtbl->GetPath(pSourceShellLink, Path, sizeof(Path) / sizeof(WCHAR), NULL, 0);
+ pSourceShellLink->lpVtbl->Release(pSourceShellLink);
+
+ if (hr != S_OK)
+ {
+ return FALSE;
+ }
+ }
+ else
+ {
+ wcscpy(Path, pContext->szTarget);
+ }
hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_ALL,
&IID_IShellLink, (void**)&pShellLink);
return FALSE;
- pShellLink->lpVtbl->SetPath(pShellLink, pContext->szTarget);
+ pShellLink->lpVtbl->SetPath(pShellLink, Path);
pShellLink->lpVtbl->SetDescription(pShellLink, pContext->szDescription);
pShellLink->lpVtbl->SetWorkingDirectory(pShellLink, pContext->szWorkingDirectory);
-
+
hr = pShellLink->lpVtbl->QueryInterface(pShellLink, &IID_IPersistFile, (void**)&pPersistFile);
if (hr != S_OK)
{
LPPSHNOTIFY lppsn;
WCHAR szPath[MAX_PATH];
WCHAR szDesc[100];
- BROWSEINFOW brws;
+ BROWSEINFOW brws;
LPITEMIDLIST pidllist;
+ IMalloc* malloc;
switch(uMsg)
{
switch(LOWORD(wParam))
{
case IDC_SHORTCUT_BROWSE:
+ ZeroMemory(&brws, sizeof(brws));
brws.hwndOwner = hwndDlg;
brws.pidlRoot = NULL;
brws.pszDisplayName = szPath;
if (SHGetPathFromIDList(pidllist, szPath))
SendDlgItemMessage(hwndDlg, IDC_SHORTCUT_LOCATION, WM_SETTEXT, 0, (LPARAM)szPath);
+ /* Free memory, if possible */
+ if (SUCCEEDED(SHGetMalloc(&malloc)))
+ {
+ IMalloc_Free(malloc, pidllist);
+ IMalloc_Release(malloc);
+ }
+
break;
}
break;
{
szDesc[0] = L'\0';
szPath[0] = L'\0';
- if (LoadStringW(hApplet, IDS_CREATE_SHORTCUT, szDesc, 100) < 100 &&
+ if (LoadStringW(hApplet, IDS_CREATE_SHORTCUT, szDesc, 100) < 100 &&
LoadStringW(hApplet, IDS_ERROR_NOT_FOUND, szPath, MAX_PATH) < MAX_PATH)
{
WCHAR szError[MAX_PATH + 100];
}
SendDlgItemMessage(hwndDlg, IDC_SHORTCUT_LOCATION, EM_SETSEL, 0, -1);
SetFocus(GetDlgItem(hwndDlg, IDC_SHORTCUT_LOCATION));
- SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
+ SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
return -1;
}
else
first[1] = L'\0';
first = wcsrchr(pContext->szDescription, L'.');
- first[0] = L'\0';
+
+ if(first)
+ first[0] = L'\0';
}
}
switch(HIWORD(wParam))
{
case EN_CHANGE:
- if (SendDlgItemMessage(hwndDlg, IDC_SHORTCUT_LOCATION, WM_GETTEXTLENGTH, 0, 0))
+ if (SendDlgItemMessage(hwndDlg, IDC_SHORTCUT_NAME, WM_GETTEXTLENGTH, 0, 0))
{
PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_FINISH);
}