Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.5 KiB

  1. #include <windows.h>
  2. #include <shlwapi.h>
  3. #include <commctrl.h>
  4. #include "dataitem.h"
  5. #include "resource.h"
  6. #include "stdio.h"
  7. #include "util.h"
  8. #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
  9. #define EXPLORER_EXE_STRING TEXT("explorer.exe")
  10. #define HTTP_PREFIX_STRING TEXT("http://")
  11. CDataItem::CDataItem()
  12. {
  13. m_szTitle[0] = 0;
  14. m_szCmdLine[0] = 0;
  15. m_szArgs[0] = 0;
  16. m_dwFlags = 0;
  17. m_dwType = 0;
  18. }
  19. CDataItem::~CDataItem()
  20. {
  21. }
  22. BOOL CDataItem::SetData( LPTSTR pszTitle, LPTSTR pszCmd, LPTSTR pszArgs, DWORD dwFlags, DWORD dwType)
  23. {
  24. BOOL fRet = FALSE;
  25. if (!m_szCmdLine[0] && // not init'd yet
  26. pszTitle &&
  27. pszCmd)
  28. {
  29. lstrcpyn(m_szTitle, pszTitle, ARRAYSIZE(m_szTitle)); // fine, we control pszTitle
  30. lstrcpyn(m_szCmdLine, pszCmd, ARRAYSIZE(m_szCmdLine)); // fine, we control pszCmd
  31. if (pszArgs)
  32. {
  33. lstrcpyn( m_szArgs, pszArgs, ARRAYSIZE(m_szArgs)); // fine, we control pszArgs
  34. }
  35. m_dwType = dwType;
  36. m_dwFlags = dwFlags;
  37. fRet = TRUE;
  38. }
  39. return fRet;
  40. }
  41. #define BUFFER_SIZE 1000
  42. BOOL CDataItem::Invoke(HWND hwnd)
  43. {
  44. BOOL fResult = FALSE;
  45. if (m_szCmdLine[0])
  46. {
  47. TCHAR szExpandedExecutable[BUFFER_SIZE];
  48. TCHAR szExpandedArgs[BUFFER_SIZE];
  49. fResult = SafeExpandEnvStringsA(m_szCmdLine, szExpandedExecutable, ARRAYSIZE(szExpandedExecutable));
  50. if (fResult)
  51. {
  52. if (m_szArgs[0])
  53. {
  54. fResult = SafeExpandEnvStringsA(m_szArgs, szExpandedArgs, ARRAYSIZE(szExpandedArgs));
  55. }
  56. else
  57. {
  58. szExpandedArgs[0] = 0;
  59. }
  60. if (fResult)
  61. {
  62. TCHAR szDirectory[MAX_PATH];
  63. int cchDirectory = GetModuleFileName(NULL, szDirectory, ARRAYSIZE(szDirectory));
  64. if (cchDirectory > 0 && cchDirectory < MAX_PATH)
  65. {
  66. if (LocalPathRemoveFileSpec(szDirectory))
  67. {
  68. if (!strncmp(szExpandedExecutable, EXPLORER_EXE_STRING, ARRAYSIZE(EXPLORER_EXE_STRING))) // explorer paths must be opened
  69. {
  70. if (szExpandedArgs[0] && !strncmp(szExpandedArgs, HTTP_PREFIX_STRING, ARRAYSIZE(HTTP_PREFIX_STRING) - 1))
  71. {
  72. // opening a weblink
  73. fResult = ((INT_PTR)ShellExecute(hwnd, TEXT("open"), szExpandedArgs, NULL, NULL, SW_SHOWNORMAL) > 32);
  74. }
  75. else
  76. {
  77. // opening a folder
  78. if (szExpandedArgs[0])
  79. {
  80. LocalPathAppendA(szDirectory, szExpandedArgs, ARRAYSIZE(szDirectory));
  81. }
  82. fResult = ((INT_PTR)ShellExecute(hwnd, TEXT("open"), szDirectory, NULL, NULL, SW_SHOWNORMAL) > 32);
  83. }
  84. }
  85. else
  86. {
  87. fResult = ((INT_PTR)ShellExecute(hwnd, NULL, szExpandedExecutable, szExpandedArgs, szDirectory, SW_SHOWNORMAL) > 32);
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. return fResult;
  95. }