Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
add missing dlls to project src
Browse files Browse the repository at this point in the history
  • Loading branch information
Tustin committed Nov 21, 2018
1 parent 6b48ab5 commit 1fb8d52
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 28 deletions.
58 changes: 36 additions & 22 deletions PlayStationDiscord/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
Expand All @@ -14,9 +12,6 @@
using PlayStationSharp.API;
using PlayStationSharp.Model.ProfileJsonTypes;
using PlayStationDiscord.Exceptions;
using Newtonsoft.Json;
using System.Windows.Media;
using Flurl.Http;
using System.IO;

namespace PlayStationDiscord
Expand Down Expand Up @@ -87,7 +82,11 @@ public void RestartDiscordControllers()
StartDiscordControllers();
}

private async Task TokenRefreshTask(CancellationToken cts)
/// <summary>
/// Task that only runs when the access token is about to expire.
/// </summary>
/// <param name="cts">CancellationToken</param>
private async void TokenRefreshTask(CancellationToken cts)
{
while (!cts.IsCancellationRequested)
{
Expand Down Expand Up @@ -116,7 +115,11 @@ private async Task TokenRefreshTask(CancellationToken cts)
}
}

private async Task UpdateTask(CancellationToken cts)
/// <summary>
/// Task which updates Discord Rich Presence every 30 seconds.
/// </summary>
/// <param name="cts">CancellationToken</param>
private async void UpdateTask(CancellationToken cts)
{
while (!cts.IsCancellationRequested)
{
Expand Down Expand Up @@ -149,24 +152,23 @@ private async Task UpdateTask(CancellationToken cts)
}
}

/// <summary>
/// Updates Discord rich presence.
/// </summary>
/// <param name="game">Game information.</param>
private void UpdateDiscordPresence(PresenceModel game)
{
var console = GetConsoleFromApplicationId(game);

// If the current console doesn't equal the latest game's console, update it and restart.
if (CurrentConsole.Key != console.Key)
{
//Logger.Write($"Detected console switch: old = {CurrentConsole.Value.Name}, new = {console.Value.Name}");
CurrentConsole = SupportedConsoles.FirstOrDefault(a => a.Key == console.Key);
RestartDiscordControllers();
return;
}

var currentStatus = game.TitleName ?? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(game.OnlineStatus);
//var encoded = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(currentStatus));

// Put any future pointers here for consistency.
//var detailsPointer = StringToPointer(encoded);

DiscordController.presence = new DiscordRpc.RichPresence
{
Expand All @@ -180,6 +182,7 @@ private void UpdateDiscordPresence(PresenceModel game)
}

string largeImageKey = CurrentConsole.Value.ImageKeyName;

// These will only be used if the user is playing a supported game.
string smallImageKey = default(string);
string smallImageText = default(string);
Expand Down Expand Up @@ -286,7 +289,7 @@ private void Button_Click(object sender, RoutedEventArgs e)
// Login form was closed by the user.
if (account == null) return;

Instantiate(account);
FinalizeLoginFlow(account);
}
catch (FileNotFoundException ex)
{
Expand All @@ -296,14 +299,16 @@ private void Button_Click(object sender, RoutedEventArgs e)

}

private void Instantiate(Account account)
/// <summary>
/// Sets up form properties, grabs information and starts up tasks.
/// </summary>
/// <param name="account">PlayStation account.</param>
private void FinalizeLoginFlow(Account account)
{
this.PlayStationAccount = account;

var game = FetchCurrentGame();

//Logger.Write($"Game = {JsonConvert.SerializeObject(game)}");

this.CurrentConsole = GetConsoleFromApplicationId(game);

lblWelcome.Content = this.PlayStationAccount.Profile.OnlineId;
Expand Down Expand Up @@ -332,7 +337,7 @@ private void SignIn_Closed(object sender, EventArgs e)
{
if (PlayStationAccount == null) return;

LoadComponents();
TryAutomaticLogin();
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
Expand All @@ -351,17 +356,25 @@ private void Window_StateChanged(object sender, EventArgs e)
if (WindowState == WindowState.Minimized) this.Hide();
}

private void LoadComponents()
/// <summary>
/// Tries to login with tokens from <see cref="TokenHandler.TokensFile"/>.
/// </summary>
private void TryAutomaticLogin()
{
try
{
var account = TokenHandler.Check();

Instantiate(account);
FinalizeLoginFlow(account);
}
catch (Exception ex)
{
Logger.Write(ex.ToString());
// Log exception only if the file was found.
if (!(ex is FileNotFoundException))
{
Logger.Write($"Error when logging in with tokens: {ex.ToString()}");
}

SetControlState(false);
}
}
Expand Down Expand Up @@ -390,6 +403,7 @@ public MainWindow()
}
}

// Create form.
InitializeComponent();

// Instantiate the config file.
Expand All @@ -412,17 +426,17 @@ public MainWindow()

this.NotifyIcon.DoubleClick += Icon_DoubleClick;

// Run our task to grab the supported game SKUs from the repo.
var games = Task.Run(SupportedGames.FetchGames).Result;

// Put this here so we can give it the list of all the games.
this.SupportedConsoles = new Dictionary<DiscordApplicationId, ConsoleInformation>()
{
{ DiscordApplicationId.PS4, new ConsoleInformation("PlayStation 4", "ps4_main", DiscordController.PS4ApplicationId, games.FirstOrDefault(a => a.Key == "ps4").Value) },
{ DiscordApplicationId.PS3, new ConsoleInformation("PlayStation 3", "ps3_main", DiscordController.PS3ApplicationId, games.FirstOrDefault(a => a.Key == "ps3").Value) },
{ DiscordApplicationId.Vita, new ConsoleInformation("PlayStation Vita", "vita_main", DiscordController.VitaApplicationId, games.FirstOrDefault(a => a.Key == "vita").Value) }
};

LoadComponents();
TryAutomaticLogin();
}

private void btnSignOut_Click(object sender, RoutedEventArgs e)
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion PlayStationDiscord/PlayStationDiscord.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y "$(ProjectDir)discord-rpc.dll" "$(TargetDir)discord-rpc.dll"
copy /Y "$(ProjectDir)PlayStationSharp.dll" "$(TargetDir)PlayStationSharp.dll"</PostBuildEvent>
copy /Y "$(ProjectDir)PlayStationSharp.dll" "$(TargetDir)PlayStationSharp.dll"
copy /Y "$(ProjectDir)Microsoft.Toolkit.Win32.UI.Controls.dll" "$(TargetDir)Microsoft.Toolkit.Win32.UI.Controls.dll"</PostBuildEvent>
</PropertyGroup>
</Project>
Binary file modified PlayStationDiscord/PlayStationSharp.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions PlayStationDiscord/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,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("2.0.0.1")]
[assembly: AssemblyFileVersion("2.0.0.1")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
2 changes: 1 addition & 1 deletion PlayStationDiscord/SupportedGames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static class SupportedGames
/// <summary>
/// Fetches the list of supported games from the repo.
///
/// Will fallback to %appdata%\PlayStationDiscord\games.cached.json if the file on GitHub hasn't changed.
/// Will fallback to <see cref="CachedGamesFile"/> if the file on GitHub hasn't changed.
///
/// This is used to get all the games which have a custom icon asset saved in the Discord application.
///
Expand Down
11 changes: 9 additions & 2 deletions PlayStationDiscord/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ public static bool Latest
try
{
var currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

_model = "https://api.github.com/repos/Tustin/PlayStationDiscord/releases/latest"
.WithHeader("User-Agent", "PlayStationDiscord")
.GetJsonAsync<GitHubReleaseModel>().Result;

#if !DEBUG
return currentVersion.Equals(_model.TagName, StringComparison.CurrentCultureIgnoreCase) && !_model.Prerelease;
#else
return currentVersion.Equals(_model.TagName, StringComparison.CurrentCultureIgnoreCase);
#endif
}
catch (Exception ex)
catch (Exception ex)
{
Logger.Write($"Failed to download update: {ex.ToString()}");
// If we can't get the latest version for some reason, just ignore.
Expand All @@ -38,6 +42,9 @@ public static bool Latest
}
}

/// <summary>
/// Tries to download and execute the latest installer from GitHub.
/// </summary>
public static void TryToInstall()
{
var newFile = Path.GetTempPath() + FileName;
Expand Down

0 comments on commit 1fb8d52

Please sign in to comment.