Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ied206 committed Oct 18, 2018
2 parents 75aa0ad + 936c9ae commit 31ae407
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 15 deletions.
11 changes: 5 additions & 6 deletions ManagedWimLib/ManagedWimLib.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net451;netstandard1.3;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard1.3;netstandard2.0</TargetFrameworks>
<Title>ManagedWimLib</Title>
<LangVersion>latest</LangVersion>
<Authors>Eric Biggers, Hajin Jang</Authors>
<Description>C# wrapper library for native wimlib.
Targets .Net Standard, supports Windows and Linux.</Description>
Supports Windows and Linux.</Description>
<Copyright>Copyright (c) 2018 Hajin Jang</Copyright>
<Company>Joveler</Company>
<PackageReleaseNotes>- .Net Standard support
- Add Linux support
- Add Wim.MountImage(), Wim.UnmountImage()</PackageReleaseNotes>
<PackageReleaseNotes>- Add .Net Framework 4.5.1 target</PackageReleaseNotes>
<PackageLicenseUrl>https://github.com/ied206/ManagedWimLib/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/ied206/ManagedWimLib</PackageProjectUrl>
<RepositoryUrl></RepositoryUrl>
<PackageTags>wim wimlib pinvoke interop</PackageTags>
<PackageIconUrl>https://raw.githubusercontent.com/ied206/ManagedWimLib/master/Image/Logo.png</PackageIconUrl>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
</PropertyGroup>
<Import Project="$(MSBuildProjectDirectory)\ManagedWimLib.targets" />
</Project>
16 changes: 11 additions & 5 deletions ManagedWimLib/ManagedWimLib.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@
<metadata>
<id>ManagedWimLib</id>
<title>ManagedWimLib</title>
<version>1.2.0</version>
<version>1.2.1</version>
<owners>ied206</owners>
<authors>Eric Biggers, Hajin Jang</authors>
<licenseUrl>https://github.com/ied206/ManagedWimLib/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/ied206/ManagedWimLib</projectUrl>
<iconUrl>https://raw.githubusercontent.com/ied206/ManagedWimLib/master/Image/Logo.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>C# pinvoke library for wimlib.
Targets .Net Standard 1.3 and 2.0, supports Windows and Linux.</description>
Supports Windows and Linux.</description>
<summary>C# pinvoke library for wimlib.</summary>
<releaseNotes>- .Net Standard 1.3 support
- Add Linux support
- Add Wim.MountImage(), Wim.UnmountImage()</releaseNotes>
<releaseNotes>- Add .Net Framework 4.5.1 target</releaseNotes>
<copyright>Copyright (c) 2018 Hajin Jang</copyright>
<tags>wim wimlib pinvoke interop</tags>
<dependencies>
<group targetFramework="net451"></group>
<group targetFramework="netstandard1.3"></group>
<group targetFramework="netstandard2.0"></group>
</dependencies>
</metadata>
<files>
<!-- .Net Framework 4.5.1 -->
<file src="bin\Release\net451\ManagedWimLib.dll" target="lib\net451" />
<file src="bin\Release\net451\ManagedWimLib.pdb" target="lib\net451" />
<file src="Precompiled\x86\libwim-15.dll" target="build\net451\Precompiled\x86" />
<file src="Precompiled\x64\libwim-15.dll" target="build\net451\Precompiled\x64" />
<file src="Precompiled\x64\libwim.so" target="build\net451\Precompiled\x64" />
<file src="ManagedWimLib.targets" target="build\net451\ManagedWimLib.targets" />
<!-- .Net Standard 1.3 -->
<file src="bin\Release\netstandard1.3\ManagedWimLib.dll" target="lib\netstandard1.3" />
<file src="bin\Release\netstandard1.3\ManagedWimLib.pdb" target="lib\netstandard1.3" />
Expand Down
6 changes: 5 additions & 1 deletion ManagedWimLib/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,15 @@ internal static class Linux
private static T GetFuncPtr<T>(string funcSymbol) where T : Delegate
{
IntPtr funcPtr;
#if! NET451
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
#endif
{
funcPtr = Win32.GetProcAddress(hModule, funcSymbol);
if (funcPtr == IntPtr.Zero)
throw new InvalidOperationException($"Cannot import [{funcSymbol}]", new Win32Exception());
}
#if !NET451
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
funcPtr = Linux.dlsym(hModule, funcSymbol);
Expand All @@ -140,6 +143,7 @@ private static T GetFuncPtr<T>(string funcSymbol) where T : Delegate
{
throw new PlatformNotSupportedException();
}
#endif

return Marshal.GetDelegateForFunctionPointer<T>(funcPtr);
}
Expand Down Expand Up @@ -1576,7 +1580,7 @@ internal static int ResolveImage(
/// corresponding header file.
/// </remarks>
internal static wimlib_get_version GetVersion;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate IntPtr wimlib_get_version_string();
internal static wimlib_get_version_string GetVersionString;
Expand Down
41 changes: 39 additions & 2 deletions ManagedWimLib/WimStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public static void GlobalInit(string libPath, InitFlags initFlags = InitFlags.DE
if (NativeMethods.Loaded)
throw new InvalidOperationException(NativeMethods.MsgAlreadyInited);

#if !NET451
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
#endif
{
NativeMethods.UseUtf16 = true;
NativeMethods.LongBitType = NativeMethods.LongBits.Long32;
Expand All @@ -115,6 +117,7 @@ public static void GlobalInit(string libPath, InitFlags initFlags = InitFlags.DE
throw new ArgumentException($"[{libPath}] is not a valid wimblib-15.dll");
}
}
#if !NET451
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
NativeMethods.UseUtf16 = false;
Expand Down Expand Up @@ -146,6 +149,7 @@ public static void GlobalInit(string libPath, InitFlags initFlags = InitFlags.DE
throw new ArgumentException($"[{libPath}] is not a valid libwim.so");
}
}
#endif

try
{
Expand All @@ -172,16 +176,20 @@ public static void GlobalCleanup()
{
NativeMethods.GlobalCleanup();
NativeMethods.ResetFunctions();
#if !NET451
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
#endif
{
int ret = NativeMethods.Win32.FreeLibrary(NativeMethods.hModule);
Debug.Assert(ret != 0);
}
#if !NET451
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
int ret = NativeMethods.Linux.dlclose(NativeMethods.hModule);
Debug.Assert(ret == 0);
}
#endif
NativeMethods.hModule = IntPtr.Zero;

if (File.Exists(ErrorFile))
Expand Down Expand Up @@ -1579,10 +1587,39 @@ public void UpdateImage(int image, UpdateCommand cmd, UpdateFlags updateFlags)
public void UpdateImage(int image, IEnumerable<UpdateCommand> cmds, UpdateFlags updateFlags)
{
ErrorCode ret;
int bits;

#if !NET451
switch (RuntimeInformation.ProcessArchitecture)
{
case Architecture.X86:
case Architecture.Arm:
bits = 32;
break;
case Architecture.X64:
case Architecture.Arm64:
bits = 64;
break;
default:
throw new PlatformNotSupportedException();
}
#else
switch (IntPtr.Size)
{
case 4:
bits = 32;
break;
case 8:
bits = 64;
break;
default:
throw new PlatformNotSupportedException();
}
#endif

switch (bits)
{
case 32:
UpdateCommand32[] cmds32 = cmds.Select(x => x.ToNativeStruct32()).ToArray();
try
{
Expand All @@ -1594,8 +1631,7 @@ public void UpdateImage(int image, IEnumerable<UpdateCommand> cmds, UpdateFlags
cmd32.Free();
}
break;
case Architecture.X64:
case Architecture.Arm64:
case 64:
UpdateCommand64[] cmds64 = cmds.Select(x => x.ToNativeStruct64()).ToArray();
try
{
Expand All @@ -1610,6 +1646,7 @@ public void UpdateImage(int image, IEnumerable<UpdateCommand> cmds, UpdateFlags
default:
throw new PlatformNotSupportedException();
}

WimLibException.CheckWimLibError(ret);
}
#endregion
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ ManagedWimLib can be installed via [nuget](https://www.nuget.org/packages/Manage

### Targeted .Net platforms

- .Net Framework 4.5.1
- .Net Standard 1.3 (.Net Framework 4.6+, .Net Core 1.0+)
- .Net Standard 2.0 (.Net Framework 4.6.1+, .Net Core 2.0+)

If you need .Net Framework 4.5 support, use Windows only [1.1.x branch](https://www.nuget.org/packages/ManagedWimLib/1.1.2).
If you need .Net Framework 4.5 support, use [1.1.x version](https://www.nuget.org/packages/ManagedWimLib/1.1.2) instead.

### Supported OS platforms

Expand Down

0 comments on commit 31ae407

Please sign in to comment.