Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuget package for native (C++) and managed (.NET) projects #926

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Project/Nuget/Native/MediaInfoLib.Native.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaInfoLib.Native</id>
<title>MediaInfoLib DLL and header for native(c++) projects</title>
<version>18.08.1</version>
<authors>MediaArea.net</authors>
<copyright>Copyright (c) MediaArea.net SARL.</copyright>
<tags>mediainfo mediainfolib libmediainfo native</tags>
<description>MediaInfo is a convenient unified display of the most relevant technical and tag data for video and audio files.</description>
<language>en-US</language>
<projectUrl>https://mediaarea.net/MediaInfo</projectUrl>
<licenseUrl>https://github.com/MediaArea/MediaInfoLib/blob/master/LICENSE</licenseUrl>
<iconUrl>https://mediaarea.net/_/img/MediaInfo_90x90.png</iconUrl>
</metadata>

<files>
<file src="..\..\MSVC2017\Win32\Release\MediaInfo.dll" target="build/native/x86/" />
<file src="..\..\MSVC2017\Win32\Release\MediaInfo.lib" target="build/native/x86/" />
<file src="..\..\MSVC2017\x64\Release\MediaInfo.dll" target="build/native/x64/" />
<file src="..\..\MSVC2017\x64\Release\MediaInfo.lib" target="build/native/x64/" />
<file src="MediaInfoLib.Native.targets" target="build/native/" />
<file src="..\..\..\Source\MediaInfoDLL\MediaInfoDLL.h" target="build/native/Include/" />
</files>
</package>
33 changes: 33 additions & 0 deletions Project/Nuget/Native/MediaInfoLib.Native.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="MediaInfoLib_init">
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\build\native\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<ResourceCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\build\native\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="x64" Condition="'$(Platform.ToLower())' == 'x64'">
<Link>
<AdditionalDependencies>$(MSBuildThisFileDirectory)..\..\build\native\x64\MediaInfo.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="Win32" Condition="'$(Platform.ToLower())' == 'win32'">
<Link>
<AdditionalDependencies>$(MSBuildThisFileDirectory)..\..\build\native\x86\MediaInfo.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Target Name="MediaInfoLib_init">
</Target>
<Target Name="CopyMediaInfoDll" AfterTargets="AfterBuild">
<ItemGroup Label="x64" Condition="'$(Platform.ToLower())' == 'x64'">
<MediaInfoDll Include="$(MSBuildThisFileDirectory)..\..\build\native\x64\MediaInfo.dll"/>
</ItemGroup>
<ItemGroup Label="Win32" Condition="'$(Platform.ToLower())' == 'win32'">
<MediaInfoDll Include="$(MSBuildThisFileDirectory)..\..\build\native\x86\MediaInfo.dll"/>
</ItemGroup>
<Copy SourceFiles="@(MediaInfoDll)" DestinationFolder="$(OutputPath)" />
</Target>
</Project>
12 changes: 12 additions & 0 deletions Project/Nuget/Wrapper/MediaInfoLib.Wrapper.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>MediaInfoLib.Wrapper</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\..\Source\MediaInfoDLL\MediaInfoDLL.cs" Link="MediaInfoDLL.cs" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions Project/Nuget/Wrapper/MediaInfoLib.Wrapper.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>MediaInfoLib.Wrapper</id>
<version>18.8.1</version>
<title>MediaInfoLib DLL wrapper for .NET projects</title>
<authors>MediaArea.net</authors>
<owners>MediaArea.net</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://github.com/MediaArea/MediaInfoLib/blob/master/LICENSE</licenseUrl>
<projectUrl>https://mediaarea.net/MediaInfo</projectUrl>
<iconUrl>https://mediaarea.net/_/img/MediaInfo_90x90.png</iconUrl>
<description>MediaInfo is a convenient unified display of the most relevant technical and tag data for video and audio files.</description>
<copyright>Copyright (c) MediaArea.net SARL.</copyright>
<language>en-US</language>
<tags>mediainfo mediainfolib libmediainfo</tags>
<dependencies>
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
</package>
88 changes: 69 additions & 19 deletions Source/MediaInfoDLL/MediaInfoDLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@

namespace MediaInfoLib
{
internal enum LoadLibraryFlags : uint
{
DEFAULT = 0x00000000,
DONT_RESOLVE_DLL_REFERENCES = 0x00000001,
LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010,
LOAD_LIBRARY_AS_DATAFILE = 0x00000002,
LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040,
LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020,
LOAD_LIBRARY_SEARCH_APPLICATION_DIR = 0x00000200,
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000,
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 0x00000100,
LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800,
LOAD_LIBRARY_SEARCH_USER_DIRS = 0x00000400,
LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008,
}

public enum StreamKind
{
General,
Expand Down Expand Up @@ -71,6 +87,13 @@ public enum Status

public class MediaInfo
{
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags);

[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool FreeLibrary(IntPtr hModule);

//Import of DLL functions. DO NOT USE until you know what you do (MediaInfo DLL do NOT use CoTaskMemAlloc to allocate memory)
[DllImport("MediaInfo.dll")]
private static extern IntPtr MediaInfo_New();
Expand Down Expand Up @@ -122,6 +145,12 @@ public class MediaInfo
//MediaInfo class
public MediaInfo()
{
Module = LoadLibraryEx("MediaInfo.dll", IntPtr.Zero, LoadLibraryFlags.DEFAULT |
LoadLibraryFlags.LOAD_LIBRARY_SEARCH_APPLICATION_DIR |
LoadLibraryFlags.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS |
LoadLibraryFlags.LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR |
LoadLibraryFlags.LOAD_LIBRARY_SEARCH_SYSTEM32);

try
{
Handle = MediaInfo_New();
Expand All @@ -135,7 +164,18 @@ public MediaInfo()
else
MustUseAnsi=false;
}
~MediaInfo() { if (Handle == (IntPtr)0) return; MediaInfo_Delete(Handle); }

~MediaInfo()
{
if (Module != (IntPtr)0)
FreeLibrary(Module);

if (Handle == (IntPtr)0)
return;

MediaInfo_Delete(Handle);
}

public int Open(String FileName)
{
if (Handle == (IntPtr)0)
Expand Down Expand Up @@ -218,6 +258,7 @@ public String Option(String Option, String Value)
public int State_Get() { if (Handle == (IntPtr)0) return 0; return (int)MediaInfo_State_Get(Handle); }
public int Count_Get(StreamKind StreamKind, int StreamNumber) { if (Handle == (IntPtr)0) return 0; return (int)MediaInfo_Count_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber); }
private IntPtr Handle;
private IntPtr Module;
private bool MustUseAnsi;

//Default values, if you know how to set default values in C#, say me
Expand All @@ -228,22 +269,6 @@ public String Option(String Option, String Value)
public int Count_Get(StreamKind StreamKind) { return Count_Get(StreamKind, -1); }
}

















public class MediaInfoList
{
//Import of DLL functions. DO NOT USE until you know what you do (MediaInfo DLL do NOT use CoTaskMemAlloc to allocate memory)
Expand All @@ -269,8 +294,32 @@ public class MediaInfoList
private static extern IntPtr MediaInfoList_Count_Get(IntPtr Handle, IntPtr FilePos, IntPtr StreamKind, IntPtr StreamNumber);

//MediaInfo class
public MediaInfoList() { Handle = MediaInfoList_New(); }
~MediaInfoList() { MediaInfoList_Delete(Handle); }
public MediaInfoList() {
Module = LoadLibraryEx("MediaInfo.dll", IntPtr.Zero, LoadLibraryFlags.DEFAULT |
LoadLibraryFlags.LOAD_LIBRARY_SEARCH_APPLICATION_DIR |
LoadLibraryFlags.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS |
LoadLibraryFlags.LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR |
LoadLibraryFlags.LOAD_LIBRARY_SEARCH_SYSTEM32);

try
{
Handle = MediaInfoList_New();
}
catch
{
Handle = (IntPtr)0;
}
}
~MediaInfoList()
{
if (Module != (IntPtr)0)
FreeLibrary(Module);

if (Handle == (IntPtr)0)
return;

MediaInfoList_Delete(Handle);
}
public int Open(String FileName, InfoFileOptions Options) { return (int)MediaInfoList_Open(Handle, FileName, (IntPtr)Options); }
public void Close(int FilePos) { MediaInfoList_Close(Handle, (IntPtr)FilePos); }
public String Inform(int FilePos) { return Marshal.PtrToStringUni(MediaInfoList_Inform(Handle, (IntPtr)FilePos, (IntPtr)0)); }
Expand All @@ -280,6 +329,7 @@ public class MediaInfoList
public int State_Get() { return (int)MediaInfoList_State_Get(Handle); }
public int Count_Get(int FilePos, StreamKind StreamKind, int StreamNumber) { return (int)MediaInfoList_Count_Get(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber); }
private IntPtr Handle;
private IntPtr Module;

//Default values, if you know how to set default values in C#, say me
public void Open(String FileName) { Open(FileName, 0); }
Expand Down