Skip to content

Commit

Permalink
Merge pull request #14 from trossr32/13_CorruptEver-property-too-larg…
Browse files Browse the repository at this point in the history
…e-for-int32

Fixes 13
  • Loading branch information
trossr32 authored Jan 14, 2022
2 parents 5040d5e + b3d86d2 commit 91ce465
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 84 deletions.
6 changes: 5 additions & 1 deletion src/PsTransmission.Core/PsTransmission.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DeviceId" Version="5.1.1" />
<PackageReference Include="DeviceId" Version="6.0.0" />
<PackageReference Include="DeviceId.Linux" Version="6.0.0" />
<PackageReference Include="DeviceId.Mac" Version="6.0.0" />
<PackageReference Include="DeviceId.Windows" Version="6.0.0" />
<PackageReference Include="DeviceId.Windows.Wmi" Version="6.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 3 additions & 5 deletions src/PsTransmission.Core/Services/EncryptionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ public static async Task<string> Decrypt(string cipherText)
/// Build an encryption key unique to the host machine
/// </summary>
/// <returns></returns>
private static string EncryptionKey()
{
return new DeviceIdBuilder()
.AddProcessorId()
private static string EncryptionKey() =>
new DeviceIdBuilder()
.OnWindows(windows => windows.AddProcessorId())
.AddMachineName()
.ToString();
}
}
}
20 changes: 4 additions & 16 deletions src/PsTransmission.Core/Services/Transmission/SessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,25 @@ public SessionService()
/// Get session information
/// </summary>
/// <returns></returns>
public async Task<SessionInformation> Get()
{
return await _client.SessionGetAsync();
}
public async Task<SessionInformation> Get() => await _client.SessionGetAsync();

/// <summary>
/// Get session statistics
/// </summary>
/// <returns></returns>
public async Task<Statistic> GetStats()
{
return await _client.SessionGetStatisticAsync();
}
public async Task<Statistic> GetStats() => await _client.SessionGetStatisticAsync();

/// <summary>
/// Set session settings
/// </summary>
/// <returns></returns>
public async Task<bool> Set(SessionSettings request)
{
return await _client.SessionSetAsync(request);
}
public async Task<bool> Set(SessionSettings request) => await _client.SessionSetAsync(request);

/// <summary>
/// Close session <br />
/// Careful with this one; it essentially shuts transmission down and will need to be restarted to bring it back.
/// </summary>
/// <returns></returns>
public async Task<bool> Close()
{
return await _client.SessionCloseAsync();
}
public async Task<bool> Close() => await _client.SessionCloseAsync();
}
}
10 changes: 2 additions & 8 deletions src/PsTransmission.Core/Services/Transmission/SystemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@ public SystemService()
/// Port test
/// </summary>
/// <returns></returns>
public async Task<bool> TestPort()
{
return await _client.PortTestAsync();
}
public async Task<bool> TestPort() => await _client.PortTestAsync();

/// <summary>
/// Update blocklists
/// </summary>
/// <returns>success flag and error message, if applicable</returns>
public async Task<(bool success, string error)> UpdateBlockList()
{
return await _client.UpdateBlockListAsync();
}
public async Task<(bool success, string error)> UpdateBlockList() => await _client.UpdateBlockListAsync();
}
}
62 changes: 20 additions & 42 deletions src/PsTransmission.Core/Services/Transmission/TorrentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,28 @@ public TorrentService()
/// Retrieve all torrents.
/// </summary>
/// <returns></returns>
public async Task<Torrent[]> GetTorrents(List<int> torrentIds = null)
{
string[] includeFields;

return torrentIds != null
public async Task<Torrent[]> GetTorrents(List<int> torrentIds = null) =>
torrentIds != null
? (await _client.TorrentGetAsync(TorrentFields.AllFields, torrentIds.ToArray()))?.TorrentList
: (await _client.TorrentGetAsync(TorrentFields.AllFields))?.TorrentList;
}

/// <summary>
/// Get completed torrents.
/// </summary>
/// <returns></returns>
public async Task<Torrent[]> GetCompletedTorrents()
{
return (await GetTorrents())
public async Task<Torrent[]> GetCompletedTorrents() =>
(await GetTorrents())
.Where(t => t.PercentDone == 1.0)
.ToArray();
}

/// <summary>
/// Get incomplete torrents.
/// </summary>
/// <returns></returns>
public async Task<Torrent[]> GetIncompleteTorrents()
{
return (await GetTorrents())
public async Task<Torrent[]> GetIncompleteTorrents() =>
(await GetTorrents())
.Where(t => t.PercentDone < 1.0)
.ToArray();
}

/// <summary>
/// Stop torrents. If the supplied list of ids is null, all torrents will be stopped.
Expand Down Expand Up @@ -244,78 +236,64 @@ public async Task<Torrent[]> GetIncompleteTorrents()
/// Move torrents in queue.
/// </summary>
/// <returns></returns>
public async Task<bool> MoveTorrents(MoveInQueue moveInQueue, List<int> torrentIds)
{
return moveInQueue switch
public async Task<bool> MoveTorrents(MoveInQueue moveInQueue, List<int> torrentIds) =>
moveInQueue switch
{
MoveInQueue.Up => await _client.TorrentQueueMoveUpAsync(torrentIds.ToArray()),
MoveInQueue.Down => await _client.TorrentQueueMoveDownAsync(torrentIds.ToArray()),
MoveInQueue.Top => await _client.TorrentQueueMoveTopAsync(torrentIds.ToArray()),
MoveInQueue.Bottom => await _client.TorrentQueueMoveBottomAsync(torrentIds.ToArray()),
_ => throw new ArgumentOutOfRangeException(nameof(moveInQueue), moveInQueue, null)
};
}

/// <summary>
/// Verify torrents.
/// </summary>
/// <returns></returns>
public async Task<bool> VerifyTorrents(List<int> torrentIds)
{
return await _client.TorrentVerifyAsync(torrentIds.ToArray());
}
public async Task<bool> VerifyTorrents(List<int> torrentIds) =>
await _client.TorrentVerifyAsync(torrentIds.ToArray());

/// <summary>
/// Re-announce torrents <br />
/// ("ask tracker for more peers")
/// </summary>
/// <param name="torrentIds"></param>
/// <returns></returns>
public async Task<bool> ReannounceTorrents(List<int> torrentIds)
{
return await _client.TorrentReannounceAsync(torrentIds.ToArray());
}
public async Task<bool> ReannounceTorrents(List<int> torrentIds) =>
await _client.TorrentReannounceAsync(torrentIds.ToArray());

/// <summary>
/// Rename a file or directory in a torrent
/// </summary>
/// <param name="torrentId">The torrent whose path will be renamed</param>
/// <param name="path">The path to the file or folder that will be renamed</param>
/// <param name="name">The file or folder's new name</param>
public async Task<RenamedTorrent> RenameTorrentPath(int torrentId, string path, string name)
{
return await _client.TorrentRenamePathAsync(torrentId, path, name);
}
public async Task<RenamedTorrent> RenameTorrentPath(int torrentId, string path, string name) =>
await _client.TorrentRenamePathAsync(torrentId, path, name);

/// <summary>
/// Set new location for torrents files (API: torrent-set-location)
/// </summary>
/// <param name="torrentIds">Torrent ids</param>
/// <param name="location">The new torrent location</param>
/// <param name="move">Move from previous location</param>
public async Task<bool> SetTorrentsLocation(List<int> torrentIds, string location, bool move)
{
return await _client.TorrentSetLocationAsync(torrentIds.ToArray(), location, move);
}
public async Task<bool> SetTorrentsLocation(List<int> torrentIds, string location, bool move) =>
await _client.TorrentSetLocationAsync(torrentIds.ToArray(), location, move);

/// <summary>
/// Set torrent params
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<bool> SetTorrents(TorrentSettings request)
{
return await _client.TorrentSetAsync(request);
}
public async Task<bool> SetTorrents(TorrentSettings request) =>
await _client.TorrentSetAsync(request);

/// <summary>
/// Add multiple torrents
/// </summary>
/// <param name="requests"></param>
/// <returns>A list of successful and failed results</returns>
public async Task<AddTorrentsResponse> AddTorrents(List<NewTorrent> requests)
{
return await _client.TorrentsAddAsync(requests);
}
public async Task<AddTorrentsResponse> AddTorrents(List<NewTorrent> requests) =>
await _client.TorrentsAddAsync(requests);
}
}
15 changes: 14 additions & 1 deletion src/PsTransmission/Base/BaseTransmissionCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ protected override void BeginProcessing()
if (TransmissionContext.HasCredentials)
return;

TransmissionContext.Credentials = Task.Run(async () => await AuthService.GetConfig()).Result;
try
{
TransmissionContext.Credentials = Task.Run(async () => await AuthService.GetConfig()).Result;
}
catch (Exception e)
{
var credsGetError = "Failed to retrieve credentials. If you have upgraded from v1.0.8 or lower then this is likely caused by the device id package dependency that is used to encrypt your credentials being upgraded. Please remove your existing credentials with Remove-TransmissionCredentials and then set them again with Set-TransmissionCredentials.";

ThrowTerminatingError(new ErrorRecord(new Exception(credsGetError, e), null, ErrorCategory.AuthenticationError, null)
{
CategoryInfo = { Reason = credsGetError },
ErrorDetails = new ErrorDetails(credsGetError)
});
}

if (TransmissionContext.HasCredentials)
return;
Expand Down
4 changes: 2 additions & 2 deletions src/PsTransmission/PsTransmission.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<AssemblyName>Transmission</AssemblyName>
<RootNamespace>Transmission</RootNamespace>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AssemblyVersion>1.0.8.0</AssemblyVersion>
<Version>1.0.8</Version>
<AssemblyVersion>1.0.9.0</AssemblyVersion>
<Version>1.0.9</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/PsTransmission/Transmission.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Transmission.dll'

# Version number of this module.
ModuleVersion = '1.0.8'
ModuleVersion = '1.0.9'

# Supported PSEditions
CompatiblePSEditions = 'Core'
Expand Down
8 changes: 2 additions & 6 deletions src/Transmission.NetCore.Client/Models/Torrent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ public class Torrent

[JsonProperty("uploadedEver")]
public long UploadedEver { get; set; }






[JsonProperty("activityDate")]
public int ActivityDate { get; set; }

Expand All @@ -78,7 +74,7 @@ public class Torrent
public string Comment { get; set; }

[JsonProperty("corruptEver")]
public int CorruptEver { get; set; }
public long CorruptEver { get; set; }

[JsonProperty("creator")]
public string Creator { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Flurl.Http" Version="3.0.0-pre4" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Flurl.Http" Version="3.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>

0 comments on commit 91ce465

Please sign in to comment.