//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// "SHLProps"-CODE-PACKAGE NATIVE SUPPORT (IMPLEMENTATION PART):
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// NativeLib DLL (for DotNetHelpers) | C+- (SysRoutine) | Author: Sergei Y.Kitáev
#include "Precompiled.h"
#include "SharedIncludes.h"
#include "partition\SHLProps.h"
//==================================================================================================

bool SHLProps::CantExtractSLProperty($A, PCWSTR propertyName, HRESULT hResult ) $ret_false
                                                                                nl_last_error
{
   $VERIFY_POINTER_ARG( propertyName );
   return NLFailure::SetCOMErrorFmt($ci, hResult, CantExtractSLProperty_Fmt(), propertyName );
}
bool SHLProps::CantExtractSLProperty($A, PCWSTR propertyName, PCWSTR headerMessageEx $optional,
                                         HRESULT hResult ) $ret_false nl_last_error
{
   if ( !headerMessageEx )
      return CantExtractSLProperty($ci, propertyName, hResult );
   $VERIFY_POINTER_ARG( propertyName );
   PWSTR pMessage = $SZ::FormatAllocNS($, CantExtractSLProperty_Fmt(), propertyName );
   $AUTO_FREE( pMessage );
   return pMessage ?
      NLFailure::SetCOMErrorFmt($, hResult, L"%s\r\n%s", headerMessageEx, pMessage ) :
      NLFailure::SetFormatAllocFailure();
}

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

bool SHLProps::CantExtractSLPropertyFmt($A, PCWSTR propertyName, HRESULT hResult,
                                            PCWSTR messageFmt, ... ) $ret_false nl_last_error
{
   $VERIFY_POINTER_ARG( messageFmt );
   va_list argList;
   bool rslt = CantExtractSLPropertyFmtVA($ci, propertyName, hResult,
      $VA_COMPLEMENT( messageFmt, argList ) );
   va_end( argList );
   return rslt;
}

bool SHLProps::CantExtractSLPropertyFmtVA($A, PCWSTR propertyName, HRESULT hResult,
                                              PCWSTR messageFmt, va_list argList ) $ret_false
                                                                                   nl_last_error
{
   PWSTR pMessage = $SZ::FormatAllocVANS($, messageFmt, argList );
   $AUTO_FREE( pMessage );
   return pMessage ?
      CantExtractSLProperty($ci, propertyName, pMessage, hResult ) :
      NLFailure::SetFormatAllocFailure();
}

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

bool SHLProps::CantSetSLProperty($A, PCWSTR propertyName, HRESULT hResult ) $ret_false nl_last_error
{
   $VERIFY_POINTER_ARG( propertyName );
   return NLFailure::SetCOMErrorFmt($ci, hResult, CantSetSLProperty_Fmt(), propertyName );
}
bool SHLProps::CantSetSLProperty($A, PCWSTR propertyName, PCWSTR headerMessageEx $optional,
                                     HRESULT hResult ) $ret_false nl_last_error
{
   if ( !headerMessageEx )
      return CantSetSLProperty($ci, propertyName, hResult );
   $VERIFY_POINTER_ARG( propertyName );
   PWSTR pMessage = $SZ::FormatAllocNS($, CantSetSLProperty_Fmt(), propertyName );
   $AUTO_FREE( pMessage );
   return pMessage ?
      NLFailure::SetCOMErrorFmt($, hResult, L"%s\r\n%s", headerMessageEx, pMessage ) :
      NLFailure::SetFormatAllocFailure();
}

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

bool SHLProps::CantSetSLPropertyFmt($A, PCWSTR propertyName, HRESULT hResult,
                                        PCWSTR messageFmt, ... ) $ret_false nl_last_error
{
   $VERIFY_POINTER_ARG( messageFmt );
   va_list argList;
   bool rslt = CantSetSLPropertyFmtVA($ci, propertyName, hResult,
      $VA_COMPLEMENT( messageFmt, argList ) );
   va_end( argList );
   return rslt;
}

bool SHLProps::CantSetSLPropertyFmtVA($A, PCWSTR propertyName, HRESULT hResult,
                                          PCWSTR messageFmt, va_list argList ) $ret_false
                                                                               nl_last_error
{
   PWSTR pMessage = $SZ::FormatAllocVANS($, messageFmt, argList );
   $AUTO_FREE( pMessage );
   return pMessage ?
      CantSetSLProperty($ci, propertyName, pMessage, hResult ) :
      NLFailure::SetFormatAllocFailure();
}

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

bool SHLProps::CantExtractSLProperty($A, PCWSTR propertyName, PCWSTR message ) $ret_false
                                                                               nl_last_error
{
   $VERIFY_POINTER_ARG( propertyName );
   $VERIFY_POINTER_ARG( message );
   PWSTR pMessage = $SZ::FormatAllocNS($, CantExtractSLProperty_Fmt(), propertyName );
   $AUTO_FREE( pMessage );
   return pMessage ?
      NLFailure::SetErrorFmt($, L"%s\r\n%s", pMessage, message ) :
      NLFailure::SetFormatAllocFailure();
}

bool SHLProps::CantExtractSLPropertyFmt($A, PCWSTR propertyName, PCWSTR messageFmt,
                                                                 ... )  $ret_false nl_last_error
{
   $VERIFY_POINTER_ARG( messageFmt );
   va_list argList;
   bool rslt = CantExtractSLPropertyFmtVA($ci, propertyName,
      $VA_COMPLEMENT( messageFmt, argList ) );
   va_end( argList );
   return rslt;
}
bool SHLProps::CantExtractSLPropertyFmtVA($A, PCWSTR propertyName, PCWSTR messageFmt,
                                                                   va_list argList ) $ret_false
                                                                                     nl_last_error
{
   $VERIFY_POINTER_ARG( propertyName );
   PWSTR pMessage = $SZ::FormatAllocVANS($ci, messageFmt, argList );
   if ( !pMessage )
      return NLFailure::SetFormatAllocFailure();
   $AUTO_FREE( pMessage );
   return CantExtractSLProperty($ci, propertyName, pMessage );
}

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

bool SHLProps::CantSetSLProperty($A, PCWSTR propertyName, PCWSTR message ) $ret_false nl_last_error
{
   $VERIFY_POINTER_ARG( propertyName );
   $VERIFY_POINTER_ARG( message );
   PWSTR pMessage = $SZ::FormatAllocNS($, CantSetSLProperty_Fmt(), propertyName );
   $AUTO_FREE( pMessage );
   return pMessage ?
      NLFailure::SetErrorFmt($, L"%s\r\n%s", pMessage, message ) :
      NLFailure::SetFormatAllocFailure();
}

bool SHLProps::CantSetSLPropertyFmt($A, PCWSTR propertyName, PCWSTR messageFmt,
                                                             ... ) $ret_false nl_last_error
{
   $VERIFY_POINTER_ARG( messageFmt );
   va_list argList;
   bool rslt = CantSetSLPropertyFmtVA($ci, propertyName, $VA_COMPLEMENT( messageFmt, argList ) );
   va_end( argList );
   return rslt;
}
bool SHLProps::CantSetSLPropertyFmtVA($A, PCWSTR propertyName, PCWSTR messageFmt,
                                                               va_list argList ) $ret_false
                                                                                 nl_last_error
{
   $VERIFY_POINTER_ARG( propertyName );
   PWSTR pMessage = $SZ::FormatAllocVANS($ci, messageFmt, argList );
   if ( !pMessage )
      return NLFailure::SetFormatAllocFailure();
   $AUTO_FREE( pMessage );
   return CantSetSLProperty($ci, propertyName, pMessage );
}

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

PCWSTR SHLProps::CantExtractSLProperty_Fmt() $static_pointer
{
   return $TEXT(
      L"Can not extract “%s” property (interface IShellLink).",
      L"Не удаётся извлечь свойство “%s” (интерфейс IShellLink)." );
}

PCWSTR SHLProps::CantSetSLProperty_Fmt() $static_pointer
{
   return $TEXT(
      L"Can not set “%s” property (interface IShellLink).",
      L"Не удаётся установить свойство “%s” (интерфейс IShellLink)." );
}

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

PCWSTR SHLProps::CantExtractDisplayNameValue_Message() $static_pointer
{
   return $TEXT(
      L"Can not obtain “DisplayName” value.",
      L"Не удаётся получить значение “DisplayName”." );
}

PCWSTR SHLProps::CantSetDisplayNameValue_Message() $static_pointer
{
   return $TEXT(
      L"Can not set property “DisplayName” (interface IShellLink).",
      L"Не удаётся установить свойство “DisplayName” (интерфейс IShellLink)." );
}

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