Skip to content

Commit

Permalink
update to .net8
Browse files Browse the repository at this point in the history
  • Loading branch information
Dyvinia committed Sep 25, 2024
1 parent 0bea196 commit 44c8b29
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace PlexampRPC {
public class Config : SettingsManager<Config> {
public bool UpdateChecker { get; set; } = true;
public bool LocalAddress { get; set; } = false;
public List<String> Skipped { get; set; } = new();
public List<string> Skipped { get; set; } = [];
public bool OwnedOnly { get; set; } = true;

public int ArtResolution { get; set; } = 128;
Expand Down
4 changes: 2 additions & 2 deletions PlexResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public class PlexResource {

JsonDocument responseJson = JsonDocument.Parse(await sendResponse.Content.ReadAsStringAsync());
PlexResource[]? sourceResources = JsonSerializer.Deserialize<PlexResource[]>(responseJson.RootElement);
List<PlexResource>? filteredResources = new();
List<PlexResource>? filteredResources = [];
if (sourceResources is null || sourceResources.Length == 0) {
Console.WriteLine("WARN: No servers found");
return null;
Expand All @@ -132,7 +132,7 @@ public class PlexResource {
i++;
}

return filteredResources.ToArray();
return [.. filteredResources];
}
catch (Exception e) {
Console.WriteLine($"WARN: Unable to get resource: {e.Message} {e.InnerException}");
Expand Down
2 changes: 1 addition & 1 deletion PlexampRPC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>

Expand Down
4 changes: 2 additions & 2 deletions Utils/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public static async Task Download(string downloadUrl, string destinationFilePath
using HttpResponseMessage response = await httpClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead);

response.EnsureSuccessStatusCode();
long? totalBytes = response.Content.Headers.ContentLength;
long totalBytes = response.Content.Headers.ContentLength ?? 0L;

using Stream contentStream = await response.Content.ReadAsStreamAsync();
long? totalBytesRead = 0L;
long totalBytesRead = 0L;
long readCount = 0L;
byte[] buffer = new byte[4096];
bool isMoreToRead = true;
Expand Down
6 changes: 4 additions & 2 deletions Utils/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

namespace DyviniaUtils {
public abstract class SettingsManager<T> where T : SettingsManager<T>, new() {
public static T Settings { get; private set; }
public static T Settings { get; private set; } = new T();

private static readonly JsonSerializerOptions serializerOptions = new() { WriteIndented = true };

public static string FilePath {
get {
Expand Down Expand Up @@ -37,7 +39,7 @@ public static void Load() {
}

public static void Save() {
string json = JsonSerializer.Serialize(Settings, new JsonSerializerOptions { WriteIndented = true });
string json = JsonSerializer.Serialize(Settings, serializerOptions);
Directory.CreateDirectory(Path.GetDirectoryName(FilePath)!);
File.WriteAllText(FilePath, json);
}
Expand Down
16 changes: 8 additions & 8 deletions Windows/LogWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,27 @@ public override void WriteLine(string? value) {
}


private string line = String.Empty;
private string line = string.Empty;
public override void Write(char value) {
if (!value.Equals('\r') && !value.Equals('\n'))
line += value;
else {
if (String.IsNullOrWhiteSpace(line)) {
line = String.Empty;
if (string.IsNullOrWhiteSpace(line)) {
line = string.Empty;
return;
}
if (line.Contains("Plex.ServerApi.Api.ApiService")) {
line = String.Empty;
line = string.Empty;
return;
}
Application.Current.Dispatcher.Invoke(new Action(() => {
if (Log.Count > 200)
Log.RemoveAt(0);

if (!String.IsNullOrWhiteSpace(line))
if (!string.IsNullOrWhiteSpace(line))
Log.Add(new LogItem(line));
}));
line = String.Empty;
line = string.Empty;
}
}

Expand All @@ -119,12 +119,12 @@ private static string RemoveTags(string text) {
if (text.Trim().StartsWith('{')) {
List<string> splitText = text.Replace("{", "{,").Split(',').ToList();
splitText.RemoveAll(u => hiddenTags.Any(c => u.Contains(c, StringComparison.OrdinalIgnoreCase)));
text = String.Join(',', splitText).Replace("{,", "{");
text = string.Join(',', splitText).Replace("{,", "{");
}
else if (text.Trim().StartsWith('<')) {
List<string> splitText = text.Split().ToList();
splitText.RemoveAll(u => hiddenTags.Any(c => u.Contains(c, StringComparison.OrdinalIgnoreCase)));
text = String.Join(' ', splitText);
text = string.Join(' ', splitText);
}
}
return text;
Expand Down

0 comments on commit 44c8b29

Please sign in to comment.