Skip to content

Commit

Permalink
Add UnixFileMode extension for ISyncService.PushAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Mar 8, 2024
1 parent b2823a8 commit 37707f6
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 15 deletions.
50 changes: 48 additions & 2 deletions AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public static partial class DeviceExtensions
/// <param name="callback">An optional parameter which, when specified, returns progress notifications. The progress is reported as a value between 0 and 100, representing the percentage of the file which has been transferred.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can be used to cancel the task.</param>
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
/// <remarks>The <paramref name="permissions"/> should coverts to a decimal number. For example, <c>644</c> should be <c>420</c> in decimal, <c>&amp;O644</c> in VB.NET and <c>0o644</c> in F# and Python.</remarks>
public static async Task PushAsync(this IAdbClient client, DeviceData device,
string remotePath, Stream stream, int permissions, DateTimeOffset timestamp,
Action<SyncProgressChangedEventArgs>? callback = null,
Expand Down Expand Up @@ -391,7 +392,7 @@ public static Task InstallMultiplePackageAsync(this IAdbClient client, DeviceDat
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
public static async Task PullAsync(this IAdbClient client, DeviceData device,
string remotePath, Stream stream,
IProgress<SyncProgressChangedEventArgs>? progress = null,
IProgress<SyncProgressChangedEventArgs>? progress,
CancellationToken cancellationToken = default)
{
using ISyncService service = Factories.SyncServiceFactory(client, device);
Expand All @@ -410,9 +411,10 @@ public static Task InstallMultiplePackageAsync(this IAdbClient client, DeviceDat
/// <param name="progress">An optional parameter which, when specified, returns progress notifications. The progress is reported as a value between 0 and 100, representing the percentage of the file which has been transferred.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can be used to cancel the task.</param>
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
/// <remarks>The <paramref name="permissions"/> should coverts to a decimal number. For example, <c>644</c> should be <c>420</c> in decimal, <c>&amp;O644</c> in VB.NET and <c>0o644</c> in F# and Python.</remarks>
public static async Task PushAsync(this IAdbClient client, DeviceData device,
string remotePath, Stream stream, int permissions, DateTimeOffset timestamp,
IProgress<SyncProgressChangedEventArgs>? progress = null,
IProgress<SyncProgressChangedEventArgs>? progress,
CancellationToken cancellationToken = default)
{
using ISyncService service = Factories.SyncServiceFactory(client, device);
Expand Down Expand Up @@ -471,6 +473,50 @@ public static Task InstallMultiplePackageAsync(this IAdbClient client, DeviceDat
PackageManager manager = new(client, device, skipInit: true);
return manager.InstallMultiplePackageAsync(splitPackageFilePaths, packageName, progress, cancellationToken, arguments);
}

#if NET7_0_OR_GREATER
/// <summary>
/// Asynchronously pushes (uploads) a file to the remote device.
/// </summary>
/// <param name="client">The <see cref="IAdbClient"/> to use when executing the command.</param>
/// <param name="device">The device on which to put the file.</param>
/// <param name="remotePath">The path, on the device, to which to push the file.</param>
/// <param name="stream">A <see cref="Stream"/> that contains the contents of the file.</param>
/// <param name="permission">The <see cref="UnixFileMode"/> that contains the permissions of the newly created file on the device.</param>
/// <param name="timestamp">The time at which the file was last modified.</param>
/// <param name="callback">An optional parameter which, when specified, returns progress notifications. The progress is reported as a value between 0 and 100, representing the percentage of the file which has been transferred.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can be used to cancel the task.</param>
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
public static async Task PushAsync(this IAdbClient client, DeviceData device,
string remotePath, Stream stream, UnixFileMode permission, DateTimeOffset timestamp,
Action<SyncProgressChangedEventArgs>? callback = null,
CancellationToken cancellationToken = default)
{
using ISyncService service = Factories.SyncServiceFactory(client, device);
await service.PushAsync(stream, remotePath, (int)permission, timestamp, callback, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Asynchronously pushes (uploads) a file to the remote device.
/// </summary>
/// <param name="client">The <see cref="IAdbClient"/> to use when executing the command.</param>
/// <param name="device">The device on which to put the file.</param>
/// <param name="remotePath">The path, on the device, to which to push the file.</param>
/// <param name="stream">A <see cref="Stream"/> that contains the contents of the file.</param>
/// <param name="permission">The <see cref="UnixFileMode"/> that contains the permissions of the newly created file on the device.</param>
/// <param name="timestamp">The time at which the file was last modified.</param>
/// <param name="progress">An optional parameter which, when specified, returns progress notifications. The progress is reported as a value between 0 and 100, representing the percentage of the file which has been transferred.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can be used to cancel the task.</param>
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
public static async Task PushAsync(this IAdbClient client, DeviceData device,
string remotePath, Stream stream, UnixFileMode permission, DateTimeOffset timestamp,
IProgress<SyncProgressChangedEventArgs>? progress,
CancellationToken cancellationToken = default)
{
using ISyncService service = Factories.SyncServiceFactory(client, device);
await service.PushAsync(stream, remotePath, (int)permission, timestamp, progress.AsAction(), cancellationToken).ConfigureAwait(false);
}
#endif
#endif

/// <summary>
Expand Down
46 changes: 45 additions & 1 deletion AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static partial class DeviceExtensions
/// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
/// <param name="device">The device on which to clear the input text.</param>
/// <param name="charCount">The length of text to clear.</param>
public static void ClearInput(this IAdbClient client, DeviceData device, int charCount)=>
public static void ClearInput(this IAdbClient client, DeviceData device, int charCount) =>
new DeviceClient(client, device).ClearInput(charCount);

/// <summary>
Expand Down Expand Up @@ -199,6 +199,7 @@ public static partial class DeviceExtensions
/// <param name="timestamp">The time at which the file was last modified.</param>
/// <param name="callback">An optional parameter which, when specified, returns progress notifications. The progress is reported as a value between 0 and 100, representing the percentage of the file which has been transferred.</param>
/// <param name="isCancelled">A <see cref="bool"/> that can be used to cancel the task.</param>
/// <remarks>The <paramref name="permissions"/> should coverts to a decimal number. For example, <c>644</c> should be <c>420</c> in decimal, <c>&amp;O644</c> in VB.NET and <c>0o644</c> in F# and Python.</remarks>
public static void Push(this IAdbClient client, DeviceData device,
string remotePath, Stream stream, int permissions, DateTimeOffset timestamp,
Action<SyncProgressChangedEventArgs>? callback = null,
Expand Down Expand Up @@ -354,6 +355,7 @@ public static void InstallMultiplePackage(this IAdbClient client, DeviceData dev
/// <param name="timestamp">The time at which the file was last modified.</param>
/// <param name="progress">An optional parameter which, when specified, returns progress notifications. The progress is reported as a value between 0 and 100, representing the percentage of the file which has been transferred.</param>
/// <param name="isCancelled">A <see cref="bool"/> that can be used to cancel the task.</param>
/// <remarks>The <paramref name="permissions"/> should coverts to a decimal number. For example, <c>644</c> should be <c>420</c> in decimal, <c>&amp;O644</c> in VB.NET and <c>0o644</c> in F# and Python.</remarks>
public static void Push(this IAdbClient client, DeviceData device,
string remotePath, Stream stream, int permissions, DateTimeOffset timestamp,
IProgress<SyncProgressChangedEventArgs>? progress = null,
Expand Down Expand Up @@ -409,6 +411,48 @@ public static void InstallMultiplePackage(this IAdbClient client, DeviceData dev
PackageManager manager = new(client, device, skipInit: true);
manager.InstallMultiplePackage(splitPackageFilePaths, packageName, progress, arguments);
}

#if NET7_0_OR_GREATER
/// <summary>
/// Pushes (uploads) a file to the remote device.
/// </summary>
/// <param name="client">The <see cref="IAdbClient"/> to use when executing the command.</param>
/// <param name="device">The device on which to put the file.</param>
/// <param name="remotePath">The path, on the device, to which to push the file.</param>
/// <param name="stream">A <see cref="Stream"/> that contains the contents of the file.</param>
/// <param name="permission">The <see cref="UnixFileMode"/> that contains the permissions of the newly created file on the device.</param>
/// <param name="timestamp">The time at which the file was last modified.</param>
/// <param name="callback">An optional parameter which, when specified, returns progress notifications. The progress is reported as a value between 0 and 100, representing the percentage of the file which has been transferred.</param>
/// <param name="isCancelled">A <see cref="bool"/> that can be used to cancel the task.</param>
public static void Push(this IAdbClient client, DeviceData device,
string remotePath, Stream stream, UnixFileMode permission, DateTimeOffset timestamp,
Action<SyncProgressChangedEventArgs>? callback = null,
in bool isCancelled = false)
{
using ISyncService service = Factories.SyncServiceFactory(client, device);
service.Push(stream, remotePath, (int)permission, timestamp, callback, in isCancelled);
}

/// <summary>
/// Pushes (uploads) a file to the remote device.
/// </summary>
/// <param name="client">The <see cref="IAdbClient"/> to use when executing the command.</param>
/// <param name="device">The device on which to put the file.</param>
/// <param name="remotePath">The path, on the device, to which to push the file.</param>
/// <param name="stream">A <see cref="Stream"/> that contains the contents of the file.</param>
/// <param name="permission">The <see cref="UnixFileMode"/> that contains the permissions of the newly created file on the device.</param>
/// <param name="timestamp">The time at which the file was last modified.</param>
/// <param name="progress">An optional parameter which, when specified, returns progress notifications. The progress is reported as a value between 0 and 100, representing the percentage of the file which has been transferred.</param>
/// <param name="isCancelled">A <see cref="bool"/> that can be used to cancel the task.</param>
public static void Push(this IAdbClient client, DeviceData device,
string remotePath, Stream stream, UnixFileMode permission, DateTimeOffset timestamp,
IProgress<SyncProgressChangedEventArgs>? progress,
in bool isCancelled = false)
{
using ISyncService service = Factories.SyncServiceFactory(client, device);
service.Push(stream, remotePath, (int)permission, timestamp, progress.AsAction(), in isCancelled);
}
#endif
#endif

/// <summary>
Expand Down

0 comments on commit 37707f6

Please sign in to comment.