//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// "SHLProps"-CODE-PACKAGE NATIVE SUPPORT (API) — "Set"-FUNCTIONS:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// NativeLib DLL (for DotNetHelpers) | C+- (SysRoutine) | Author: Sergei Y.Kitáev
#include "Precompiled.h"
#include "SharedIncludes.h"
#include "partition\SHLProps.h"
//==================================================================================================
NL_API
BOOL WINAPI SHLProps_SetPath($CI_TAG, HANDLE instancePtr, PCWSTR value ) nl_last_error
{
   NL_SHLP_API_ENTRY_CONST();
   $TCI_VERIFY_POINTER_ARG( value );

   HRESULT hResult = HND.PSLInterface -> SetPath( value );
   if ( FAILED( hResult ) )
      return SHLProps::CantSetSLProperty($, L"Path", hResult );

   WCHAR szValue[ MAX_PATH ];
   if ( FAILED( hResult = HND.PSLInterface -> GetPath(
        $ARRAY_N_COUNT_OF(szValue), nullptr, SLGP_RAWPATH ) ) )
      return SHLProps::CantSetSLProperty($, L"Path", $TEXT(
         L"Verificational extraction of setted path has failed.",
         L"Проверочное извлечение значения установленного маршрута не прошло." ),
         hResult );
   if ( ::_wcsicmp( szValue, value ) )
      return SHLProps::CantSetSLPropertyFmt($, L"Path", $TEXT(
         L"Verificational extracted value of setted path varies from "
         L"the setted value.%s",
         L"Проверочно извлечённое значение установленного маршрута отлично от "
         L"устанавливаемого.%s" ),
         ::wcschr( value, L'%' ) ? $TEXT(
            L"\r\n(Environment variables are not expanded during the control comparison.)",
            L"\r\n(Переменные среды окружения при проверочном сравнении не разворачиваются.)" ) :
         L"" );

   return NL_SUCCEED();
}

//--------------------------------------------------------------------------------------------------
NL_API
BOOL WINAPI SHLProps_SetArguments($CI_TAG, HANDLE instancePtr, PCWSTR value ) nl_last_error
{
   NL_SHLP_API_ENTRY_CONST();
   $TCI_VERIFY_POINTER_ARG( value );
   HRESULT hResult = HND.PSLInterface -> SetArguments( value );
   return SUCCEEDED( hResult ) ? NL_SUCCEED() :
      SHLProps::CantSetSLProperty($, L"Arguments", hResult );
}

//--------------------------------------------------------------------------------------------------
NL_API
BOOL WINAPI SHLProps_SetDescription($CI_TAG, HANDLE instancePtr, PCWSTR value ) nl_last_error
{
   NL_SHLP_API_ENTRY_CONST();
   $TCI_VERIFY_POINTER_ARG( value );
   HRESULT hResult = HND.PSLInterface -> SetDescription( value );
   return SUCCEEDED( hResult ) ? NL_SUCCEED() :
      SHLProps::CantSetSLProperty($, L"Description", hResult );
}

//--------------------------------------------------------------------------------------------------
NL_API
BOOL WINAPI SHLProps_SetHotkey($CI_TAG, HANDLE instancePtr, USHORT value ) nl_last_error
{
   NL_SHLP_API_ENTRY_CONST();
   HRESULT hResult = HND.PSLInterface -> SetHotkey( value );
   return SUCCEEDED( hResult ) ? NL_SUCCEED() :
      SHLProps::CantSetSLProperty($, L"Hotkey", hResult );
}

//--------------------------------------------------------------------------------------------------
NL_API
BOOL WINAPI SHLProps_SetDisplayName($CI_TAG, HANDLE instancePtr, PCWSTR value ) nl_last_error
{
   NL_SHLP_API_ENTRY_CONST();
   $TCI_VERIFY_POINTER_ARG( value );

   IBindCtx *pIBindCtx = NULL;
   $COM_AUTO( pIBindCtx );
   HRESULT hResult;
   if ( FAILED( hResult = ::CreateBindCtx( 0, &pIBindCtx ) ) )
      return NL_FAIL_COM( hResult );

   $COMDummyObject dummyInterface;
   if ( FAILED( hResult = pIBindCtx -> RegisterObjectParam(
        STR_PARSE_DONT_REQUIRE_VALIDATED_URLS, &dummyInterface )))
      return NL_FAIL_COM( hResult );

   ::BIND_OPTS bindOpts = {};
   bindOpts.cbStruct = sizeof( bindOpts );
   bindOpts.grfMode = STGM_CREATE;
   if ( FAILED( pIBindCtx -> SetBindOptions( &bindOpts ) ))
      return NL_FAIL_COM( hResult );

   PIDLIST_RELATIVE pIDList = nullptr;
   $TASKMEM_AUTO( pIDList );
   if ( FAILED( hResult = ::SHParseDisplayName( value, pIBindCtx, &pIDList, 0, nullptr ) ) )
      return NLFailure::SetCOMErrorFmt($, hResult, $TEXT(
         L"Can not parse “DisplayName” value: “%s”.",
         L"Не удаётся разобрать значение “DisplayName”: “%s”."
      ), value );

   return SUCCEEDED( hResult = HND.PSLInterface -> SetIDList( pIDList ) ) ?
      NL_SUCCEED() : SHLProps::CantSetSLProperty($, L"SetIDList", hResult );
}

//--------------------------------------------------------------------------------------------------
NL_API
BOOL WINAPI SHLProps_SetShowCmd($CI_TAG, HANDLE instancePtr, INT value ) nl_last_error
{
   NL_SHLP_API_ENTRY_CONST();
   HRESULT hResult = HND.PSLInterface -> SetShowCmd( value );
   return SUCCEEDED( hResult ) ? NL_SUCCEED() :
      SHLProps::CantSetSLProperty($, L"ShowCmd", hResult );
}

//--------------------------------------------------------------------------------------------------
NL_API
BOOL WINAPI SHLProps_SetWorkingDirectory($CI_TAG, HANDLE instancePtr, PCWSTR value ) nl_last_error
{
   NL_SHLP_API_ENTRY_CONST();
   $TCI_VERIFY_POINTER_ARG( value );
   HRESULT hResult = HND.PSLInterface -> SetWorkingDirectory( value );
   return SUCCEEDED( hResult ) ? NL_SUCCEED() :
      SHLProps::CantSetSLProperty($, L"WorkingDirectory", hResult );
}

//==================================================================================================
NL_API
BOOL WINAPI SHLProps_SetIconLocation($CI_TAG, HANDLE instancePtr,
                                              PCWSTR path, INT index ) nl_last_error
{
   NL_SHLP_API_ENTRY_CONST();
   $TCI_VERIFY_POINTER_ARG( path );
   HRESULT hResult = HND.PSLInterface -> SetIconLocation( path, index );
   return SUCCEEDED( hResult ) ? NL_SUCCEED() :
      SHLProps::CantSetSLProperty($, L"IconLocation", hResult );
}

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