2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-10-12 19:55:00 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Destructor.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-12 19:55:00 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Direct device access.
|
2015-10-12 19:55:00 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Returns the device to the operating system.
|
2015-10-12 19:55:00 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
2015-10-12 19:55:00 +01:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// Lesser General Public License for more details.
|
2015-10-12 19:55:00 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2015-10-12 19:55:00 +01:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2015-10-12 19:55:00 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2017-12-19 03:50:57 +00:00
|
|
|
using System;
|
2018-12-01 19:34:05 +00:00
|
|
|
using DiscImageChef.Devices.Linux;
|
2015-10-12 19:55:00 +01:00
|
|
|
using Microsoft.Win32.SafeHandles;
|
2018-06-25 19:08:16 +01:00
|
|
|
using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID;
|
2015-10-12 19:55:00 +01:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Devices
|
|
|
|
|
{
|
|
|
|
|
public partial class Device
|
|
|
|
|
{
|
2015-10-12 20:08:56 +01:00
|
|
|
/// <summary>
|
2017-12-23 20:04:36 +00:00
|
|
|
/// Releases unmanaged resources and performs other cleanup operations before the
|
|
|
|
|
/// <see cref="Device" /> is reclaimed by garbage collection.
|
2015-10-12 20:08:56 +01:00
|
|
|
/// </summary>
|
2015-10-12 19:55:00 +01:00
|
|
|
~Device()
|
2018-09-01 23:27:14 +01:00
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Close()
|
2015-10-12 19:55:00 +01:00
|
|
|
{
|
2017-12-21 07:19:46 +00:00
|
|
|
if(FileHandle == null) return;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
2017-12-21 07:19:46 +00:00
|
|
|
switch(PlatformId)
|
2017-12-21 06:06:19 +00:00
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
case PlatformID.Win32NT:
|
2018-12-01 19:34:05 +00:00
|
|
|
(FileHandle as SafeFileHandle)?.Close();
|
2017-12-21 06:06:19 +00:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case PlatformID.Linux:
|
2018-12-01 19:34:05 +00:00
|
|
|
Extern.close((int)FileHandle);
|
2017-12-21 06:06:19 +00:00
|
|
|
break;
|
2017-12-21 14:30:38 +00:00
|
|
|
case PlatformID.FreeBSD:
|
2017-12-21 07:19:46 +00:00
|
|
|
FreeBSD.Extern.cam_close_device((IntPtr)FileHandle);
|
2017-12-21 06:06:19 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2018-12-01 19:31:04 +00:00
|
|
|
|
|
|
|
|
FileHandle = null;
|
2015-10-12 19:55:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|