diff --git a/Samples/StoragePickers/README.md b/Samples/StoragePickers/README.md new file mode 100644 index 000000000..d71eee3f2 --- /dev/null +++ b/Samples/StoragePickers/README.md @@ -0,0 +1,94 @@ +## The Storage Pickers Samples + +- Demonstrates the `Microsoft.Windows.Storage.Pickers` APIs inside a Windows App SDK app. +- Targets Windows App SDK **1.8 or later**. +- Three tabs showcase `FileOpenPicker`, `FileSavePicker`, and `FolderPicker` usage end to end. + +## 📸 Screenshot of App Layout + +![img](images/screenshot-storage-pickers.png) + +## Deploy the Sample Packaged App Locally + +1. Open `cpp-sample/FilePickersAppSinglePackaged.sln` or `cs-sample/FilePickersAppSinglePackaged.sln` in Visual Studio, right click on the project, select "Package and Publish" > "Create App Package" + +![img](images/deploy1.png) + +2. Select Sideloading > Next + +![img](images/deploy2.png) + +3. Create and Trust your own test certification + +![img](images/deploy3.png) + +![img](images/deploy4.png) + +4. Create package + +![img](images/deploy5.png) + +5. Open the built result + +![img](images/deploy6.png) + +5. Run Install.ps1 in powershell + +![img](images/deploy7.png) + +*Note:* + +If encountering error like below: + +> Add-AppxPackage: Cannot find path 'C:\FilePickersAppSinglePackaged_1.0.1.0_x64_Debug_Test\Dependencies\x86\Microsoft.VCLibs.x86.Debug.14.00.appx C:\FilePickersAppSinglePackaged_1.0.1.0_x64_Debug_Test\Dependencies\x86\Microsoft.VCLibs.x86.Debug.14.00.Desktop.appx C:\FilePickersAppSinglePackaged_1.0.1.0_x64_Debug_Test\Dependencies\x64\Microsoft.VCLibs.x64.Debug.14.00.appx C:\FilePickersAppSinglePackaged_1.0.1.0_x64_Debug_Test\Dependencies\x64\Microsoft.VCLibs.x64.Debug.14.00.Desktop.appx' because it does not exist. + +Replace lines 483-491 in `Add-AppDevPackage.ps1` with below script and try again: + +```ps +if ($DependencyPackages.FullName.Count -gt 0) +{ + Write-Host $UiStrings.DependenciesFound + $DependencyPackages.FullName + + + # Install dependencies one by one first + foreach ($dep in $DependencyPackages.FullName) { + echo "Installing dependency: $dep" + try { + Add-AppxPackage -Path $dep -ForceApplicationShutdown + echo "Successfully installed: $dep" + } catch { + echo "Failed to install dependency: $dep - $($_.Exception.Message)" + } + } + + # Now install the main package + echo "Installing main package: $($DeveloperPackagePath.FullName)" + Add-AppxPackage -Path $DeveloperPackagePath.FullName -ForceApplicationShutdown +} +``` + +Screenshot of this error: +![img](images/deploy8.png) + +Screenshot of this mitigation: + +![img](images/deploy9.png) + +With the dependency *.appx files correctly installed, the project should be debugged in Visual Studio smoothly. + +![img](images/deploy10.png) + + +## 🚀 Run + +1. Open `cpp-sample/FilePickersAppSinglePackaged.sln` or `cs-sample/FilePickersAppSinglePackaged.sln` in Visual Studio. +1. Restore NuGet packages and ensure the Windows App SDK 1.8 runtime is installed locally. +1. Build and run. + + +## More to explore + +- [Microsoft.Windows.Storage.Pickers Namespace](https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers) +- [Design Specs of Microsoft.Windows.Storage.Pickers](https://github.com/microsoft/WindowsAppSDK/blob/release/1.8-stable/specs/Storage.Pickers/Microsoft.Windows.Storage.Pickers.md) +- [Windows App SDK](https://github.com/microsoft/WindowsAppSDK/) diff --git a/Samples/StoragePickers/cpp-sample/App.xaml b/Samples/StoragePickers/cpp-sample/App.xaml new file mode 100644 index 000000000..5a11fec41 --- /dev/null +++ b/Samples/StoragePickers/cpp-sample/App.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + diff --git a/Samples/StoragePickers/cpp-sample/App.xaml.cpp b/Samples/StoragePickers/cpp-sample/App.xaml.cpp new file mode 100644 index 000000000..673e30140 --- /dev/null +++ b/Samples/StoragePickers/cpp-sample/App.xaml.cpp @@ -0,0 +1,43 @@ +#include "pch.h" +#include "App.xaml.h" +#include "MainWindow.xaml.h" + +using namespace winrt; +using namespace Microsoft::UI::Xaml; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace winrt::FilePickersAppSinglePackaged::implementation +{ + /// + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). + /// + App::App() + { + // Xaml objects should not call InitializeComponent during construction. + // See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent + +#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION + UnhandledException([](IInspectable const&, UnhandledExceptionEventArgs const& e) + { + if (IsDebuggerPresent()) + { + auto errorMessage = e.Message(); + __debugbreak(); + } + }); +#endif + } + + /// + /// Invoked when the application is launched. + /// + /// Details about the launch request and process. + void App::OnLaunched([[maybe_unused]] LaunchActivatedEventArgs const& e) + { + window = make(); + window.Activate(); + } +} diff --git a/Samples/StoragePickers/cpp-sample/App.xaml.h b/Samples/StoragePickers/cpp-sample/App.xaml.h new file mode 100644 index 000000000..bf0d7c789 --- /dev/null +++ b/Samples/StoragePickers/cpp-sample/App.xaml.h @@ -0,0 +1,16 @@ +#pragma once + +#include "App.xaml.g.h" + +namespace winrt::FilePickersAppSinglePackaged::implementation +{ + struct App : AppT + { + App(); + + void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&); + + private: + winrt::Microsoft::UI::Xaml::Window window{ nullptr }; + }; +} diff --git a/Samples/StoragePickers/cpp-sample/Assets/LockScreenLogo.scale-200.png b/Samples/StoragePickers/cpp-sample/Assets/LockScreenLogo.scale-200.png new file mode 100644 index 000000000..7440f0d4b Binary files /dev/null and b/Samples/StoragePickers/cpp-sample/Assets/LockScreenLogo.scale-200.png differ diff --git a/Samples/StoragePickers/cpp-sample/Assets/SplashScreen.scale-200.png b/Samples/StoragePickers/cpp-sample/Assets/SplashScreen.scale-200.png new file mode 100644 index 000000000..32f486a86 Binary files /dev/null and b/Samples/StoragePickers/cpp-sample/Assets/SplashScreen.scale-200.png differ diff --git a/Samples/StoragePickers/cpp-sample/Assets/Square150x150Logo.scale-200.png b/Samples/StoragePickers/cpp-sample/Assets/Square150x150Logo.scale-200.png new file mode 100644 index 000000000..53ee3777e Binary files /dev/null and b/Samples/StoragePickers/cpp-sample/Assets/Square150x150Logo.scale-200.png differ diff --git a/Samples/StoragePickers/cpp-sample/Assets/Square44x44Logo.scale-200.png b/Samples/StoragePickers/cpp-sample/Assets/Square44x44Logo.scale-200.png new file mode 100644 index 000000000..f713bba67 Binary files /dev/null and b/Samples/StoragePickers/cpp-sample/Assets/Square44x44Logo.scale-200.png differ diff --git a/Samples/StoragePickers/cpp-sample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/Samples/StoragePickers/cpp-sample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 000000000..dc9f5bea0 Binary files /dev/null and b/Samples/StoragePickers/cpp-sample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png differ diff --git a/Samples/StoragePickers/cpp-sample/Assets/StoreLogo.png b/Samples/StoragePickers/cpp-sample/Assets/StoreLogo.png new file mode 100644 index 000000000..a4586f26b Binary files /dev/null and b/Samples/StoragePickers/cpp-sample/Assets/StoreLogo.png differ diff --git a/Samples/StoragePickers/cpp-sample/Assets/Wide310x150Logo.scale-200.png b/Samples/StoragePickers/cpp-sample/Assets/Wide310x150Logo.scale-200.png new file mode 100644 index 000000000..8b4a5d0dd Binary files /dev/null and b/Samples/StoragePickers/cpp-sample/Assets/Wide310x150Logo.scale-200.png differ diff --git a/Samples/StoragePickers/cpp-sample/FilePickersAppSinglePackaged.sln b/Samples/StoragePickers/cpp-sample/FilePickersAppSinglePackaged.sln new file mode 100644 index 000000000..cb1b06ddf --- /dev/null +++ b/Samples/StoragePickers/cpp-sample/FilePickersAppSinglePackaged.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35707.178 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FilePickersAppSinglePackaged", "FilePickersAppSinglePackaged.vcxproj", "{FC188327-1E71-4DC4-9B57-EB2A2CACEE12}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM64 = Debug|ARM64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|ARM64 = Release|ARM64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|ARM64.Build.0 = Debug|ARM64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|ARM64.Deploy.0 = Debug|ARM64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x64.ActiveCfg = Debug|x64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x64.Build.0 = Debug|x64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x64.Deploy.0 = Debug|x64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x86.ActiveCfg = Debug|Win32 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x86.Build.0 = Debug|Win32 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Debug|x86.Deploy.0 = Debug|Win32 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|ARM64.ActiveCfg = Release|ARM64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|ARM64.Build.0 = Release|ARM64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|ARM64.Deploy.0 = Release|ARM64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x64.ActiveCfg = Release|x64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x64.Build.0 = Release|x64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x64.Deploy.0 = Release|x64 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x86.ActiveCfg = Release|Win32 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x86.Build.0 = Release|Win32 + {FC188327-1E71-4DC4-9B57-EB2A2CACEE12}.Release|x86.Deploy.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Samples/StoragePickers/cpp-sample/FilePickersAppSinglePackaged.vcxproj b/Samples/StoragePickers/cpp-sample/FilePickersAppSinglePackaged.vcxproj new file mode 100644 index 000000000..ba8b94708 --- /dev/null +++ b/Samples/StoragePickers/cpp-sample/FilePickersAppSinglePackaged.vcxproj @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + true + true + true + {fc188327-1e71-4dc4-9b57-eb2a2cacee12} + FilePickersAppSinglePackaged + FilePickersAppSinglePackaged + + $(RootNamespace) + en-US + 16.0 + false + true + Windows Store + 10.0 + 10.0 + 10.0.17763.0 + true + true + true + + + + + Debug + Win32 + + + Debug + x64 + + + Debug + ARM64 + + + Release + Win32 + + + Release + x64 + + + Release + ARM64 + + + + Application + v143 + Unicode + true + + + true + true + + + false + true + false + + + + + + + + + + + Use + pch.h + $(IntDir)pch.pch + Level4 + %(AdditionalOptions) /bigobj + + + + + _DEBUG;%(PreprocessorDefinitions) + + + + + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + + + + Designer + + + + + + + + + App.xaml + + + MainWindow.xaml + + + + + + + + + Create + + + App.xaml + + + MainWindow.xaml + + + + + + Code + MainWindow.xaml + + + + + false + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/StoragePickers/cpp-sample/FilePickersAppSinglePackaged.vcxproj.filters b/Samples/StoragePickers/cpp-sample/FilePickersAppSinglePackaged.vcxproj.filters new file mode 100644 index 000000000..d10d1473d --- /dev/null +++ b/Samples/StoragePickers/cpp-sample/FilePickersAppSinglePackaged.vcxproj.filters @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + + + {fc188327-1e71-4dc4-9b57-eb2a2cacee12} + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/StoragePickers/cpp-sample/MainWindow.idl b/Samples/StoragePickers/cpp-sample/MainWindow.idl new file mode 100644 index 000000000..2c7202940 --- /dev/null +++ b/Samples/StoragePickers/cpp-sample/MainWindow.idl @@ -0,0 +1,8 @@ +namespace FilePickersAppSinglePackaged +{ + [default_interface] + runtimeclass MainWindow : Microsoft.UI.Xaml.Window + { + MainWindow(); + } +} diff --git a/Samples/StoragePickers/cpp-sample/MainWindow.xaml b/Samples/StoragePickers/cpp-sample/MainWindow.xaml new file mode 100644 index 000000000..0bce46907 --- /dev/null +++ b/Samples/StoragePickers/cpp-sample/MainWindow.xaml @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +