Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<Compile Include="..\PCLStorage.Abstractions\IFile.cs">
<Link>IFile.cs</Link>
</Compile>
<Compile Include="..\PCLStorage.Abstractions\IFileStats.cs">
<Link>IFileStats.cs</Link>
</Compile>
<Compile Include="..\PCLStorage.Abstractions\IFileSystem.cs">
<Link>IFileSystem.cs</Link>
</Compile>
Expand Down
35 changes: 35 additions & 0 deletions src/PCLStorage.Abstractions/IFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,40 @@ public interface IFile
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task which will complete after the file is moved.</returns>
Task MoveAsync(string newPath, NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Gets the FileStats of this file
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task which will return FileStats after completion.</returns>
Task<IFileStats> GetFileStats(CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Writes creation time
/// </summary>
/// <param name="creationTime">The time at which the file has been created</param>
/// <param name="utc">Set to true if you want to write utc time</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task which will complete after the creation time was written.</returns>
Task SetCreationTime(DateTime creationTime, bool utc = false, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Writes last access time
/// </summary>
/// <param name="lastAccessTime">The time at which the file has been last accessed</param>
/// <param name="utc">Set to true if you want to write utc time</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task which will complete after the last access time was written.</returns>
Task SetLastAccessTime(DateTime lastAccessTime, bool utc = false, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Writes last write time
/// </summary>
/// <param name="lastWriteTime">The time at which the file has been last written</param>
/// <param name="utc">Set to true if you want to write utc time</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task which will complete after the last write time was written.</returns>
Task SetLastWriteTime(DateTime lastWriteTime, bool utc = false, CancellationToken cancellationToken = default(CancellationToken));

}
}
71 changes: 71 additions & 0 deletions src/PCLStorage.Abstractions/IFileStats.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PCLStorage
{
/// <summary>
/// FileStats
/// </summary>
public interface IFileStats
{

/// <summary>
/// Name
/// </summary>
/// <value>The name</value>
string Name { get; }

/// <summary>
/// Extension
/// </summary>
/// <value>The extension</value>
string Extension { get; }

/// <summary>
/// Creation time.
/// </summary>
/// <value>The creation time.</value>
DateTime CreationTime { get; }

/// <summary>
/// Creation time UTC.
/// </summary>
/// <value>The creation time UTC.</value>
DateTime CreationTimeUTC { get; }

/// <summary>
/// Last access time.
/// </summary>
/// <value>The last access time.</value>
DateTime LastAccessTime { get;}

/// <summary>
/// Last access time UTC.
/// </summary>
/// <value>The last access time UTC.</value>
DateTime LastAccessTimeUTC { get; }

/// <summary>
/// Last write time.
/// </summary>
/// <value>The last write time.</value>
DateTime LastWriteTime { get; }

/// <summary>
/// Last write time UTC.
/// </summary>
/// <value>The last write time UTC.</value>
DateTime LastWriteTimeUTC { get; }



/// <summary>
/// Length of the data
/// </summary>
/// <value>The length.</value>
long Length { get; }

}
}
1 change: 1 addition & 0 deletions src/PCLStorage.Abstractions/PCLStorage.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
</Compile>
<Compile Include="ExistenceCheckResult.cs" />
<Compile Include="FileExtensions.cs" />
<Compile Include="IFileStats.cs" />
<Compile Include="IFile.cs" />
<Compile Include="IFileSystem.cs" />
<Compile Include="IFolder.cs" />
Expand Down
3 changes: 3 additions & 0 deletions src/PCLStorage.Android/PCLStorage.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<Compile Include="..\PCLStorage.FileSystem.Desktop\FileSystemFile.cs">
<Link>FileSystemFile.cs</Link>
</Compile>
<Compile Include="..\PCLStorage.FileSystem.Desktop\FileSystemFileStats.cs">
<Link>FileSystemFileStats.cs</Link>
</Compile>
<Compile Include="..\PCLStorage.FileSystem.Desktop\FileSystemFolder.cs">
<Link>FileSystemFolder.cs</Link>
</Compile>
Expand Down
8 changes: 4 additions & 4 deletions src/PCLStorage.Android/Resources/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions src/PCLStorage.FileSystem.Desktop/FileSystemFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,50 @@ public async Task MoveAsync(string newPath, NameCollisionOption collisionOption,
return;
}
}

public async Task<IFileStats> GetFileStats(CancellationToken cancellationToken = new CancellationToken())
{

await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

return FileSystemFileStats.FromPath(Path);

}

public async Task SetCreationTime(DateTime creationTime, bool utc = false, CancellationToken cancellationToken = new CancellationToken())
{

await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

if (utc)
File.SetCreationTimeUtc(Path, creationTime);
else
File.SetCreationTime(Path, creationTime);

}

public async Task SetLastAccessTime(DateTime lastAccessTime, bool utc = false, CancellationToken cancellationToken = new CancellationToken())
{

await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

if (utc)
File.SetLastAccessTimeUtc(Path, lastAccessTime);
else
File.SetLastAccessTime(Path, lastAccessTime);

}

public async Task SetLastWriteTime(DateTime lastWriteTime, bool utc = false, CancellationToken cancellationToken = new CancellationToken())
{

await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

if (utc)
File.SetLastWriteTimeUtc(Path, lastWriteTime);
else
File.SetLastWriteTime(Path, lastWriteTime);

}
}
}
63 changes: 63 additions & 0 deletions src/PCLStorage.FileSystem.Desktop/FileSystemFileStats.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PCLStorage
{
class FileSystemFileStats : IFileStats
{
#region IFileStats Member

public string Name { get; internal set; }
public string Extension { get; internal set; }
public DateTime CreationTime { get; internal set; }
public DateTime CreationTimeUTC { get; internal set; }

public DateTime LastAccessTime { get; internal set; }
public DateTime LastAccessTimeUTC { get; internal set; }

public DateTime LastWriteTime { get; internal set; }
public DateTime LastWriteTimeUTC { get; internal set; }

public long Length { get; internal set; }

#endregion

#if !WINDOWS_PHONE

internal static FileSystemFileStats FromPath(string path)
{



var fileInfo = new FileInfo(path);

var fileStats = new FileSystemFileStats()
{
Name = fileInfo.Name,
Extension = fileInfo.Extension,
CreationTime = fileInfo.CreationTime,
LastWriteTime = fileInfo.LastWriteTime,
LastAccessTime = fileInfo.LastAccessTime,
Length = fileInfo.Length
};

#if !SILVERLIGHT
fileStats.CreationTimeUTC = fileInfo.CreationTimeUtc;
fileStats.LastWriteTimeUTC = fileInfo.LastWriteTimeUtc;
fileStats.LastAccessTimeUTC = fileInfo.LastAccessTimeUtc;
#endif

return fileStats;



}
#endif

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
</Compile>
<Compile Include="DesktopFileSystem.cs" />
<Compile Include="FileSystemFile.cs" />
<Compile Include="FileSystemFileStats.cs" />
<Compile Include="FileSystemFolder.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
44 changes: 44 additions & 0 deletions src/PCLStorage.IsoStore.SL/IsoStoreFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public async Task<Stream> OpenAsync(FileAccess fileAccess, CancellationToken can

try
{

IsolatedStorageFileStream stream = _root.OpenFile(Path, FileMode.Open, nativeFileAccess, FileShare.Read);
return stream;
}
Expand Down Expand Up @@ -234,5 +235,48 @@ public async Task MoveAsync(string newPath, NameCollisionOption collisionOption,
return;
}
}

public async Task<IFileStats> GetFileStats(CancellationToken cancellationToken = new CancellationToken())
{

await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken);

var localCreationTime = _root.GetCreationTime(_path);
var localLastWriteTime = _root.GetLastWriteTime(_path);
var localLastAccessTime = _root.GetLastAccessTime(_path);

var fileStats = new FileSystemFileStats()
{
Name = _name,
Extension = System.IO.Path.GetExtension(_name),
CreationTime = localCreationTime.DateTime,
CreationTimeUTC = localCreationTime.UtcDateTime,
LastWriteTime = localLastWriteTime.DateTime,
LastWriteTimeUTC = localLastWriteTime.UtcDateTime,
LastAccessTime = localLastAccessTime.DateTime,
LastAccessTimeUTC = localLastAccessTime.UtcDateTime
};

return fileStats;

}

public Task SetCreationTime(DateTime creationTime, bool utc = false,
CancellationToken cancellationToken = new CancellationToken())
{
throw new NotSupportedException();
}

public Task SetLastAccessTime(DateTime lastAccessTime, bool utc = false,
CancellationToken cancellationToken = new CancellationToken())
{
throw new NotSupportedException();
}

public Task SetLastWriteTime(DateTime lastWriteTime, bool utc = false,
CancellationToken cancellationToken = new CancellationToken())
{
throw new NotSupportedException();
}
}
}
3 changes: 3 additions & 0 deletions src/PCLStorage.IsoStore.SL/PCLStorage.IsoStore.SL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
<Compile Include="..\..\common\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\PCLStorage.FileSystem.Desktop\FileSystemFileStats.cs">
<Link>FileSystemFileStats.cs</Link>
</Compile>
<Compile Include="..\PCLStorage\AwaitExtensions.cs">
<Link>AwaitExtensions.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions src/PCLStorage.iOS-Unified/PCLStorage.iOS-Unified.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<Compile Include="..\PCLStorage.FileSystem.Desktop\FileSystemFile.cs">
<Link>FileSystemFile.cs</Link>
</Compile>
<Compile Include="..\PCLStorage.FileSystem.Desktop\FileSystemFileStats.cs">
<Link>FileSystemFileStats.cs</Link>
</Compile>
<Compile Include="..\PCLStorage.FileSystem.Desktop\FileSystemFolder.cs">
<Link>FileSystemFolder.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions src/PCLStorage.iOS/PCLStorage.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<Compile Include="..\PCLStorage.FileSystem.Desktop\FileSystemFile.cs">
<Link>FileSystemFile.cs</Link>
</Compile>
<Compile Include="..\PCLStorage.FileSystem.Desktop\FileSystemFileStats.cs">
<Link>FileSystemFileStats.cs</Link>
</Compile>
<Compile Include="..\PCLStorage.FileSystem.Desktop\FileSystemFolder.cs">
<Link>FileSystemFolder.cs</Link>
</Compile>
Expand Down
1 change: 1 addition & 0 deletions src/PCLStorage/FileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<AndroidApplication>true</AndroidApplication>
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<TargetFrameworkVersion>v3.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0.3</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
8 changes: 4 additions & 4 deletions test/PCLStorage.Test.Android/Resources/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading