{
namespace
{
- BOOL fAssemblyBinderInitialized = FALSE;
-
//
// This defines the assembly equivalence relation
//
/* static */
HRESULT AssemblyBinder::Startup()
{
+ STATIC_CONTRACT_NOTHROW;
+
HRESULT hr = S_OK;
- if (!BINDER_SPACE::fAssemblyBinderInitialized)
- {
- g_BinderVariables = new Variables();
- IF_FAIL_GO(g_BinderVariables->Init());
+ // This should only be called once
+ _ASSERTE(g_BinderVariables == NULL);
+ g_BinderVariables = new Variables();
+ IF_FAIL_GO(g_BinderVariables->Init());
- // Setup Debug log
- BINDER_LOG_STARTUP();
-
- // We're done
- BINDER_SPACE::fAssemblyBinderInitialized = TRUE;
- }
+ // Setup Debug log
+ BINDER_LOG_STARTUP();
Exit:
return hr;
Assembly **ppSystemAssembly,
bool fBindToNativeImage)
{
- _ASSERTE(BINDER_SPACE::fAssemblyBinderInitialized == TRUE);
+ // Indirect check that binder was initialized.
+ _ASSERTE(g_BinderVariables != NULL);
HRESULT hr = S_OK;
BINDER_LOG_ENTER(W("AssemblyBinder:BindToSystem"));
// At run-time, System.Private.CoreLib.dll is expected to be the NI image.
sCoreLib = sCoreLibDir;
sCoreLib.Append(CoreLibName_IL_W);
- BOOL fExplicitBindToNativeImage = (fBindToNativeImage == true)? TRUE:FALSE;
IF_FAIL_GO(AssemblyBinder::GetAssembly(sCoreLib,
TRUE /* fIsInGAC */,
- fExplicitBindToNativeImage,
+ fBindToNativeImage,
&pSystemAssembly));
*ppSystemAssembly = pSystemAssembly.Extract();
SString &cultureName,
Assembly **ppSystemAssembly)
{
- _ASSERTE(BINDER_SPACE::fAssemblyBinderInitialized == TRUE);
+ // Indirect check that binder was initialized.
+ _ASSERTE(g_BinderVariables != NULL);
HRESULT hr = S_OK;
BINDER_LOG_ENTER(W("AssemblyBinder:BindToSystemSatellite"));
HRESULT hr = E_FAIL;
BINDER_LOG_ENTER(W("AssemblyBinder::BindUsingPEImage"));
- _ASSERTE(BINDER_SPACE::fAssemblyBinderInitialized == TRUE);
+ // Indirect check that binder was initialized.
+ _ASSERTE(g_BinderVariables != NULL);
LONG kContextVersion = 0;
BindResult bindResult;
#include "utils.hpp"
-#include <shlwapi.h>
-
#include "strongname.h"
#include "corpriv.h"
{
namespace
{
- inline BOOL IsPathSeparator(WCHAR wcChar)
- {
- // Invariant: Valid only for MutateUrlToPath treated pathes
- return (wcChar == W('\\'));
- }
-
inline const WCHAR *GetPlatformPathSeparator()
{
#ifdef PLATFORM_UNIX
return W("/");
#else
return W("\\");
-#endif // PLATFORM_UNIX
- }
-
- inline WCHAR ToPlatformPathSepator(WCHAR wcChar)
- {
-#ifdef PLATFORM_UNIX
- if (IsPathSeparator(wcChar))
- {
- wcChar = W('/');
- }
#endif // PLATFORM_UNIX
-
- return wcChar;
- }
-
- inline BOOL IsDoublePathSeparator(SString::CIterator &cur)
- {
- return (IsPathSeparator(cur[0]) && IsPathSeparator(cur[1]));
- }
-
- bool NeedToRemoveDoubleAndNormalizePathSeparators(SString const &path)
- {
-#ifdef PLATFORM_UNIX
- return true;
-#else
- SString::CIterator begin = path.Begin();
- SString::CIterator end = path.End();
- SString::CIterator cur = path.Begin();
-
- while (cur < end)
- {
- if ((cur != begin) && ((cur + 2) < end) && IsDoublePathSeparator(cur))
- {
- return true;
- }
-
- cur++;
- }
-
- return false;
-#endif
- }
-
- void RemoveDoubleAndNormalizePathSeparators(SString &path)
- {
- BINDER_LOG_ENTER(W("Utils::RemoveDoubleAndNormalizePathSeparators"));
-
- SString::Iterator begin = path.Begin();
- SString::Iterator end = path.End();
- SString::Iterator cur = path.Begin();
- PathString resultPath;
-
- BINDER_LOG_STRING(W("path"), path);
-
- while (cur < end)
- {
- if ((cur != begin) && ((cur + 2) < end) && IsDoublePathSeparator(cur))
- {
- // Skip the doublette
- cur++;
- }
-
- resultPath.Append(ToPlatformPathSepator(cur[0]));
- cur++;
- }
-
- BINDER_LOG_STRING(W("resultPath"), resultPath);
-
- path.Set(resultPath);
-
- BINDER_LOG_LEAVE(W("Utils::RemoveDoubleAndNormalizePathSeparators"));
}
}
- HRESULT FileOrDirectoryExists(PathString &path)
- {
- HRESULT hr = S_FALSE;
-
- DWORD dwFileAttributes = WszGetFileAttributes(path.GetUnicode());
- if (dwFileAttributes == INVALID_FILE_ATTRIBUTES)
- {
- hr = HRESULT_FROM_GetLastError();
-
- if ((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) ||
- (hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)))
- {
- hr = S_FALSE;
- }
- }
- else
- {
- hr = S_TRUE;
- }
-
- return hr;
- }
-
- HRESULT FileOrDirectoryExistsLog(PathString &path)
- {
- HRESULT hr = S_FALSE;
- BINDER_LOG_ENTER(W("Utils::FileOrDirectoryExistsLog"));
- BINDER_LOG_STRING(W("path"), path);
-
- hr = FileOrDirectoryExists(path);
-
- BINDER_LOG_LEAVE_HR(W("Utils::FileOrDirectoryExistsLog"), hr);
- return hr;
- }
-
void MutateUrlToPath(SString &urlOrPath)
{
BINDER_LOG_ENTER(W("Utils::MutateUrlToPath"));
BINDER_LOG_LEAVE(W("Utils::MutateUrlToPath"));
}
- void PlatformPath(SString &path)
- {
- BINDER_LOG_ENTER(W("Utils::PlatformPath"));
- BINDER_LOG_STRING(W("input path"), path);
-
- // Create platform representation
- MutateUrlToPath(path);
- if (NeedToRemoveDoubleAndNormalizePathSeparators(path))
- RemoveDoubleAndNormalizePathSeparators(path);
-
- BINDER_LOG_STRING(W("platform path"), path);
-
- BINDER_LOG_LEAVE(W("Utils::PlatformPath"));
- }
-
void CombinePath(SString &pathA,
SString &pathB,
SString &combinedPath)