| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | //***************************************************************************** |
| 5 | // RegMeta.cpp |
| 6 | // |
| 7 | |
| 8 | // |
| 9 | // Implementation for meta data public interface methods. |
| 10 | // |
| 11 | //***************************************************************************** |
| 12 | #include "stdafx.h" |
| 13 | #include "regmeta.h" |
| 14 | #include "metadata.h" |
| 15 | #include "corerror.h" |
| 16 | #include "mdutil.h" |
| 17 | #include "rwutil.h" |
| 18 | #include "mdlog.h" |
| 19 | #include "importhelper.h" |
| 20 | #include "filtermanager.h" |
| 21 | #include "mdperf.h" |
| 22 | #include "switches.h" |
| 23 | #include "posterror.h" |
| 24 | #include "stgio.h" |
| 25 | #include "sstring.h" |
| 26 | |
| 27 | #include <metamodelrw.h> |
| 28 | |
| 29 | #define DEFINE_CUSTOM_NODUPCHECK 1 |
| 30 | #define DEFINE_CUSTOM_DUPCHECK 2 |
| 31 | #define SET_CUSTOM 3 |
| 32 | |
| 33 | #if defined(_DEBUG) && defined(_TRACE_REMAPS) |
| 34 | #define LOGGING |
| 35 | #endif |
| 36 | #include <log.h> |
| 37 | |
| 38 | #ifdef _MSC_VER |
| 39 | #pragma warning(disable: 4102) |
| 40 | #endif |
| 41 | |
| 42 | #ifdef FEATURE_METADATA_EMIT |
| 43 | |
| 44 | //***************************************************************************** |
| 45 | // Merge the pImport scope to this scope |
| 46 | //***************************************************************************** |
| 47 | STDMETHODIMP RegMeta::Merge( // S_OK or error. |
| 48 | IMetaDataImport *pImport, // [IN] The scope to be merged. |
| 49 | IMapToken *pHostMapToken, // [IN] Host IMapToken interface to receive token remap notification |
| 50 | IUnknown *pHandler) // [IN] An object to receive to receive error notification. |
| 51 | { |
| 52 | return E_NOTIMPL; |
| 53 | } // RegMeta::Merge |
| 54 | |
| 55 | |
| 56 | //***************************************************************************** |
| 57 | // real merge takes place here |
| 58 | //***************************************************************************** |
| 59 | STDMETHODIMP RegMeta::MergeEnd() // S_OK or error. |
| 60 | { |
| 61 | return E_NOTIMPL; |
| 62 | } // RegMeta::MergeEnd |
| 63 | |
| 64 | |
| 65 | //***************************************************************************** |
| 66 | // As the Stgdb object to get the save size for the metadata delta. |
| 67 | //***************************************************************************** |
| 68 | STDMETHODIMP RegMeta::GetDeltaSaveSize( // S_OK or error. |
| 69 | CorSaveSize fSave, // [IN] cssAccurate or cssQuick. |
| 70 | DWORD *pdwSaveSize) // [OUT] Put the size here. |
| 71 | { |
| 72 | #ifdef FEATURE_METADATA_EMIT_ALL |
| 73 | HRESULT hr = S_OK; |
| 74 | |
| 75 | BEGIN_ENTRYPOINT_NOTHROW; |
| 76 | |
| 77 | // Make sure we're in EnC mode |
| 78 | if (!IsENCOn()) |
| 79 | { |
| 80 | _ASSERTE(!"Not in EnC mode!" ); |
| 81 | IfFailGo(META_E_NOT_IN_ENC_MODE); |
| 82 | } |
| 83 | |
| 84 | m_pStgdb->m_MiniMd.EnableDeltaMetadataGeneration(); |
| 85 | hr = GetSaveSize(fSave, pdwSaveSize); |
| 86 | m_pStgdb->m_MiniMd.DisableDeltaMetadataGeneration(); |
| 87 | |
| 88 | ErrExit: |
| 89 | END_ENTRYPOINT_NOTHROW; |
| 90 | |
| 91 | return hr; |
| 92 | #else //!FEATURE_METADATA_EMIT_ALL |
| 93 | return E_NOTIMPL; |
| 94 | #endif //!FEATURE_METADATA_EMIT_ALL |
| 95 | } // RegMeta::GetDeltaSaveSize |
| 96 | |
| 97 | //***************************************************************************** |
| 98 | // Saves a metadata delta to a file of a given name. |
| 99 | //***************************************************************************** |
| 100 | STDMETHODIMP RegMeta::SaveDelta( // S_OK or error. |
| 101 | LPCWSTR szFile, // [IN] The filename to save to. |
| 102 | DWORD dwSaveFlags) // [IN] Flags for the save. |
| 103 | { |
| 104 | #ifdef FEATURE_METADATA_EMIT_ALL |
| 105 | HRESULT hr = S_OK; |
| 106 | |
| 107 | BEGIN_ENTRYPOINT_NOTHROW; |
| 108 | |
| 109 | |
| 110 | // Make sure we're in EnC mode |
| 111 | if (!IsENCOn()) |
| 112 | { |
| 113 | _ASSERTE(!"Not in EnC mode!" ); |
| 114 | IfFailGo(META_E_NOT_IN_ENC_MODE); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | |
| 119 | m_pStgdb->m_MiniMd.EnableDeltaMetadataGeneration(); |
| 120 | hr = Save(szFile, dwSaveFlags); |
| 121 | m_pStgdb->m_MiniMd.DisableDeltaMetadataGeneration(); |
| 122 | |
| 123 | ErrExit: |
| 124 | |
| 125 | END_ENTRYPOINT_NOTHROW; |
| 126 | |
| 127 | return hr; |
| 128 | #else //!FEATURE_METADATA_EMIT_ALL |
| 129 | return E_NOTIMPL; |
| 130 | #endif //!FEATURE_METADATA_EMIT_ALL |
| 131 | } // RegMeta::SaveDelta |
| 132 | |
| 133 | //***************************************************************************** |
| 134 | // Saves a metadata delta to a stream. |
| 135 | //***************************************************************************** |
| 136 | STDMETHODIMP RegMeta::SaveDeltaToStream( // S_OK or error. |
| 137 | IStream *pIStream, // [IN] A writable stream to save to. |
| 138 | DWORD dwSaveFlags) // [IN] Flags for the save. |
| 139 | { |
| 140 | #ifdef FEATURE_METADATA_EMIT_ALL |
| 141 | HRESULT hr = S_OK; |
| 142 | |
| 143 | BEGIN_ENTRYPOINT_NOTHROW; |
| 144 | |
| 145 | // Make sure we're in EnC mode |
| 146 | if (!IsENCOn()) |
| 147 | { |
| 148 | _ASSERTE(!"Not in EnC mode!" ); |
| 149 | IfFailGo(META_E_NOT_IN_ENC_MODE); |
| 150 | } |
| 151 | |
| 152 | |
| 153 | |
| 154 | m_pStgdb->m_MiniMd.EnableDeltaMetadataGeneration(); |
| 155 | hr = SaveToStream(pIStream, dwSaveFlags); |
| 156 | m_pStgdb->m_MiniMd.DisableDeltaMetadataGeneration(); |
| 157 | |
| 158 | ErrExit: |
| 159 | END_ENTRYPOINT_NOTHROW; |
| 160 | |
| 161 | return hr; |
| 162 | #else //!FEATURE_METADATA_EMIT_ALL |
| 163 | return E_NOTIMPL; |
| 164 | #endif //!FEATURE_METADATA_EMIT_ALL |
| 165 | } // RegMeta::SaveDeltaToStream |
| 166 | |
| 167 | //***************************************************************************** |
| 168 | // Saves a copy of the scope into the memory buffer provided. The buffer size |
| 169 | // must be at least as large as the GetSaveSize value. |
| 170 | //***************************************************************************** |
| 171 | STDMETHODIMP RegMeta::SaveDeltaToMemory( // S_OK or error. |
| 172 | void *pbData, // [OUT] Location to write data. |
| 173 | ULONG cbData) // [IN] Max size of data buffer. |
| 174 | { |
| 175 | #ifdef FEATURE_METADATA_EMIT_ALL |
| 176 | HRESULT hr = S_OK; |
| 177 | |
| 178 | BEGIN_ENTRYPOINT_NOTHROW; |
| 179 | |
| 180 | // Make sure we're in EnC mode |
| 181 | if (!IsENCOn()) |
| 182 | { |
| 183 | _ASSERTE(!"Not in EnC mode!" ); |
| 184 | IfFailGo(META_E_NOT_IN_ENC_MODE); |
| 185 | } |
| 186 | |
| 187 | |
| 188 | m_pStgdb->m_MiniMd.EnableDeltaMetadataGeneration(); |
| 189 | hr = SaveToMemory(pbData, cbData); |
| 190 | m_pStgdb->m_MiniMd.DisableDeltaMetadataGeneration(); |
| 191 | |
| 192 | ErrExit: |
| 193 | |
| 194 | END_ENTRYPOINT_NOTHROW; |
| 195 | |
| 196 | return hr; |
| 197 | #else //!FEATURE_METADATA_EMIT_ALL |
| 198 | return E_NOTIMPL; |
| 199 | #endif //!FEATURE_METADATA_EMIT_ALL |
| 200 | } // RegMeta::SaveDeltaToMemory |
| 201 | |
| 202 | //***************************************************************************** |
| 203 | // Resets the current edit and continue session |
| 204 | // |
| 205 | // Implements public API code:IMetaDataEmit2::ResetENCLog. |
| 206 | //***************************************************************************** |
| 207 | STDMETHODIMP |
| 208 | RegMeta::ResetENCLog() |
| 209 | { |
| 210 | #ifdef FEATURE_METADATA_EMIT_ALL |
| 211 | HRESULT hr = S_OK; |
| 212 | |
| 213 | BEGIN_ENTRYPOINT_NOTHROW; |
| 214 | |
| 215 | // Make sure we're in EnC mode |
| 216 | if (!IsENCOn()) |
| 217 | { |
| 218 | _ASSERTE(!"Not in EnC mode!" ); |
| 219 | IfFailGo(META_E_NOT_IN_ENC_MODE); |
| 220 | } |
| 221 | |
| 222 | IfFailGo(m_pStgdb->m_MiniMd.ResetENCLog()); |
| 223 | ErrExit: |
| 224 | END_ENTRYPOINT_NOTHROW; |
| 225 | |
| 226 | return hr; |
| 227 | #else //!FEATURE_METADATA_EMIT_ALL |
| 228 | return E_NOTIMPL; |
| 229 | #endif //!FEATURE_METADATA_EMIT_ALL |
| 230 | } // RegMeta::ResetENCLog |
| 231 | |
| 232 | #endif //FEATURE_METADATA_EMIT |
| 233 | |