2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2015-10-12 19:55:00 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-02-18 10:02:53 +00:00
|
|
|
// Copyright © 2011-2022 Natalia Portillo
|
2015-10-12 19:55:00 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
namespace Aaru.Devices;
|
|
|
|
|
|
2021-09-14 20:44:06 +01:00
|
|
|
using Aaru.CommonTypes.Interop;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.Devices.Linux;
|
2015-10-12 19:55:00 +01:00
|
|
|
using Microsoft.Win32.SafeHandles;
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
public sealed partial class Device
|
2015-10-12 19:55:00 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Releases unmanaged resources and performs other cleanup operations before the <see cref="Device" /> is
|
|
|
|
|
/// reclaimed by garbage collection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
~Device() => Close();
|
2018-09-01 23:27:14 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Closes a device</summary>
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
if(_remote != null)
|
2015-10-12 19:55:00 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
_remote.Close();
|
|
|
|
|
_remote.Disconnect();
|
2019-10-26 15:47:36 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(FileHandle == null)
|
|
|
|
|
return;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
switch(PlatformId)
|
|
|
|
|
{
|
|
|
|
|
case PlatformID.Win32NT:
|
|
|
|
|
(FileHandle as SafeFileHandle)?.Close();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case PlatformID.Linux:
|
|
|
|
|
Extern.close((int)FileHandle);
|
2018-12-01 19:31:04 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
2015-10-12 19:55:00 +01:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
FileHandle = null;
|
2015-10-12 19:55:00 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|