Merge remote-tracking branch 'refs/remotes/origin/devel'
# Conflicts: # SharpPhysFS/PhysFS.cspull/2/head
						commit
						a0794f5ea2
					
				| 
						 | 
				
			
			@ -99,6 +99,7 @@ namespace SharpPhysFS
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  class Interop
 | 
			
		||||
    : IDisposable
 | 
			
		||||
  {
 | 
			
		||||
    InvalidOperationException initException = new InvalidOperationException("Callbacks not initialized yet");
 | 
			
		||||
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
 | 
			
		||||
| 
						 | 
				
			
			@ -201,6 +202,11 @@ namespace SharpPhysFS
 | 
			
		|||
      : this($"{libname}.dll", $"{libname}.dylib", $"{libname}.so")
 | 
			
		||||
    { }
 | 
			
		||||
 | 
			
		||||
    Func<string, IntPtr> loadLibrary;
 | 
			
		||||
    Func<IntPtr, string, IntPtr> loadSymbol;
 | 
			
		||||
    Func<IntPtr, bool> freeLibrary;
 | 
			
		||||
    IntPtr library;
 | 
			
		||||
 | 
			
		||||
    public Interop(string winlib, string maclib, string unixlib)
 | 
			
		||||
    {
 | 
			
		||||
      /* This method is used to dynamically load the physfs
 | 
			
		||||
| 
						 | 
				
			
			@ -212,28 +218,27 @@ namespace SharpPhysFS
 | 
			
		|||
       * pointers from the loaded library
 | 
			
		||||
       */
 | 
			
		||||
 | 
			
		||||
      Func<string, IntPtr> loadLibrary;
 | 
			
		||||
      Func<IntPtr, string, IntPtr> loadSymbol;
 | 
			
		||||
      string libraryName;
 | 
			
		||||
 | 
			
		||||
      IntPtr library;
 | 
			
		||||
 | 
			
		||||
      if (Environment.OSVersion.Platform == PlatformID.Win32NT)
 | 
			
		||||
      {
 | 
			
		||||
        loadLibrary = DynamicLoader.LoadLibrary;
 | 
			
		||||
        loadSymbol = DynamicLoader.GetProcAddress;
 | 
			
		||||
        freeLibrary = DynamicLoader.FreeLibrary;
 | 
			
		||||
        libraryName = winlib;
 | 
			
		||||
      }
 | 
			
		||||
      else if(Environment.OSVersion.Platform == PlatformID.MacOSX)
 | 
			
		||||
      {
 | 
			
		||||
        loadLibrary = n => DynamicLoader.osx_dlopen(n, 1);
 | 
			
		||||
        loadSymbol = DynamicLoader.osx_dlsym;
 | 
			
		||||
        freeLibrary = DynamicLoader.osx_dlclose;
 | 
			
		||||
        libraryName = maclib;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        loadLibrary = n => DynamicLoader.unix_dlopen(n, 1);
 | 
			
		||||
        loadSymbol = DynamicLoader.unix_dlsym;
 | 
			
		||||
        freeLibrary = DynamicLoader.unix_dlclose;
 | 
			
		||||
        libraryName = unixlib;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -253,5 +258,29 @@ namespace SharpPhysFS
 | 
			
		|||
        field.SetValue(this, del);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #region IDisposable Support
 | 
			
		||||
    private bool disposedValue = false; // To detect redundant calls
 | 
			
		||||
 | 
			
		||||
    protected virtual void Dispose(bool disposing)
 | 
			
		||||
    {
 | 
			
		||||
      if (!disposedValue)
 | 
			
		||||
      {
 | 
			
		||||
        /*if (disposing)
 | 
			
		||||
        {
 | 
			
		||||
          // TODO: dispose managed state (managed objects).
 | 
			
		||||
        }*/
 | 
			
		||||
 | 
			
		||||
        freeLibrary(library);
 | 
			
		||||
 | 
			
		||||
        disposedValue = true;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Dispose()
 | 
			
		||||
    {
 | 
			
		||||
      Dispose(true);
 | 
			
		||||
    }
 | 
			
		||||
    #endregion
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -684,7 +684,7 @@ namespace SharpPhysFS
 | 
			
		|||
    /// <see cref="EnumerateFilesCallback(string, Action{string, string})"/> if you don't need
 | 
			
		||||
    /// to pass custom data to the callback.
 | 
			
		||||
    /// </remarks>
 | 
			
		||||
    /// <typeparam name="T">Type of data passed to callbakc</typeparam>
 | 
			
		||||
    /// <typeparam name="T">Type of data passed to callback</typeparam>
 | 
			
		||||
    /// <param name="dir">Directory, in platform-independent notation, to enumerate.</param>
 | 
			
		||||
    /// <param name="c">Callback function to notify about search path elements.</param>
 | 
			
		||||
    /// <param name="data">Application-defined data passed to callback. Can be null.</param>
 | 
			
		||||
| 
						 | 
				
			
			@ -725,9 +725,25 @@ namespace SharpPhysFS
 | 
			
		|||
      return new PhysFSStream(this, handle, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool disposed = false;
 | 
			
		||||
 | 
			
		||||
    protected virtual void Dispose(bool disposing)
 | 
			
		||||
    {
 | 
			
		||||
      if (!disposed)
 | 
			
		||||
      {
 | 
			
		||||
        if (disposing)
 | 
			
		||||
        {
 | 
			
		||||
          Deinit();
 | 
			
		||||
          interop.Dispose();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        disposed = true;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Dispose()
 | 
			
		||||
    {
 | 
			
		||||
      Deinit();
 | 
			
		||||
      Dispose(true);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue