Skip to content

Commit 5cac345

Browse files
ArtjomPAragas
authored andcommitted
Times & UWP support updating (#15)
* Times have been added to IFile StorageFolder & StorageFile have been implemented for UWP * Fixing Times * Fixing Times tests * Fixing UWP async implementations
1 parent 9d0dedb commit 5cac345

File tree

16 files changed

+872
-29
lines changed

16 files changed

+872
-29
lines changed

src/PCLExt.FileStorage.NetFX/DefaultFileImplementation.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ internal class DefaultFileImplementation : IFile
3131
public bool Exists => File.Exists(Path);
3232
/// <inheritdoc />
3333
public long Size => Exists ? new FileInfo(Path).Length : -1;
34+
/// <inheritdoc />
35+
public DateTime CreationTime => File.GetCreationTime(Path);
36+
/// <inheritdoc />
37+
public DateTime CreationTimeUTC => File.GetCreationTimeUtc(Path);
38+
/// <inheritdoc />
39+
public DateTime LastAccessTime => File.GetLastAccessTime(Path);
40+
/// <inheritdoc />
41+
public DateTime LastAccessTimeUTC => File.GetLastAccessTimeUtc(Path);
42+
/// <inheritdoc />
43+
public DateTime LastWriteTime => File.GetLastWriteTime(Path);
44+
/// <inheritdoc />
45+
public DateTime LastWriteTimeUTC => File.GetLastWriteTimeUtc(Path);
3446

3547
/// <summary>
3648
/// Creates a new <see cref="IFile"/> corresponding to the specified path.

src/PCLExt.FileStorage.Portable111/Files/FileFromPath.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
namespace PCLExt.FileStorage.Files
1+
#if WINDOWS_UWP
2+
using PCLExt.FileStorage.UWP;
3+
#endif
4+
5+
namespace PCLExt.FileStorage.Files
26
{
37
/// <summary>
48
/// Represents a folder created by a given path
@@ -19,6 +23,11 @@ private static IFile GetFileFromPath(string path)
1923
return new DefaultFileImplementation(path);
2024
else
2125
throw new Exceptions.FileNotFoundException($"File does not exists on {path}");
26+
#elif WINDOWS_UWP
27+
var result = new StorageFileImplementation(path);
28+
if(!result.Exists)
29+
throw new Exceptions.FileNotFoundException($"File does not exists on {path}");
30+
return result;
2231
#endif
2332

2433
throw Exceptions.ExceptionsHelper.NotImplementedInReferenceAssembly();

src/PCLExt.FileStorage.Portable111/Folders/ApplicationRootFolder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ private static IFolder GetApplicationFolder()
2121
#elif NETSTANDARD2_0
2222
return new DefaultFolderImplementation(System.AppContext.BaseDirectory);
2323
#elif WINDOWS_UWP
24-
return null;
24+
return new UWP.StorageFolderImplementation(
25+
Windows.ApplicationModel.Package.Current.InstalledLocation);
2526
#endif
2627
}
2728
#else

src/PCLExt.FileStorage.Portable111/Folders/DocumentsRootFolder.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ private static IFolder GetDocumentsFolder()
1818
return new DefaultFolderImplementation(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments));
1919
#elif DESKTOP || __MACOS__ || NETSTANDARD2_0
2020
return new DefaultFolderImplementation(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)).GetDataFolder();
21-
#elif WINDOWS_UWP
22-
return null;
23-
// TODO
24-
return new DefaultFolderImplementation(Windows.Storage.KnownFolders.DocumentsLibrary.Path);
21+
#elif WINDOWS_UWP
22+
return new UWP.StorageFolderImplementation(Windows.Storage.KnownFolders.DocumentsLibrary);
2523
#endif
2624
}
2725
#else

src/PCLExt.FileStorage.Portable111/Folders/FolderFromPath.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ private static IFolder GetFolderFromPath(string path)
1616

1717
#if DESKTOP || ANDROID || __IOS__ || __MACOS__ || NETSTANDARD2_0
1818
return System.IO.Directory.Exists(path) ? new DefaultFolderImplementation(path, true) : null;
19+
#elif WINDOWS_UWP
20+
return new UWP.StorageFolderImplementation(path);
1921
#endif
2022

2123
throw Exceptions.ExceptionsHelper.NotImplementedInReferenceAssembly();

src/PCLExt.FileStorage.Portable111/Folders/LocalRootFolder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ private static IFolder GetLocalFolder()
4545
#elif DESKTOP || NETSTANDARD2_0
4646
return new DefaultFolderImplementation(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData)).GetDataFolder();
4747
#elif WINDOWS_UWP
48-
return null;
49-
return new DefaultFolderImplementation(Windows.Storage.ApplicationData.Current.LocalFolder.Path);
48+
return new UWP.StorageFolderImplementation(
49+
Windows.Storage.ApplicationData.Current.LocalFolder);
5050
#endif
5151
}
5252
#else

src/PCLExt.FileStorage.Portable111/Folders/RoamingRootFolder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ private static IFolder GetRoamingFolder()
2121
#elif DESKTOP || __MACOS__ || NETSTANDARD2_0
2222
return new DefaultFolderImplementation(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)).GetDataFolder();
2323
#elif WINDOWS_UWP
24-
return null;
25-
return new DefaultFolderImplementation(Windows.Storage.ApplicationData.Current.RoamingFolder.Path);
24+
return new UWP.StorageFolderImplementation(
25+
Windows.Storage.ApplicationData.Current.RoamingFolder);
2626
#endif
2727
}
2828
#else

src/PCLExt.FileStorage.Portable111/Folders/TempRootFolder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public TempRootFolder() : base(GetTempFolder()) { }
1313
private static IFolder GetTempFolder()
1414
{
1515
#if WINDOWS_UWP
16-
return null;
17-
return new DefaultFolderImplementation(Windows.Storage.ApplicationData.Current.TemporaryFolder.Path);
16+
return new UWP.StorageFolderImplementation(
17+
Windows.Storage.ApplicationData.Current.TemporaryFolder);
1818
#else
1919
return new DefaultFolderImplementation(System.IO.Path.GetTempPath());
2020
#endif

src/PCLExt.FileStorage.Portable111/PortablePath.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public static char DirectorySeparatorChar
2323
{
2424
get
2525
{
26-
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__
27-
return System.IO.Path.DirectorySeparatorChar;
26+
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__ || WINDOWS_UWP
27+
return System.IO.Path.DirectorySeparatorChar;
2828
#endif
2929

3030
throw ExceptionsHelper.NotImplementedInReferenceAssembly();
@@ -38,7 +38,7 @@ public static char DirectorySeparatorChar
3838
/// <returns>A combined path.</returns>
3939
public static string Combine(params string[] paths)
4040
{
41-
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__
41+
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__ || WINDOWS_UWP
4242
return System.IO.Path.Combine(paths);
4343
#endif
4444

@@ -58,8 +58,8 @@ public static string Combine(params string[] paths)
5858
/// <exception cref="System.ArgumentException"><paramref name="path" /> contains one or more invalid characters.</exception>
5959
public static string GetExtension(string path)
6060
{
61-
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__
62-
return System.IO.Path.GetExtension(path);
61+
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__ || WINDOWS_UWP
62+
return System.IO.Path.GetExtension(path);
6363
#endif
6464

6565
throw ExceptionsHelper.NotImplementedInReferenceAssembly();
@@ -82,8 +82,8 @@ public static string GetExtension(string path)
8282
/// <exception cref="System.ArgumentException"><paramref name="path" /> contains one or more invalid characters.</exception>
8383
public static string GetFileName(string path)
8484
{
85-
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__
86-
return System.IO.Path.GetFileName(path);
85+
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__ || WINDOWS_UWP
86+
return System.IO.Path.GetFileName(path);
8787
#endif
8888

8989
throw ExceptionsHelper.NotImplementedInReferenceAssembly();
@@ -101,8 +101,8 @@ public static string GetFileName(string path)
101101
/// <exception cref="System.ArgumentException"><paramref name="path" /> contains one or more invalid characters.</exception>
102102
public static string GetFileNameWithoutExtension(string path)
103103
{
104-
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__
105-
return System.IO.Path.GetFileNameWithoutExtension(path);
104+
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__ || WINDOWS_UWP
105+
return System.IO.Path.GetFileNameWithoutExtension(path);
106106
#endif
107107

108108
throw ExceptionsHelper.NotImplementedInReferenceAssembly();
@@ -121,8 +121,8 @@ public static string GetFileNameWithoutExtension(string path)
121121
/// <exception cref="System.ArgumentException"><paramref name="path" /> contains one or more invalid characters.</exception>
122122
public static bool HasExtension(string path)
123123
{
124-
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__
125-
return System.IO.Path.HasExtension(path);
124+
#if NETSTANDARD2_0 || DESKTOP || __MACOS__ || ANDROID || __IOS__ || WINDOWS_UWP
125+
return System.IO.Path.HasExtension(path);
126126
#endif
127127

128128
throw ExceptionsHelper.NotImplementedInReferenceAssembly();

src/PCLExt.FileStorage.Standard.Abstractions/BaseFile.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Threading;
34
using System.Threading.Tasks;
45

@@ -17,7 +18,18 @@ public abstract class BaseFile : IFile
1718
public bool Exists => _file.Exists;
1819
/// <inheritdoc />
1920
public long Size => _file.Size;
20-
21+
/// <inheritdoc />
22+
public DateTime CreationTime => _file.CreationTime;
23+
/// <inheritdoc />
24+
public DateTime CreationTimeUTC => _file.CreationTimeUTC;
25+
/// <inheritdoc />
26+
public DateTime LastAccessTime => _file.LastAccessTime;
27+
/// <inheritdoc />
28+
public DateTime LastAccessTimeUTC => _file.LastAccessTimeUTC;
29+
/// <inheritdoc />
30+
public DateTime LastWriteTime => _file.LastWriteTime;
31+
/// <inheritdoc />
32+
public DateTime LastWriteTimeUTC => _file.LastWriteTimeUTC;
2133

2234
/// <summary>
2335
/// Wraps an <see cref="IFile"/>

0 commit comments

Comments
 (0)