Source code of Windows XP (NT5)
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.

190 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. link.c
  5. Abstract:
  6. This file implements the code to save to a link file.
  7. Author:
  8. Rick Turner (RickTu) Sep-12-1995
  9. --*/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. #include "shlobj.h"
  13. #include "shlwapi.h"
  14. #include "shlwapip.h"
  15. #include "shlobjp.h"
  16. #include "initguid.h"
  17. #include "oleguid.h"
  18. #include "shlguid.h"
  19. #include "shlguidp.h"
  20. BOOL PathIsLink(LPCTSTR szFile)
  21. {
  22. BOOL fRet;
  23. LPCTSTR pszExt = PathFindExtension(szFile);
  24. if (pszExt)
  25. {
  26. fRet = (lstrcmpi(TEXT(".lnk"), pszExt) == 0);
  27. }
  28. else
  29. {
  30. fRet = FALSE;
  31. }
  32. return fRet;
  33. }
  34. BOOL
  35. WereWeStartedFromALnk()
  36. {
  37. STARTUPINFO si;
  38. GetStartupInfo( &si );
  39. // Check to make sure we were started from a link
  40. if (si.dwFlags & STARTF_TITLEISLINKNAME)
  41. {
  42. if (PathIsLink(si.lpTitle))
  43. return TRUE;
  44. }
  45. return FALSE;
  46. }
  47. BOOL
  48. SetLinkValues(
  49. PCONSOLE_STATE_INFO pStateInfo
  50. )
  51. /*++
  52. Routine Description:
  53. This routine writes values to the link file that spawned this console
  54. window. The link file name is still in the startinfo structure.
  55. Arguments:
  56. pStateInfo - pointer to structure containing information
  57. Return Value:
  58. none
  59. --*/
  60. {
  61. STARTUPINFO si;
  62. IShellLink * psl;
  63. IPersistFile * ppf;
  64. IShellLinkDataList * psldl;
  65. NT_CONSOLE_PROPS props;
  66. #if defined(FE_SB)
  67. NT_FE_CONSOLE_PROPS fe_props;
  68. #endif
  69. BOOL bRet;
  70. GetStartupInfo( &si );
  71. // Check to make sure we were started from a link
  72. if (!(si.dwFlags & STARTF_TITLEISLINKNAME) )
  73. return FALSE;
  74. // Make sure we are dealing w/a link file
  75. if (!PathIsLink(si.lpTitle))
  76. return FALSE;
  77. // Ok, load the link so we can modify it...
  78. if (FAILED(SHCoCreateInstance( NULL, &CLSID_ShellLink, NULL, &IID_IShellLink, &psl )))
  79. return FALSE;
  80. if (SUCCEEDED(psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, &ppf)))
  81. {
  82. WCHAR wszPath[ MAX_PATH ];
  83. StrToOleStr(wszPath, si.lpTitle );
  84. if (FAILED(ppf->lpVtbl->Load(ppf, wszPath, 0)))
  85. {
  86. ppf->lpVtbl->Release(ppf);
  87. psl->lpVtbl->Release(psl);
  88. return FALSE;
  89. }
  90. }
  91. // Now the link is loaded, generate new console settings section to replace
  92. // the one in the link.
  93. ((LPDBLIST)&props)->cbSize = sizeof(props);
  94. ((LPDBLIST)&props)->dwSignature = NT_CONSOLE_PROPS_SIG;
  95. props.wFillAttribute = pStateInfo->ScreenAttributes;
  96. props.wPopupFillAttribute = pStateInfo->PopupAttributes;
  97. props.dwScreenBufferSize = pStateInfo->ScreenBufferSize;
  98. props.dwWindowSize = pStateInfo->WindowSize;
  99. props.dwWindowOrigin.X = (SHORT)pStateInfo->WindowPosX;
  100. props.dwWindowOrigin.Y = (SHORT)pStateInfo->WindowPosY;
  101. props.nFont = 0;
  102. props.nInputBufferSize = 0;
  103. props.dwFontSize = pStateInfo->FontSize;
  104. props.uFontFamily = pStateInfo->FontFamily;
  105. props.uFontWeight = pStateInfo->FontWeight;
  106. CopyMemory( props.FaceName, pStateInfo->FaceName, sizeof(props.FaceName) );
  107. props.uCursorSize = pStateInfo->CursorSize;
  108. props.bFullScreen = pStateInfo->FullScreen;
  109. props.bQuickEdit = pStateInfo->QuickEdit;
  110. props.bInsertMode = pStateInfo->InsertMode;
  111. props.bAutoPosition = pStateInfo->AutoPosition;
  112. props.uHistoryBufferSize = pStateInfo->HistoryBufferSize;
  113. props.uNumberOfHistoryBuffers = pStateInfo->NumberOfHistoryBuffers;
  114. props.bHistoryNoDup = pStateInfo->HistoryNoDup;
  115. CopyMemory( props.ColorTable, pStateInfo->ColorTable, sizeof(props.ColorTable) );
  116. #if defined(FE_SB)
  117. ((LPDBLIST)&fe_props)->cbSize = sizeof(fe_props);
  118. ((LPDBLIST)&fe_props)->dwSignature = NT_FE_CONSOLE_PROPS_SIG;
  119. fe_props.uCodePage = pStateInfo->CodePage;
  120. #endif
  121. if (SUCCEEDED(psl->lpVtbl->QueryInterface(psl, &IID_IShellLinkDataList, &psldl)))
  122. {
  123. //
  124. // Store the changes back into the link...
  125. //
  126. psldl->lpVtbl->RemoveDataBlock( psldl, NT_CONSOLE_PROPS_SIG );
  127. psldl->lpVtbl->AddDataBlock( psldl, (LPVOID)&props );
  128. #if defined(FE_SB)
  129. if (gfFESystem) {
  130. psldl->lpVtbl->RemoveDataBlock( psldl, NT_FE_CONSOLE_PROPS_SIG );
  131. psldl->lpVtbl->AddDataBlock( psldl, (LPVOID)&fe_props );
  132. }
  133. #endif
  134. psldl->lpVtbl->Release( psldl );
  135. }
  136. bRet = SUCCEEDED(ppf->lpVtbl->Save( ppf, NULL, TRUE ));
  137. ppf->lpVtbl->Release(ppf);
  138. psl->lpVtbl->Release(psl);
  139. return bRet;
  140. }