Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new methods in StorageFolder and StorageFile #33

Merged
merged 3 commits into from
Apr 23, 2019
Merged
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
7 changes: 6 additions & 1 deletion source/Windows.Storage/IStorageItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ public interface IStorageItem

// public bool IsOfType(StorageItemTypes type);

// public IAsyncAction RenameAsync(String desiredName);

/// <summary>
/// Renames the current item.
/// </summary>
/// <param name="desiredName">The desired, new name of the item.</param>
void Rename(String desiredName);

// public IAsyncAction RenameAsync(String desiredName, NameCollisionOption option);

Expand Down
56 changes: 51 additions & 5 deletions source/Windows.Storage/StorageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,23 @@ public string FileType
// public static IAsyncOperation<StorageFile> CreateStreamedFileFromUriAsync(String displayNameWithExtension, Uri uri, IRandomAccessStreamReference thumbnail)
// { }

// public IAsyncAction DeleteAsync()
// { }

/// <summary>
/// Delete the current file.
/// </summary>
/// <remarks>
/// <para>
/// If the file doesn't exist this method will throw an exception.
/// </para>
/// <para>
/// This method is exclusive of nanoFramework and it's not available in the UWP API.
/// The equivalent method would be DeleteAsync().
/// </para>
/// </remarks>
public void Delete()
{
DeleteFileNative();
}

// public IAsyncAction DeleteAsync(StorageDeleteOption option)
// { }

Expand Down Expand Up @@ -239,8 +253,30 @@ public static StorageFile GetFileFromPath(String path)
// public IAsyncOperation<StorageStreamTransaction> OpenTransactedWriteAsync(StorageOpenOptions options)
// { }

// public IAsyncAction RenameAsync(String desiredName)
// { }
/// <summary>
/// Renames the current file.
/// </summary>
/// <param name="desiredName">The desired new name of the current file.</param>
/// <remarks>
/// <para>
/// If the name you specify is invalid or already exists, this method throws an exception
/// </para>
/// <para>
/// This method is exclusive of nanoFramework and it's not available in the UWP API.
/// The equivalent method would be RenameAsync(String desiredName).
/// </para>
/// </remarks>
public void Rename(string desiredName)
{
// Construct path for new name
string desiredPath = _path.Substring(0, _path.Length - _name.Length) + desiredName;

RenameFileNative(desiredPath);

// No exception, so update file Path & name
_path = desiredPath;
_name = desiredName;
}

// public IAsyncAction RenameAsync(String desiredName, NameCollisionOption option)
// { }
Expand All @@ -257,5 +293,15 @@ public static StorageFile GetFileFromPath(String path)
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void CheckFileNative(string filePath);

[System.Diagnostics.DebuggerStepThrough]
[System.Diagnostics.DebuggerHidden]
[MethodImpl(MethodImplOptions.InternalCall)]
private extern void DeleteFileNative();

[System.Diagnostics.DebuggerStepThrough]
[System.Diagnostics.DebuggerHidden]
[MethodImpl(MethodImplOptions.InternalCall)]
private extern void RenameFileNative(String desiredName);

}
}
82 changes: 76 additions & 6 deletions source/Windows.Storage/StorageFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public sealed class StorageFolder : IStorageFolder//, IStorageFolder2, IStorageI
#pragma warning restore 0649

[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private readonly string _name;
private string _name;

[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private readonly string _path;
private string _path;

#endregion

Expand Down Expand Up @@ -195,8 +195,10 @@ public StorageFolder CreateFolder(String desiredName)
/// When this method completes, it returns a <see cref="StorageFolder"/> that represents the new subfolder.
/// </returns>
///<remarks>
/// <para>
/// This method is exclusive of nanoFramework and it's not available in the UWP API.
/// The equivalent method would be CreateFolderAsync(String, CreationCollisionOption).
/// </para>
///</remarks>
public StorageFolder CreateFolder(String desiredName, CreationCollisionOption options)
{
Expand All @@ -218,8 +220,21 @@ public StorageFolder CreateFolder(String desiredName, CreationCollisionOption op
// public StorageItemQueryResult CreateItemQueryWithOptions(QueryOptions queryOptions)
// { }

// public IAsyncAction DeleteAsync()
// { }
/// <summary>
/// Delete the current folder.
/// </summary>
/// <remarks>
/// <para>
/// If the folder doesn't exist then this method will throw an exception.
/// </para>
/// <para>This method is exclusive of nanoFramework and it's not available in the UWP API.
/// The equivalent method would be DeleteAsync().
/// </para>
/// </remarks>
public void Delete()
{
DeleteFolderNative();
}

// public IAsyncAction DeleteAsync(StorageDeleteOption option)
// { }
Expand Down Expand Up @@ -296,6 +311,27 @@ public StorageFile[] GetFiles(CommonFileQuery query, UInt32 startIndex, UInt32 m
return GetStorageFilesNative(startIndex, maxItemsToRetrieve);
}

/// <summary>
/// Gets the subfolder with the specified name from the current folder.
/// </summary>
/// <param name="name">The name (or path relative to the current folder) of the subfolder to get.</param>
/// <returns>
/// When this method completes successfully, it returns a StorageFolder that represents the specified subfolder.
/// </returns>
/// <remarks>
/// <para>
/// If the folder doesn't exist it will throw an exception.
/// </para>
/// <para>
/// This method is exclusive of nanoFramework and it's not available in the UWP API.
/// The equivalent method would be GetFolderAsync(String name).
/// </para>
/// </remarks>
public StorageFolder GetFolder(String name)
{
return GetFolderNative(name);
}

// public IAsyncOperation<StorageFolder> GetFolderAsync(String name)
// { }

Expand Down Expand Up @@ -395,8 +431,28 @@ public bool IsCommonFileQuerySupported(CommonFileQuery query)
// public bool IsOfType(StorageItemTypes type)
// { }

// public IAsyncAction RenameAsync(String desiredName)
// { }
/// <summary>
/// Renames the current folder.
/// </summary>
/// <param name="desiredName">The desired, new name for the current folder.</param>
/// <remarks>
/// <para>If the name you specify is invalid or a folder with the same name already exists,
/// this method throws an exception. If the target device doesn't support folders then this will also
/// throw an exception.</para>
/// <para>This method is exclusive of nanoFramework and it's not available in the UWP API.
/// The equivalent method would be RenameAsync(String desiredName).</para>
/// </remarks>
public void Rename(String desiredName)
{
// Create path to disired folder
string desiredPath = _path.Substring(0, _path.Length - _name.Length) + desiredName;

RenameFolderNative(desiredPath);

// No exception, so update folder Path & name
_path = desiredPath;
_name = desiredName;
}

// public IAsyncAction RenameAsync(String desiredName, NameCollisionOption option)
// { }
Expand Down Expand Up @@ -439,6 +495,20 @@ public bool IsCommonFileQuerySupported(CommonFileQuery query)
[MethodImpl(MethodImplOptions.InternalCall)]
private extern StorageFolder CreateFolderNative(string desiredName, uint options);

[System.Diagnostics.DebuggerStepThrough]
[System.Diagnostics.DebuggerHidden]
[MethodImpl(MethodImplOptions.InternalCall)]
private extern void DeleteFolderNative();

[System.Diagnostics.DebuggerStepThrough]
[System.Diagnostics.DebuggerHidden]
[MethodImpl(MethodImplOptions.InternalCall)]
private extern void RenameFolderNative(String desiredPath);

[System.Diagnostics.DebuggerStepThrough]
[System.Diagnostics.DebuggerHidden]
[MethodImpl(MethodImplOptions.InternalCall)]
private extern StorageFolder GetFolderNative(String name);
#endregion

}
Expand Down