Fix SevenZipLibraryManager.LoadLibrary

This commit is contained in:
YoshiRulz 2019-10-14 00:51:44 +10:00
parent 7df71f2c86
commit 462bd891af
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 44 additions and 44 deletions

View File

@ -134,54 +134,54 @@ namespace SevenZip
/// <param name="format">Archive format</param> /// <param name="format">Archive format</param>
public static void LoadLibrary(object user, Enum format) public static void LoadLibrary(object user, Enum format)
{ {
lock (_syncRoot) lock (_syncRoot)
{
if (_inArchives == null
#if COMPRESS
|| _outArchives == null
#endif
)
{ {
Init(); if (_inArchives == null
} #if COMPRESS
|| _outArchives == null
#endif
)
{
Init();
}
#if !WINCE && !MONO #if !WINCE && !MONO
if (_modulePtr == IntPtr.Zero) if (_modulePtr == IntPtr.Zero)
{
//zero 29-oct-2012 - this check isnt useful since LoadLibrary can pretty much check for the same thing. and it wrecks our dll relocation scheme
//if (!File.Exists(_libraryFileName))
//{
// throw new SevenZipLibraryException("DLL file does not exist.");
//}
if ((_modulePtr = libLoader.LoadOrNull(_libraryFileName).Value) == IntPtr.Zero)
{ {
//try a different directory //zero 29-oct-2012 - this check isnt useful since LoadOrNull can pretty much check for the same thing. and it wrecks our dll relocation scheme
string alternateFilename = Path.Combine(Path.Combine(Path.GetDirectoryName(_libraryFileName),"dll"),"7z.dll"); //if (!File.Exists(_libraryFileName))
if ((_modulePtr = libLoader.LoadOrNull(_libraryFileName).Value) == IntPtr.Zero) //{
throw new SevenZipLibraryException("failed to load library."); // throw new SevenZipLibraryException("DLL file does not exist.");
} //}
if (libLoader.GetProcAddr(_modulePtr, "GetHandlerProperty") == IntPtr.Zero) var newPtr = libLoader.LoadOrNull(_libraryFileName);
{ if (!newPtr.HasValue)
libLoader.FreeByPtr(_modulePtr); {
throw new SevenZipLibraryException("library is invalid."); //try a different directory
} newPtr = libLoader.LoadOrNull(Path.Combine(Path.Combine(Path.GetDirectoryName(_libraryFileName), "dll"), "7z.dll"));
} if (!newPtr.HasValue) throw new SevenZipLibraryException("failed to load library.");
#endif }
if (format is InArchiveFormat) _modulePtr = newPtr.Value;
{
InitUserInFormat(user, (InArchiveFormat) format);
return;
}
#if COMPRESS
if (format is OutArchiveFormat)
{
InitUserOutFormat(user, (OutArchiveFormat) format);
return;
}
#endif
throw new ArgumentException(
"Enum " + format + " is not a valid archive format attribute!");
}
if (libLoader.GetProcAddr(_modulePtr, "GetHandlerProperty") == IntPtr.Zero)
{
libLoader.FreeByPtr(_modulePtr);
throw new SevenZipLibraryException("library is invalid.");
}
}
#endif
if (format is InArchiveFormat)
{
InitUserInFormat(user, (InArchiveFormat) format);
return;
}
#if COMPRESS
if (format is OutArchiveFormat)
{
InitUserOutFormat(user, (OutArchiveFormat) format);
return;
}
#endif
throw new ArgumentException("Enum " + format + " is not a valid archive format attribute!");
}
} }
/*/// <summary> /*/// <summary>