| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | ContainerVolume.cpp |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | This file contains the implementation of the WinRT wrapper for the WSLC SDK ContainerVolume class. |
| 12 | |
| 13 | --*/ |
| 14 | |
| 15 | #include "precomp.h" |
| 16 | #include "ContainerVolume.h" |
| 17 | #include "Microsoft.WSL.Containers.ContainerVolume.g.cpp" |
| 18 | |
| 19 | namespace winrt::Microsoft::WSL::Containers::implementation { |
| 20 | |
| 21 | ContainerVolume::ContainerVolume(hstring const& windowsPath, hstring const& containerPath, bool readOnly) : |
| 22 | m_windowsPath(windowsPath), m_containerPath(winrt::to_string(containerPath)), m_readOnly(readOnly) |
| 23 | { |
| 24 | if (windowsPath.empty()) |
| 25 | { |
| 26 | throw hresult_invalid_argument(L"Windows path cannot be empty"); |
| 27 | } |
| 28 | |
| 29 | if (containerPath.empty()) |
| 30 | { |
| 31 | throw hresult_invalid_argument(L"Container path cannot be empty"); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | hstring ContainerVolume::WindowsPath() |
| 36 | { |
| 37 | return hstring(m_windowsPath); |
| 38 | } |
| 39 | |
| 40 | void ContainerVolume::WindowsPath(hstring const& value) |
| 41 | { |
| 42 | if (m_containerVolume) |
| 43 | { |
| 44 | throw hresult_illegal_state_change(L"Cannot change value after options have been applied"); |
| 45 | } |
| 46 | |
| 47 | if (value.empty()) |
| 48 | { |
| 49 | throw hresult_invalid_argument(L"Windows path cannot be empty"); |
| 50 | } |
| 51 | |
| 52 | m_windowsPath = value; |
| 53 | } |
| 54 | |
| 55 | hstring ContainerVolume::ContainerPath() |
| 56 | { |
| 57 | return winrt::to_hstring(m_containerPath); |
| 58 | } |
| 59 | |
| 60 | void ContainerVolume::ContainerPath(hstring const& value) |
| 61 | { |
| 62 | if (m_containerVolume) |
| 63 | { |
| 64 | throw hresult_illegal_state_change(L"Cannot change value after options have been applied"); |
| 65 | } |
| 66 | |
| 67 | if (value.empty()) |
| 68 | { |
| 69 | throw hresult_invalid_argument(L"Container path cannot be empty"); |
| 70 | } |
| 71 | |
| 72 | m_containerPath = winrt::to_string(value); |
| 73 | } |
| 74 | |
| 75 | bool ContainerVolume::ReadOnly() |
| 76 | { |
| 77 | return m_readOnly; |
| 78 | } |
| 79 | |
| 80 | void ContainerVolume::ReadOnly(bool value) |
| 81 | { |
| 82 | if (m_containerVolume) |
| 83 | { |
| 84 | throw hresult_illegal_state_change(L"Cannot change value after options have been applied"); |
| 85 | } |
| 86 | |
| 87 | m_readOnly = value; |
| 88 | } |
| 89 | |
| 90 | WslcContainerVolume ContainerVolume::ToStruct() |
| 91 | { |
| 92 | if (!m_containerVolume) |
| 93 | { |
| 94 | m_containerVolume = std::make_unique<WslcContainerVolume>(); |
| 95 | m_containerVolume->windowsPath = m_windowsPath.c_str(); |
| 96 | m_containerVolume->containerPath = m_containerPath.c_str(); |
| 97 | m_containerVolume->readOnly = m_readOnly; |
| 98 | } |
| 99 | |
| 100 | return *m_containerVolume; |
| 101 | } |
| 102 | |
| 103 | } // namespace winrt::Microsoft::WSL::Containers::implementation |