├── .gitignore ├── .nuget ├── NuGet.Config └── nuget.exe ├── LICENSE ├── PCLStorage.sln ├── README.md ├── build.bat ├── build ├── Build.tasks └── build.proj ├── common ├── CommonAssemblyInfo.cs ├── PCLStorage.nuspec ├── pickles.png ├── pickles.txt ├── pickles_64.png ├── pickles_square.png └── strongnamekey.snk ├── src ├── PCLStorage.Abstractions.NoSL │ ├── PCLStorage.Abstractions.NoSL.csproj │ └── Properties │ │ └── AssemblyInfo.cs ├── PCLStorage.Abstractions │ ├── ExistenceCheckResult.cs │ ├── FileExtensions.cs │ ├── IFile.cs │ ├── IFileSystem.cs │ ├── IFolder.cs │ ├── NameCollisionOption.cs │ ├── PCLStorage.Abstractions.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config ├── PCLStorage.Android │ ├── PCLStorage.Android.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Resources │ │ └── Resource.Designer.cs │ └── app.config ├── PCLStorage.FileSystem.Desktop │ ├── DesktopFileSystem.cs │ ├── FileSystemFile.cs │ ├── FileSystemFolder.cs │ ├── PCLStorage.FileSystem.Desktop.csproj │ └── Properties │ │ └── AssemblyInfo.cs ├── PCLStorage.IsoStore.SL │ ├── IsoStoreFile.cs │ ├── IsoStoreFileSystem.cs │ ├── IsoStoreFolder.cs │ ├── PCLStorage.IsoStore.SL.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── app.config │ └── packages.config ├── PCLStorage.NoSL │ ├── PCLStorage.NoSL.csproj │ └── Properties │ │ └── AssemblyInfo.cs ├── PCLStorage.WinRT │ ├── AwaitExtensions.WinRT.cs │ ├── PCLStorage.WinRT.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── WinRTFile.cs │ ├── WinRTFileSystem.cs │ └── WinRTFolder.cs ├── PCLStorage.WindowsPhone │ ├── PCLStorage.WindowsPhone.csproj │ └── Properties │ │ └── AssemblyInfo.cs ├── PCLStorage.iOS-Unified │ ├── PCLStorage.iOS-Unified.csproj │ └── Properties │ │ └── AssemblyInfo.cs ├── PCLStorage.iOS │ ├── PCLStorage.iOS.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ └── app.config └── PCLStorage │ ├── AwaitExtensions.cs │ ├── Exceptions │ └── PCLStorageExceptions.cs │ ├── FileSystem.cs │ ├── PCLStorage.csproj │ ├── PortablePath.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Requires.cs │ ├── app.config │ └── packages.config └── test ├── PCLStorage.Test.Android ├── Activity1.cs ├── Assets │ └── AboutAssets.txt ├── PCLStorage.Test.Android.csproj ├── Properties │ ├── AndroidManifest.xml │ └── AssemblyInfo.cs ├── Resources │ ├── AboutResources.txt │ ├── Drawable │ │ └── Icon.png │ ├── Layout │ │ └── Main.axml │ ├── Resource.Designer.cs │ └── Values │ │ └── Strings.xml ├── app.config └── packages.config ├── PCLStorage.Test.Desktop ├── AwaitExtensionsTest.cs ├── PCLStorage.Test.Desktop.csproj ├── Properties │ └── AssemblyInfo.cs ├── UIDispatcherMock.cs └── packages.config ├── PCLStorage.Test.SL ├── App.xaml ├── App.xaml.cs ├── MainPage.xaml ├── MainPage.xaml.cs ├── PCLStorage.Test.SL.csproj ├── Properties │ ├── AppManifest.xml │ └── AssemblyInfo.cs ├── app.config └── packages.config ├── PCLStorage.Test.WinRT ├── FileTestsForDesktop.cs ├── Images │ ├── UnitTestLogo.png │ ├── UnitTestSmallLogo.png │ ├── UnitTestSplashScreen.png │ └── UnitTestStoreLogo.png ├── PCLStorage.Test.WinRT.csproj ├── PCLStorage.Test.WinRT_TemporaryKey.pfx ├── Package.appxmanifest ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── PCLStorage.Test.WindowsPhone ├── App.xaml ├── App.xaml.cs ├── ApplicationIcon.png ├── Background.png ├── MainPage.xaml ├── MainPage.xaml.cs ├── PCLStorage.Test.WindowsPhone.csproj ├── Properties │ ├── AppManifest.xml │ ├── AssemblyInfo.cs │ └── WMAppManifest.xml ├── SplashScreenImage.jpg └── packages.config └── PCLStorage.Test ├── FileSystemTests.cs ├── FileTests.cs ├── FolderTests.cs ├── PCLStorage.Test.csproj ├── Properties └── AssemblyInfo.cs ├── app.config └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # NuGet packages 10 | packages/ 11 | 12 | # Build results 13 | 14 | [Dd]ebug/ 15 | [Rr]elease/ 16 | x64/ 17 | #build/ 18 | [Bb]in/ 19 | [Oo]bj/ 20 | [Oo]utput/ 21 | 22 | *.sln.ide/ 23 | 24 | # MSTest test Results 25 | [Tt]est[Rr]esult*/ 26 | [Bb]uild[Ll]og.* 27 | 28 | *_i.c 29 | *_p.c 30 | *.ilk 31 | *.meta 32 | *.obj 33 | *.pch 34 | *.pdb 35 | *.pgc 36 | *.pgd 37 | *.rsp 38 | *.sbr 39 | *.tlb 40 | *.tli 41 | *.tlh 42 | *.tmp 43 | *.tmp_proj 44 | *.log 45 | *.vspscc 46 | *.vssscc 47 | .builds 48 | *.pidb 49 | *.log 50 | *.scc 51 | 52 | # Visual C++ cache files 53 | ipch/ 54 | *.aps 55 | *.ncb 56 | *.opensdf 57 | *.sdf 58 | *.cachefile 59 | 60 | # Visual Studio profiler 61 | *.psess 62 | *.vsp 63 | *.vspx 64 | 65 | # Guidance Automation Toolkit 66 | *.gpState 67 | 68 | # ReSharper is a .NET coding add-in 69 | _ReSharper*/ 70 | *.[Rr]e[Ss]harper 71 | 72 | # TeamCity is a build add-in 73 | _TeamCity* 74 | 75 | # DotCover is a Code Coverage Tool 76 | *.dotCover 77 | 78 | # NCrunch 79 | *.ncrunch* 80 | .*crunch*.local.xml 81 | 82 | # Installshield output folder 83 | [Ee]xpress/ 84 | 85 | # DocProject is a documentation generator add-in 86 | DocProject/buildhelp/ 87 | DocProject/Help/*.HxT 88 | DocProject/Help/*.HxC 89 | DocProject/Help/*.hhc 90 | DocProject/Help/*.hhk 91 | DocProject/Help/*.hhp 92 | DocProject/Help/Html2 93 | DocProject/Help/html 94 | 95 | # Click-Once directory 96 | publish/ 97 | 98 | # Publish Web Output 99 | *.Publish.xml 100 | *.pubxml 101 | 102 | # NuGet Packages Directory 103 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 104 | #packages/ 105 | 106 | # Windows Azure Build Output 107 | csx 108 | *.build.csdef 109 | 110 | # Windows Store app package directory 111 | AppPackages/ 112 | 113 | # Others 114 | sql/ 115 | *.Cache 116 | ClientBin/ 117 | [Ss]tyle[Cc]op.* 118 | ~$* 119 | *~ 120 | *.dbmdl 121 | *.[Pp]ublish.xml 122 | *.pfx 123 | *.publishsettings 124 | 125 | # RIA/Silverlight projects 126 | Generated_Code/ 127 | 128 | # Backup & report files from converting an old project file to a newer 129 | # Visual Studio version. Backup files are not needed, because we have git ;-) 130 | _UpgradeReport_Files/ 131 | Backup*/ 132 | UpgradeLog*.XML 133 | UpgradeLog*.htm 134 | 135 | # SQL Server files 136 | App_Data/*.mdf 137 | App_Data/*.ldf 138 | 139 | # ========================= 140 | # Windows detritus 141 | # ========================= 142 | 143 | # Windows image file caches 144 | Thumbs.db 145 | ehthumbs.db 146 | 147 | # Folder config file 148 | Desktop.ini 149 | 150 | # Recycle Bin used on file shares 151 | $RECYCLE.BIN/ 152 | 153 | # Mac crap 154 | .DS_Store 155 | -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/nuget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsplaisted/PCLStorage/367df4961332f3edb5156eb47d64af6b1dcc8de7/.nuget/nuget.exe -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Microsoft Public License (Ms-PL) 2 | 3 | This license governs use of the accompanying software. If you use the software, 4 | you accept this license. If you do not accept the license, do not use the 5 | software. 6 | 7 | 1. Definitions 8 | 9 | The terms "reproduce," "reproduction," "derivative works," and "distribution" 10 | have the same meaning here as under U.S. copyright law. 11 | 12 | A "contribution" is the original software, or any additions or changes to the 13 | software. 14 | 15 | A "contributor" is any person that distributes its contribution under this 16 | license. 17 | 18 | "Licensed patents" are a contributor's patent claims that read directly on its 19 | contribution. 20 | 21 | 2. Grant of Rights 22 | 23 | (A) Copyright Grant- Subject to the terms of this license, including the license 24 | conditions and limitations in section 3, each contributor grants you a 25 | non-exclusive, worldwide, royalty-free copyright license to reproduce its 26 | contribution, prepare derivative works of its contribution, and distribute its 27 | contribution or any derivative works that you create. 28 | 29 | (B) Patent Grant- Subject to the terms of this license, including the license 30 | conditions and limitations in section 3, each contributor grants you a 31 | non-exclusive, worldwide, royalty-free license under its licensed patents to 32 | make, have made, use, sell, offer for sale, import, and/or otherwise dispose of 33 | its contribution in the software or derivative works of the contribution in the 34 | software. 35 | 36 | 3. Conditions and Limitations 37 | 38 | (A) No Trademark License- This license does not grant you rights to use any 39 | contributors' name, logo, or trademarks. 40 | 41 | (B) If you bring a patent claim against any contributor over patents that you 42 | claim are infringed by the software, your patent license from such contributor 43 | to the software ends automatically. 44 | 45 | (C) If you distribute any portion of the software, you must retain all 46 | copyright, patent, trademark, and attribution notices that are present in the 47 | software. 48 | 49 | (D) If you distribute any portion of the software in source code form, you may 50 | do so only under this license by including a complete copy of this license with 51 | your distribution. If you distribute any portion of the software in compiled or 52 | object code form, you may only do so under a license that complies with this 53 | license. 54 | 55 | (E) The software is licensed "as-is." You bear the risk of using it. The 56 | contributors give no express warranties, guarantees or conditions. You may have 57 | additional consumer rights under your local laws which this license cannot 58 | change. To the extent permitted under your local laws, the contributors exclude 59 | the implied warranties of merchantability, fitness for a particular purpose and 60 | non-infringement. 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PCL Storage 2 | 3 | ![PCL Storage](https://dsplaisted.blob.core.windows.net/oss/pickles_64.png) 4 | 5 | PCL Storage provides a consistent, portable set of local file IO APIs for .NET, 6 | Windows Phone, Windows Store, Xamarin.iOS, Xamarin.Android, and Silverlight. 7 | This makes it easier to create cross-platform .NET libraries and apps. 8 | 9 | Here is a sample showing how you can use PCL Storage to create a folder and 10 | write to a text file in that folder: 11 | 12 | ```C# 13 | public async Task PCLStorageSample() 14 | { 15 | IFolder rootFolder = FileSystem.Current.LocalStorage; 16 | IFolder folder = await rootFolder.CreateFolderAsync("MySubFolder", 17 | CreationCollisionOption.OpenIfExists); 18 | IFile file = await folder.CreateFileAsync("answer.txt", 19 | CreationCollisionOption.ReplaceExisting); 20 | await file.WriteAllTextAsync("42"); 21 | } 22 | ``` 23 | 24 | ## Installation 25 | 26 | Install the [PCLStorage NuGet Package](http://nuget.org/packages/pclstorage). 27 | 28 | If you reference the package from a Portable Class Library, you will also need 29 | to reference the package from each platform-specific app. This is because the 30 | Portable Class Library version of PCL Storage doesn't contain the actual 31 | implementation of the storage APIs (because it differs from platform to 32 | platform), so referencing the package from an app will ensure that the 33 | platform-specific version of PCL Storage is included in the app and used at 34 | runtime. 35 | 36 | ## Background information 37 | 38 | Different .NET platforms have different APIs for accessing the file system or 39 | an app-local persisted storage area. The full .NET Framework provides the 40 | standard file and directory APIs (in the System.IO namespace), Silverlight and 41 | Windows Phone provide isolated storage APIs, and WinRT provides storage APIs in 42 | the Windows.Storage namespace. 43 | 44 | These differing APIs make it harder to write cross-platform code. Traditionally, 45 | you could handle this via conditional compilation. However, that means you can't 46 | take advantage of Portable Class Libraries, and in any case may not scale well 47 | as your code gets complex (and especially because for WinRT you need to use 48 | async APIs). 49 | 50 | Alternatively, you can create an abstraction for the functionality you need 51 | across platforms, and implement the abstraction for each platform you need to 52 | use. This approach allows you to use Portable Class Libraries, and in general 53 | makes your code cleaner and more maintainable by isolating the platform-specific 54 | pieces instead of having them sprinkled arbitrarily throughout your code. 55 | 56 | Writing an abstraction layer is a bit of a barrier to entry to writing 57 | cross-platform code, and there's no reason everyone should have to do it 58 | separately for functionality as commonly needed as local file IO. PCL Storage 59 | aims to provide a common abstraction that is easy to take advantage of. 60 | 61 | ## APIs 62 | 63 | [API documentation for PCL 64 | Storage](http://www.nudoq.org/#!/Packages/PCLStorage/PCLStorage/FileSystem) can 65 | be found at [NuDoq](http://www.nudoq.org). The definitions for the main 66 | APIs in PCL Storage are below. 67 | 68 | The primary APIs in PCL Storage are the [IFile][], [IFolder][], and 69 | [IFileSystem][] interfaces. The APIs should be mostly self-explanatory and 70 | should feel very familiar if you have used the WinRT storage APIs. 71 | 72 | [IFile]: http://www.nudoq.org/#!/Packages/PCLStorage/PCLStorage.Abstractions/IFile "IFile documentation" 73 | [IFolder]: http://www.nudoq.org/#!/Packages/PCLStorage/PCLStorage.Abstractions/IFolder "IFolder documentation" 74 | [IFileSystem]: http://www.nudoq.org/#!/Packages/PCLStorage/PCLStorage.Abstractions/IFileSystem "IFileSystem documentation" 75 | 76 | The [IFileSystem][] interface is the main API entry point. You can get an instance 77 | of the implementation for the current platform with the [FileSystem.Current][] 78 | property. 79 | 80 | [FileSystem.Current]: http://www.nudoq.org/#!/Packages/PCLStorage/PCLStorage/FileSystem/P/Current "FileSystem.Current documentation" 81 | 82 | ```C# 83 | namespace PCLStorage 84 | { 85 | public static class FileSystem 86 | { 87 | public static IFileSystem Current { get; } 88 | } 89 | 90 | public interface IFileSystem 91 | { 92 | IFolder LocalStorage { get; } 93 | IFolder RoamingStorage { get; } 94 | 95 | Task GetFileFromPathAsync(string path); 96 | Task GetFolderFromPathAsync(string path); 97 | } 98 | 99 | public enum CreationCollisionOption 100 | { 101 | GenerateUniqueName = 0, 102 | ReplaceExisting = 1, 103 | FailIfExists = 2, 104 | OpenIfExists = 3, 105 | } 106 | 107 | public interface IFolder 108 | { 109 | string Name { get; } 110 | string Path { get; } 111 | 112 | Task CreateFileAsync(string desiredName, CreationCollisionOption option); 113 | Task GetFileAsync(string name); 114 | Task> GetFilesAsync(); 115 | 116 | Task CreateFolderAsync(string desiredName, 117 | CreationCollisionOption option); 118 | Task GetFolderAsync(string name); 119 | Task> GetFoldersAsync(); 120 | 121 | Task CheckExistsAsync(string name, 122 | CancellationToken cancellationToken = default(CancellationToken)); 123 | 124 | Task DeleteAsync(); 125 | } 126 | 127 | public enum FileAccess 128 | { 129 | Read, 130 | ReadAndWrite 131 | } 132 | 133 | public interface IFile 134 | { 135 | string Name { get; } 136 | string Path { get; } 137 | 138 | Task OpenAsync(FileAccess fileAccess); 139 | Task DeleteAsync(); 140 | Task RenameAsync(string newName, 141 | NameCollisionOption collisionOption = NameCollisionOption.FailIfExists, 142 | CancellationToken cancellationToken = default(CancellationToken)); 143 | Task MoveAsync(string newPath, 144 | NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting, 145 | CancellationToken cancellationToken = default(CancellationToken)); 146 | } 147 | 148 | public static class PortablePath 149 | { 150 | public static char DirectorySeparatorChar { get; } 151 | public static string Combine(params string[] paths); 152 | } 153 | public static class FileExtensions 154 | { 155 | public static async Task ReadAllTextAsync(this IFile file) 156 | public static async Task WriteAllTextAsync(this IFile file, string contents); 157 | } 158 | } 159 | ``` 160 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | msbuild %~dp0build\build.proj /p:Configuration=Release /t:Clean;BuildPackage -------------------------------------------------------------------------------- /build/Build.tasks: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /build/build.proj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $(MSBuildProjectDirectory)\.. 7 | $(PCLStorageRoot)\.nuget\NuGet.exe 8 | Release 9 | 10 | 11 | 12 | 1 13 | 0 14 | 2 15 | 0 16 | 17 | 18 | $(MajorVersion).$(MinorVersion).$(Build).$(Revision) 19 | $(MajorVersion).$(MinorVersion).$(Build).$(Revision) 20 | $(MajorVersion).$(MinorVersion).$(Build) 21 | 22 | 23 | 24 | 25 | AssemblyVersion\("\d+\.\d+\.\d+\.\d+"\) 26 | AssemblyVersion("$(AssemblyVersion)") 27 | 28 | 29 | AssemblyFileVersion\("\d+\.\d+\.\d+\.\d+"\) 30 | AssemblyFileVersion("$(AssemblyFileVersion)") 31 | 32 | 33 | 34 | 35 | RestorePackages;UpdateVersion 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /common/CommonAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | //[assembly: AssemblyTitle("PCLStorage")] 10 | //[assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("PCLStorage")] 14 | [assembly: AssemblyCopyright("Copyright © 2013")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | [assembly: NeutralResourcesLanguage("en")] 18 | 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Build and Revision Numbers 27 | // by using the '*' as shown below: 28 | // [assembly: AssemblyVersion("1.0.*")] 29 | [assembly: AssemblyVersion("1.0.2.0")] 30 | [assembly: AssemblyFileVersion("1.0.2.0")] 31 | -------------------------------------------------------------------------------- /common/PCLStorage.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PCLStorage 5 | 1.0.1 6 | PCL Storage - Portable Storage APIs 7 | Daniel Plaisted 8 | Daniel Plaisted 9 | https://github.com/dsplaisted/PCLStorage/blob/master/LICENSE 10 | https://github.com/dsplaisted/PCLStorage 11 | https://dsplaisted.blob.core.windows.net/oss/pickles_64.png 12 | false 13 | PCL Storage provides a consistent, portable set of local file IO APIs for .NET, Windows Phone, Windows Store, Xamarin.iOS, Xamarin.Android, and Silverlight. This makes it easier to create cross-platform .NET libraries and apps. 14 | PCL Storage provides a consistent, portable set of local file IO APIs across .NET platforms. 15 | io storage file portable pcl winrt android ios xamarin monoandroid monodroid monotouch 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /common/pickles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsplaisted/PCLStorage/367df4961332f3edb5156eb47d64af6b1dcc8de7/common/pickles.png -------------------------------------------------------------------------------- /common/pickles.txt: -------------------------------------------------------------------------------- 1 | The pickle jar logo is from sweetclipart.com (http://sweetclipart.com/jar-green-pickles-1226), and is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported license (http://creativecommons.org/licenses/by-nc-sa/3.0/). -------------------------------------------------------------------------------- /common/pickles_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsplaisted/PCLStorage/367df4961332f3edb5156eb47d64af6b1dcc8de7/common/pickles_64.png -------------------------------------------------------------------------------- /common/pickles_square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsplaisted/PCLStorage/367df4961332f3edb5156eb47d64af6b1dcc8de7/common/pickles_square.png -------------------------------------------------------------------------------- /common/strongnamekey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsplaisted/PCLStorage/367df4961332f3edb5156eb47d64af6b1dcc8de7/common/strongnamekey.snk -------------------------------------------------------------------------------- /src/PCLStorage.Abstractions.NoSL/PCLStorage.Abstractions.NoSL.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 11.0 6 | Debug 7 | AnyCPU 8 | {8F4C2E94-B8C5-477B-A315-CA58C70617E4} 9 | Library 10 | Properties 11 | PCLStorage 12 | PCLStorage.Abstractions 13 | v4.5 14 | Profile78 15 | 512 16 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 17 | ..\..\ 18 | true 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | bin\Debug\PCLStorage.Abstractions.XML 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | bin\Release\PCLStorage.Abstractions.XML 38 | 39 | 40 | true 41 | 42 | 43 | ..\..\common\strongnamekey.snk 44 | 45 | 46 | 47 | Properties\CommonAssemblyInfo.cs 48 | 49 | 50 | ExistenceCheckResult.cs 51 | 52 | 53 | FileExtensions.cs 54 | 55 | 56 | IFile.cs 57 | 58 | 59 | IFileSystem.cs 60 | 61 | 62 | IFolder.cs 63 | 64 | 65 | 66 | NameCollisionOption.cs 67 | 68 | 69 | 70 | 77 | -------------------------------------------------------------------------------- /src/PCLStorage.Abstractions.NoSL/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("PCLStorage.Abstractions")] 10 | [assembly: AssemblyDescription("")] -------------------------------------------------------------------------------- /src/PCLStorage.Abstractions/ExistenceCheckResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PCLStorage 7 | { 8 | /// 9 | /// Describes the result of a file or folder existence check. 10 | /// 11 | public enum ExistenceCheckResult 12 | { 13 | /// 14 | /// No file system entity was found at the given path. 15 | /// 16 | NotFound, 17 | 18 | /// 19 | /// A file was found at the given path. 20 | /// 21 | FileExists, 22 | 23 | /// 24 | /// A folder was found at the given path. 25 | /// 26 | FolderExists, 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/PCLStorage.Abstractions/FileExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PCLStorage 9 | { 10 | /// 11 | /// Provides extension methods for the class 12 | /// 13 | public static class FileExtensions 14 | { 15 | /// 16 | /// Reads the contents of a file as a string 17 | /// 18 | /// The file to read 19 | /// The contents of the file 20 | public static async Task ReadAllTextAsync(this IFile file) 21 | { 22 | using (var stream = await file.OpenAsync(FileAccess.Read).ConfigureAwait(false)) 23 | { 24 | using (var sr = new StreamReader(stream)) 25 | { 26 | string text = await sr.ReadToEndAsync().ConfigureAwait(false); 27 | return text; 28 | } 29 | } 30 | } 31 | 32 | /// 33 | /// Writes text to a file, overwriting any existing data 34 | /// 35 | /// The file to write to 36 | /// The content to write to the file 37 | /// A task which completes when the write operation finishes 38 | public static async Task WriteAllTextAsync(this IFile file, string contents) 39 | { 40 | using (var stream = await file.OpenAsync(FileAccess.ReadAndWrite).ConfigureAwait(false)) 41 | { 42 | stream.SetLength(0); 43 | using (var sw = new StreamWriter(stream)) 44 | { 45 | await sw.WriteAsync(contents).ConfigureAwait(false); 46 | } 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/PCLStorage.Abstractions/IFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace PCLStorage 10 | { 11 | /// 12 | /// Specifies whether a file should be opened for write access or not 13 | /// 14 | public enum FileAccess 15 | { 16 | /// 17 | /// Specifies that a file should be opened for read-only access 18 | /// 19 | Read, 20 | /// 21 | /// Specifies that a file should be opened for read/write access 22 | /// 23 | ReadAndWrite 24 | } 25 | 26 | /// 27 | /// Represents a file 28 | /// 29 | public interface IFile 30 | { 31 | /// 32 | /// The name of the file 33 | /// 34 | string Name { get; } 35 | /// 36 | /// The "full path" of the file, which should uniquely identify it within a given 37 | /// 38 | string Path { get; } 39 | 40 | /// 41 | /// Opens the file 42 | /// 43 | /// Specifies whether the file should be opened in read-only or read/write mode 44 | /// The cancellation token. 45 | /// A which can be used to read from or write to the file 46 | Task OpenAsync(FileAccess fileAccess, CancellationToken cancellationToken = default(CancellationToken)); 47 | 48 | /// 49 | /// Deletes the file 50 | /// 51 | /// The cancellation token. 52 | /// 53 | /// A task which will complete after the file is deleted. 54 | /// 55 | Task DeleteAsync(CancellationToken cancellationToken = default(CancellationToken)); 56 | 57 | /// 58 | /// Renames a file without changing its location. 59 | /// 60 | /// The new leaf name of the file. 61 | /// How to deal with collisions with existing files. 62 | /// The cancellation token. 63 | /// 64 | /// A task which will complete after the file is renamed. 65 | /// 66 | Task RenameAsync(string newName, NameCollisionOption collisionOption = NameCollisionOption.FailIfExists, CancellationToken cancellationToken = default(CancellationToken)); 67 | 68 | /// 69 | /// Moves a file. 70 | /// 71 | /// The new full path of the file. 72 | /// How to deal with collisions with existing files. 73 | /// The cancellation token. 74 | /// A task which will complete after the file is moved. 75 | Task MoveAsync(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting, CancellationToken cancellationToken = default(CancellationToken)); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/PCLStorage.Abstractions/IFileSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace PCLStorage 9 | { 10 | /// 11 | /// Represents a file system. 12 | /// 13 | public interface IFileSystem 14 | { 15 | /// 16 | /// A folder representing storage which is local to the current device 17 | /// 18 | IFolder LocalStorage { get; } 19 | /// 20 | /// A folder representing storage which may be synced with other devices for the same user 21 | /// 22 | IFolder RoamingStorage { get; } 23 | 24 | /// 25 | /// Gets a file, given its path. Returns null if the file does not exist. 26 | /// 27 | /// The path to a file, as returned from the property. 28 | /// The cancellation token. 29 | /// A file for the given path, or null if it does not exist. 30 | Task GetFileFromPathAsync(string path, CancellationToken cancellationToken = default(CancellationToken)); 31 | 32 | /// 33 | /// Gets a folder, given its path. Returns null if the folder does not exist. 34 | /// 35 | /// The path to a folder, as returned from the property. 36 | /// The cancellation token. 37 | /// A folder for the specified path, or null if it does not exist. 38 | Task GetFolderFromPathAsync(string path, CancellationToken cancellationToken = default(CancellationToken)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/PCLStorage.Abstractions/IFolder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace PCLStorage 9 | { 10 | /// 11 | /// Specifies what should happen when trying to create a file or folder that already exists. 12 | /// 13 | public enum CreationCollisionOption 14 | { 15 | /// 16 | /// Creates a new file with a unique name of the form "name (2).txt" 17 | /// 18 | GenerateUniqueName = 0, 19 | /// 20 | /// Replaces any existing file with a new (empty) one 21 | /// 22 | ReplaceExisting = 1, 23 | /// 24 | /// Throws an exception if the file exists 25 | /// 26 | FailIfExists = 2, 27 | /// 28 | /// Opens the existing file, if any 29 | /// 30 | OpenIfExists = 3, 31 | } 32 | 33 | /// 34 | /// Represents a file system folder 35 | /// 36 | public interface IFolder 37 | { 38 | /// 39 | /// The name of the folder 40 | /// 41 | string Name { get; } 42 | /// 43 | /// The "full path" of the folder, which should uniquely identify it within a given 44 | /// 45 | string Path { get; } 46 | 47 | /// 48 | /// Creates a file in this folder 49 | /// 50 | /// The name of the file to create 51 | /// Specifies how to behave if the specified file already exists 52 | /// The cancellation token. 53 | /// The newly created file 54 | Task CreateFileAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken = default(CancellationToken)); 55 | 56 | /// 57 | /// Gets a file in this folder 58 | /// 59 | /// The name of the file to get 60 | /// The cancellation token. 61 | /// The requested file, or null if it does not exist 62 | Task GetFileAsync(string name, CancellationToken cancellationToken = default(CancellationToken)); 63 | 64 | /// 65 | /// Gets a list of the files in this folder 66 | /// 67 | /// The cancellation token. 68 | /// A list of the files in the folder 69 | Task> GetFilesAsync(CancellationToken cancellationToken = default(CancellationToken)); 70 | 71 | /// 72 | /// Creates a subfolder in this folder 73 | /// 74 | /// The name of the folder to create 75 | /// Specifies how to behave if the specified folder already exists 76 | /// The cancellation token. 77 | /// The newly created folder 78 | Task CreateFolderAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken = default(CancellationToken)); 79 | 80 | /// 81 | /// Gets a subfolder in this folder 82 | /// 83 | /// The name of the folder to get 84 | /// The cancellation token. 85 | /// The requested folder, or null if it does not exist 86 | Task GetFolderAsync(string name, CancellationToken cancellationToken = default(CancellationToken)); 87 | 88 | /// 89 | /// Gets a list of subfolders in this folder 90 | /// 91 | /// The cancellation token. 92 | /// A list of subfolders in the folder 93 | Task> GetFoldersAsync(CancellationToken cancellationToken = default(CancellationToken)); 94 | 95 | /// 96 | /// Checks whether a folder or file exists at the given location. 97 | /// 98 | /// The name of the file or folder to check for. 99 | /// The cancellation token. 100 | /// A task whose result is the result of the existence check. 101 | Task CheckExistsAsync(string name, CancellationToken cancellationToken = default(CancellationToken)); 102 | 103 | /// 104 | /// Deletes this folder and all of its contents 105 | /// 106 | /// The cancellation token. 107 | /// A task which will complete after the folder is deleted 108 | Task DeleteAsync(CancellationToken cancellationToken = default(CancellationToken)); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/PCLStorage.Abstractions/NameCollisionOption.cs: -------------------------------------------------------------------------------- 1 | namespace PCLStorage 2 | { 3 | /// 4 | /// Specifies what should happen when trying to create/rename a file or folder to a name that already exists. 5 | /// 6 | public enum NameCollisionOption 7 | { 8 | /// 9 | /// Automatically generate a unique name by appending a number to the name of 10 | /// the file or folder. 11 | /// 12 | GenerateUniqueName = 0, 13 | 14 | /// 15 | /// Replace the existing file or folder. Your app must have permission to access 16 | /// the location that contains the existing file or folder. 17 | /// 18 | ReplaceExisting = 1, 19 | 20 | /// 21 | /// Return an error if another file or folder exists with the same name and abort 22 | /// the operation. 23 | /// 24 | FailIfExists = 2, 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/PCLStorage.Abstractions/PCLStorage.Abstractions.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 10.0 6 | Debug 7 | AnyCPU 8 | {EEBB53F3-EBDF-4DD0-82E5-FF9A2C8DBD72} 9 | Library 10 | Properties 11 | PCLStorage 12 | PCLStorage.Abstractions 13 | v4.0 14 | Profile158 15 | 512 16 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 17 | ..\..\ 18 | true 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | bin\Debug\PCLStorage.Abstractions.XML 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | bin\Release\PCLStorage.Abstractions.XML 38 | 39 | 40 | true 41 | 42 | 43 | ..\..\common\strongnamekey.snk 44 | 45 | 46 | 47 | Properties\CommonAssemblyInfo.cs 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | ..\..\packages\Microsoft.Bcl.Async.1.0.165\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.dll 63 | 64 | 65 | ..\..\packages\Microsoft.Bcl.Async.1.0.165\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.Extensions.dll 66 | 67 | 68 | ..\..\packages\Microsoft.Bcl.1.1.6\lib\portable-net40+sl5+win8+wp8\System.IO.dll 69 | 70 | 71 | ..\..\packages\Microsoft.Bcl.1.1.6\lib\portable-net40+sl5+win8+wp8\System.Runtime.dll 72 | 73 | 74 | ..\..\packages\Microsoft.Bcl.1.1.6\lib\portable-net40+sl5+win8+wp8\System.Threading.Tasks.dll 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 90 | -------------------------------------------------------------------------------- /src/PCLStorage.Abstractions/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("PCLStorage.Abstractions")] 10 | [assembly: AssemblyDescription("")] -------------------------------------------------------------------------------- /src/PCLStorage.Abstractions/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/PCLStorage.Android/PCLStorage.Android.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {D813C9D8-D6D1-4D2B-AF04-0D877656F47E} 9 | {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10 | Library 11 | Properties 12 | PCLStorage 13 | PCLStorage 14 | 512 15 | Resources\Resource.Designer.cs 16 | Off 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | TRACE;DEBUG;XAMARIN;ANDROID;FILE_SYSTEM 24 | prompt 25 | 4 26 | bin\Debug\PCLStorage.XML 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE;XAMARIN;ANDROID;FILE_SYSTEM 33 | prompt 34 | 4 35 | bin\Release\PCLStorage.XML 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | Properties\CommonAssemblyInfo.cs 48 | 49 | 50 | DesktopFileSystem.cs 51 | 52 | 53 | FileSystemFile.cs 54 | 55 | 56 | FileSystemFolder.cs 57 | 58 | 59 | AwaitExtensions.cs 60 | 61 | 62 | Exceptions\PCLStorageExceptions.cs 63 | 64 | 65 | FileSystem.cs 66 | 67 | 68 | PortablePath.cs 69 | 70 | 71 | Requires.cs 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | {8F4C2E94-B8C5-477B-A315-CA58C70617E4} 82 | PCLStorage.Abstractions.NoSL 83 | 84 | 85 | 86 | 93 | -------------------------------------------------------------------------------- /src/PCLStorage.Android/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using Android.App; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("PCLStorage.Android")] 10 | [assembly: AssemblyDescription("")] 11 | 12 | [assembly: ComVisible(false)] 13 | 14 | 15 | // Add some common permissions, these can be removed if not needed 16 | //[assembly: UsesPermission(Android.Manifest.Permission.Internet)] 17 | //[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)] 18 | -------------------------------------------------------------------------------- /src/PCLStorage.Android/Resources/Resource.Designer.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsplaisted/PCLStorage/367df4961332f3edb5156eb47d64af6b1dcc8de7/src/PCLStorage.Android/Resources/Resource.Designer.cs -------------------------------------------------------------------------------- /src/PCLStorage.Android/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/PCLStorage.FileSystem.Desktop/DesktopFileSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace PCLStorage 10 | { 11 | /// 12 | /// Implementation of over classic .NET file I/O APIs 13 | /// 14 | public class DesktopFileSystem : IFileSystem 15 | { 16 | /// 17 | /// A folder representing storage which is local to the current device 18 | /// 19 | public IFolder LocalStorage 20 | { 21 | get 22 | { 23 | // SpecialFolder.LocalApplicationData is not app-specific, so use the Windows Forms API to get the app data path 24 | //var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); 25 | #if ANDROID 26 | var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); 27 | #elif IOS 28 | var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); 29 | var localAppData = Path.Combine(documents, "..", "Library"); 30 | #else 31 | var localAppData = System.Windows.Forms.Application.LocalUserAppDataPath; 32 | #endif 33 | return new FileSystemFolder(localAppData); 34 | } 35 | } 36 | 37 | /// 38 | /// A folder representing storage which may be synced with other devices for the same user 39 | /// 40 | public IFolder RoamingStorage 41 | { 42 | get 43 | { 44 | #if ANDROID || IOS 45 | return null; 46 | #else 47 | // SpecialFolder.ApplicationData is not app-specific, so use the Windows Forms API to get the app data path 48 | //var roamingAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); 49 | var roamingAppData = System.Windows.Forms.Application.UserAppDataPath; 50 | return new FileSystemFolder(roamingAppData); 51 | #endif 52 | } 53 | } 54 | 55 | /// 56 | /// Gets a file, given its path. Returns null if the file does not exist. 57 | /// 58 | /// The path to a file, as returned from the property. 59 | /// The cancellation token. 60 | /// A file for the given path, or null if it does not exist. 61 | public async Task GetFileFromPathAsync(string path, CancellationToken cancellationToken) 62 | { 63 | Requires.NotNullOrEmpty(path, "path"); 64 | 65 | await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); 66 | 67 | if (File.Exists(path)) 68 | { 69 | return new FileSystemFile(path); 70 | } 71 | 72 | return null; 73 | } 74 | 75 | /// 76 | /// Gets a folder, given its path. Returns null if the folder does not exist. 77 | /// 78 | /// The path to a folder, as returned from the property. 79 | /// The cancellation token. 80 | /// A folder for the specified path, or null if it does not exist. 81 | public async Task GetFolderFromPathAsync(string path, CancellationToken cancellationToken) 82 | { 83 | Requires.NotNullOrEmpty(path, "path"); 84 | 85 | await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); 86 | if (Directory.Exists(path)) 87 | { 88 | return new FileSystemFolder(path, true); 89 | } 90 | 91 | return null; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/PCLStorage.FileSystem.Desktop/FileSystemFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Globalization; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | 11 | namespace PCLStorage 12 | { 13 | /// 14 | /// Represents a file in the 15 | /// 16 | [DebuggerDisplay("Name = {_name}")] 17 | public class FileSystemFile : IFile 18 | { 19 | string _name; 20 | string _path; 21 | 22 | /// 23 | /// Creates a new corresponding to the specified path 24 | /// 25 | /// The file path 26 | public FileSystemFile(string path) 27 | { 28 | _name = System.IO.Path.GetFileName(path); 29 | _path = path; 30 | } 31 | 32 | /// 33 | /// The name of the file 34 | /// 35 | public string Name 36 | { 37 | get { return _name; } 38 | } 39 | 40 | /// 41 | /// The "full path" of the file, which should uniquely identify it within a given 42 | /// 43 | public string Path 44 | { 45 | get { return _path; } 46 | } 47 | 48 | /// 49 | /// Opens the file 50 | /// 51 | /// Specifies whether the file should be opened in read-only or read/write mode 52 | /// The cancellation token. 53 | /// A which can be used to read from or write to the file 54 | public async Task OpenAsync(FileAccess fileAccess, CancellationToken cancellationToken) 55 | { 56 | await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); 57 | 58 | if (fileAccess == FileAccess.Read) 59 | { 60 | return File.OpenRead(Path); 61 | } 62 | else if (fileAccess == FileAccess.ReadAndWrite) 63 | { 64 | return File.Open(Path, FileMode.Open, System.IO.FileAccess.ReadWrite); 65 | } 66 | else 67 | { 68 | throw new ArgumentException("Unrecognized FileAccess value: " + fileAccess); 69 | } 70 | } 71 | 72 | /// 73 | /// Deletes the file 74 | /// 75 | /// A task which will complete after the file is deleted. 76 | public async Task DeleteAsync(CancellationToken cancellationToken) 77 | { 78 | await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); 79 | 80 | if (!File.Exists(Path)) 81 | { 82 | throw new PCLStorage.Exceptions.FileNotFoundException("File does not exist: " + Path); 83 | } 84 | 85 | File.Delete(Path); 86 | } 87 | 88 | /// 89 | /// Renames a file without changing its location. 90 | /// 91 | /// The new leaf name of the file. 92 | /// How to deal with collisions with existing files. 93 | /// The cancellation token. 94 | /// 95 | /// A task which will complete after the file is renamed. 96 | /// 97 | public async Task RenameAsync(string newName, NameCollisionOption collisionOption, CancellationToken cancellationToken) 98 | { 99 | Requires.NotNullOrEmpty(newName, "newName"); 100 | 101 | await MoveAsync(PortablePath.Combine(System.IO.Path.GetDirectoryName(_path), newName), collisionOption, cancellationToken); 102 | } 103 | 104 | /// 105 | /// Moves a file. 106 | /// 107 | /// The new full path of the file. 108 | /// How to deal with collisions with existing files. 109 | /// The cancellation token. 110 | /// 111 | /// A task which will complete after the file is moved. 112 | /// 113 | public async Task MoveAsync(string newPath, NameCollisionOption collisionOption, CancellationToken cancellationToken) 114 | { 115 | Requires.NotNullOrEmpty(newPath, "newPath"); 116 | 117 | await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); 118 | 119 | string newDirectory = System.IO.Path.GetDirectoryName(newPath); 120 | string newName = System.IO.Path.GetFileName(newPath); 121 | 122 | for (int counter = 1; ; counter++) 123 | { 124 | cancellationToken.ThrowIfCancellationRequested(); 125 | string candidateName = newName; 126 | if (counter > 1) 127 | { 128 | candidateName = String.Format( 129 | CultureInfo.InvariantCulture, 130 | "{0} ({1}){2}", 131 | System.IO.Path.GetFileNameWithoutExtension(newName), 132 | counter, 133 | System.IO.Path.GetExtension(newName)); 134 | } 135 | 136 | string candidatePath = PortablePath.Combine(newDirectory, candidateName); 137 | 138 | if (File.Exists(candidatePath)) 139 | { 140 | switch (collisionOption) 141 | { 142 | case NameCollisionOption.FailIfExists: 143 | throw new IOException("File already exists."); 144 | case NameCollisionOption.GenerateUniqueName: 145 | continue; // try again with a new name. 146 | case NameCollisionOption.ReplaceExisting: 147 | File.Delete(candidatePath); 148 | break; 149 | } 150 | } 151 | 152 | File.Move(_path, candidatePath); 153 | _path = candidatePath; 154 | _name = candidateName; 155 | return; 156 | } 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/PCLStorage.FileSystem.Desktop/PCLStorage.FileSystem.Desktop.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {9D3F208D-8BB4-47A9-8323-4CFD24314341} 8 | Library 9 | Properties 10 | PCLStorage 11 | PCLStorage 12 | v4.5 13 | 512 14 | 15 | ..\..\ 16 | true 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | FILE_SYSTEM;DEBUG;TRACE 24 | prompt 25 | 4 26 | false 27 | bin\Debug\PCLStorage.XML 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | FILE_SYSTEM;TRACE 34 | prompt 35 | 4 36 | false 37 | bin\Release\PCLStorage.XML 38 | 39 | 40 | true 41 | 42 | 43 | ..\..\common\strongnamekey.snk 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | Properties\CommonAssemblyInfo.cs 58 | 59 | 60 | AwaitExtensions.cs 61 | 62 | 63 | Exceptions\PCLStorageExceptions.cs 64 | 65 | 66 | FileSystem.cs 67 | 68 | 69 | PortablePath.cs 70 | 71 | 72 | Requires.cs 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | {8f4c2e94-b8c5-477b-a315-ca58c70617e4} 82 | PCLStorage.Abstractions.NoSL 83 | 84 | 85 | 86 | 93 | -------------------------------------------------------------------------------- /src/PCLStorage.FileSystem.Desktop/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PCLStorage.FileSystem.Desktop")] 9 | [assembly: AssemblyDescription("")] 10 | 11 | // Setting ComVisible to false makes the types in this assembly not visible 12 | // to COM components. If you need to access a type in this assembly from 13 | // COM, set the ComVisible attribute to true on that type. 14 | [assembly: ComVisible(false)] 15 | 16 | // The following GUID is for the ID of the typelib if this project is exposed to COM 17 | [assembly: Guid("f26846b3-a2df-49f6-ad89-b67165823ab5")] 18 | -------------------------------------------------------------------------------- /src/PCLStorage.IsoStore.SL/IsoStoreFileSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO.IsolatedStorage; 3 | using System.Net; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Documents; 9 | using System.Windows.Ink; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Animation; 13 | using System.Windows.Shapes; 14 | 15 | #if WINDOWS_PHONE 16 | using TaskEx = System.Threading.Tasks.Task; 17 | #endif 18 | 19 | namespace PCLStorage 20 | { 21 | /// 22 | /// Implementation of over Isolated Storage APIs 23 | /// 24 | public class IsoStoreFileSystem : IFileSystem 25 | { 26 | IsolatedStorageFile Root = IsolatedStorageFile.GetUserStoreForApplication(); 27 | 28 | /// 29 | /// A folder representing storage which is local to the current device 30 | /// 31 | public IFolder LocalStorage 32 | { 33 | get 34 | { 35 | return new IsoStoreFolder(Root); 36 | } 37 | } 38 | 39 | /// 40 | /// Returns null, as roaming storage isn't supported by the Isolated Storage APIs 41 | /// 42 | public IFolder RoamingStorage 43 | { 44 | get 45 | { 46 | return null; 47 | } 48 | } 49 | 50 | /// 51 | /// Gets a file, given its path. Returns null if the file does not exist. 52 | /// 53 | /// The path to a file, as returned from the property. 54 | /// The cancellation token. 55 | /// A file for the given path, or null if it does not exist. 56 | public async Task GetFileFromPathAsync(string path, CancellationToken cancellationToken) 57 | { 58 | Requires.NotNullOrEmpty(path, "path"); 59 | await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); 60 | 61 | if (Root.FileExists(path)) 62 | { 63 | return new IsoStoreFile(Root, path); 64 | } 65 | return null; 66 | 67 | } 68 | 69 | /// 70 | /// Gets a folder, given its path. Returns null if the folder does not exist. 71 | /// 72 | /// The path to a folder, as returned from the property. 73 | /// The cancellation token. 74 | /// A folder for the specified path, or null if it does not exist. 75 | public async Task GetFolderFromPathAsync(string path, CancellationToken cancellationToken) 76 | { 77 | Requires.NotNullOrEmpty(path, "path"); 78 | await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); 79 | 80 | if (Root.DirectoryExists(path)) 81 | { 82 | return new IsoStoreFolder(Root, path); 83 | } 84 | 85 | return null; 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/PCLStorage.IsoStore.SL/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PCLStorage.IsoStore.SL")] 9 | [assembly: AssemblyDescription("")] 10 | 11 | // Setting ComVisible to false makes the types in this assembly not visible 12 | // to COM components. If you need to access a type in this assembly from 13 | // COM, set the ComVisible attribute to true on that type. 14 | [assembly: ComVisible(false)] 15 | 16 | // The following GUID is for the ID of the typelib if this project is exposed to COM 17 | [assembly: Guid("793b3b5b-060e-47fd-8928-8edf8ad0d6ec")] -------------------------------------------------------------------------------- /src/PCLStorage.IsoStore.SL/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/PCLStorage.IsoStore.SL/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/PCLStorage.NoSL/PCLStorage.NoSL.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 11.0 6 | Debug 7 | AnyCPU 8 | {F878EC6F-6C59-4860-A2D1-0CD2C97760A7} 9 | Library 10 | Properties 11 | PCLStorage 12 | PCLStorage 13 | v4.5 14 | Profile78 15 | 512 16 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 17 | ..\ 18 | true 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | PORTABLE;DEBUG;TRACE 26 | prompt 27 | 4 28 | bin\Debug\PCLStorage.XML 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | PORTABLE;TRACE 35 | prompt 36 | 4 37 | bin\Release\PCLStorage.XML 38 | 39 | 40 | true 41 | 42 | 43 | ..\..\common\strongnamekey.snk 44 | 45 | 46 | 47 | Properties\CommonAssemblyInfo.cs 48 | 49 | 50 | PCLStorageExceptions.cs 51 | 52 | 53 | FileSystem.cs 54 | 55 | 56 | PortablePath.cs 57 | 58 | 59 | 60 | 61 | 62 | {8F4C2E94-B8C5-477B-A315-CA58C70617E4} 63 | PCLStorage.Abstractions.NoSL 64 | 65 | 66 | 67 | 74 | -------------------------------------------------------------------------------- /src/PCLStorage.NoSL/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("PCLStorage")] 10 | [assembly: AssemblyDescription("")] 11 | -------------------------------------------------------------------------------- /src/PCLStorage.WinRT/AwaitExtensions.WinRT.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.CompilerServices; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Windows.Foundation; 9 | 10 | namespace PCLStorage 11 | { 12 | /// 13 | /// Extensions for use internally by PCLStorage for awaiting. 14 | /// 15 | internal static partial class AwaitExtensions 16 | { 17 | /// 18 | /// Returns a task that completes when the async operation completes, 19 | /// but never throws to the person awaiting it. 20 | /// 21 | /// The type of value returned by the async operation. 22 | /// The async operation. 23 | /// The cancellation token. 24 | /// A task whose result is the completed task. 25 | internal static Task> AsTaskNoThrow(this IAsyncOperation operation, CancellationToken cancellationToken) 26 | { 27 | var tcs = new TaskCompletionSource>(); 28 | var task = operation.AsTask(cancellationToken); 29 | task.ContinueWith((t, state) => ((TaskCompletionSource>)state).SetResult(t), tcs); 30 | return tcs.Task; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/PCLStorage.WinRT/PCLStorage.WinRT.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 8.0.30703 8 | 2.0 9 | {AAC0913D-649A-49DD-834B-EF23D092D72B} 10 | Library 11 | Properties 12 | PCLStorage 13 | PCLStorage 14 | en-US 15 | 512 16 | {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 17 | ..\..\ 18 | true 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE;NETFX_CORE 26 | prompt 27 | 4 28 | bin\Debug\PCLStorage.XML 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE;NETFX_CORE 35 | prompt 36 | 4 37 | bin\Release\PCLStorage.XML 38 | 39 | 40 | true 41 | bin\ARM\Debug\ 42 | DEBUG;TRACE;NETFX_CORE 43 | ;2008 44 | full 45 | ARM 46 | false 47 | prompt 48 | true 49 | 50 | 51 | bin\ARM\Release\ 52 | TRACE;NETFX_CORE 53 | true 54 | ;2008 55 | pdbonly 56 | ARM 57 | false 58 | prompt 59 | true 60 | 61 | 62 | true 63 | bin\x64\Debug\ 64 | DEBUG;TRACE;NETFX_CORE 65 | ;2008 66 | full 67 | x64 68 | false 69 | prompt 70 | true 71 | 72 | 73 | bin\x64\Release\ 74 | TRACE;NETFX_CORE 75 | true 76 | ;2008 77 | pdbonly 78 | x64 79 | false 80 | prompt 81 | true 82 | 83 | 84 | true 85 | bin\x86\Debug\ 86 | DEBUG;TRACE;NETFX_CORE 87 | ;2008 88 | full 89 | x86 90 | false 91 | prompt 92 | true 93 | 94 | 95 | bin\x86\Release\ 96 | TRACE;NETFX_CORE 97 | true 98 | ;2008 99 | pdbonly 100 | x86 101 | false 102 | prompt 103 | true 104 | 105 | 106 | 107 | Properties\CommonAssemblyInfo.cs 108 | 109 | 110 | AwaitExtensions.cs 111 | 112 | 113 | Exceptions\PCLStorageExceptions.cs 114 | 115 | 116 | FileSystem.cs 117 | 118 | 119 | PortablePath.cs 120 | 121 | 122 | Requires.cs 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | {8f4c2e94-b8c5-477b-a315-ca58c70617e4} 133 | PCLStorage.Abstractions.NoSL 134 | 135 | 136 | 137 | 11.0 138 | 139 | 140 | true 141 | 142 | 143 | ..\..\common\strongnamekey.snk 144 | 145 | 146 | 153 | -------------------------------------------------------------------------------- /src/PCLStorage.WinRT/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PCLStorage.WinRT")] 9 | [assembly: AssemblyDescription("")] 10 | 11 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /src/PCLStorage.WinRT/WinRTFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using Windows.Storage; 10 | 11 | namespace PCLStorage 12 | { 13 | /// 14 | /// Represents a file in the 15 | /// 16 | [DebuggerDisplay("Name = {Name}")] 17 | public class WinRTFile : IFile 18 | { 19 | /// 20 | /// The HRESULT on a System.Exception thrown when a file collision occurs. 21 | /// 22 | internal const int FILE_ALREADY_EXISTS = unchecked((int)0x800700B7); 23 | 24 | private readonly IStorageFile _wrappedFile; 25 | 26 | /// 27 | /// Creates a new 28 | /// 29 | /// The WinRT to wrap 30 | public WinRTFile(IStorageFile wrappedFile) 31 | { 32 | _wrappedFile = wrappedFile; 33 | } 34 | 35 | /// 36 | /// The name of the file 37 | /// 38 | public string Name 39 | { 40 | get { return _wrappedFile.Name; } 41 | } 42 | 43 | /// 44 | /// The "full path" of the file, which should uniquely identify it within a given 45 | /// 46 | public string Path 47 | { 48 | get { return _wrappedFile.Path; } 49 | } 50 | 51 | /// 52 | /// Opens the file 53 | /// 54 | /// Specifies whether the file should be opened in read-only or read/write mode 55 | /// The cancellation token. 56 | /// A which can be used to read from or write to the file 57 | public async Task OpenAsync(FileAccess fileAccess, CancellationToken cancellationToken) 58 | { 59 | FileAccessMode fileAccessMode; 60 | if (fileAccess == FileAccess.Read) 61 | { 62 | fileAccessMode = FileAccessMode.Read; 63 | } 64 | else if (fileAccess == FileAccess.ReadAndWrite) 65 | { 66 | fileAccessMode = FileAccessMode.ReadWrite; 67 | } 68 | else 69 | { 70 | throw new ArgumentException("Unrecognized FileAccess value: " + fileAccess); 71 | } 72 | 73 | var wrtStream = await _wrappedFile.OpenAsync(fileAccessMode).AsTask(cancellationToken).ConfigureAwait(false); 74 | return wrtStream.AsStream(); 75 | } 76 | 77 | /// 78 | /// Deletes the file 79 | /// 80 | /// A task which will complete after the file is deleted. 81 | public async Task DeleteAsync(CancellationToken cancellationToken) 82 | { 83 | cancellationToken.ThrowIfCancellationRequested(); 84 | await _wrappedFile.DeleteAsync().AsTask(cancellationToken).ConfigureAwait(false); 85 | } 86 | 87 | /// 88 | /// Renames a file without changing its location. 89 | /// 90 | /// The new leaf name of the file. 91 | /// How to deal with collisions with existing files. 92 | /// The cancellation token. 93 | /// 94 | /// A task which will complete after the file is renamed. 95 | /// 96 | public async Task RenameAsync(string newName, NameCollisionOption collisionOption, CancellationToken cancellationToken) 97 | { 98 | Requires.NotNullOrEmpty(newName, "newName"); 99 | 100 | try 101 | { 102 | await _wrappedFile.RenameAsync(newName, (Windows.Storage.NameCollisionOption)collisionOption).AsTask(cancellationToken).ConfigureAwait(false); 103 | } 104 | catch (Exception ex) 105 | { 106 | if (ex.HResult == FILE_ALREADY_EXISTS) 107 | { 108 | throw new IOException("File already exists.", ex); 109 | } 110 | 111 | throw; 112 | } 113 | } 114 | 115 | /// 116 | /// Moves a file. 117 | /// 118 | /// The new full path of the file. 119 | /// How to deal with collisions with existing files. 120 | /// The cancellation token. 121 | /// 122 | /// A task which will complete after the file is moved. 123 | /// 124 | public async Task MoveAsync(string newPath, NameCollisionOption collisionOption, CancellationToken cancellationToken) 125 | { 126 | Requires.NotNullOrEmpty(newPath, "newPath"); 127 | 128 | var newFolder = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.GetDirectoryName(newPath)).AsTask(cancellationToken).ConfigureAwait(false); 129 | string newName = System.IO.Path.GetFileName(newPath); 130 | 131 | try 132 | { 133 | await _wrappedFile.MoveAsync(newFolder, newName, (Windows.Storage.NameCollisionOption)collisionOption).AsTask(cancellationToken).ConfigureAwait(false); 134 | } 135 | catch (Exception ex) 136 | { 137 | if (ex.HResult == FILE_ALREADY_EXISTS) 138 | { 139 | throw new IOException("File already exists.", ex); 140 | } 141 | 142 | throw; 143 | } 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/PCLStorage.WinRT/WinRTFileSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Windows.Storage; 9 | 10 | namespace PCLStorage 11 | { 12 | /// 13 | /// Implementation of over WinRT Storage APIs 14 | /// 15 | public class WinRTFileSystem : IFileSystem 16 | { 17 | Windows.Storage.ApplicationData _applicationData; 18 | 19 | /// 20 | /// Creates a new instance of 21 | /// 22 | public WinRTFileSystem() 23 | { 24 | _applicationData = ApplicationData.Current; 25 | } 26 | /// 27 | /// A folder representing storage which is local to the current device 28 | /// 29 | public IFolder LocalStorage 30 | { 31 | get 32 | { 33 | return new WinRTFolder(_applicationData.LocalFolder); 34 | } 35 | } 36 | 37 | /// 38 | /// A folder representing storage which may be synced with other devices for the same user 39 | /// 40 | public IFolder RoamingStorage 41 | { 42 | get 43 | { 44 | #if WINDOWS_PHONE 45 | return null; 46 | #else 47 | return new WinRTFolder(_applicationData.RoamingFolder); 48 | #endif 49 | } 50 | } 51 | 52 | /// 53 | /// Gets a file, given its path. Returns null if the file does not exist. 54 | /// 55 | /// The path to a file, as returned from the property. 56 | /// The cancellation token. 57 | /// A file for the given path, or null if it does not exist. 58 | public async Task GetFileFromPathAsync(string path, CancellationToken cancellationToken) 59 | { 60 | Requires.NotNullOrEmpty(path, "path"); 61 | 62 | StorageFile storageFile; 63 | try 64 | { 65 | storageFile = await StorageFile.GetFileFromPathAsync(path).AsTask(cancellationToken).ConfigureAwait(false); 66 | } 67 | catch (FileNotFoundException) 68 | { 69 | return null; 70 | } 71 | 72 | return new WinRTFile(storageFile); 73 | } 74 | 75 | /// 76 | /// Gets a folder, given its path. Returns null if the folder does not exist. 77 | /// 78 | /// The path to a folder, as returned from the property. 79 | /// The cancellation token. 80 | /// A folder for the specified path, or null if it does not exist. 81 | public async Task GetFolderFromPathAsync(string path, CancellationToken cancellationToken) 82 | { 83 | Requires.NotNullOrEmpty(path, "path"); 84 | 85 | StorageFolder storageFolder; 86 | try 87 | { 88 | storageFolder = await StorageFolder.GetFolderFromPathAsync(path).AsTask(cancellationToken).ConfigureAwait(false); 89 | } 90 | catch (FileNotFoundException) 91 | { 92 | return null; 93 | } 94 | 95 | return new WinRTFolder(storageFolder); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/PCLStorage.WindowsPhone/PCLStorage.WindowsPhone.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {D6BDB17D-1B42-49DA-BADB-B09D7DB4B4EA} 9 | {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 10 | Library 11 | Properties 12 | PCLStorage 13 | PCLStorage 14 | v8.0 15 | 16 | 17 | 18 | 19 | WindowsPhone 20 | false 21 | true 22 | true 23 | ..\ 24 | true 25 | 11.0 26 | true 27 | ..\..\common\strongnamekey.snk 28 | 29 | 30 | true 31 | full 32 | false 33 | Bin\Debug 34 | DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE 35 | true 36 | true 37 | prompt 38 | 4 39 | Bin\Debug\PCLStorage.XML 40 | false 41 | 42 | 43 | pdbonly 44 | true 45 | Bin\Release 46 | TRACE;SILVERLIGHT;WINDOWS_PHONE 47 | true 48 | true 49 | prompt 50 | 4 51 | Bin\Release\PCLStorage.XML 52 | false 53 | 54 | 55 | true 56 | Bin\x86\Debug 57 | DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE 58 | Bin\Debug\PCLStorage.XML 59 | true 60 | full 61 | 62 | 63 | prompt 64 | MinimumRecommendedRules.ruleset 65 | false 66 | 67 | 68 | Bin\x86\Release 69 | TRACE;SILVERLIGHT;WINDOWS_PHONE 70 | Bin\Release\PCLStorage.XML 71 | true 72 | true 73 | pdbonly 74 | 75 | 76 | prompt 77 | MinimumRecommendedRules.ruleset 78 | 79 | 80 | true 81 | Bin\ARM\Debug 82 | DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE 83 | Bin\Debug\PCLStorage.XML 84 | true 85 | full 86 | 87 | 88 | prompt 89 | MinimumRecommendedRules.ruleset 90 | false 91 | 92 | 93 | Bin\ARM\Release 94 | TRACE;SILVERLIGHT;WINDOWS_PHONE 95 | Bin\Release\PCLStorage.XML 96 | true 97 | true 98 | pdbonly 99 | 100 | 101 | prompt 102 | MinimumRecommendedRules.ruleset 103 | 104 | 105 | 106 | Properties\CommonAssemblyInfo.cs 107 | 108 | 109 | AwaitExtensions.WinRT.cs 110 | 111 | 112 | WinRTFile.cs 113 | 114 | 115 | WinRTFileSystem.cs 116 | 117 | 118 | WinRTFolder.cs 119 | 120 | 121 | AwaitExtensions.cs 122 | 123 | 124 | Exceptions\PCLStorageExceptions.cs 125 | 126 | 127 | FileSystem.cs 128 | 129 | 130 | PortablePath.cs 131 | 132 | 133 | Requires.cs 134 | 135 | 136 | 137 | 138 | 139 | {8F4C2E94-B8C5-477B-A315-CA58C70617E4} 140 | PCLStorage.Abstractions.NoSL 141 | 142 | 143 | 144 | 145 | 146 | 153 | -------------------------------------------------------------------------------- /src/PCLStorage.WindowsPhone/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Resources; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("PCLStorage.IsoStore.WindowsPhone")] 10 | [assembly: AssemblyDescription("")] 11 | 12 | // Setting ComVisible to false makes the types in this assembly not visible 13 | // to COM components. If you need to access a type in this assembly from 14 | // COM, set the ComVisible attribute to true on that type. 15 | [assembly: ComVisible(false)] 16 | 17 | // The following GUID is for the ID of the typelib if this project is exposed to COM 18 | [assembly: Guid("d6bdb17d-1b42-49da-badb-b09d7db4b4ea")] 19 | -------------------------------------------------------------------------------- /src/PCLStorage.iOS-Unified/PCLStorage.iOS-Unified.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | iPhoneSimulator 6 | 8.0.30703 7 | 2.0 8 | {3B479AED-CC1C-46F7-AF55-8BF9E8BA1C01} 9 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10 | Library 11 | PCLStorage 12 | Resources 13 | PCLStorage 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\iPhone\Debug 20 | DEBUG;__UNIFIED__;__MOBILE__;__IOS__;IOS;XAMARIN;FILE_SYSTEM 21 | prompt 22 | 4 23 | false 24 | true 25 | iPhone Developer 26 | 27 | 28 | pdbonly 29 | true 30 | bin\iPhone\Release 31 | prompt 32 | 4 33 | false 34 | iPhone Developer 35 | __UNIFIED__;__MOBILE__;__IOS__;IOS;XAMARIN;FILE_SYSTEM 36 | true 37 | bin\iPhone\Release\PCLStorage.XML 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | Properties\CommonAssemblyInfo.cs 49 | 50 | 51 | DesktopFileSystem.cs 52 | 53 | 54 | FileSystemFile.cs 55 | 56 | 57 | FileSystemFolder.cs 58 | 59 | 60 | AwaitExtensions.cs 61 | 62 | 63 | Exceptions\PCLStorageExceptions.cs 64 | 65 | 66 | FileSystem.cs 67 | 68 | 69 | PortablePath.cs 70 | 71 | 72 | Requires.cs 73 | 74 | 75 | 76 | 77 | 78 | {8f4c2e94-b8c5-477b-a315-ca58c70617e4} 79 | PCLStorage.Abstractions.NoSL 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /src/PCLStorage.iOS-Unified/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PCLStorage.iOS-Unified")] 9 | [assembly: AssemblyDescription("")] 10 | 11 | // Setting ComVisible to false makes the types in this assembly not visible 12 | // to COM components. If you need to access a type in this assembly from 13 | // COM, set the ComVisible attribute to true on that type. 14 | [assembly: ComVisible(false)] 15 | 16 | // The following GUID is for the ID of the typelib if this project is exposed to COM 17 | [assembly: Guid("38630605-fe4f-4d55-8f9a-8bcbf066fb0a")] -------------------------------------------------------------------------------- /src/PCLStorage.iOS/PCLStorage.iOS.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | iPhoneSimulator 6 | 8.0.30703 7 | 2.0 8 | {27A782B4-6683-4849-B951-601289C23F73} 9 | {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10 | Library 11 | PCLStorage 12 | Resources 13 | PCLStorage 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\iPhone\Debug 20 | DEBUG;__IOS__;__MOBILE__;IOS;XAMARIN;FILE_SYSTEM 21 | prompt 22 | 4 23 | false 24 | true 25 | iPhone Developer 26 | bin\iPhone\Debug\PCLStorage.XML 27 | 28 | 29 | none 30 | true 31 | bin\iPhone\Release 32 | prompt 33 | 4 34 | false 35 | iPhone Developer 36 | __IOS__;__MOBILE__;IOS;XAMARIN;FILE_SYSTEM 37 | bin\iPhone\Release\PCLStorage.XML 38 | 39 | 40 | 41 | Properties\CommonAssemblyInfo.cs 42 | 43 | 44 | DesktopFileSystem.cs 45 | 46 | 47 | FileSystemFile.cs 48 | 49 | 50 | FileSystemFolder.cs 51 | 52 | 53 | AwaitExtensions.cs 54 | 55 | 56 | Exceptions\PCLStorageExceptions.cs 57 | 58 | 59 | FileSystem.cs 60 | 61 | 62 | PortablePath.cs 63 | 64 | 65 | Requires.cs 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | {8F4C2E94-B8C5-477B-A315-CA58C70617E4} 81 | PCLStorage.Abstractions.NoSL 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/PCLStorage.iOS/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PCLStorage.iOS")] 9 | [assembly: AssemblyDescription("")] 10 | 11 | // Setting ComVisible to false makes the types in this assembly not visible 12 | // to COM components. If you need to access a type in this assembly from 13 | // COM, set the ComVisible attribute to true on that type. 14 | [assembly: ComVisible(false)] 15 | 16 | // The following GUID is for the ID of the typelib if this project is exposed to COM 17 | [assembly: Guid("38630605-fe4f-4d55-8f9a-8bcbf066fb0a")] -------------------------------------------------------------------------------- /src/PCLStorage.iOS/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/PCLStorage/AwaitExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.CompilerServices; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace PCLStorage 10 | { 11 | /// 12 | /// Extensions for use internally by PCLStorage for awaiting. 13 | /// 14 | internal static partial class AwaitExtensions 15 | { 16 | /// 17 | /// Causes the caller who awaits this method to 18 | /// switch off the Main thread. It has no effect if 19 | /// the caller is already off the main thread. 20 | /// 21 | /// The cancellation token. 22 | /// An awaitable that does the thread switching magic. 23 | internal static TaskSchedulerAwaiter SwitchOffMainThreadAsync(CancellationToken cancellationToken) 24 | { 25 | cancellationToken.ThrowIfCancellationRequested(); 26 | return new TaskSchedulerAwaiter( 27 | SynchronizationContext.Current != null ? TaskScheduler.Default : null, 28 | cancellationToken); 29 | } 30 | 31 | internal struct TaskSchedulerAwaiter : INotifyCompletion 32 | { 33 | private TaskScheduler taskScheduler; 34 | private CancellationToken cancellationToken; 35 | 36 | internal TaskSchedulerAwaiter(TaskScheduler taskScheduler, CancellationToken cancellationToken) 37 | { 38 | this.taskScheduler = taskScheduler; 39 | this.cancellationToken = cancellationToken; 40 | } 41 | 42 | internal TaskSchedulerAwaiter GetAwaiter() 43 | { 44 | return this; 45 | } 46 | 47 | public bool IsCompleted 48 | { 49 | get { return this.taskScheduler == null; } 50 | } 51 | 52 | public void OnCompleted(Action continuation) 53 | { 54 | if (this.taskScheduler == null) 55 | { 56 | throw new InvalidOperationException("IsCompleted is true, so this is unexpected."); 57 | } 58 | 59 | Task.Factory.StartNew( 60 | continuation, 61 | CancellationToken.None, 62 | TaskCreationOptions.None, 63 | this.taskScheduler); 64 | } 65 | 66 | public void GetResult() 67 | { 68 | this.cancellationToken.ThrowIfCancellationRequested(); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/PCLStorage/Exceptions/PCLStorageExceptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace PCLStorage.Exceptions 8 | { 9 | /// 10 | public class FileNotFoundException 11 | #if PORTABLE 12 | : IOException 13 | #else 14 | : System.IO.FileNotFoundException 15 | #endif 16 | { 17 | /// 18 | public FileNotFoundException(string message) 19 | : base(message) 20 | { 21 | 22 | } 23 | 24 | /// 25 | public FileNotFoundException(string message, Exception innerException) 26 | : base(message, innerException) 27 | { 28 | 29 | } 30 | } 31 | 32 | /// 33 | public class DirectoryNotFoundException 34 | #if PORTABLE 35 | : IOException 36 | #elif NETFX_CORE 37 | : System.IO.FileNotFoundException 38 | #else 39 | : System.IO.DirectoryNotFoundException 40 | #endif 41 | { 42 | /// 43 | public DirectoryNotFoundException(string message) 44 | : base(message) 45 | { 46 | 47 | } 48 | 49 | /// 50 | public DirectoryNotFoundException(string message, Exception innerException) 51 | : base(message, innerException) 52 | { 53 | 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/PCLStorage/FileSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PCLStorage 7 | { 8 | /// 9 | /// Provides access to an implementation of for the current platform 10 | /// 11 | public static class FileSystem 12 | { 13 | static Lazy _fileSystem = new Lazy(() => CreateFileSystem(), System.Threading.LazyThreadSafetyMode.PublicationOnly); 14 | 15 | /// 16 | /// The implementation of for the current platform 17 | /// 18 | public static IFileSystem Current 19 | { 20 | get 21 | { 22 | IFileSystem ret = _fileSystem.Value; 23 | if (ret == null) 24 | { 25 | throw FileSystem.NotImplementedInReferenceAssembly(); 26 | } 27 | return ret; 28 | } 29 | } 30 | 31 | static IFileSystem CreateFileSystem() 32 | { 33 | #if NETFX_CORE || WINDOWS_PHONE 34 | return new WinRTFileSystem(); 35 | #elif SILVERLIGHT 36 | return new IsoStoreFileSystem(); 37 | #elif FILE_SYSTEM 38 | return new DesktopFileSystem(); 39 | #else 40 | return null; 41 | #endif 42 | } 43 | 44 | internal static Exception NotImplementedInReferenceAssembly() 45 | { 46 | return new NotImplementedException("This functionality is not implemented in the portable version of this assembly. You should reference the PCLStorage NuGet package from your main application project in order to reference the platform-specific implementation."); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/PCLStorage/PCLStorage.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 10.0 6 | Debug 7 | AnyCPU 8 | {31F6B895-4FF7-481B-B483-E0E6B63CC312} 9 | Library 10 | Properties 11 | PCLStorage 12 | PCLStorage 13 | v4.0 14 | Profile158 15 | 512 16 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 17 | ..\ 18 | true 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | PORTABLE;DEBUG;TRACE 26 | prompt 27 | 4 28 | bin\Debug\PCLStorage.XML 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | PORTABLE;TRACE 35 | prompt 36 | 4 37 | bin\Release\PCLStorage.XML 38 | 39 | 40 | true 41 | 42 | 43 | ..\..\common\strongnamekey.snk 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | Properties\CommonAssemblyInfo.cs 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | {eebb53f3-ebdf-4dd0-82e5-ff9a2c8dbd72} 64 | PCLStorage.Abstractions 65 | 66 | 67 | 68 | 69 | ..\..\packages\Microsoft.Bcl.Async.1.0.165\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.dll 70 | 71 | 72 | ..\..\packages\Microsoft.Bcl.Async.1.0.165\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.Extensions.dll 73 | 74 | 75 | ..\..\packages\Microsoft.Bcl.1.1.6\lib\portable-net40+sl5+win8+wp8\System.IO.dll 76 | 77 | 78 | ..\..\packages\Microsoft.Bcl.1.1.6\lib\portable-net40+sl5+win8+wp8\System.Runtime.dll 79 | 80 | 81 | ..\..\packages\Microsoft.Bcl.1.1.6\lib\portable-net40+sl5+win8+wp8\System.Threading.Tasks.dll 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 97 | -------------------------------------------------------------------------------- /src/PCLStorage/PortablePath.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | 7 | namespace PCLStorage 8 | { 9 | /// 10 | /// Provides portable versions of APIs such as Path.Combine 11 | /// 12 | public static class PortablePath 13 | { 14 | /// 15 | /// The character used to separate elements in a file system path 16 | /// 17 | public static char DirectorySeparatorChar 18 | { 19 | get 20 | { 21 | #if NETFX_CORE 22 | return '\\'; 23 | #elif PORTABLE 24 | throw FileSystem.NotImplementedInReferenceAssembly(); 25 | #else 26 | return Path.DirectorySeparatorChar; 27 | #endif 28 | } 29 | } 30 | 31 | /// 32 | /// Combines multiple strings into a path 33 | /// 34 | /// Path elements to combine 35 | /// A combined path 36 | public static string Combine(params string[] paths) 37 | { 38 | #if PORTABLE 39 | throw FileSystem.NotImplementedInReferenceAssembly(); 40 | #elif WINDOWS_PHONE 41 | // WP7 only implements Path.Combine with two arguments, so implement this in terms of that 42 | if (paths.Length == 0) 43 | { 44 | return string.Empty; 45 | } 46 | else if (paths.Length == 1) 47 | { 48 | return paths[0]; 49 | } 50 | else 51 | { 52 | string ret = Path.Combine(paths[0], paths[1]); 53 | foreach (string p in paths.Skip(2)) 54 | { 55 | ret = Path.Combine(ret, p); 56 | } 57 | return ret; 58 | } 59 | #else 60 | return Path.Combine(paths); 61 | #endif 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/PCLStorage/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("PCLStorage")] 10 | [assembly: AssemblyDescription("")] 11 | -------------------------------------------------------------------------------- /src/PCLStorage/Requires.cs: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------- 2 | // 3 | // Copyright (c) Andrew Arnott. All rights reserved. 4 | // 5 | // This file is a derivation of: 6 | // https://github.com/AArnott/Validation/blob/master/src/Validation/Requires.cs 7 | // Which is released under the MS-PL license. 8 | //----------------------------------------------------------------------- 9 | 10 | namespace PCLStorage 11 | { 12 | using System; 13 | using System.Collections.Generic; 14 | using System.Diagnostics; 15 | using System.Globalization; 16 | 17 | /// 18 | /// Common runtime checks that throw ArgumentExceptions upon failure. 19 | /// 20 | internal static class Requires 21 | { 22 | private const string Argument_EmptyString = "'{0}' cannot be an empty string (\"\") or start with the null character."; 23 | 24 | /// 25 | /// Throws an exception if the specified parameter's value is null. 26 | /// 27 | /// The type of the parameter. 28 | /// The value of the argument. 29 | /// The name of the parameter to include in any thrown exception. 30 | /// The value of the parameter. 31 | /// Thrown if is null 32 | [DebuggerStepThrough] 33 | public static T NotNull(T value, string parameterName) 34 | where T : class // ensures value-types aren't passed to a null checking method 35 | { 36 | if (value == null) 37 | { 38 | throw new ArgumentNullException(parameterName); 39 | } 40 | 41 | return value; 42 | } 43 | 44 | /// 45 | /// Throws an exception if the specified parameter's value is null or empty. 46 | /// 47 | /// The value of the argument. 48 | /// The name of the parameter to include in any thrown exception. 49 | /// Thrown if is null or empty. 50 | [DebuggerStepThrough] 51 | public static void NotNullOrEmpty(string value, string parameterName) 52 | { 53 | // To the guy that is doing random code cleaning: 54 | // Consider the perfomance when changing the code to delegate to NotNull. 55 | // In general do not chain call to another function, check first and return as earlier as possible. 56 | if (value == null) 57 | { 58 | throw new ArgumentNullException(parameterName); 59 | } 60 | 61 | if (value.Length == 0 || value[0] == '\0') 62 | { 63 | throw new ArgumentException(Format(Argument_EmptyString, parameterName), parameterName); 64 | } 65 | } 66 | 67 | /// 68 | /// Helper method that formats string arguments. 69 | /// 70 | /// The formatted string. 71 | private static string Format(string format, params object[] arguments) 72 | { 73 | return string.Format(CultureInfo.CurrentCulture, format, arguments); 74 | } 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /src/PCLStorage/app.config: -------------------------------------------------------------------------------- 1 |  2 | -------------------------------------------------------------------------------- /src/PCLStorage/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /test/PCLStorage.Test.Android/Activity1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Android.App; 4 | using Android.Content; 5 | using Android.Runtime; 6 | using Android.Views; 7 | using Android.Widget; 8 | using Android.OS; 9 | using PCLTesting.Infrastructure; 10 | 11 | namespace PCLStorage.Test.Android 12 | { 13 | [Activity(Label = "PCLStorage.Test.Android", MainLauncher = true, Icon = "@drawable/icon")] 14 | public class Activity1 : Activity 15 | { 16 | //int count = 1; 17 | 18 | Button _runTestsButton; 19 | Button _clearStorageButton; 20 | 21 | TextView _resultsTextView; 22 | 23 | protected override void OnCreate(Bundle bundle) 24 | { 25 | base.OnCreate(bundle); 26 | 27 | // Set our view from the "main" layout resource 28 | SetContentView(Resource.Layout.Main); 29 | 30 | //// Get our button from the layout resource, 31 | //// and attach an event to it 32 | _runTestsButton = FindViewById