Skip to content

Commit

Permalink
Fix #5 and bump dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
An0n-00 committed Jan 7, 2025
1 parent 46cbb61 commit 0269890
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 49 deletions.
86 changes: 39 additions & 47 deletions SpotifyABClient/Dashboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using SharpCompress.Readers;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Windows.UI.Notifications;

namespace SpotifyAB
{
Expand All @@ -13,7 +12,7 @@ public partial class Dashboard : Form
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool FlashWindow(IntPtr hwnd, bool bInvert);

private ToolTip toolTip1;
private ToolTip toolTip;

public Dashboard()
{
Expand Down Expand Up @@ -55,8 +54,8 @@ public void Startup(Dashboard dashboard)
{
Log("Starting SpotifyAB");

dashboard.toolTip1 = new ToolTip();
dashboard.toolTip1.SetToolTip(dashboard.linkLabel1, "Visit SpotifyAB's GitHub Repository");
dashboard.toolTip = new ToolTip();
dashboard.toolTip.SetToolTip(dashboard.linkLabel1, "Visit SpotifyAB's GitHub Repository");

if (IsSpotifyInstalled())
{
Expand All @@ -65,26 +64,28 @@ public void Startup(Dashboard dashboard)
var savedVersion = GetRegistryKey("SpotifyVersion");
if (string.IsNullOrEmpty(savedVersion))
{
CheckSpotifyABInstallation(dashboard);
CheckSpotifyAbInstallation(dashboard);
}
else if (currentVersion != savedVersion)
else if (currentVersion != savedVersion && IsSpotifyAbInstalled())
{
SetRegistryKey("Installed", "False");
//SetRegistryKey("Installed", "True");
Log("Spotify version has changed. Reinstalling SpotifyAB on in this new version.");
if (MessageBox.Show("Spotify version has changed. Reinstall SpotifyAB?", "Update SpotifyAB", MessageBoxButtons.YesNo) == DialogResult.Yes)
if (MessageBox.Show(@"Spotify version has changed. Reinstall SpotifyAB?", @"Update SpotifyAB", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
DownloadAndInstallSpotifyAB(dashboard).Wait();
DeleteSpotifyAbFiles();
SetRegistryKey("Installed", "False");
installBtn_Click(dashboard, null);
Log("SpotifyAB reinstalled.");
}
else
{
CheckSpotifyABInstallation(dashboard);
CheckSpotifyAbInstallation(dashboard);
Log("SpotifyAB not reinstalled.");
}
}
else
{
CheckSpotifyABInstallation(dashboard);
CheckSpotifyAbInstallation(dashboard);
}
}
else
Expand All @@ -102,24 +103,25 @@ private string GetRegistryKey(string keyName)
private bool IsSpotifyInstalled() =>
File.Exists($@"C:\Users\{Environment.UserName}\AppData\Roaming\Spotify\Spotify.exe");

private void CheckSpotifyABInstallation(Dashboard dashboard)
private void CheckSpotifyAbInstallation(Dashboard dashboard)
{
var installed = IsSpotifyABInstalled();
var installed = IsSpotifyAbInstalled();
if (installed) SetRegistryKey("SpotifyVersion", GetSpotifyVersion());
dashboard.installBtn.Enabled = !installed;
dashboard.uninstallBtn.Enabled = installed;
Log(installed ? "SpotifyAB is installed." : "SpotifyAB is not installed.");
}

private bool IsSpotifyABInstalled() =>
private bool IsSpotifyAbInstalled() =>
Registry.CurrentUser.OpenSubKey("Software\\SpotifyAB")?.GetValue("Installed")?.ToString() == "True";

private void HandleSpotifyNotInstalled(Dashboard dashboard)
{
Log("Spotify is not installed.");
Log("Spotify is not installed (or broken).");
ShowError(dashboard, "Please install Spotify first. SpotifyAB only works with the desktop version.");
if (MessageBox.Show("Open Spotify download page?", "Download Spotify", MessageBoxButtons.YesNo) == DialogResult.Yes)
OpenUrl("https://www.spotify.com/download/windows/#download-cdn");
Log("Direct Installer link: https://download.scdn.co/SpotifySetup.exe");

SetRegistryKey("Installed", "False");
DisableButtons(dashboard);
Expand Down Expand Up @@ -152,11 +154,18 @@ public void Log(string message)
logBox.AppendText($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] - {message}\r\n");
}

private void ShowError(Dashboard dashboard, string message)
private void ShowError(Dashboard dashboard, string message)
{
if (dashboard != null)
{
dashboard.Invoke((MethodInvoker)delegate { MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); });
if (dashboard.IsHandleCreated)
{
dashboard.Invoke((MethodInvoker)delegate { MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); });
}
else
{
MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
Expand All @@ -183,37 +192,21 @@ private async void installBtn_Click(object sender, EventArgs e)
{
if (!IsSpotifyInstalledProperly())
{
ShowError(this, "Spotify is installed strangely. I cannot find the XPUI file.");
ShowError(this, "Spotify is installed strangely. I cannot find the XPUI file. Please reinstall Spotify.");
HandleSpotifyNotInstalled(this);
Log("Error: Cannot find the XPUI file");
return;
}

await DownloadAndInstallSpotifyAB(this);
await DownloadAndInstallSpotifyAb(this);
installBtn.Enabled = false;
uninstallBtn.Enabled = true;
}

private bool IsSpotifyInstalledProperly()
{
if (File.Exists($@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\Spotify\Apps\xpui.spa"))
{
return true;
}
else
{
if (File.Exists($@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\Spotify\Apps\xpui-original.spa"))
{
File.Move($@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\Spotify\Apps\xpui-original.spa", $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\Spotify\Apps\xpui.spa");
return true;
}
else
{
return false;
}
}
}
private bool IsSpotifyInstalledProperly() =>
File.Exists($@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\Spotify\Apps\xpui.spa");

private async Task DownloadAndInstallSpotifyAB(Dashboard dashboard)
private async Task DownloadAndInstallSpotifyAb(Dashboard dashboard)
{
var fileUrl = "https://github.com/An0n-00/SpotifyAB/releases/latest/download/xpui.spa";
var downloadPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "xpui.spa");
Expand Down Expand Up @@ -278,9 +271,9 @@ private async Task DownloadAndInstallSpotifyAB(Dashboard dashboard)
{
ShowError(dashboard, $"An error occurred: {d.Message}");
Log("An error occurred while downloading the file.");

Log(d.InnerException.ToString());
success = 1;
return;
throw new Exception("An error occurred while downloading the file.");
}

// Move the downloaded file to the Spotify directory
Expand Down Expand Up @@ -327,7 +320,6 @@ private async Task DownloadAndInstallSpotifyAB(Dashboard dashboard)

SetRegistryKey("Installed", "True");

Log("SpotifyAB installed successfully.");
ShowSuccess("SpotifyAB installed successfully.");
}
catch (Exception f)
Expand All @@ -348,7 +340,7 @@ private string GetSpotifyVersion()

private void BackupOriginalFile(string destinationPath)
{
if (File.Exists(destinationPath) && !IsSpotifyABInstalled())
if (File.Exists(destinationPath) && !IsSpotifyAbInstalled())
{
File.Move(destinationPath, destinationPath.Replace(".spa", "-original.spa"));
}
Expand Down Expand Up @@ -419,20 +411,19 @@ private int RunPowerShellScript(string scriptPath)

private void uninstallABbtn_Click(object sender, EventArgs e)
{
if (!IsSpotifyABInstalled())
if (!IsSpotifyAbInstalled())
{
ShowError(this, "SpotifyAB is not installed.");
return;
}

DeleteSpotifyABFiles();
DeleteSpotifyAbFiles();
ShowSuccess("SpotifyAB uninstalled successfully.");
installBtn.Enabled = true;
uninstallBtn.Enabled = false;
SetRegistryKey("Installed", "False");
}

private void DeleteSpotifyABFiles()
private void DeleteSpotifyAbFiles()
{
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var xpuiPath = Path.Combine(appDataPath, "Spotify\\Apps\\xpui.spa");
Expand All @@ -441,6 +432,7 @@ private void DeleteSpotifyABFiles()
if (File.Exists(xpuiPath)) File.Delete(xpuiPath);
if (Directory.Exists(Path.Combine(appDataPath, "Spotify\\Apps\\xpui"))) Directory.Delete(Path.Combine(appDataPath, "Spotify\\Apps\\xpui"), true);
if (File.Exists(xpuiOriginalPath)) File.Move(xpuiOriginalPath, xpuiPath);
SetRegistryKey("Installed", "False");
}
}
}
2 changes: 1 addition & 1 deletion SpotifyABClient/SpotifyAB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SharpCompress" Version="0.37.2" />
<PackageReference Include="SharpCompress" Version="0.38.0" />
<PackageReference Include="System.Management.Automation" Version="7.4.5" />
</ItemGroup>

Expand Down
5 changes: 4 additions & 1 deletion SpotifyABClient/SpotifyAB.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AApplication_002Ecs_002Fl_003AC_0021_003FUsers_003FSatap_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F039307c2fa2545cd802cb86d49b3afc7cef930_003Fdf_003Fdb8ea5e6_003FApplication_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=2bca8134_002D1280_002D4af2_002Da4d3_002Dfb77a63731fd/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="All tests from Form1.cs" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;ProjectFile&gt;3F0546CF-A066-4711-A649-7E06010845D2/f:Form1.cs&lt;/ProjectFile&gt;&#xD;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
&lt;/SessionState&gt;</s:String>
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=SpotifyAB_002FDashboard/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>

0 comments on commit 0269890

Please sign in to comment.