From 242dc3d579d1affbede9df6e838574e318c8d6e5 Mon Sep 17 00:00:00 2001 From: Anton Fedchin Date: Tue, 3 Apr 2018 17:19:34 +0300 Subject: [win10] storage: move implementation to platform folder. --- cmake/treedata/windowsstore/subdirs.txt | 2 +- xbmc/platform/win10/storage/CMakeLists.txt | 5 + .../win10/storage/Win10StorageProvider.cpp | 134 +++++++++++++++++++++ xbmc/platform/win10/storage/Win10StorageProvider.h | 47 ++++++++ xbmc/storage/win10/CMakeLists.txt | 5 - xbmc/storage/win10/Win10StorageProvider.cpp | 134 --------------------- xbmc/storage/win10/Win10StorageProvider.h | 47 -------- 7 files changed, 187 insertions(+), 187 deletions(-) create mode 100644 xbmc/platform/win10/storage/CMakeLists.txt create mode 100644 xbmc/platform/win10/storage/Win10StorageProvider.cpp create mode 100644 xbmc/platform/win10/storage/Win10StorageProvider.h delete mode 100644 xbmc/storage/win10/CMakeLists.txt delete mode 100644 xbmc/storage/win10/Win10StorageProvider.cpp delete mode 100644 xbmc/storage/win10/Win10StorageProvider.h diff --git a/cmake/treedata/windowsstore/subdirs.txt b/cmake/treedata/windowsstore/subdirs.txt index 4b94e81e44..97d22730d5 100644 --- a/cmake/treedata/windowsstore/subdirs.txt +++ b/cmake/treedata/windowsstore/subdirs.txt @@ -1,5 +1,6 @@ xbmc/platform/win10 platform/win10 xbmc/platform/win10/filesystem platform/win10/filesystem +xbmc/platform/win10/storage platfrom/win10/storage xbmc/platform/win32/filesystem platform/win32/filesystem xbmc/input/touch input/touch xbmc/input/touch/generic input/touch/generic @@ -7,7 +8,6 @@ xbmc/network/win10 network/win10 xbmc/network/mdns network/mdns xbmc/peripherals/bus/win10 peripherals/bus/win10 xbmc/powermanagement/win10 powermanagement/win10 -xbmc/storage/win10 storage/win10 xbmc/utils/win32 utils/win32 xbmc/rendering/dx rendering/dx xbmc/threads/platform/win threads/win diff --git a/xbmc/platform/win10/storage/CMakeLists.txt b/xbmc/platform/win10/storage/CMakeLists.txt new file mode 100644 index 0000000000..84f3f595bf --- /dev/null +++ b/xbmc/platform/win10/storage/CMakeLists.txt @@ -0,0 +1,5 @@ +set(SOURCES Win10StorageProvider.cpp) + +set(HEADERS Win10StorageProvider.h) + +core_add_library(platform_win10_storage) diff --git a/xbmc/platform/win10/storage/Win10StorageProvider.cpp b/xbmc/platform/win10/storage/Win10StorageProvider.cpp new file mode 100644 index 0000000000..56371ba6a8 --- /dev/null +++ b/xbmc/platform/win10/storage/Win10StorageProvider.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2005-2013 Team XBMC + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * . + * + */ +#include "Win10StorageProvider.h" +#include "guilib/LocalizeStrings.h" +#include "filesystem/SpecialProtocol.h" +#include "platform/win10/AsyncHelpers.h" +#include "platform/win10/filesystem/WinLibraryDirectory.h" +#include "platform/win32/CharsetConverter.h" +#include "storage/MediaManager.h" +#include "utils/JobManager.h" +#include "utils/log.h" +#include "utils/StringUtils.h" + +using namespace Windows::Foundation; +using namespace Windows::Devices::Enumeration; + +IStorageProvider* IStorageProvider::CreateInstance() +{ + return new CStorageProvider(); +} + +CStorageProvider::~CStorageProvider() +{ + if (m_watcher && m_watcher->Status == DeviceWatcherStatus::Started) + m_watcher->Stop(); +} + +void CStorageProvider::Initialize() +{ + m_changed = false; + // TODO check for a optical drive (available on desktop) + g_mediaManager.SetHasOpticalDrive(false); + + m_watcher = DeviceInformation::CreateWatcher(DeviceClass::PortableStorageDevice); + auto handler = [this](DeviceWatcher^, DeviceInformation^) + { + m_changed = true; + }; + auto handler2 = [this](DeviceWatcher^, DeviceInformationUpdate^) + { + m_changed = true; + }; + + m_watcher->Added += ref new TypedEventHandler(handler); + m_watcher->Removed += ref new TypedEventHandler(handler2); + m_watcher->Updated += ref new TypedEventHandler(handler2); + m_watcher->Start(); +} + +void CStorageProvider::GetLocalDrives(VECSOURCES &localDrives) +{ + CMediaSource share; + share.strPath = CSpecialProtocol::TranslatePath("special://home"); + share.strName = g_localizeStrings.Get(21440); + share.m_ignore = true; + share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL; + + localDrives.push_back(share); +} + +void CStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives) +{ + using KODI::PLATFORM::WINDOWS::FromW; + try + { + auto devicesView = Wait(Windows::Storage::KnownFolders::RemovableDevices->GetFoldersAsync()); + for (unsigned i = 0; i < devicesView->Size; i++) + { + CMediaSource source; + auto device = devicesView->GetAt(i); + source.strName = FromW(device->DisplayName->Data()); + std::string driveLetter = FromW(device->Name->Data()).substr(0, 1); + source.strPath = "win-lib://removable/" + driveLetter + "/"; + source.m_iDriveType = CMediaSource::SOURCE_TYPE_REMOVABLE; + + removableDrives.push_back(source); + } + } + catch (Platform::Exception^) + { + } +} + +std::string CStorageProvider::GetFirstOpticalDeviceFileName() +{ + return ""; +} + +bool CStorageProvider::Eject(const std::string& mountpath) +{ + return false; +} + +std::vector CStorageProvider::GetDiskUsage() +{ + std::vector result; + ULARGE_INTEGER ULTotal = { { 0 } }; + ULARGE_INTEGER ULTotalFree = { { 0 } }; + std::string strRet; + + Platform::String^ localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path; + std::wstring folderNameW(localfolder->Data()); + + GetDiskFreeSpaceExW(folderNameW.c_str(), nullptr, &ULTotal, &ULTotalFree); + strRet = KODI::PLATFORM::WINDOWS::FromW(StringUtils::Format(L"%d MB %s", (ULTotalFree.QuadPart / (1024 * 1024)), g_localizeStrings.Get(160).c_str())); + result.push_back(strRet); + + return result; +} + +bool CStorageProvider::PumpDriveChangeEvents(IStorageEventsCallback *callback) +{ + bool res = m_changed.load(); + m_changed = false; + return res; +} + diff --git a/xbmc/platform/win10/storage/Win10StorageProvider.h b/xbmc/platform/win10/storage/Win10StorageProvider.h new file mode 100644 index 0000000000..b22e2deb6c --- /dev/null +++ b/xbmc/platform/win10/storage/Win10StorageProvider.h @@ -0,0 +1,47 @@ +#pragma once +/* + * Copyright (C) 2005-2013 Team XBMC + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * . + * + */ + +#include +#include +#include + +#include "storage/IStorageProvider.h" +#include "utils/Job.h" + +class CStorageProvider : public IStorageProvider +{ +public: + virtual ~CStorageProvider(); + + void Initialize() override; + void Stop() override { } + + void GetLocalDrives(VECSOURCES &localDrives) override; + void GetRemovableDrives(VECSOURCES &removableDrives) override; + std::string GetFirstOpticalDeviceFileName() override; + bool Eject(const std::string& mountpath) override; + std::vector GetDiskUsage() override; + bool PumpDriveChangeEvents(IStorageEventsCallback *callback) override; + +private: + Windows::Devices::Enumeration::DeviceWatcher^ m_watcher{ nullptr }; + std::atomic m_changed; +}; diff --git a/xbmc/storage/win10/CMakeLists.txt b/xbmc/storage/win10/CMakeLists.txt deleted file mode 100644 index 22d796e8df..0000000000 --- a/xbmc/storage/win10/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -set(SOURCES Win10StorageProvider.cpp) - -set(HEADERS Win10StorageProvider.h) - -core_add_library(storage_win10) diff --git a/xbmc/storage/win10/Win10StorageProvider.cpp b/xbmc/storage/win10/Win10StorageProvider.cpp deleted file mode 100644 index 56371ba6a8..0000000000 --- a/xbmc/storage/win10/Win10StorageProvider.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ -#include "Win10StorageProvider.h" -#include "guilib/LocalizeStrings.h" -#include "filesystem/SpecialProtocol.h" -#include "platform/win10/AsyncHelpers.h" -#include "platform/win10/filesystem/WinLibraryDirectory.h" -#include "platform/win32/CharsetConverter.h" -#include "storage/MediaManager.h" -#include "utils/JobManager.h" -#include "utils/log.h" -#include "utils/StringUtils.h" - -using namespace Windows::Foundation; -using namespace Windows::Devices::Enumeration; - -IStorageProvider* IStorageProvider::CreateInstance() -{ - return new CStorageProvider(); -} - -CStorageProvider::~CStorageProvider() -{ - if (m_watcher && m_watcher->Status == DeviceWatcherStatus::Started) - m_watcher->Stop(); -} - -void CStorageProvider::Initialize() -{ - m_changed = false; - // TODO check for a optical drive (available on desktop) - g_mediaManager.SetHasOpticalDrive(false); - - m_watcher = DeviceInformation::CreateWatcher(DeviceClass::PortableStorageDevice); - auto handler = [this](DeviceWatcher^, DeviceInformation^) - { - m_changed = true; - }; - auto handler2 = [this](DeviceWatcher^, DeviceInformationUpdate^) - { - m_changed = true; - }; - - m_watcher->Added += ref new TypedEventHandler(handler); - m_watcher->Removed += ref new TypedEventHandler(handler2); - m_watcher->Updated += ref new TypedEventHandler(handler2); - m_watcher->Start(); -} - -void CStorageProvider::GetLocalDrives(VECSOURCES &localDrives) -{ - CMediaSource share; - share.strPath = CSpecialProtocol::TranslatePath("special://home"); - share.strName = g_localizeStrings.Get(21440); - share.m_ignore = true; - share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL; - - localDrives.push_back(share); -} - -void CStorageProvider::GetRemovableDrives(VECSOURCES &removableDrives) -{ - using KODI::PLATFORM::WINDOWS::FromW; - try - { - auto devicesView = Wait(Windows::Storage::KnownFolders::RemovableDevices->GetFoldersAsync()); - for (unsigned i = 0; i < devicesView->Size; i++) - { - CMediaSource source; - auto device = devicesView->GetAt(i); - source.strName = FromW(device->DisplayName->Data()); - std::string driveLetter = FromW(device->Name->Data()).substr(0, 1); - source.strPath = "win-lib://removable/" + driveLetter + "/"; - source.m_iDriveType = CMediaSource::SOURCE_TYPE_REMOVABLE; - - removableDrives.push_back(source); - } - } - catch (Platform::Exception^) - { - } -} - -std::string CStorageProvider::GetFirstOpticalDeviceFileName() -{ - return ""; -} - -bool CStorageProvider::Eject(const std::string& mountpath) -{ - return false; -} - -std::vector CStorageProvider::GetDiskUsage() -{ - std::vector result; - ULARGE_INTEGER ULTotal = { { 0 } }; - ULARGE_INTEGER ULTotalFree = { { 0 } }; - std::string strRet; - - Platform::String^ localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path; - std::wstring folderNameW(localfolder->Data()); - - GetDiskFreeSpaceExW(folderNameW.c_str(), nullptr, &ULTotal, &ULTotalFree); - strRet = KODI::PLATFORM::WINDOWS::FromW(StringUtils::Format(L"%d MB %s", (ULTotalFree.QuadPart / (1024 * 1024)), g_localizeStrings.Get(160).c_str())); - result.push_back(strRet); - - return result; -} - -bool CStorageProvider::PumpDriveChangeEvents(IStorageEventsCallback *callback) -{ - bool res = m_changed.load(); - m_changed = false; - return res; -} - diff --git a/xbmc/storage/win10/Win10StorageProvider.h b/xbmc/storage/win10/Win10StorageProvider.h deleted file mode 100644 index b22e2deb6c..0000000000 --- a/xbmc/storage/win10/Win10StorageProvider.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once -/* - * Copyright (C) 2005-2013 Team XBMC - * http://kodi.tv - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#include -#include -#include - -#include "storage/IStorageProvider.h" -#include "utils/Job.h" - -class CStorageProvider : public IStorageProvider -{ -public: - virtual ~CStorageProvider(); - - void Initialize() override; - void Stop() override { } - - void GetLocalDrives(VECSOURCES &localDrives) override; - void GetRemovableDrives(VECSOURCES &removableDrives) override; - std::string GetFirstOpticalDeviceFileName() override; - bool Eject(const std::string& mountpath) override; - std::vector GetDiskUsage() override; - bool PumpDriveChangeEvents(IStorageEventsCallback *callback) override; - -private: - Windows::Devices::Enumeration::DeviceWatcher^ m_watcher{ nullptr }; - std::atomic m_changed; -}; -- cgit v1.2.3