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.

127 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Abstract:
  4. create the assembly directory name with input as a manifest file
  5. Author:
  6. Xiaoyu Wu(xiaoyuw) 01-Aug-2001
  7. --*/
  8. #include "windows.h"
  9. #include "stdio.h"
  10. #include "sxsapi.h"
  11. EXTERN_C BOOL FusionpInitializeHeap(HINSTANCE hInstance);
  12. extern BOOL SxspInitActCtxContributors();
  13. extern BOOL SxspGenerateManifestPathOnAssemblyIdentity(PCWSTR str, PWSTR pszOut, ULONG *pCchstr, PASSEMBLY_IDENTITY *ppAssemblyIdentity);
  14. void PrintUsage(PCWSTR exename)
  15. {
  16. fprintf(stderr, "Generate Directory name under winsxs for assembly.\n\n");
  17. fprintf(stderr, "%S [-ManifestToAsmDir manifest_filename] [-ManifestToAsmID manifest_filename] [-AsmIdToAsmDir Textual_Assembly_Identity_string]\n");
  18. return;
  19. }
  20. BOOL GetAsmDir_Initialize()
  21. {
  22. if (!FusionpInitializeHeap(NULL)){
  23. fprintf(stderr,"fusion heap could not be initialized\n");
  24. return FALSE;
  25. }
  26. if (!SxspInitActCtxContributors())
  27. {
  28. fprintf(stderr,"Sxs ActCtxContributors could not be initialized\n");
  29. return FALSE;
  30. }
  31. return TRUE;
  32. }
  33. #define GET_ASSEMBLY_DIR_FROM_MANIFEST 1
  34. #define GET_ASSEMBLY_IDENTITY_FROM_MANIFEST 2
  35. #define Get_ASSEMBLY_DIR_FROM_TEXTUAL_ASSEMBLY_IDENTITY 3
  36. extern "C" { void (__cdecl * _aexit_rtn)(int); }
  37. extern "C" int __cdecl wmain(int argc, wchar_t** argv)
  38. {
  39. DWORD op = 0;
  40. //
  41. // check the parameters
  42. //
  43. if (argc != 3)
  44. {
  45. PrintUsage(argv[0]);
  46. return 1;
  47. }
  48. if (_wcsicmp(argv[1], L"-ManifestToAsmDir") == 0)
  49. {
  50. op = GET_ASSEMBLY_DIR_FROM_MANIFEST;
  51. }
  52. else if (_wcsicmp(argv[1], L"-ManifestToAsmID") == 0)
  53. {
  54. op = GET_ASSEMBLY_IDENTITY_FROM_MANIFEST;
  55. }
  56. else if (_wcsicmp(argv[1], L"-AsmIDToAsmDir") == 0)
  57. {
  58. op = Get_ASSEMBLY_DIR_FROM_TEXTUAL_ASSEMBLY_IDENTITY;
  59. }else
  60. {
  61. PrintUsage(argv[0]);
  62. return 1;
  63. }
  64. if (GetAsmDir_Initialize() == FALSE)
  65. return 1;
  66. if ((op == GET_ASSEMBLY_DIR_FROM_MANIFEST) || (op == GET_ASSEMBLY_IDENTITY_FROM_MANIFEST))
  67. {
  68. struct {
  69. SXS_MANIFEST_INFORMATION_BASIC mib;
  70. WCHAR buf1[1024];
  71. } buff;
  72. if ( GetFileAttributesW(argv[2]) == (DWORD) (-1))
  73. {
  74. fprintf(stderr, " the manifest %S could not be found with current PATH setting\n", argv[2]);
  75. return 1;
  76. }
  77. if (!SxsQueryManifestInformation(0, argv[2], SXS_QUERY_MANIFEST_INFORMATION_INFOCLASS_BASIC, 0, sizeof(buff), &buff, NULL))
  78. {
  79. fprintf(stderr, "SxsQueryManifestInformation failed.\n");
  80. return 1;
  81. }
  82. else
  83. { if (op == GET_ASSEMBLY_DIR_FROM_MANIFEST)
  84. fprintf(stdout, "%S", buff.mib.lpShortName);
  85. else if (op == GET_ASSEMBLY_IDENTITY_FROM_MANIFEST)
  86. fprintf(stdout, "%S", buff.mib.lpIdentity);
  87. return 0;
  88. }
  89. }else if (op == Get_ASSEMBLY_DIR_FROM_TEXTUAL_ASSEMBLY_IDENTITY)
  90. {
  91. WCHAR buf[1024];
  92. ULONG ulBufSize = 1024;
  93. if (! SxspGenerateManifestPathOnAssemblyIdentity(argv[2], buf, &ulBufSize, NULL))
  94. {
  95. fprintf(stderr, "SxspGenerateManifestPathOnAssemblyIdentity failed.\n");
  96. return 1;
  97. }
  98. else
  99. {
  100. fprintf(stdout, "%S", buf);
  101. return 0;
  102. }
  103. }
  104. return 1; // failed case
  105. }