Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Samples/CloudMirror/CloudMirror/CloudMirror.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,33 @@
<ProjectGuid>{93C711E5-7D66-45DC-9658-4323CE0892B0}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>CloudMirror</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
<CppWinRTEnabled>true</CppWinRTEnabled>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
10 changes: 9 additions & 1 deletion Samples/CloudMirror/CloudMirror/Placeholders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void Placeholders::Create(
// This icon is just for the sample. You should provide your own branded icon here
prop.IconResource(L"shell32.dll,-44");

wprintf(L"Applying custom state for %sx\n", relativeName.data());
wprintf(L"Applying custom state for %s\n", relativeName.data());
Utilities::ApplyCustomStateToPlaceholderFile(destPath, relativeName.data(), prop);

if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
Expand All @@ -131,6 +131,14 @@ void Placeholders::Create(
// certainly noteworthy for production code
}

if (std::wstring_view(relativeName).find(L"error") != std::wstring::npos)
{
wprintf(L"Apply error state to %s\n", relativeName.c_str());

auto placeholderPath = std::filesystem::path(destPath) / relativeName;
Utilities::UpdateErrorOnItem(placeholderPath.c_str(), true);
}

} while (FindNextFile(hFileHandle, &findData));

FindClose(hFileHandle);
Expand Down
34 changes: 34 additions & 0 deletions Samples/CloudMirror/CloudMirror/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,38 @@ void Utilities::ApplyCustomStateToPlaceholderFile(PCWSTR path, PCWSTR filename,
// otherwise the exception will get rethrown and this method will crash out as it should
wprintf(L"Failed to set custom state with %08x\n", static_cast<HRESULT>(winrt::to_hresult()));
}
}

void Utilities::UpdateErrorOnItem(PCWSTR path, bool setError)
{
try
{
winrt::com_ptr<IShellItem2> item;
winrt::check_hresult(SHCreateItemFromParsingName(path, nullptr, IID_PPV_ARGS(item.put())));

winrt::com_ptr<IPropertyStore> propertyStore;
winrt::check_hresult(item->GetPropertyStore(GPS_READWRITE | GPS_EXTRINSICPROPERTIESONLY, IID_PPV_ARGS(propertyStore.put())));

PROPVARIANT propVar{};
if (setError)
{
propVar.vt = VT_UI4;
propVar.ulVal = static_cast<unsigned long>(E_FAIL);
winrt::check_hresult(propertyStore->SetValue(PKEY_LastSyncError, propVar));
}
else
{
// Clear by setting to empty
propVar.vt = VT_EMPTY;
winrt::check_hresult(propertyStore->SetValue(PKEY_LastSyncError, propVar));
}

winrt::check_hresult(propertyStore->Commit());
}
catch (...)
{
// winrt::to_hresult() will eat the exception if it is a result of winrt::check_hresult,
// otherwise the exception will get rethrown and this method will crash out as it should
wprintf(L"Failed to set error state with %08x\n", static_cast<HRESULT>(winrt::to_hresult()));
}
}
1 change: 1 addition & 0 deletions Samples/CloudMirror/CloudMirror/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Utilities
static void AddFolderToSearchIndexer(_In_ PCWSTR folder);
static void ApplyTransferStateToFile(_In_ PCWSTR fullPath, _In_ CF_CALLBACK_INFO& callbackInfo, UINT64 total, UINT64 completed);
static void ApplyCustomStateToPlaceholderFile(_In_ PCWSTR path, _In_ PCWSTR filename, _In_ winrt::StorageProviderItemProperty& prop);
static void UpdateErrorOnItem(PCWSTR path, bool setError);

static winrt::com_array<wchar_t> ConvertSidToStringSid(_In_ PSID sid)
{
Expand Down
1 change: 1 addition & 0 deletions Samples/CloudMirror/CloudMirror/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <winrt\Windows.Security.Cryptography.h>
#include <ppltasks.h>
#include <strsafe.h>
#include <filesystem>

namespace winrt {
using namespace Windows::Foundation;
Expand Down