Skip to content
This repository has been archived by the owner on Dec 4, 2021. It is now read-only.

Commit

Permalink
App ID Configuration in Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeclean committed Aug 4, 2021
1 parent a570aba commit 92a18c5
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 138 deletions.
76 changes: 0 additions & 76 deletions INIReader.cs

This file was deleted.

55 changes: 55 additions & 0 deletions IniParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace MusicBeePlugin
{
public class IniParser // revision 11
{
string Path;
string EXE = Assembly.GetExecutingAssembly().GetName().Name;

[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath);

[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);

public IniParser(string IniPath = null)
{
Path = new FileInfo(IniPath ?? EXE + ".ini").FullName;
}

public string Read(string Key, string Section = null)
{
var RetVal = new StringBuilder(255);
GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path);
return RetVal.ToString();
}

public void Write(string Key, string Value, string Section = null)
{
WritePrivateProfileString(Section ?? EXE, Key, Value, Path);
}

public void DeleteKey(string Key, string Section = null)
{
Write(Key, null, Section ?? EXE);
}

public void DeleteSection(string Section = null)
{
Write(null, null, Section ?? EXE);
}

public bool KeyExists(string Key, string Section = null)
{
return Read(Key, Section).Length > 0;
}
}
}
21 changes: 0 additions & 21 deletions Models.cs

This file was deleted.

33 changes: 18 additions & 15 deletions Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
using System.Net.Http;
using MusicBeePlugin;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using System.IO;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Utils
{
Expand All @@ -35,7 +35,6 @@ public static string Utf16ToUtf8(string utf16String)
}
}


public static string AssureByteSize(string input, int maxLength)
{
for (var i = input.Length - 1; i >= 0; i--)
Expand All @@ -49,15 +48,6 @@ public static string AssureByteSize(string input, int maxLength)
return string.Empty;
}

public static string HashAlbum(string text)
{
if (string.IsNullOrEmpty(text))
return text;

var hashed = BitConverter.ToString(new System.Security.Cryptography.SHA256Managed().ComputeHash(System.Text.Encoding.UTF8.GetBytes(text))).Replace("-", string.Empty);
return AssureByteSize(hashed, 10);
}

public static string SanitizeAlbumName(string albumName)
{
var albumArray = albumName.ToCharArray();
Expand All @@ -71,6 +61,19 @@ public static string SanitizeAlbumName(string albumName)

return newAlbum;
}

public static string DiscordAPPID()
{
string app_id = Plugin.iniParser.Read("AppID", "Discord");

if (string.IsNullOrEmpty(app_id))
{
MessageBox.Show("Add your Discord Application ID for the Plugin in [Preferences -> Plugins]", "Failed to read Application ID");
return string.Empty;
}

return app_id;
}
}

public static class Discord
Expand Down Expand Up @@ -100,9 +103,9 @@ public static async Task UploadAsset(string albumName, string imageData)
var responseContent = await response.Content.ReadAsStringAsync();

if (responseContent.Contains(albumName))
Plugin.MbApiInterface.MB_SetBackgroundTaskMessage("Successfully uploaded artwork.");
Plugin.MbApiInterface.MB_SetBackgroundTaskMessage($"Successfully Uploaded Artwork for {albumName}");
else
Plugin.MbApiInterface.MB_SetBackgroundTaskMessage("Artwork upload failed, check log.");
Plugin.MbApiInterface.MB_SetBackgroundTaskMessage($"Failed Artwork Upload for {albumName}");

Plugin.Logging.LogWrite(responseContent);
}
Expand Down Expand Up @@ -132,7 +135,7 @@ private static string grabToken(string file)
}
}

return authToken;
return authToken != "" ? authToken : "FAIL";
}
private static bool findLdb(ref string levelDB)
{
Expand Down Expand Up @@ -171,7 +174,7 @@ public static string GetAuthToken()
string pathStr = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\discord\\Local Storage\\leveldb\\";

if (!findLdb(ref pathStr))
return "";
return "FAIL";

string tokenStr = grabToken(pathStr);

Expand Down
2 changes: 1 addition & 1 deletion app.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>

0 comments on commit 92a18c5

Please sign in to comment.