diff --git a/.editorconfig b/.editorconfig index e03d14c..92e783f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,7 +1,7 @@ [*.cs] # CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. -dotnet_diagnostic.CS8632.severity = silent +dotnet_diagnostic.CS8632.severity = suggestion # CS4014: Because this call is not awaited, execution of the current method continues before the call is completed dotnet_diagnostic.CS4014.severity = suggestion diff --git a/.vs/WindowsFormsApplication2/v16/.suo b/.vs/WindowsFormsApplication2/v16/.suo index 076db4d..52164df 100644 Binary files a/.vs/WindowsFormsApplication2/v16/.suo and b/.vs/WindowsFormsApplication2/v16/.suo differ diff --git a/WindowsFormsApplication2/ConfigManager.cs b/WindowsFormsApplication2/ConfigManager.cs index 450a367..b70e52f 100644 --- a/WindowsFormsApplication2/ConfigManager.cs +++ b/WindowsFormsApplication2/ConfigManager.cs @@ -25,21 +25,25 @@ namespace JellyfinRPC if (!File.Exists(ConfigFile)) saveCfg(); - using StreamReader cfgReader = File.OpenText(ConfigFile); - for (string line = cfgReader.ReadLine(); line != null; line = cfgReader.ReadLine()) + using (StreamReader cfgReader = File.OpenText(ConfigFile)) { - if (line.StartsWith("*")) continue; - string[] values = line.Split(SEPERATOR.First()); - cfgEntries.Add(values.First().Trim(), String.Join(SEPERATOR, values.Skip(1)).Trim()); + for (string line = cfgReader.ReadLine(); line != null; line = cfgReader.ReadLine()) + { + if (line.StartsWith("*")) continue; + string[] values = line.Split(SEPERATOR.First()); + cfgEntries.Add(values.First().Trim(), String.Join(SEPERATOR, values.Skip(1)).Trim()); + } } } private static void saveCfg() { - using StreamWriter cfgWriter = File.CreateText(ConfigFile); - cfgWriter.WriteLine("**JellyfinDiscordRPC Config**"); - foreach (KeyValuePair values in cfgEntries) + using (StreamWriter cfgWriter = File.CreateText(ConfigFile)) { - cfgWriter.WriteLine(String.Join(SEPERATOR, new String[] { values.Key.Trim(), values.Value.Trim() })); + cfgWriter.WriteLine("**JellyfinDiscordRPC Config**"); + foreach (KeyValuePair values in cfgEntries) + { + cfgWriter.WriteLine(String.Join(SEPERATOR, new String[] { values.Key.Trim(), values.Value.Trim() } )); + } } } public static void SetEntry(string key, string value) diff --git a/WindowsFormsApplication2/DiscordRPC.cs b/WindowsFormsApplication2/DiscordRPC.cs index a84fa1d..5b04eaa 100644 --- a/WindowsFormsApplication2/DiscordRPC.cs +++ b/WindowsFormsApplication2/DiscordRPC.cs @@ -11,13 +11,13 @@ namespace JellyfinRPC public static Int64 discordAppID = Int64.Parse(ConfigManager.GetEntry("DiscordClientID")); - public static void UpdateActivity(Discord.Discord discord) + static void UpdateActivity(Discord.Discord discord) { var activityManager = discord.GetActivityManager(); string[] RPCVari = JellyfinAPI.Jellyfin().Result.Split('|'); if (JellyfinAPI.Jellyfin().Result != null) { - Activity activity = new Activity + var activity = new Discord.Activity { Details = RPCVari.GetValue(int.Parse("2")).ToString(), State = RPCVari.GetValue(int.Parse("3")).ToString(), diff --git a/WindowsFormsApplication2/JellyfinAPI.cs b/WindowsFormsApplication2/JellyfinAPI.cs index 3b46799..6688e1b 100644 --- a/WindowsFormsApplication2/JellyfinAPI.cs +++ b/WindowsFormsApplication2/JellyfinAPI.cs @@ -179,6 +179,7 @@ namespace JellyfinRPC } return "album_cover"; } + private static Dictionary jsonEntries = new Dictionary(); public static async Task SendQuickConnectRequest() { using var httpClient = new HttpClient(); @@ -197,18 +198,36 @@ namespace JellyfinRPC { response.EnsureSuccessStatusCode(); var jsonResponse = await response.Content.ReadAsStringAsync(); - var jsonObject = JObject.Parse(jsonResponse); + string[] splitEmUp = jsonResponse.Split(','); - if (!jsonObject.HasValues) + if (!splitEmUp.Any()) { return "Error: Server did not respond."; } else { - string quickConnectCode = jsonObject.Value("Code"); - string quickConnectToken = jsonObject.Value("Secret"); - return quickConnectCode; + foreach (var splitstring in splitEmUp) + { + string[] values = splitstring.Split(':'); + jsonEntries.Add(values.First().Trim(), String.Join(":", values.Skip(1)).Trim()); + + } } + + + if (jsonEntries.ContainsKey("\"Code\"")) + { + return jsonEntries["\"Code\""].Replace('"', ' ').Trim(); + + } + else + { + return "Error: Server did not return code."; + } + + + + } catch (Exception ex) { @@ -225,12 +244,14 @@ namespace JellyfinRPC public static string DeviceID() { - using RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); - byte[] randomNumber = new byte[4]; - rng.GetBytes(randomNumber); - int value = BitConverter.ToInt32(randomNumber, 0); - byte[] valueBytes = System.Text.Encoding.UTF8.GetBytes(value.ToString()); - return System.Convert.ToBase64String(valueBytes); + using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) + { + byte[] randomNumber = new byte[4]; + rng.GetBytes(randomNumber); + int value = BitConverter.ToInt32(randomNumber, 0); + byte[] valueBytes = System.Text.Encoding.UTF8.GetBytes(value.ToString()); + return System.Convert.ToBase64String(valueBytes); + } } public static async Task GetTokenFromUsernameAndPassword(string Username, string Password) @@ -273,10 +294,8 @@ namespace JellyfinRPC public class Login { -#pragma warning disable IDE1006 // Naming Styles public string username { get; set; } public string pw { get; set; } -#pragma warning restore IDE1006 // Naming Styles } public class QuickConnect { diff --git a/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.exe b/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.exe index 3e12006..f5a6372 100644 Binary files a/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.exe and b/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.exe differ diff --git a/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.pdb b/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.pdb index f50af8e..6a5c5fb 100644 Binary files a/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.pdb and b/WindowsFormsApplication2/bin/Debug/Jellyfin Rich Presence.pdb differ diff --git a/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.exe b/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.exe index 3e12006..f5a6372 100644 Binary files a/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.exe and b/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.exe differ diff --git a/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.pdb b/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.pdb index f50af8e..6a5c5fb 100644 Binary files a/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.pdb and b/WindowsFormsApplication2/obj/x86/Debug/Jellyfin Rich Presence.pdb differ diff --git a/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.AssemblyReference.cache b/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.AssemblyReference.cache deleted file mode 100644 index 244d765..0000000 Binary files a/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.AssemblyReference.cache and /dev/null differ diff --git a/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.FileListAbsolute.txt b/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.FileListAbsolute.txt index 193c0b9..ad66299 100644 --- a/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.FileListAbsolute.txt +++ b/WindowsFormsApplication2/obj/x86/Debug/JellyfinRPCGUI.csproj.FileListAbsolute.txt @@ -39,4 +39,3 @@ C:\Users\random()\Documents\Visual Studio 2010\Projects\WindowsFormsApplication2 C:\Users\random()\Documents\Visual Studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\x86\Debug\JellyfinRPCGUI.csproj.CopyComplete C:\Users\random()\Documents\Visual Studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\x86\Debug\Jellyfin Rich Presence.exe C:\Users\random()\Documents\Visual Studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\x86\Debug\Jellyfin Rich Presence.pdb -C:\Users\random()\Documents\Visual Studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\obj\x86\Debug\JellyfinRPCGUI.csproj.AssemblyReference.cache