//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// CommonHelpers satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;

namespace CommonHelpers {

//**************************************************************************************************
partial class ShellLinkPropertiesImpl {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="HOperationFailedException" />
public ShellLinkPropertiesImpl()
{
   VERIFY( _Handle_ = SHLPropsNL.CreateInstance(
      "BEE130C2-DFDA-4491-A1DF-4D486AAC01A3" ));
}

//--------------------------------------------------------------------------------------------------

/// <exception cref="HOperationFailedException" />
public void Release()
{
   if ( _Handle_ != IntPtr.Zero )
      SHLPropsNL.Release( "41CE14FF-8E41-48F1-8CAB-D95F2210AE7F",
         HPointer.NullValueExchange( ref _Handle_ ) );
}

//==================================================================================================

/// <exception cref="ArgumentNullException" />
/// <exception cref="HOperationFailedException" />
public void Load(string filePath,out HShellLinkSpecialProps specialProps)
{
   HArgChecking.VerifyNotNull( filePath );
   specialProps = new HShellLinkSpecialProps();
   NLShellLinkSpecialPropsStruct nsp;
   VERIFY( SHLPropsNL.Load(
      "5AA2A21E-56DE-46C9-93F8-692BCD33C009",
      _Handle_, FilePathToAbsolute( filePath ), out nsp ));
   try
      { specialProps.FromNative( ref nsp ); }
   finally
      { nsp.Free(); }
}

/// <exception cref="ArgumentNullException" />
/// <exception cref="ArgumentException" />
/// <exception cref="HOperationFailedException" />
public void Save(string filePath,[HOptional] HShellLinkSpecialProps specialProps)
{
   HArgChecking.VerifyNotNull( filePath );
   var nsp = new NLShellLinkSpecialPropsStruct( ref specialProps );
   try
   {
      VERIFY( SHLPropsNL.SaveEx(
         "7EA5C22B-E31A-46BA-914E-D5D2B2B44655",
         _Handle_, FilePathToAbsolute( filePath ), ref nsp ));
   }
   finally
   {
      nsp.Free();
   }
}

//==================================================================================================

/// <exception cref="ArgumentNullException" />
/// <exception cref="HOperationFailedException" />
public string Arguments
{
   get
   {
      return STR( SHLPropsNL.GetArguments(
         "75E13CC5-537D-429D-8583-61C2DFED4554",
         _Handle_ ));
   }
   set
   {
      HArgChecking.VerifyNotNull( value );
      VERIFY( SHLPropsNL.SetArguments(
         "E8DC1E39-5FEF-47A0-A7F0-DCB46555740F",
         _Handle_, value ));
   }
}

/// <exception cref="ArgumentNullException" />
/// <exception cref="HOperationFailedException" />
public string Description
{
   get
   {
      return STR( SHLPropsNL.GetDescription(
         "4E54320F-B0EE-4367-8ABE-C1A66A902B02",
         _Handle_ ));
   }
   set
   {
      HArgChecking.VerifyNotNull( value );
      VERIFY( SHLPropsNL.SetDescription(
         "9BA64113-9FFE-4946-81C3-CF7CFD2BD2C7",
         _Handle_, value ));
   }
}

/// <exception cref="HOperationFailedException" />
public ushort HotKey
{
   get
   {
      UInt16 value;
      VERIFY( SHLPropsNL.GetHotkey(
         "A1C86700-56D1-461B-9BFC-5A5525386346",
         _Handle_, out value ));
      return value;
   }
   set
   {
      VERIFY( SHLPropsNL.SetHotkey(
         "2F2FDACE-5C2D-453A-B2E7-0C9B853A6DB5",
         _Handle_, value ));
   }
}

/// <exception cref="ArgumentNullException" />
/// <exception cref="HOperationFailedException" />
public string Path
{
   get
   {
      return STR( SHLPropsNL.GetPath(
         "01FA0BFE-06DE-4FAF-875A-2B03E2E219F9",
         _Handle_ ));
   }
   set
   {
      HArgChecking.VerifyNotNull( value );
      VERIFY( SHLPropsNL.SetPath(
         "63E98F8B-732F-43F2-9798-E975BD6066B6",
         _Handle_, value ));
   }
}

/// <exception cref="ArgumentNullException" />
/// <exception cref="HOperationFailedException" />
public string DisplayName
{
   get
   {
      return STR( SHLPropsNL.GetDisplayName(
         "C50EB71E-AA43-426E-960A-18F4E7ED7794",
         _Handle_ ));
   }
   set
   {
      HArgChecking.VerifyNotNull( value );
      VERIFY( SHLPropsNL.SetDisplayName(
         "283ACF4A-C9F7-497B-BAB4-AABBD6C11EC4",
         _Handle_, value ));
   }
}

/// <exception cref="HOperationFailedException" />
public int ShowCmd
{
   get
   {
      Int32 value;
      VERIFY( SHLPropsNL.GetShowCmd(
         "4A96EBB6-40FF-4C3C-B615-66AB02C013D7",
         _Handle_, out value ));
      return value;
   }
   set
   {
      VERIFY( SHLPropsNL.SetShowCmd(
         "644D99A1-CFA7-4184-8464-A1CEA5C6F2C0",
         _Handle_, value ));
   }
}

/// <exception cref="ArgumentNullException" />
/// <exception cref="HOperationFailedException" />
public string WorkingDirectory
{
   get
   {
      return STR( SHLPropsNL.GetWorkingDirectory(
         "B8E899BC-5B04-47E7-AC2E-5DCECF989B21",
         _Handle_ ));
   }
   set
   {
      HArgChecking.VerifyNotNull( value );
      VERIFY( SHLPropsNL.SetWorkingDirectory(
         "857E1B3B-F998-4422-A0B4-C560C510D796",
         _Handle_, value ));
   }
}

//--------------------------------------------------------------------------------------------------

/// <exception cref="HOperationFailedException" />
public string GetIconLocation(out int index)
{
   return STR( SHLPropsNL.GetIconLocation(
      "E7A8D714-3AE6-4396-A22B-9F713F44263B",
      _Handle_, out index ));
}

/// <exception cref="ArgumentNullException" />
/// <exception cref="HOperationFailedException" />
public void SetIconLocation(string path,int index)
{
   HArgChecking.VerifyNotNull( path );
   VERIFY( SHLPropsNL.SetIconLocation(
      "652ABADE-595D-4176-8158-2B45D57AB3D6",
      _Handle_, path, index ));
}

//==================================================================================================

IntPtr _Handle_;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // ShellLinkPropertiesImpl
//**************************************************************************************************

} // CommonHelpers
