Commit bbcfed31 authored by Soomin Lee's avatar Soomin Lee Committed by Hugo Beauzée-Luyssen

fs: darwin: Add DeviceLister

Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent ef5a2eda
......@@ -137,6 +137,7 @@ noinst_HEADERS = \
src/filesystem/common/CommonFile.h \
src/filesystem/common/CommonDirectory.h \
src/filesystem/common/CommonDevice.h \
src/filesystem/darwin/DeviceLister.h \
src/filesystem/unix/Device.h \
src/filesystem/unix/Directory.h \
src/filesystem/unix/File.h \
......@@ -204,7 +205,8 @@ endif
if HAVE_DARWIN
libmedialibrary_macos_la_CPPFLAGS = $(libmedialibrary_la_CPPFLAGS)
libmedialibrary_macos_la_SOURCES = \
src/filesystem/darwin/DeviceLister.mm
src/filesystem/darwin/DeviceLister.mm \
$(NULL)
endif
endif
......
......@@ -35,6 +35,9 @@
# if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
# define USE_BUILTIN_DEVICE_LISTER 1
# endif
#elif defined(__APPLE__)
# include "filesystem/darwin/DeviceLister.h"
# define USE_BUILTIN_DEVICE_LISTER 1
#endif
medialibrary::DeviceListerPtr medialibrary::factory::createDeviceLister()
......
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015-2017 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "medialibrary/IDeviceLister.h"
namespace medialibrary
{
namespace fs
{
class DeviceLister : public IDeviceLister
{
public:
virtual std::vector<std::tuple<std::string, std::string, bool>> devices() const override;
};
}
}
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015-2016 Hugo Beauzée-Luyssen, Videolabs
* Copyright (C) 2015-2017 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
* Felix Paul Kühne <fkuehne@videolan.org>
* Soomin Lee <thehungrybu@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
......@@ -22,4 +24,34 @@
*****************************************************************************/
#import <Foundation/Foundation.h>
#import "DeviceLister.h"
#include "logging/Logger.h"
#include <vector>
std::vector<std::tuple<std::string, std::string, bool>> medialibrary::fs::DeviceLister::devices() const
{
std::vector<std::tuple<std::string, std::string, bool>> res;
NSArray *keys = [NSArray arrayWithObjects:NSURLVolumeUUIDStringKey, NSURLVolumeIsRemovableKey, nil];
NSArray *mountPoints = [[NSFileManager defaultManager] mountedVolumeURLsIncludingResourceValuesForKeys:keys options:0];
if ( mountPoints.count == 0 )
{
LOG_WARN( "Failed to detect any mountpoint" );
return res;
}
for ( NSURL *url in mountPoints )
{
bool isRemovable;
std::string uuid;
NSString *tmp;
NSDictionary<NSURLResourceKey, id> *deviceInfo = [url resourceValuesForKeys:keys error:nil];
tmp = deviceInfo[NSURLVolumeUUIDStringKey];
uuid = ( tmp != nil ) ? [tmp UTF8String] : "";
isRemovable = ( ( NSNumber * )deviceInfo[NSURLVolumeIsRemovableKey] ).boolValue;
res.emplace_back( std::make_tuple( uuid, [[url absoluteString] UTF8String], isRemovable ) );
}
return res;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment