/* * Copyright (c) 2017 Samsung Electronics Co., Ltd * * Licensed under the Flora License, Version 1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://floralicense.org/license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Xamarin.Forms; namespace LibTVRefCommonPortable.Utils { /// /// A class for file system control function. /// class FileSystemUtils { /// /// A instance of file system port layer /// private static IFileSystemAPIs fileSystemAPIs; /// /// A instance of FileSystemUtils /// private static readonly FileSystemUtils instance = new FileSystemUtils(); /// /// A property of FileSystemUtils instance /// public static FileSystemUtils Instance { get { return instance; } } /// /// A unit test stub for FileSystemUtils /// private class TestStub : IFileSystemAPIs { /// /// A directory path which should be used for app data storing. /// public string AppDataStorage { get { return "test_app_data_path/"; } } /// /// A directory path which should be used for app resource storing. /// public string AppResourceStorage { get { return "test_app_resource_path/"; } } /// /// A directory path which should be used for sharing between apps. /// public string PlatformShareStorage { get { return "test_platform_share_path/"; } } /// /// A method closes the file. /// /// A file descriptor public void CloseFile(Stream stream) { } /// /// A method flushing the stream to write remains. /// /// A file descriptor public void Flush(Stream stream) { } /// /// A method checks if a file existence in the file system. /// /// A file path /// An existence of the file public bool IsFileExist(string filePath) { return true; } /// /// A method checks if file is read to use. /// /// A file path /// A status of ready public bool IsFileReady(string filePath) { return true; } /// /// A method opens a file on the given mode. /// /// A file path /// An opening mode /// A file descriptor public Stream OpenFile(string filePath, UtilFileMode mode) { throw new NotImplementedException(); } } /// /// A constructor /// private FileSystemUtils() { fileSystemAPIs = new TestStub(); try { if (DependencyService.Get() != null) { fileSystemAPIs = DependencyService.Get(); } } catch (InvalidOperationException e) { DebuggingUtils.Err(e.Message); } } /// /// A directory path which should be used for app data storing. /// public string AppDataStorage { get { return fileSystemAPIs.AppDataStorage; } } /// /// A directory path which should be used for app resource storing. /// public string AppResourceStorage { get { return fileSystemAPIs.AppResourceStorage; } } /// /// A directory path which should be used for sharing between apps. /// public string PlatformShareStorage { get { return fileSystemAPIs.PlatformShareStorage; } } /// /// A method opens a file on the given mode. /// /// A file path /// An opening mode /// A file descriptor public Stream OpenFile(string filePath, UtilFileMode mode) { return fileSystemAPIs.OpenFile(filePath, mode); } /// /// A method flushing the stream to write remains. /// /// A file descriptor public void Flush(Stream stream) { fileSystemAPIs.Flush(stream); } /// /// A method closes the file. /// /// A file descriptor public void CloseFile(Stream stream) { fileSystemAPIs.CloseFile(stream); } /// /// A method checks if a file existence in the file system. /// /// A file path /// An existence of the file public bool IsFileExist(String filePath) { return fileSystemAPIs.IsFileExist(filePath); } /// /// A method checks if file is read to use. /// /// A file path /// A status of ready public bool IsFileReady(String filePath) { return fileSystemAPIs.IsFileReady(filePath); } } }