Skip to content

Commit 288a4b9

Browse files
committed
Removed Storage.cs
Aded non async operations, this isn't bad amrite?
1 parent 9c0ccb5 commit 288a4b9

File tree

14 files changed

+653
-171
lines changed

14 files changed

+653
-171
lines changed

common/CommonAssemblyInfo.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
using System.Reflection;
22

3-
//[assembly: AssemblyTitle("PCLExt.FileStorage")]
4-
//[assembly: AssemblyDescription("")]
53
[assembly: AssemblyConfiguration("")]
64
[assembly: AssemblyCompany("")]
75
[assembly: AssemblyProduct("PCLExt.FileStorage")]
86
[assembly: AssemblyCopyright("Copyright © 2016")]
97
[assembly: AssemblyTrademark("")]
108
[assembly: AssemblyCulture("")]
119

12-
[assembly: AssemblyVersion("1.0.3.0")]
13-
[assembly: AssemblyFileVersion("1.0.3.0")]
10+
[assembly: AssemblyVersion("1.0.9.0")]
11+
[assembly: AssemblyFileVersion("1.0.9.0")]

common/PCLExt.FileStorage.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata>
44
<id>PCLExt.FileStorage</id>
5-
<version>1.0.5</version>
5+
<version>1.0.9</version>
66
<title>PCL Extension - File Storage API</title>
77
<authors>Daniel Plaisted,Aragas</authors>
88
<owners>Aragas</owners>

src/PCLExt.FileStorage.Abstractions/IFile.cs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public interface IFile
4242
/// </summary>
4343
string Path { get; }
4444

45+
/// <summary>
46+
/// Opens the file
47+
/// </summary>
48+
/// <param name="fileAccess">Specifies whether the file should be opened in read-only or read/write mode</param>
49+
/// <returns>A <see cref="Stream"/> which can be used to read from or write to the file</returns>
50+
Stream Open(FileAccess fileAccess);
51+
4552
/// <summary>
4653
/// Opens the file
4754
/// </summary>
@@ -50,6 +57,14 @@ public interface IFile
5057
/// <returns>A <see cref="Stream"/> which can be used to read from or write to the file</returns>
5158
Task<Stream> OpenAsync(FileAccess fileAccess, CancellationToken cancellationToken = default(CancellationToken));
5259

60+
/// <summary>
61+
/// Deletes the file
62+
/// </summary>
63+
/// <returns>
64+
/// A task which will complete after the file is deleted.
65+
/// </returns>
66+
void Delete();
67+
5368
/// <summary>
5469
/// Deletes the file
5570
/// </summary>
@@ -64,12 +79,29 @@ public interface IFile
6479
/// </summary>
6580
/// <param name="newName">The new leaf name of the file.</param>
6681
/// <param name="collisionOption">How to deal with collisions with existing files.</param>
67-
/// <param name="cancellationToken">The cancellation token.</param>
82+
/// <returns>
83+
/// A task which will complete after the file is renamed.
84+
/// </returns>
85+
void Rename(string newName, NameCollisionOption collisionOption = NameCollisionOption.FailIfExists);
86+
87+
/// <summary>
88+
/// Renames a file without changing its location.
89+
/// </summary>
90+
/// <param name="newName">The new leaf name of the file.</param>
91+
/// <param name="collisionOption">How to deal with collisions with existing files.</param>
6892
/// <returns>
6993
/// A task which will complete after the file is renamed.
7094
/// </returns>
7195
Task RenameAsync(string newName, NameCollisionOption collisionOption = NameCollisionOption.FailIfExists, CancellationToken cancellationToken = default(CancellationToken));
7296

97+
/// <summary>
98+
/// Moves a file.
99+
/// </summary>
100+
/// <param name="newPath">The new full path of the file.</param>
101+
/// <param name="collisionOption">How to deal with collisions with existing files.</param>
102+
/// <returns>A task which will complete after the file is moved.</returns>
103+
void Move(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting);
104+
73105
/// <summary>
74106
/// Moves a file.
75107
/// </summary>
@@ -84,8 +116,16 @@ public interface IFile
84116
/// </summary>
85117
/// <param name="newPath">The new full path of the file.</param>
86118
/// <param name="collisionOption">How to deal with collisions with existing files.</param>
87-
/// <param name="cancellationToken">The cancellation token.</param>
88119
/// <returns>A task which will complete after the file is moved.</returns>
89-
Task CopyAsync(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting, CancellationToken cancellationToken = default(CancellationToken));
120+
void Copy(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting);
121+
122+
/// <summary>
123+
/// Copies a file.
124+
/// </summary>
125+
/// <param name="newPath">The new full path of the file.</param>
126+
/// <param name="collisionOption">How to deal with collisions with existing files.</param>
127+
/// <param name="cancellationToken">The cancellation token.</param>
128+
/// <returns>A task which will complete after the file is moved.</returns>
129+
Task CopyAsync(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting, CancellationToken cancellationToken = default(CancellationToken));
90130
}
91131
}

src/PCLExt.FileStorage.Abstractions/IFileSystem.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public interface IFileSystem
3030
/// </summary>
3131
IFolder RoamingStorage { get; }
3232

33+
/// <summary>
34+
/// Gets a file, given its path. Returns null if the file does not exist.
35+
/// </summary>
36+
/// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
37+
/// <returns>A file for the given path, or null if it does not exist.</returns>
38+
IFile GetFileFromPath(string path);
39+
3340
/// <summary>
3441
/// Gets a file, given its path. Returns null if the file does not exist.
3542
/// </summary>
@@ -38,6 +45,13 @@ public interface IFileSystem
3845
/// <returns>A file for the given path, or null if it does not exist.</returns>
3946
Task<IFile> GetFileFromPathAsync(string path, CancellationToken cancellationToken = default(CancellationToken));
4047

48+
/// <summary>
49+
/// Gets a folder, given its path. Returns null if the folder does not exist.
50+
/// </summary>
51+
/// <param name="path">The path to a folder, as returned from the <see cref="IFolder.Path"/> property.</param>
52+
/// <returns>A folder for the specified path, or null if it does not exist.</returns>
53+
IFolder GetFolderFromPath(string path);
54+
4155
/// <summary>
4256
/// Gets a folder, given its path. Returns null if the folder does not exist.
4357
/// </summary>

src/PCLExt.FileStorage.Abstractions/IFolder.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ public interface IFolder
5050
/// </summary>
5151
string Path { get; }
5252

53+
/// <summary>
54+
/// Creates a file in this folder
55+
/// </summary>
56+
/// <param name="desiredName">The name of the file to create</param>
57+
/// <param name="option">Specifies how to behave if the specified file already exists</param>
58+
/// <returns>The newly created file</returns>
59+
IFile CreateFile(string desiredName, CreationCollisionOption option);
60+
5361
/// <summary>
5462
/// Creates a file in this folder
5563
/// </summary>
@@ -59,6 +67,13 @@ public interface IFolder
5967
/// <returns>The newly created file</returns>
6068
Task<IFile> CreateFileAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken = default(CancellationToken));
6169

70+
/// <summary>
71+
/// Gets a file in this folder
72+
/// </summary>
73+
/// <param name="name">The name of the file to get</param>
74+
/// <returns>The requested file, or null if it does not exist</returns>
75+
IFile GetFile(string name);
76+
6277
/// <summary>
6378
/// Gets a file in this folder
6479
/// </summary>
@@ -67,13 +82,27 @@ public interface IFolder
6782
/// <returns>The requested file, or null if it does not exist</returns>
6883
Task<IFile> GetFileAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
6984

85+
/// <summary>
86+
/// Gets a list of the files in this folder
87+
/// </summary>
88+
/// <returns>A list of the files in the folder</returns>
89+
IList<IFile> GetFiles();
90+
7091
/// <summary>
7192
/// Gets a list of the files in this folder
7293
/// </summary>
7394
/// <param name="cancellationToken">The cancellation token.</param>
7495
/// <returns>A list of the files in the folder</returns>
7596
Task<IList<IFile>> GetFilesAsync(CancellationToken cancellationToken = default(CancellationToken));
7697

98+
/// <summary>
99+
/// Creates a subfolder in this folder
100+
/// </summary>
101+
/// <param name="desiredName">The name of the folder to create</param>
102+
/// <param name="option">Specifies how to behave if the specified folder already exists</param>
103+
/// <returns>The newly created folder</returns>
104+
IFolder CreateFolder(string desiredName, CreationCollisionOption option);
105+
77106
/// <summary>
78107
/// Creates a subfolder in this folder
79108
/// </summary>
@@ -83,6 +112,13 @@ public interface IFolder
83112
/// <returns>The newly created folder</returns>
84113
Task<IFolder> CreateFolderAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken = default(CancellationToken));
85114

115+
/// <summary>
116+
/// Gets a subfolder in this folder
117+
/// </summary>
118+
/// <param name="name">The name of the folder to get</param>
119+
/// <returns>The requested folder, or null if it does not exist</returns>
120+
IFolder GetFolder(string name);
121+
86122
/// <summary>
87123
/// Gets a subfolder in this folder
88124
/// </summary>
@@ -91,13 +127,26 @@ public interface IFolder
91127
/// <returns>The requested folder, or null if it does not exist</returns>
92128
Task<IFolder> GetFolderAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
93129

130+
/// <summary>
131+
/// Gets a list of subfolders in this folder
132+
/// </summary>
133+
/// <returns>A list of subfolders in the folder</returns>
134+
IList<IFolder> GetFolders();
135+
94136
/// <summary>
95137
/// Gets a list of subfolders in this folder
96138
/// </summary>
97139
/// <param name="cancellationToken">The cancellation token.</param>
98140
/// <returns>A list of subfolders in the folder</returns>
99141
Task<IList<IFolder>> GetFoldersAsync(CancellationToken cancellationToken = default(CancellationToken));
100142

143+
/// <summary>
144+
/// Checks whether a folder or file exists at the given location.
145+
/// </summary>
146+
/// <param name="name">The name of the file or folder to check for.</param>
147+
/// <returns>A task whose result is the result of the existence check.</returns>
148+
ExistenceCheckResult CheckExists(string name);
149+
101150
/// <summary>
102151
/// Checks whether a folder or file exists at the given location.
103152
/// </summary>
@@ -106,11 +155,34 @@ public interface IFolder
106155
/// <returns>A task whose result is the result of the existence check.</returns>
107156
Task<ExistenceCheckResult> CheckExistsAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
108157

158+
/// <summary>
159+
/// Deletes this folder and all of its contents
160+
/// </summary>
161+
/// <returns>A task which will complete after the folder is deleted</returns>
162+
void Delete();
163+
109164
/// <summary>
110165
/// Deletes this folder and all of its contents
111166
/// </summary>
112167
/// <param name="cancellationToken">The cancellation token.</param>
113168
/// <returns>A task which will complete after the folder is deleted</returns>
114169
Task DeleteAsync(CancellationToken cancellationToken = default(CancellationToken));
170+
171+
/// <summary>
172+
/// Moves this folder and all of its contents to the given folder, current folder will be deleted.
173+
/// </summary>
174+
/// <param name="folder">The folder in which content will be moved</param>
175+
/// <param name="option">Specifies how to behave if the specified folder/file already exists</param>
176+
/// <returns>The folder with moved content.</returns>
177+
IFolder Move(IFolder folder, NameCollisionOption option = NameCollisionOption.ReplaceExisting);
178+
179+
/// <summary>
180+
/// Moves this folder and all of its contents to the given folder, current folder will be deleted.
181+
/// </summary>
182+
/// <param name="folder">The folder in which content will be moved</param>
183+
/// <param name="option">Specifies how to behave if the specified folder/file already exists</param>
184+
/// <param name="cancellationToken">The cancellation token.</param>
185+
/// <returns>The folder with moved content.</returns>
186+
Task<IFolder> MoveAsync(IFolder folder, NameCollisionOption option = NameCollisionOption.ReplaceExisting, CancellationToken cancellationToken = default(CancellationToken));
115187
}
116188
}

src/PCLExt.FileStorage.Android/PCLExt.FileStorage.Android.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@
6262
<Compile Include="$(SolutionDir)\src\PCLExt.FileStorage\Requires.cs">
6363
<Link>Requires.cs</Link>
6464
</Compile>
65-
<Compile Include="$(SolutionDir)\src\PCLExt.FileStorage\Storage.cs">
66-
<Link>Storage.cs</Link>
67-
</Compile>
6865
<Compile Include="Properties\AssemblyInfo.cs" />
6966
<Compile Include="$(SolutionDir)\src\PCLExt.FileStorage\FileSystem.cs">
7067
<Link>FileSystem.cs</Link>

src/PCLExt.FileStorage.Desktop/DesktopFileSystem.cs

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,28 @@ public IFolder RoamingStorage
9393
}
9494
}
9595

96-
/// <summary>
97-
/// Gets a file, given its path. Returns null if the file does not exist.
98-
/// </summary>
99-
/// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
100-
/// <param name="cancellationToken">The cancellation token.</param>
101-
/// <returns>A file for the given path, or null if it does not exist.</returns>
102-
public async Task<IFile> GetFileFromPathAsync(string path, CancellationToken cancellationToken)
96+
/// <summary>
97+
/// Gets a file, given its path. Returns null if the file does not exist.
98+
/// </summary>
99+
/// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
100+
/// <returns>A file for the given path, or null if it does not exist.</returns>
101+
public IFile GetFileFromPath(string path)
102+
{
103+
Requires.NotNullOrEmpty(path, "path");
104+
105+
if (System.IO.File.Exists(path))
106+
return new FileSystemFile(path);
107+
108+
return null;
109+
}
110+
111+
/// <summary>
112+
/// Gets a file, given its path. Returns null if the file does not exist.
113+
/// </summary>
114+
/// <param name="path">The path to a file, as returned from the <see cref="IFile.Path"/> property.</param>
115+
/// <param name="cancellationToken">The cancellation token.</param>
116+
/// <returns>A file for the given path, or null if it does not exist.</returns>
117+
public async Task<IFile> GetFileFromPathAsync(string path, CancellationToken cancellationToken)
103118
{
104119
Requires.NotNullOrEmpty(path, "path");
105120

@@ -110,21 +125,36 @@ public async Task<IFile> GetFileFromPathAsync(string path, CancellationToken can
110125
return null;
111126
}
112127

113-
/// <summary>
114-
/// Gets a folder, given its path. Returns null if the folder does not exist.
115-
/// </summary>
116-
/// <param name="path">The path to a folder, as returned from the <see cref="IFolder.Path"/> property.</param>
117-
/// <param name="cancellationToken">The cancellation token.</param>
118-
/// <returns>A folder for the specified path, or null if it does not exist.</returns>
119-
public async Task<IFolder> GetFolderFromPathAsync(string path, CancellationToken cancellationToken)
120-
{
121-
Requires.NotNullOrEmpty(path, "path");
128+
/// <summary>
129+
/// Gets a folder, given its path. Returns null if the folder does not exist.
130+
/// </summary>
131+
/// <param name="path">The path to a folder, as returned from the <see cref="IFolder.Path"/> property.</param>
132+
/// <returns>A folder for the specified path, or null if it does not exist.</returns>
133+
public IFolder GetFolderFromPath(string path)
134+
{
135+
Requires.NotNullOrEmpty(path, "path");
122136

123-
await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);
124-
if (System.IO.Directory.Exists(path))
125-
return new FileSystemFolder(path, true);
137+
if (System.IO.Directory.Exists(path))
138+
return new FileSystemFolder(path, true);
126139

127-
return null;
128-
}
129-
}
140+
return null;
141+
}
142+
143+
/// <summary>
144+
/// Gets a folder, given its path. Returns null if the folder does not exist.
145+
/// </summary>
146+
/// <param name="path">The path to a folder, as returned from the <see cref="IFolder.Path"/> property.</param>
147+
/// <param name="cancellationToken">The cancellation token.</param>
148+
/// <returns>A folder for the specified path, or null if it does not exist.</returns>
149+
public async Task<IFolder> GetFolderFromPathAsync(string path, CancellationToken cancellationToken)
150+
{
151+
Requires.NotNullOrEmpty(path, "path");
152+
153+
await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);
154+
if (System.IO.Directory.Exists(path))
155+
return new FileSystemFolder(path, true);
156+
157+
return null;
158+
}
159+
}
130160
}

0 commit comments

Comments
 (0)