Skip to content

Commit

Permalink
Spotify patch better on updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeroday committed Jul 27, 2018
1 parent 1d5cbfd commit 3c3a8ab
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
34 changes: 17 additions & 17 deletions EZBlocker/EZBlocker/EZBlockerMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,23 @@ private void Main_Load(object sender, EventArgs e)
return;
}

// Patch Spotify
patcher = new SpotifyPatcher();
string currentVersion = FileVersionInfo.GetVersionInfo(spotifyPath).FileVersion;
if (!Properties.Settings.Default.LastPatched.Equals(currentVersion) || true) // Always attempt to patch
{
// MessageBox.Show("EZBlocker needs to modify Spotify.\r\n\r\nTo return to the original, right click the EZBlocker icon in your task tray and choose 'Remove Patch'.", "EZBlocker");
if (!patcher.Patch())
{
MessageBox.Show(Properties.strings.PatchErrorMessageBox, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
Properties.Settings.Default.LastPatched = currentVersion;
Properties.Settings.Default.Save();
}
}

// Start Spotify and give EZBlocker higher priority
try
{
Expand Down Expand Up @@ -255,23 +272,6 @@ private void Main_Load(object sender, EventArgs e)
}
a = new Analytics(Properties.Settings.Default.CID, Assembly.GetExecutingAssembly().GetName().Version.ToString());

// Patch Spotify
patcher = new SpotifyPatcher();
string currentVersion = FileVersionInfo.GetVersionInfo(spotifyPath).FileVersion;
if (!Properties.Settings.Default.LastPatched.Equals(currentVersion))
{
// MessageBox.Show("EZBlocker needs to modify Spotify.\r\n\r\nTo return to the original, right click the EZBlocker icon in your task tray and choose 'Remove Patch'.", "EZBlocker");
if (!patcher.Patch())
{
MessageBox.Show(Properties.strings.PatchErrorMessageBox, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
Properties.Settings.Default.LastPatched = currentVersion;
Properties.Settings.Default.Save();
}
}

// Start Spotify hook
hook = new SpotifyHook();

Expand Down
3 changes: 0 additions & 3 deletions EZBlocker/EZBlocker/Listener.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Net;

namespace EZBlocker
Expand Down Expand Up @@ -47,8 +46,6 @@ private void Handle(HttpListenerRequest request, HttpListenerResponse response)
Message = path;
}

Debug.WriteLine(Message);

byte[] buffer = System.Text.Encoding.UTF8.GetBytes("1");
response.ContentLength64 = buffer.Length;
System.IO.Stream output = response.OutputStream;
Expand Down
4 changes: 2 additions & 2 deletions EZBlocker/EZBlocker/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.2.4")]
[assembly: AssemblyFileVersion("1.7.2.4")]
[assembly: AssemblyVersion("1.7.2.5")]
[assembly: AssemblyFileVersion("1.7.2.5")]
16 changes: 8 additions & 8 deletions EZBlocker/EZBlocker/SpotifyPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public bool Patch()
}
catch (Exception e)
{
Debug.WriteLine(e);
Directory.Delete(workingDir, true);
Restore();
return false;
Expand All @@ -74,15 +75,14 @@ public bool Patch()
{
foreach (Process p in Process.GetProcessesByName("spotify"))
{
if (p.MainWindowTitle.Length > 1)
{
p.Kill();
Thread.Sleep(3000);
Process.Start(spotifyPath);
break;
}
p.Kill();
}
} catch { };
} catch (Exception e) {
Debug.WriteLine(e);
}

Thread.Sleep(3000);
Process.Start(spotifyPath);

return true;
}
Expand Down

0 comments on commit 3c3a8ab

Please sign in to comment.