Compare commits

...

4 Commits

22 changed files with 347 additions and 193 deletions

View File

@ -9,8 +9,9 @@ using namespace System::Security::Permissions;
[assembly:AssemblyTitleAttribute(L"Vanara.PInvoke.VssApi")];
[assembly:AssemblyDescriptionAttribute(L"PInvoke API (methods, structures and constants) imported from Windows Volume Shadow Copy Service (VssApi.dll).")];
[assembly:AssemblyProductAttribute(L"Vanara")];
[assembly:AssemblyCopyrightAttribute(L"Copyright © 2017-2022")];
[assembly:AssemblyCopyrightAttribute(L"Copyright © 2017-2023")];
[assembly:AssemblyKeyFileAttribute(L"..\\..\\Vanara.snk")]
[assembly:AssemblyVersionAttribute("3.4.12")];
[assembly:AssemblyVersionAttribute("4.0.0")];
[assembly:AssemblyInformationalVersionAttribute("4.0.0-beta")];
[assembly:ComVisible(false)];
[assembly:ComVisible(false)];

View File

@ -3,67 +3,72 @@
#include <guiddef.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Runtime::InteropServices;
ref class Utils sealed
{
public:
static void ThrowIfFailed(::HRESULT hr)
{
if (hr < 0)
throw gcnew Runtime::InteropServices::COMException(nullptr, hr);
}
static void ThrowIfFailed(::HRESULT hr)
{
if (SUCCEEDED(hr)) return;
auto exceptionForHR = Marshal::GetExceptionForHR(hr);
if (exceptionForHR->GetType() == COMException::typeid && HRESULT_FACILITY(hr) == FACILITY_WIN32)
exceptionForHR = gcnew Win32Exception(HRESULT_CODE(hr));
throw exceptionForHR;
}
static Guid FromGUID(_GUID& guid) {
return Guid(guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2],
guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
}
static Guid FromGUID(_GUID& guid) {
return Guid(guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2],
guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
}
static _GUID ToGUID(Guid& guid) {
array<Byte>^ guidData = guid.ToByteArray();
pin_ptr<Byte> data = &(guidData[0]);
static _GUID ToGUID(Guid& guid) {
array<Byte>^ guidData = guid.ToByteArray();
pin_ptr<Byte> data = &(guidData[0]);
return *(_GUID*)data;
}
return *(_GUID*)data;
}
static _GUID* ToGUIDArray([System::Runtime::InteropServices::In] array<Guid>^ input)
{
if (input == nullptr)
return nullptr;
pin_ptr<Guid> pg = &input[0];
VSS_ID* buf = new VSS_ID[input->Length];
for (int i = 0; i < input->Length; i++)
buf[i] = Utils::ToGUID(pg[i]);
return buf;
}
static _GUID* ToGUIDArray([System::Runtime::InteropServices::In] array<Guid>^ input)
{
if (input == nullptr)
return nullptr;
pin_ptr<Guid> pg = &input[0];
VSS_ID* buf = new VSS_ID[input->Length];
for (int i = 0; i < input->Length; i++)
buf[i] = Utils::ToGUID(pg[i]);
return buf;
}
generic <class TIN, class TOUT>
delegate TOUT Conv(TIN input);
generic <class TIN, class TOUT>
delegate TOUT Conv(TIN input);
template <class TIN, class TOUT>
static TOUT* ToNative(array<TIN>^ input, Conv<TIN, TOUT>^ func)
{
if (input == nullptr)
return nullptr;
if (input->Length == 0)
return new TOUT[0];
pin_ptr<TIN> pin = &input[0];
TIN* p = pin;
TOUT* buf = new TOUT[input->Length];
for (int i = 0; i < input->Len; i++)
{
input[i] = func(pin[i]);
}
return buf;
}
template <class TIN, class TOUT>
static TOUT* ToNative(array<TIN>^ input, Conv<TIN, TOUT>^ func)
{
if (input == nullptr)
return nullptr;
if (input->Length == 0)
return new TOUT[0];
pin_ptr<TIN> pin = &input[0];
TIN* p = pin;
TOUT* buf = new TOUT[input->Length];
for (int i = 0; i < input->Len; i++)
{
input[i] = func(pin[i]);
}
return buf;
}
};
class SmartGuid
{
private:
_GUID mGuid;
_GUID mGuid;
public:
SmartGuid(_GUID& guid) : mGuid(guid) {}
SmartGuid(Guid& guid) : mGuid(Utils::ToGUID(guid)) {}
operator Guid() { return Utils::FromGUID(mGuid); }
operator _GUID() { return mGuid; }
};
SmartGuid(_GUID& guid) : mGuid(guid) {}
SmartGuid(Guid& guid) : mGuid(Utils::ToGUID(guid)) {}
operator Guid() { return Utils::FromGUID(mGuid); }
operator _GUID() { return mGuid; }
};

View File

@ -1,36 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<package >
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>$id$</id>
<id>Vanara.PInvoke.VssApi</id>
<version>$version$</version>
<title>$title$</title>
<description>$description$</description>
<copyright>$copyright$</copyright>
<authors>$author$</authors>
<owners>$author$</owners>
<description>PInvoke API (methods, structures and constants) imported from Windows Volume Shadow Copy Service (VssApi.dll).</description>
<copyright>Copyright © 2017-2023</copyright>
<authors>David Hall</authors>
<tags>pinvoke,vanara,net-extensions,interop,VSS,VssApi,volume shadow copy service</tags>
<license type="expression">MIT</license>
<projectUrl>https://github.com/dahall/vanara</projectUrl>
<icon>Vanara48x48.png</icon>
<icon>Vanara64x64.png</icon>
<readme>pkgreadme.md</readme>
<repository type="git" url="https://github.com/dahall/Vanara.git" />
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<language>en-US</language>
<dependencies>
<group targetFramework="net45">
<dependency id="Vanara.Core" version="$version$" exclude="Build,Analyzers" />
<dependency id="Vanara.PInvoke.Shared" version="$version$" exclude="Build,Analyzers" />
</group>
<group targetFramework="net48">
<dependency id="Vanara.Core" version="$version$" exclude="Build,Analyzers" />
<dependency id="Vanara.PInvoke.Shared" version="$version$" exclude="Build,Analyzers" />
</group>
<group targetFramework="net6.0">
<dependency id="Vanara.Core" version="$version$" exclude="Build,Analyzers" />
<dependency id="Vanara.PInvoke.Shared" version="$version$" exclude="Build,Analyzers" />
</group>
<group targetFramework="net7.0">
<dependency id="Vanara.Core" version="$version$" exclude="Build,Analyzers" />
<dependency id="Vanara.PInvoke.Shared" version="$version$" exclude="Build,Analyzers" />
</group>
<group targetFramework="netcoreapp3.1">
<dependency id="Vanara.Core" version="$version$" exclude="Build,Analyzers" />
<dependency id="Vanara.PInvoke.Shared" version="$version$" exclude="Build,Analyzers" />
</group>
</dependencies>
<releaseNotes></releaseNotes>
</metadata>
<files>
<file src="bin\Release\net6.0\Vanara.PInvoke.VssApi.dll" target="lib\net6.0" />
<file src="bin\Release\net6.0\Vanara.PInvoke.VssApi.xml" target="lib\net6.0" />
<file src="bin\Release\net6.0\Vanara.PInvoke.VssApi.pdb" target="lib\net6.0" />
<file src="bin\Release\net6.0\Vanara.PInvoke.VssApiMgd.dll" target="lib\net6.0" />
<file src="..\VssApiMgd\bin\Release\net6.0\Vanara.PInvoke.VssApiMgd.xml" target="lib\net6.0" />
<file src="..\VssApiMgd\bin\Release\net6.0\Vanara.PInvoke.VssApiMgd.pdb" target="lib\net6.0" />
<file src="..\..\docs\icons\Vanara48x48.png" target="" />
<file src="..\VssApiMgd\pkgreadme.md" target="" />
<file src="bin\Release\net45\Win32\Vanara.PInvoke.VssApi*.???" target="lib\net45" />
<file src="bin\Release\net45\Win32\Vanara.PInvoke.VssApi*.???" target="runtimes\win10-x86\lib\net45" />
<file src="bin\Release\net45\x64\Vanara.PInvoke.VssApi*.???" target="runtimes\win10-x64\lib\net45" />
<file src="bin\Release\net48\Win32\Vanara.PInvoke.VssApi*.???" target="lib\net48" />
<file src="bin\Release\net48\Win32\Vanara.PInvoke.VssApi*.???" target="runtimes\win10-x86\lib\net48" />
<file src="bin\Release\net48\x64\Vanara.PInvoke.VssApi*.???" target="runtimes\win10-x64\lib\net48" />
<file src="bin\Release\net6.0\Win32\Vanara.PInvoke.VssApi*.???" target="lib\net6.0" />
<file src="bin\Release\net6.0\Win32\Vanara.PInvoke.VssApi*.???" target="runtimes\win10-x86\lib\net6.0" />
<file src="bin\Release\net6.0\x64\Vanara.PInvoke.VssApi*.???" target="runtimes\win10-x64\lib\net6.0" />
<file src="bin\Release\net7.0\Win32\Vanara.PInvoke.VssApi*.???" target="lib\net7.0" />
<file src="bin\Release\net7.0\Win32\Vanara.PInvoke.VssApi*.???" target="runtimes\win10-x86\lib\net7.0" />
<file src="bin\Release\net7.0\x64\Vanara.PInvoke.VssApi*.???" target="runtimes\win10-x64\lib\net7.0" />
<file src="bin\Release\netcoreapp3.1\Win32\Vanara.PInvoke.VssApi*.???" target="lib\netcoreapp3.1" />
<file src="bin\Release\netcoreapp3.1\Win32\Vanara.PInvoke.VssApi*.???" target="runtimes\win10-x86\lib\netcoreapp3.1" />
<file src="bin\Release\netcoreapp3.1\x64\Vanara.PInvoke.VssApi*.???" target="runtimes\win10-x64\lib\netcoreapp3.1" />
<file src="..\..\docs\icons\Vanara64x64.png" target="Vanara64x64.png" />
<file src="pkgreadme.md" target="pkgreadme.md" />
</files>
</package>

View File

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\Microsoft.SourceLink.GitHub.8.0.0\build\Microsoft.SourceLink.GitHub.props" Condition="Exists('..\..\packages\Microsoft.SourceLink.GitHub.8.0.0\build\Microsoft.SourceLink.GitHub.props')" />
<Import Project="..\..\packages\Microsoft.SourceLink.Common.8.0.0\build\Microsoft.SourceLink.Common.props" Condition="Exists('..\..\packages\Microsoft.SourceLink.Common.8.0.0\build\Microsoft.SourceLink.Common.props')" />
<Import Project="..\..\packages\Microsoft.Build.Tasks.Git.8.0.0\build\Microsoft.Build.Tasks.Git.props" Condition="Exists('..\..\packages\Microsoft.Build.Tasks.Git.8.0.0\build\Microsoft.Build.Tasks.Git.props')" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
@ -18,55 +21,74 @@
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ProjectExtensions>
<SupportedDlls>vssapi.dll</SupportedDlls>
<IncludeAssembly>Vanara.PInvoke.VssApiMgd.dll</IncludeAssembly>
<UpdateFiles PackageSource="..\..\Package.targets" UpdateProjectFile="false">
<File Path="AssemblyInfo.cpp">
<Version>AssemblyInformationalVersionAttribute</Version>
<Version type="sem">AssemblyVersionAttribute</Version>
<Copyright>AssemblyCopyrightAttribute</Copyright>
<Product>AssemblyProductAttribute</Product>
</File>
<File Path="Vanara.PInvoke.VssApi.nuspec">
<Version>version</Version>
<Copyright>copyright</Copyright>
<Authors>authors</Authors>
<PackageLicenseExpression>license</PackageLicenseExpression>
<PackageIcon>icon</PackageIcon>
<PackageProjectUrl>projectUrl</PackageProjectUrl>
<RepositoryType>repository|type</RepositoryType>
<RepositoryUrl>repository|url</RepositoryUrl>
</File>
</UpdateFiles>
</ProjectExtensions>
<PropertyGroup>
<TargetFramework Condition="'$(TargetFramework)'==''">net6.0</TargetFramework>
<TargetFrameworks>$(TargetFramework)</TargetFrameworks>
<CoreBuild Condition="!$(TargetFramework.StartsWith('net4'))">true</CoreBuild>
<IncludeSymbols>true</IncludeSymbols>
<EmbedAllSources>true</EmbedAllSources>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<AssetTargetFallback>$(AssetTargetFallback);native</AssetTargetFallback>
</PropertyGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<EnableManagedPackageReferenceSupport>true</EnableManagedPackageReferenceSupport>
<EnableManagedPackageReferenceSupport Condition="'$(CoreBuild)'=='true'">true</EnableManagedPackageReferenceSupport>
<ProjectGuid>{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}</ProjectGuid>
<Keyword>NetCoreCProj</Keyword>
<Keyword Condition="'$(CoreBuild)'!='true'">ManagedCProj</Keyword>
<Keyword Condition="'$(CoreBuild)'=='true'">NetCoreCProj</Keyword>
<RootNamespace>VssApi</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>7.0</WindowsTargetPlatformMinVersion>
<TargetFrameworkVersion Condition="$(TargetFramework.StartsWith('net4'))">$([System.Text.RegularExpressions.Regex]::Replace($(TargetFramework), `net([2-4])([0-9])`, `v$1.$2`))</TargetFrameworkVersion>
<ProjectName>Vanara.PInvoke.VssApi</ProjectName>
<TargetFrameworks>
</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<Description>PInvoke API (methods, structures and constants) imported from Windows Volume Shadow Copy Service (VssApi.dll).</Description>
<AssemblyTitle>$(AssemblyName)</AssemblyTitle>
<AssemblyName>Vanara.PInvoke.VssApi</AssemblyName>
<PackageId>$(AssemblyName)</PackageId>
<PackageTags>pinvoke;vanara;net-extensions;interop;VSS;VssApi;volume shadow copy service</PackageTags>
<GeneratePackageOnBuild Condition="'$(Configuration)'=='Release'">true</GeneratePackageOnBuild>
<NuspecFile>VssApi.nuspec</NuspecFile>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<PropertyGroup Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CLRSupport>NetCore</CLRSupport>
<CLRSupport Condition="'$(CoreBuild)'=='true'">NetCore</CLRSupport>
<CLRSupport Condition="'$(CoreBuild)'!='true'">true</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CLRSupport>NetCore</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CLRSupport>NetCore</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CLRSupport>NetCore</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@ -88,32 +110,26 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<TargetName>$(ProjectName)</TargetName>
<OutDir>bin\$(Configuration)\$(TargetFramework)\</OutDir>
<IntDir>obj\$(Configuration)\$(TargetFramework)\</IntDir>
<OutDir>bin\$(Configuration)\$(TargetFramework)\$(Platform)\</OutDir>
<IntDir>obj\$(Configuration)\$(TargetFramework)\$(Platform)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<AdditionalUsingDirectories>$(MSBuildThisFileDirectory)..\VssApiMgd\bin\$(Configuration)\$(TargetFramework)</AdditionalUsingDirectories>
<GenerateXMLDocumentationFiles>true</GenerateXMLDocumentationFiles>
</ClCompile>
<Link>
<AdditionalDependencies>vssapi.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<AdditionalUsingDirectories>$(MSBuildThisFileDirectory)..\VssApiMgd\bin\$(Configuration)\$(TargetFramework)</AdditionalUsingDirectories>
<GenerateXMLDocumentationFiles>true</GenerateXMLDocumentationFiles>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>vssapi.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>vssapi.lib</AdditionalDependencies>
@ -124,10 +140,9 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<AdditionalUsingDirectories>$(MSBuildThisFileDirectory)..\VssApiMgd\bin\$(Configuration)\$(TargetFramework)</AdditionalUsingDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<GenerateXMLDocumentationFiles>true</GenerateXMLDocumentationFiles>
<DisableSpecificWarnings>4945</DisableSpecificWarnings>
</ClCompile>
<Link>
<AdditionalDependencies>vssapi.lib</AdditionalDependencies>
@ -138,21 +153,14 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<AdditionalUsingDirectories>$(MSBuildThisFileDirectory)..\VssApiMgd\bin\$(Configuration)\$(TargetFramework)</AdditionalUsingDirectories>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<GenerateXMLDocumentationFiles>true</GenerateXMLDocumentationFiles>
<DisableSpecificWarnings>4945</DisableSpecificWarnings>
</ClCompile>
<Link>
<AdditionalDependencies>vssapi.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="6.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BaseWrapper.h" />
<ClInclude Include="CliLists.h" />
@ -169,8 +177,8 @@
<ItemGroup>
<ClCompile Include="AssemblyInfo.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
@ -179,24 +187,47 @@
<ClCompile Include="VssFactory.cpp" />
<ClCompile Include="VsWriter.cpp" />
</ItemGroup>
<!--<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<SourceRoot Include="$(MSBuildThisFileDirectory)/" />
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="6.8.0" PrivateAssets="All" />
</ItemGroup>-->
<ItemGroup>
<ProjectReference Include="..\VssApiMgd\Vanara.PInvoke.VssApiMgd.csproj">
<Project>{39aedd51-c627-41b9-96d3-44f481ed4e7c}</Project>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<!--<CopyLocalSatelliteAssemblies>true</CopyLocalSatelliteAssemblies>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>-->
</ProjectReference>
<!--<ProjectReference Include="..\Shared\Vanara.PInvoke.Shared.csproj">
<Project>{a5e519e9-feba-4fe3-93a5-b8269bef72f4}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Core\Vanara.Core.csproj">
<Project>{241f73ee-9298-45c9-b869-a045dff94c03}</Project>
</ProjectReference>-->
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />
<None Include="packages.config" />
<None Include="Vanara.PInvoke.VssApi.nuspec" />
</ItemGroup>
<!--<ItemGroup>
<None Include="..\VssApiMgd\bin\Debug\net6.0\Vanara.PInvoke.VssApiMgd.dll" />
</ItemGroup>-->
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\packages\Microsoft.Build.Tasks.Git.8.0.0\build\Microsoft.Build.Tasks.Git.targets" Condition="Exists('..\..\packages\Microsoft.Build.Tasks.Git.8.0.0\build\Microsoft.Build.Tasks.Git.targets')" />
<Import Project="..\..\packages\Microsoft.SourceLink.Common.8.0.0\build\Microsoft.SourceLink.Common.targets" Condition="Exists('..\..\packages\Microsoft.SourceLink.Common.8.0.0\build\Microsoft.SourceLink.Common.targets')" />
<Import Project="..\..\packages\Microsoft.SourceLink.GitHub.8.0.0\build\Microsoft.SourceLink.GitHub.targets" Condition="Exists('..\..\packages\Microsoft.SourceLink.GitHub.8.0.0\build\Microsoft.SourceLink.GitHub.targets')" />
</ImportGroup>
<Target Name="WipeObj" BeforeTargets="Clean;CoreClean">
<!-- obj -->
<RemoveDir Directories="$(ProjectDir)$(BaseIntermediateOutputPath)" />
</Target>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Microsoft.Build.Tasks.Git.8.0.0\build\Microsoft.Build.Tasks.Git.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Build.Tasks.Git.8.0.0\build\Microsoft.Build.Tasks.Git.props'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.Build.Tasks.Git.8.0.0\build\Microsoft.Build.Tasks.Git.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Build.Tasks.Git.8.0.0\build\Microsoft.Build.Tasks.Git.targets'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.SourceLink.Common.8.0.0\build\Microsoft.SourceLink.Common.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.SourceLink.Common.8.0.0\build\Microsoft.SourceLink.Common.props'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.SourceLink.Common.8.0.0\build\Microsoft.SourceLink.Common.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.SourceLink.Common.8.0.0\build\Microsoft.SourceLink.Common.targets'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.SourceLink.GitHub.8.0.0\build\Microsoft.SourceLink.GitHub.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.SourceLink.GitHub.8.0.0\build\Microsoft.SourceLink.GitHub.props'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.SourceLink.GitHub.8.0.0\build\Microsoft.SourceLink.GitHub.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.SourceLink.GitHub.8.0.0\build\Microsoft.SourceLink.GitHub.targets'))" />
</Target>
</Project>

View File

@ -74,5 +74,7 @@
<Filter>Resource Files</Filter>
</None>
<None Include="Vanara.PInvoke.VssApi.nuspec" />
<None Include="packages.config" />
<None Include="cpp.hint" />
</ItemGroup>
</Project>

View File

@ -6,7 +6,7 @@ namespace Vanara { namespace PInvoke { namespace VssApi {
Vanara::PInvoke::VssApi::VSS_COMPONENTINFO CVssWMComponent::GetComponentInfo() {
RefreshInfo();
return Marshal::PtrToStructure<Vanara::PInvoke::VssApi::VSS_COMPONENTINFO>(IntPtr((void*)pInfo));
return (Vanara::PInvoke::VssApi::VSS_COMPONENTINFO)Marshal::PtrToStructure(IntPtr((void*)pInfo), Vanara::PInvoke::VssApi::VSS_COMPONENTINFO::typeid);
}
void CVssExamineWriterMetadata::RefreshRestoreMethod()
@ -41,12 +41,21 @@ namespace Vanara { namespace PInvoke { namespace VssApi {
Vanara::PInvoke::VssApi::VSS_SOURCE_TYPE% pSource)
{
::VSS_ID inst, writer;
SafeBSTR name;
SafeBSTR name, wrName;
::VSS_USAGE_TYPE use;
::VSS_SOURCE_TYPE src;
Utils::ThrowIfFailed(pNative->GetIdentity(&inst, &writer, &name, &use, &src));
::IVssExamineWriterMetadataEx* pNativeEx = nullptr;
if (pNative->QueryInterface(::IID_IVssExamineWriterMetadataEx, (void**)&pNativeEx) >= 0)
{
Utils::ThrowIfFailed(pNativeEx->GetIdentityEx(&inst, &writer, &wrName, &name, &use, &src));
}
else
{
Utils::ThrowIfFailed(pNative->GetIdentity(&inst, &writer, &name, &use, &src));
}
pidInstance = Utils::FromGUID(inst);
pidWriter = Utils::FromGUID(writer);
pbstrWriterName = wrName;
pbstrInstanceName = name;
pUsage = static_cast<Vanara::PInvoke::VssApi::VSS_USAGE_TYPE>(use);
pSource = static_cast<Vanara::PInvoke::VssApi::VSS_SOURCE_TYPE>(src);

View File

@ -31,9 +31,9 @@ namespace Vanara {
return f##prop; } }
DEFINE_WM_COMP_ROLIST(DatabaseFiles, IVssWMFiledesc, cDatabases, GetDatabaseFile, CVssWMFiledesc)
DEFINE_WM_COMP_ROLIST(Files, IVssWMFiledesc, cFileCount, GetFile, CVssWMFiledesc)
DEFINE_WM_COMP_ROLIST(DatabaseLogFiles, IVssWMFiledesc, cLogFiles, GetDatabaseLogFile, CVssWMFiledesc)
DEFINE_WM_COMP_ROLIST(Dependencies, IVssWMDependency, cDependencies, GetDependency, CVssWMDependency)
DEFINE_WM_COMP_ROLIST(Files, IVssWMFiledesc, cFileCount, GetFile, CVssWMFiledesc)
DEFINE_WM_COMP_ROLIST(DatabaseLogFiles, IVssWMFiledesc, cLogFiles, GetDatabaseLogFile, CVssWMFiledesc)
DEFINE_WM_COMP_ROLIST(Dependencies, IVssWMDependency, cDependencies, GetDependency, CVssWMDependency)
private:
::VSS_COMPONENTINFO* pInfo;
@ -80,7 +80,7 @@ namespace Vanara {
SafeComPtr<::IVssBackupComponentsEx3*> p = pNative;
Utils::ThrowIfFailed(p->AddSnapshotToRecoverySet(SmartGuid(snapshotId), dwFlags, SafeWString(pwszDestinationVolume)));
}
virtual Guid AddToSnapshotSet(String^ pwszVolumeName, Guid ProviderId)
virtual Guid AddToSnapshotSet(String^ pwszVolumeName, [System::Runtime::InteropServices::Optional] Guid ProviderId)
{
VSS_ID id;
Utils::ThrowIfFailed(pNative->AddToSnapshotSet(SafeWString(pwszVolumeName), SmartGuid(ProviderId), &id));
@ -100,13 +100,14 @@ namespace Vanara {
Utils::ThrowIfFailed(p->BreakSnapshotSetEx(SmartGuid(SnapshotSetID), static_cast<::VSS_HARDWARE_OPTIONS>(dwBreakFlags), &pa));
return mgd_cast(IVssAsync, pa);
}
virtual void DeleteSnapshots(Guid SourceObjectId, VSS_OBJECT_TYPE eSourceObjectType, Boolean bForceDelete, [System::Runtime::InteropServices::Out] Int32% plDeletedSnapshots, [System::Runtime::InteropServices::Out] Guid% pNondeletedSnapshotID)
virtual HRESULT DeleteSnapshots(Guid SourceObjectId, VSS_OBJECT_TYPE eSourceObjectType, Boolean bForceDelete, [System::Runtime::InteropServices::Out] Int32% plDeletedSnapshots, [System::Runtime::InteropServices::Out] Guid% pNondeletedSnapshotID)
{
LONG dSnap;
GUID sId;
Utils::ThrowIfFailed(pNative->DeleteSnapshots(SmartGuid(SourceObjectId), static_cast<::VSS_OBJECT_TYPE>(eSourceObjectType), bForceDelete, &dSnap, &sId));
LONG dSnap = 0;
GUID sId = { };
auto hr = pNative->DeleteSnapshots(SmartGuid(SourceObjectId), static_cast<::VSS_OBJECT_TYPE>(eSourceObjectType), bForceDelete, &dSnap, &sId);
plDeletedSnapshots = dSnap;
pNondeletedSnapshotID = Utils::FromGUID(sId);
return hr;
}
virtual void DisableWriterClasses([In] array<Guid>^ rgWriterClassId)
{
@ -173,11 +174,14 @@ namespace Vanara {
Utils::ThrowIfFailed(pNative->GatherWriterStatus(&pa));
return mgd_cast(IVssAsync, pa);
}
virtual void GetRootAndLogicalPrefixPaths(String^ pwszFilePath, [System::Runtime::InteropServices::Out] String^% ppwszRootPath, [System::Runtime::InteropServices::Out] String^% ppwszLogicalPrefix, [System::Runtime::InteropServices::Optional] Boolean bNormalizeFQDNforRootPath)
virtual void GetRootAndLogicalPrefixPaths(String^ pwszFilePath, [System::Runtime::InteropServices::Out] String^% ppwszRootPath,
[System::Runtime::InteropServices::Out] String^% ppwszLogicalPrefix, [System::Runtime::InteropServices::Optional] Boolean bNormalizeFQDNforRootPath)
{
SafeComPtr<::IVssBackupComponentsEx4*> p = pNative;
VSS_PWSZ rPath, lPref;
Utils::ThrowIfFailed(p->GetRootAndLogicalPrefixPaths(SafeWString(pwszFilePath), &rPath, &lPref, bNormalizeFQDNforRootPath));
ppwszRootPath = Marshal::PtrToStringUni(IntPtr(rPath));
ppwszLogicalPrefix = Marshal::PtrToStringUni(IntPtr(lPref));
}
virtual Guid GetSessionId()
{
@ -190,7 +194,7 @@ namespace Vanara {
{
::VSS_SNAPSHOT_PROP prop;
Utils::ThrowIfFailed(pNative->GetSnapshotProperties(SmartGuid(SnapshotId), &prop));
return Marshal::PtrToStructure<VSS_SNAPSHOT_PROP>(IntPtr(&prop));
return (VSS_SNAPSHOT_PROP)Marshal::PtrToStructure(IntPtr(&prop), VSS_SNAPSHOT_PROP::typeid);
}
virtual IVssAsync^ ImportSnapshots()
{
@ -208,7 +212,7 @@ namespace Vanara {
}
virtual Boolean IsVolumeSupported(Guid ProviderId, String^ pwszVolumeName)
{
::BOOL b;
::BOOL b = 0;
Utils::ThrowIfFailed(pNative->IsVolumeSupported(SmartGuid(ProviderId), SafeWString(pwszVolumeName), &b));
return b;
}
@ -357,8 +361,8 @@ namespace Vanara {
return f##prop; } }
DEFINE_BC_ROLIST(WriterComponents, IVssWriterComponentsExt^, GetWriterComponentsCount)
DEFINE_BC_ROLIST(WriterMetadata, IVssExamineWriterMetadata^, GetWriterMetadataCount)
DEFINE_BC_ROLIST(WriterStatus, VssWriterStatus, GetWriterStatusCount)
DEFINE_BC_ROLIST(WriterMetadata, IVssExamineWriterMetadata^, GetWriterMetadataCount)
DEFINE_BC_ROLIST(WriterStatus, VssWriterStatus, GetWriterStatusCount)
};
value struct VSS_RESTORE_METHOD

View File

@ -22,13 +22,20 @@ DEFINE_COMP_ROLIST(AlternateLocationMappings, GetAlternateLocationMappingCount,
DEFINE_COMP_ROLIST(NewTargets, GetNewTargetCount, IVssWMFiledesc, GetNewTarget, CVssWMFiledesc)
void CVssComponent::AddDifferencedFile(VssDifferencedFile item)
{
auto llft = item.LastModifyTime.ToFileTime();
::FILETIME ft = *(::FILETIME*)&llft;
Utils::ThrowIfFailed(pNative->AddDifferencedFilesByLastModifyTime(SafeWString(item.Path), SafeWString(item.FileSpec), item.Recursive, ft));
}
VssDifferencedFile CVssComponent::GetDifferencedFilesItem(int i)
{
SafeBSTR path, filespec, lsn;
::BOOL recur;
::FILETIME ft;
Utils::ThrowIfFailed(pNative->GetDifferencedFile(i, &path, &filespec, &recur, &lsn, &ft));
VssDifferencedFile e;
VssDifferencedFile e {};
e.Path = path;
e.FileSpec = filespec;
e.Recursive = recur;
@ -37,13 +44,6 @@ VssDifferencedFile CVssComponent::GetDifferencedFilesItem(int i)
return e;
}
void CVssComponent::AddDifferencedFile(VssDifferencedFile item)
{
auto llft = item.LastModifyTime.ToFileTime();
::FILETIME ft = *(::FILETIME*)&llft;
Utils::ThrowIfFailed(pNative->AddDifferencedFilesByLastModifyTime(SafeWString(item.Path), SafeWString(item.FileSpec), item.Recursive, ft));
}
IAppendOnlyList<VssDifferencedFile>^ CVssComponent::DifferencedFiles::get()
{
return gcnew AppendOnlyList<Vanara::PInvoke::VssApi::VssDifferencedFile>(
@ -128,7 +128,7 @@ void CVssComponent::GetFailure(Vanara::PInvoke::HRESULT% phr, Vanara::PInvoke::H
void CVssComponent::GetRollForward(VSS_ROLLFORWARD_TYPE% pRollType, System::String^% pbstrPoint)
{
SafeComPtr<::IVssComponentEx*> p = pNative;
::VSS_ROLLFORWARD_TYPE type;
::VSS_ROLLFORWARD_TYPE type{};
SafeBSTR pt;
Utils::ThrowIfFailed(p->GetRollForward(&type, &pt));
pRollType = static_cast<VSS_ROLLFORWARD_TYPE>(type);

View File

@ -31,4 +31,4 @@ namespace Vanara { namespace PInvoke { namespace VssApi {
return HRESULT(hr);
}
}}}
}}}

View File

@ -8,7 +8,7 @@ using namespace Runtime::InteropServices;
namespace Vanara { namespace PInvoke { namespace VssApi {
/// <summary>Contains methods that create VSS objects.</summary>
/// <summary>Exposes methods that create the VSS objects <see cref="IVssExamineWriterMetadata"/>, <see cref="IVssExpressWriter"/>, and <see cref="IVssBackupComponents"/>.</summary>
public ref class VssFactory abstract sealed
{
public:

16
PInvoke/VssApi/cpp.hint Normal file
View File

@ -0,0 +1,16 @@
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers
// such as names of functions and macros.
// For more information see https://go.microsoft.com/fwlink/?linkid=865984
#define DEFINE_COMP_ROLIST(prop, cFunc, iElem, gFunc, cElem) IReadOnlyList<Vanara::PInvoke::VssApi::IVssWMFiledesc^>^ CVssComponent::prop::get() { UINT c; Utils::ThrowIfFailed(pNative->cFunc(&c)); auto ret = gcnew List<iElem^>(); ::iElem* v; for (UINT i = 0; i < c; i++) { pNative->gFunc(i, &v); ret->Add(gcnew cElem(v)); } return ret; }
#define DEFINE_WRAPPER_STRING_PROP(prop, meth) virtual property String^ prop { String^ get() { SafeBSTR v; Utils::ThrowIfFailed(pNative->meth(&v)); return (String^)v; } }
#define DEFINE_WRAPPER_PROP(prop, rtype, gtype, meth) DEFINE_WRAPPER_PROPC(prop, rtype, gtype, meth, static_cast<rtype>)
#define DEFINE_WRAPPER_QI_PROP(prop, rtype, gtype, meth, qitf) virtual property rtype prop { rtype get() { SafeComPtr<qitf*> p = pNative; gtype v; Utils::ThrowIfFailed(p->meth(&v)); return static_cast<rtype>(v); } }
#define DEFINE_WRAPPER_STRING_GS_PROP(prop) virtual property String^ prop { String^ get() { SafeBSTR v; Utils::ThrowIfFailed(pNative->Get##prop(&v)); return (String^)v; } void set(String^ value) { SafeString v(value); Utils::ThrowIfFailed(pNative->Set##prop(v)); } }
#define DEFINE_WRAPPER_PROPC(prop, rtype, gtype, meth, conv) virtual property rtype prop { rtype get() { gtype v; Utils::ThrowIfFailed(pNative->meth(&v)); return conv(v); } }
#define DEFINE_WRAPPER_GS_PROP(prop, rtype, gtype) virtual property rtype prop { rtype get() { gtype v; Utils::ThrowIfFailed(pNative->Get##prop(&v)); return static_cast<rtype>(v); } void set(rtype value) { Utils::ThrowIfFailed(pNative->Set##prop(static_cast<gtype>(value))); } }
#define DEFINE_WRAPPER_STRING_QI_GS_PROP(prop, qitf) virtual property String^ prop { String^ get() { SafeComPtr<qitf*> p = pNative; SafeBSTR v; Utils::ThrowIfFailed(p->Get##prop(&v)); return (String^)v; } void set(String^ value) { SafeComPtr<qitf*> p = pNative; SafeString v(value); Utils::ThrowIfFailed(p->Set##prop(v)); } }
#define DEFINE_WRAPPER_STRING_QI_PROP(prop, meth, qitf) virtual property String^ prop { String^ get() { SafeComPtr<qitf*> p = pNative; SafeBSTR v; Utils::ThrowIfFailed(p->meth(&v)); return (String^)v; } }
#define DEFINE_WM_COMP_ROLIST(prop, itf, cfield, gfunc, cwrap) private: ListImplBase<itf^>^ f##prop; int Get##prop##Count() { RefreshInfo(); return pInfo->cfield; } itf^ Get##prop(int i) { ::itf* p; Utils::ThrowIfFailed(pNative->gfunc(i, &p)); return gcnew cwrap(p); } public: property IReadOnlyList<itf^>^ prop { virtual IReadOnlyList<itf^>^ get() { if (!f##prop) f##prop = gcnew ListImplBase<itf^>(gcnew GetCount(this, &CVssWMComponent::Get##prop##Count), gcnew GetValue<itf^>(this, &CVssWMComponent::Get##prop)); return f##prop; } }
#define mgd_cast(T, t) (T^)Marshal::GetObjectForIUnknown(IntPtr((void*)t));
#define DEFINE_BC_ROLIST(prop, itf, ref) private: ListImplBase<itf>^ f##prop; int Get##prop##Count() { UINT c; Utils::ThrowIfFailed(pNative->ref(&c)); return c; } public: property IReadOnlyList<itf>^ prop { virtual IReadOnlyList<itf>^ get() { if (!f##prop) f##prop = gcnew ListImplBase<itf>(gcnew GetCount(this, &CVssBackupComponents::Get##prop##Count), gcnew GetValue<itf>(this, &CVssBackupComponents::Get##prop)); return f##prop; } }
#define DEFINE_EWM_ROLIST(prop, itf, gfunc, cwrap, ref, cexp) private: ListImplBase<itf^>^ f##prop; int Get##prop##Count() { ref(); return cexp; } itf^ Get##prop(int i) { ::itf* p; Utils::ThrowIfFailed(pNative->gfunc(i, &p)); return gcnew cwrap(p); } public: property IReadOnlyList<itf^>^ prop { virtual IReadOnlyList<itf^>^ get() { if (!f##prop) f##prop = gcnew ListImplBase<itf^>(gcnew GetCount(this, &CVssExamineWriterMetadata::Get##prop##Count), gcnew GetValue<itf^>(this, &CVssExamineWriterMetadata::Get##prop)); return f##prop; } }

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Build.Tasks.Git" version="8.0.0" targetFramework="native" developmentDependency="true" />
<package id="Microsoft.SourceLink.Common" version="8.0.0" targetFramework="native" developmentDependency="true" />
<package id="Microsoft.SourceLink.GitHub" version="8.0.0" targetFramework="native" developmentDependency="true" />
<package id="Vanara.Core" version="4.0.0-beta" targetFramework="native" developmentDependency="true" />
<package id="Vanara.PInvoke.Shared" version="4.0.0-beta" targetFramework="native" developmentDependency="true" />
</packages>

View File

@ -20,8 +20,8 @@
#include "Utils.h"
#include "Macros.h"
#using <Vanara.Core.dll>
#using <Vanara.PInvoke.Shared.dll>
#using <Vanara.PInvoke.VssApiMgd.dll>
//#using <Vanara.Core.dll>
//#using <Vanara.PInvoke.Shared.dll>
//#using <Vanara.PInvoke.VssApiMgd.dll>
#endif //PCH_H

View File

@ -1,31 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<ProjectExtensions>
<SupportedDlls>vssapi.dll</SupportedDlls>
<Exclude>true</Exclude>
</ProjectExtensions>
<PropertyGroup>
<Description>PInvoke API (methods, structures and constants) imported from Windows Volume Shadow Copy Service (VssApi.dll).</Description>
<AssemblyTitle>$(AssemblyName)</AssemblyTitle>
<AssemblyName>Vanara.PInvoke.VssApiMgd</AssemblyName>
<PackageId>$(AssemblyName)</PackageId>
<PackageTags>pinvoke;vanara;net-extensions;interop;VSS;VssApi;volume shadow copy service</PackageTags>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageReleaseNotes>Currently implements:
Functions
IsVolumeSnapshotted ShouldBlockRevert
Structures
VDS_INTERCONNECT VDS_LUN_INFORMATION VDS_STORAGE_DEVICE_ID_DESCRIPTOR VDS_STORAGE_IDENTIFIER VssDifferencedFile VssDirectedTarget VssPartialFile VssRestoreSubcomponent VssWriterStatus VSS_COMPONENTINFO VSS_DIFF_AREA_PROP VSS_DIFF_VOLUME_PROP VSS_MGMT_OBJECT_PROP VSS_MGMT_OBJECT_UNION VSS_OBJECT_PROP VSS_OBJECT_UNION VSS_PROVIDER_PROP VSS_SNAPSHOT_PROP VSS_VOLUME_PROP VSS_VOLUME_PROTECTION_INFO
Interfaces
IVssAdmin IVssAdminEx IVssAsync IVssCreateExpressWriterMetadata IVssDifferentialSoftwareSnapshotMgmt IVssDifferentialSoftwareSnapshotMgmt2 IVssDifferentialSoftwareSnapshotMgmt3 IVssEnumMgmtObject IVssEnumObject IVssFileShareSnapshotProvider IVssHardwareSnapshotProvider IVssHardwareSnapshotProviderEx IVssProviderCreateSnapshotSet IVssProviderNotifications IVssSnapshotMgmt IVssSnapshotMgmt2 IVssSoftwareSnapshotProvider
</PackageReleaseNotes>
<PackageReadmeFile>pkgreadme.md</PackageReadmeFile>
<IsPackable>false</IsPackable>
<!--<TargetFrameworks>net6.0</TargetFrameworks>-->
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\Vanara.Core.csproj" />
<ProjectReference Include="..\Shared\Vanara.PInvoke.Shared.csproj" />
</ItemGroup>
<Target Name="WipeObj" BeforeTargets="Clean;CoreClean">
<!-- obj -->
<RemoveDir Directories="$(ProjectDir)$(BaseIntermediateOutputPath)" ContinueOnError="true" />
</Target>
</Project>

View File

@ -635,7 +635,7 @@ public interface IVssBackupComponents
// https://docs.microsoft.com/en-us/windows/win32/api/vsbackup/nf-vsbackup-ivssbackupcomponents-deletesnapshots HRESULT
// DeleteSnapshots( [in] VSS_ID SourceObjectId, [in] VSS_OBJECT_TYPE eSourceObjectType, [in] BOOL bForceDelete, [out] LONG
// *plDeletedSnapshots, [out] VSS_ID *pNondeletedSnapshotID );
void DeleteSnapshots(Guid SourceObjectId, VSS_OBJECT_TYPE eSourceObjectType, bool bForceDelete,
HRESULT DeleteSnapshots(Guid SourceObjectId, VSS_OBJECT_TYPE eSourceObjectType, bool bForceDelete,
out int plDeletedSnapshots, out Guid pNondeletedSnapshotID);
/// <summary>The <c>DisableWriterClasses</c> method prevents a specific class of writers from receiving any events.</summary>

View File

@ -1966,6 +1966,13 @@ public struct VSS_PROVIDER_PROP
/// <summary>Class identifier of the component registered in the local machine's COM catalog.</summary>
public Guid m_ClassId;
/// <summary>Releases unmanaged resources.</summary>
public void Dispose()
{
m_pwszProviderName.Free();
m_pwszProviderVersion.Free();
}
}
/// <summary>The <c>VSS_SNAPSHOT_PROP</c> structure contains the properties of a shadow copy or shadow copy set.</summary>
@ -2066,4 +2073,15 @@ public struct VSS_SNAPSHOT_PROP
/// <summary>Current shadow copy creation status. See VSS_SNAPSHOT_STATE.</summary>
public VSS_SNAPSHOT_STATE m_eStatus;
/// <summary>Releases unmanaged resources.</summary>
public void Dispose()
{
m_pwszSnapshotDeviceObject.Free();
m_pwszOriginalVolumeName.Free();
m_pwszOriginatingMachine.Free();
m_pwszServiceMachine.Free();
m_pwszExposedName.Free();
m_pwszExposedPath.Free();
}
}

View File

@ -12,7 +12,7 @@
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);NETSDK1105;NETSDK1138</MSBuildWarningsAsMessages>
</PropertyGroup>
<ItemGroup Condition="!$(MSBuildProjectDirectory.Contains('UnitTests'))" >
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<SourceRoot Include="$(MSBuildThisFileDirectory)/" />
</ItemGroup>
</Project>

View File

@ -2,7 +2,6 @@
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<AssemblyName>UnitTest.PInvoke.VssApi</AssemblyName>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic">
@ -18,6 +17,6 @@
<ItemGroup>
<ProjectReference Include="..\..\..\PInvoke\Kernel32\Vanara.PInvoke.Kernel32.csproj" />
<ProjectReference Include="..\..\..\PInvoke\VssApiMgd\Vanara.PInvoke.VssApiMgd.csproj" />
<ProjectReference Include="..\..\..\PInvoke\VssApi\VssApi.vcxproj" />
<ProjectReference Include="..\..\..\PInvoke\VssApi\Vanara.PInvoke.VssApi.vcxproj" />
</ItemGroup>
</Project>

View File

@ -9,7 +9,15 @@ namespace Vanara.PInvoke.Tests;
[TestFixture]
public class VssApiTests
{
static readonly Guid ProviderId = new("{b5946137-7b9f-4925-af80-51abd60b20d5}");
static readonly Lazy<Guid> ProviderId = new(() =>
{
Assert.That(VssFactory.CreateVssBackupComponents(out IVssBackupComponents backup), ResultIs.Successful);
backup.InitializeForBackup();
VSS_OBJECT_PROP prop = backup.Query(default, VSS_OBJECT_TYPE.VSS_OBJECT_NONE, VSS_OBJECT_TYPE.VSS_OBJECT_PROVIDER).Enumerate().FirstOrDefault();
Assert.That(prop.Obj.Prov.m_ProviderId, Is.Not.EqualTo(Guid.Empty));
return prop.Obj.Prov.m_ProviderId;
});
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
string[] vols;
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
@ -25,13 +33,39 @@ public class VssApiTests
{
}
[Test]
public void OpenStreamOnVSSCopy()
{
Assert.That(VssFactory.CreateVssBackupComponents(out IVssBackupComponents backup), ResultIs.Successful);
backup.InitializeForBackup();
backup.GatherWriterMetadata();
backup.FreeWriterMetadata();
backup.SetBackupState(false, true, VSS_BACKUP_TYPE.VSS_BT_FULL, false);
var setId = backup.StartSnapshotSet();
try
{
Assert.True(backup.IsVolumeSupported(default, "C:\\"));
var snapId = backup.AddToSnapshotSet("C:\\");
var props = backup.GetSnapshotProperties(snapId);
TestContext.WriteLine(props.m_pwszSnapshotDeviceObject);
props.Dispose();
}
finally
{
HRESULT hr = backup.DeleteSnapshots(setId, VSS_OBJECT_TYPE.VSS_OBJECT_SNAPSHOT_SET, true, out _, out var badId);
if (hr.Failed)
TestContext.WriteLine($"Failed to delete snapshot {badId}");
}
_ = backup.PrepareForBackup();
}
[Test]
public void QueryDiffAreasForVolumeTest()
{
Assert.That(vols, Has.Length.GreaterThan(0));
IVssSnapshotMgmt imgr = new();
var diffmgr = imgr.GetProviderMgmtInterface<IVssDifferentialSoftwareSnapshotMgmt>(ProviderId);
var diffmgr = imgr.GetProviderMgmtInterface<IVssDifferentialSoftwareSnapshotMgmt>(ProviderId.Value);
foreach (var vol in vols)
{
TestContext.WriteLine($"Volume: {vol}");
@ -65,9 +99,14 @@ public class VssApiTests
}
[Test]
public void Test()
public void TestBackupSnapshots()
{
Assert.That(VssFactory.CreateVssBackupComponents(out IVssBackupComponents vss), ResultIs.Successful);
vss.InitializeForBackup();
Assert.That(VssFactory.CreateVssBackupComponents(out IVssBackupComponents backup), ResultIs.Successful);
backup.InitializeForBackup();
foreach (VSS_OBJECT_PROP prop in backup.Query(default, VSS_OBJECT_TYPE.VSS_OBJECT_NONE, VSS_OBJECT_TYPE.VSS_OBJECT_SNAPSHOT).Enumerate())
{
TestContext.WriteLine($"Snapshot: {prop.Obj.Snap.m_pwszOriginalVolumeName} ({prop.Obj.Snap.m_SnapshotId})");
prop.Obj.Snap.Dispose();
}
}
}

View File

@ -198,7 +198,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vanara.PInvoke.Version", "P
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vanara.PInvoke.VirtDisk", "PInvoke\VirtDisk\Vanara.PInvoke.VirtDisk.csproj", "{5CE784D4-42B7-4AA7-B2D0-E175C7FB40C8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Vanara.PInvoke.VssApi", "PInvoke\VssApi\VssApi.vcxproj", "{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Vanara.PInvoke.VssApi", "PInvoke\VssApi\Vanara.PInvoke.VssApi.vcxproj", "{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}"
ProjectSection(ProjectDependencies) = postProject
{39AEDD51-C627-41B9-96D3-44F481ED4E7C} = {39AEDD51-C627-41B9-96D3-44F481ED4E7C}
EndProjectSection
@ -2046,8 +2046,8 @@ Global
{5CE784D4-42B7-4AA7-B2D0-E175C7FB40C8}.Release|x64.Build.0 = Release|x64
{5CE784D4-42B7-4AA7-B2D0-E175C7FB40C8}.Release|x86.ActiveCfg = Release|x86
{5CE784D4-42B7-4AA7-B2D0-E175C7FB40C8}.Release|x86.Build.0 = Release|x86
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Debug|Any CPU.ActiveCfg = Debug|x64
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Debug|Any CPU.Build.0 = Debug|x64
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Debug|Any CPU.ActiveCfg = Debug|Win32
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Debug|Any CPU.Build.0 = Debug|Win32
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Debug|x64.ActiveCfg = Debug|x64
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Debug|x64.Build.0 = Debug|x64
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Debug|x86.ActiveCfg = Debug|Win32
@ -2058,7 +2058,8 @@ Global
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.DebugNoTests|x64.Build.0 = Debug|x64
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.DebugNoTests|x86.ActiveCfg = Debug|Win32
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.DebugNoTests|x86.Build.0 = Debug|Win32
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Release|Any CPU.ActiveCfg = Release|x64
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Release|Any CPU.ActiveCfg = Release|Win32
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Release|Any CPU.Build.0 = Release|Win32
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Release|x64.ActiveCfg = Release|x64
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Release|x64.Build.0 = Release|x64
{11EF8FFF-25DE-4ADB-A951-FA10A421FFE4}.Release|x86.ActiveCfg = Release|Win32
@ -3456,8 +3457,11 @@ Global
{B62EE3FD-4AA8-4A99-AAB3-3A4022AEB682}.DebugNoTests|x86.ActiveCfg = DebugNoTests|x86
{B62EE3FD-4AA8-4A99-AAB3-3A4022AEB682}.DebugNoTests|x86.Build.0 = DebugNoTests|x86
{B62EE3FD-4AA8-4A99-AAB3-3A4022AEB682}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B62EE3FD-4AA8-4A99-AAB3-3A4022AEB682}.Release|Any CPU.Build.0 = Release|Any CPU
{B62EE3FD-4AA8-4A99-AAB3-3A4022AEB682}.Release|x64.ActiveCfg = Release|x64
{B62EE3FD-4AA8-4A99-AAB3-3A4022AEB682}.Release|x64.Build.0 = Release|x64
{B62EE3FD-4AA8-4A99-AAB3-3A4022AEB682}.Release|x86.ActiveCfg = Release|x86
{B62EE3FD-4AA8-4A99-AAB3-3A4022AEB682}.Release|x86.Build.0 = Release|x86
{35B95D64-CC7E-48B4-B104-4886411531AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35B95D64-CC7E-48B4-B104-4886411531AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35B95D64-CC7E-48B4-B104-4886411531AC}.Debug|x64.ActiveCfg = Debug|x64