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.

148 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. CorrectPathChangesBase.cpp
  5. Abstract:
  6. Several paths were changed between Win9x and WinNT. This routine defines
  7. the CorrectPathChangesBase routines that is called with a Win9x path and returns
  8. the corresponding WinNT path.
  9. History:
  10. 03-Mar-00 robkenny Converted CorrectPathChanges.cpp to this class.
  11. 08/14/2001 robkenny Inserted inside the ShimLib namespace.
  12. --*/
  13. #pragma once
  14. #include "ShimHook.h"
  15. #include "ShimLib.h"
  16. #include "CharVector.h"
  17. namespace ShimLib
  18. {
  19. class StringPairW
  20. {
  21. public:
  22. WCHAR lpOld[MAX_PATH];
  23. DWORD dwLenOld;
  24. WCHAR lpNew[MAX_PATH];
  25. DWORD dwLenNew;
  26. StringPairW(const WCHAR * lpszOld, const WCHAR * lpszNew)
  27. {
  28. dwLenOld = wcslen(lpszOld);
  29. SafeStringCopyW(lpOld, MAX_PATH, lpszOld, dwLenOld + 1);
  30. dwLenNew = wcslen(lpszNew);
  31. SafeStringCopyW(lpNew, MAX_PATH, lpszNew, dwLenNew + 1);
  32. }
  33. };
  34. class EnvironmentValues : public VectorT<StringPairW>
  35. {
  36. protected:
  37. BOOL bInitialized;
  38. public:
  39. EnvironmentValues();
  40. ~EnvironmentValues();
  41. void Initialize();
  42. WCHAR * ExpandEnvironmentValueW(const WCHAR * lpOld);
  43. char * ExpandEnvironmentValueA(const char * lpOld);
  44. void AddEnvironmentValue(const WCHAR * lpOld, const WCHAR * lpNew);
  45. enum eAddNameEnum
  46. {
  47. eIgnoreName = 0,
  48. eAddName = 1,
  49. };
  50. enum eAddNoDLEnum
  51. {
  52. eIgnoreNoDL = 0,
  53. eAddNoDL = 1,
  54. };
  55. void AddAll_CSIDL();
  56. void Add_Variants(const WCHAR * lpEnvName, const WCHAR * lpEnvValue, eAddNameEnum eName, eAddNoDLEnum eNoDL);
  57. void Add_CSIDL(const WCHAR * lpEnvName, int nFolder, eAddNameEnum eName, eAddNoDLEnum eNoDL);
  58. };
  59. class CorrectPathChangesBase
  60. {
  61. protected:
  62. EnvironmentValues * lpEnvironmentValues;
  63. DWORD dwKnownPathFixesCount;
  64. StringPairW * lpKnownPathFixes;
  65. BOOL bInitialized;
  66. BOOL bEnabled;
  67. CRITICAL_SECTION csCritical;
  68. protected:
  69. virtual void InitializeCorrectPathChanges();
  70. virtual void InitializePathFixes();
  71. virtual void InitializeEnvironmentValuesW();
  72. void AddEnvironmentValue(const WCHAR * lpOld, const WCHAR * lpNew);
  73. void InsertPathChangeW( const WCHAR * lpOld, const WCHAR * lpNew);
  74. void EnterCS();
  75. void LeaveCS();
  76. public:
  77. CorrectPathChangesBase();
  78. virtual ~CorrectPathChangesBase();
  79. virtual WCHAR * ExpandEnvironmentValueW(const WCHAR * lpOld);
  80. virtual char * ExpandEnvironmentValueA(const char * lpOld);
  81. virtual void AddPathChangeW(const WCHAR * lpOld, const WCHAR * lpNew);
  82. virtual void AddCommandLineA(const char * lpCommandLine );
  83. virtual void AddCommandLineW(const WCHAR * lpCommandLine );
  84. virtual void AddFromToPairW(const WCHAR * lpFromToPair );
  85. virtual char * CorrectPathAllocA(const char * str);
  86. virtual WCHAR * CorrectPathAllocW(const WCHAR * str);
  87. inline void Enable(BOOL enable);
  88. };
  89. /*++
  90. Enable (or disable if value is FALSE) changing of paths.
  91. --*/
  92. inline void CorrectPathChangesBase::Enable(BOOL isEnabled)
  93. {
  94. bEnabled = isEnabled;
  95. }
  96. // Typical path fixes
  97. class CorrectPathChangesUser : public CorrectPathChangesBase
  98. {
  99. protected:
  100. virtual void InitializePathFixes();
  101. };
  102. // Typical path fixes, moving user directories to All Users
  103. class CorrectPathChangesAllUser : public CorrectPathChangesUser
  104. {
  105. protected:
  106. virtual void InitializePathFixes();
  107. };
  108. }; // end of namespace ShimLib