From 0304be32258e3fc47797efbe3a15899ab911099b Mon Sep 17 00:00:00 2001
From: TheBoxyBear <15822255+TheBoxyBear@users.noreply.github.com>
Date: Thu, 4 Mar 2021 16:10:12 -0500
Subject: [PATCH 1/3] Fix crash when selecting a background image before login
---
.../PlayStationSharp.TestApp.csproj | 3 +
PlayStationSharp.TestApp/TestForm.Designer.cs | 171 +++++++++---------
PlayStationSharp.TestApp/TestForm.cs | 20 +-
3 files changed, 103 insertions(+), 91 deletions(-)
diff --git a/PlayStationSharp.TestApp/PlayStationSharp.TestApp.csproj b/PlayStationSharp.TestApp/PlayStationSharp.TestApp.csproj
index 42019dc..ecc151b 100644
--- a/PlayStationSharp.TestApp/PlayStationSharp.TestApp.csproj
+++ b/PlayStationSharp.TestApp/PlayStationSharp.TestApp.csproj
@@ -32,6 +32,9 @@
prompt
4
+
+ PlayStationSharp.TestApp.Program
+
..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
diff --git a/PlayStationSharp.TestApp/TestForm.Designer.cs b/PlayStationSharp.TestApp/TestForm.Designer.cs
index bfb5c9b..166fda1 100644
--- a/PlayStationSharp.TestApp/TestForm.Designer.cs
+++ b/PlayStationSharp.TestApp/TestForm.Designer.cs
@@ -28,91 +28,92 @@ protected override void Dispose(bool disposing)
///
private void InitializeComponent()
{
- this.btnLogin = new System.Windows.Forms.Button();
- this.lblOnlineId = new System.Windows.Forms.Label();
- this.lstFriends = new System.Windows.Forms.ListBox();
- this.lblFriends = new System.Windows.Forms.Label();
- this.btnBackgroundColor = new System.Windows.Forms.Button();
- this.colorBackgroundColor = new System.Windows.Forms.ColorDialog();
- this.btnBackgroundImage = new System.Windows.Forms.Button();
- this.SuspendLayout();
- //
- // btnLogin
- //
- this.btnLogin.Location = new System.Drawing.Point(165, 106);
- this.btnLogin.Name = "btnLogin";
- this.btnLogin.Size = new System.Drawing.Size(130, 37);
- this.btnLogin.TabIndex = 0;
- this.btnLogin.Text = "Login with PlayStation";
- this.btnLogin.UseVisualStyleBackColor = true;
- this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
- //
- // lblOnlineId
- //
- this.lblOnlineId.AutoSize = true;
- this.lblOnlineId.Location = new System.Drawing.Point(12, 9);
- this.lblOnlineId.Name = "lblOnlineId";
- this.lblOnlineId.Size = new System.Drawing.Size(35, 13);
- this.lblOnlineId.TabIndex = 1;
- this.lblOnlineId.Text = "label1";
- this.lblOnlineId.Visible = false;
- //
- // lstFriends
- //
- this.lstFriends.FormattingEnabled = true;
- this.lstFriends.Location = new System.Drawing.Point(361, 28);
- this.lstFriends.Name = "lstFriends";
- this.lstFriends.Size = new System.Drawing.Size(138, 238);
- this.lstFriends.TabIndex = 2;
- this.lstFriends.Visible = false;
- this.lstFriends.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lstFriends_MouseDoubleClick);
- //
- // lblFriends
- //
- this.lblFriends.AutoSize = true;
- this.lblFriends.Location = new System.Drawing.Point(358, 12);
- this.lblFriends.Name = "lblFriends";
- this.lblFriends.Size = new System.Drawing.Size(41, 13);
- this.lblFriends.TabIndex = 3;
- this.lblFriends.Text = "Friends";
- //
- // btnBackgroundColor
- //
- this.btnBackgroundColor.Location = new System.Drawing.Point(12, 243);
- this.btnBackgroundColor.Name = "btnBackgroundColor";
- this.btnBackgroundColor.Size = new System.Drawing.Size(151, 23);
- this.btnBackgroundColor.TabIndex = 4;
- this.btnBackgroundColor.Text = "Background Color";
- this.btnBackgroundColor.UseVisualStyleBackColor = true;
- this.btnBackgroundColor.Visible = false;
- this.btnBackgroundColor.Click += new System.EventHandler(this.btnBackgroundColor_Click);
- //
- // btnBackgroundImage
- //
- this.btnBackgroundImage.Location = new System.Drawing.Point(204, 243);
- this.btnBackgroundImage.Name = "btnBackgroundImage";
- this.btnBackgroundImage.Size = new System.Drawing.Size(151, 23);
- this.btnBackgroundImage.TabIndex = 5;
- this.btnBackgroundImage.Text = "Background Image";
- this.btnBackgroundImage.UseVisualStyleBackColor = true;
- this.btnBackgroundImage.Click += new System.EventHandler(this.btnBackgroundImage_Click);
- //
- // TestForm
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(511, 278);
- this.Controls.Add(this.btnBackgroundImage);
- this.Controls.Add(this.btnBackgroundColor);
- this.Controls.Add(this.lblFriends);
- this.Controls.Add(this.lstFriends);
- this.Controls.Add(this.lblOnlineId);
- this.Controls.Add(this.btnLogin);
- this.Name = "TestForm";
- this.Text = "Form1";
- this.Load += new System.EventHandler(this.TestForm_Load);
- this.ResumeLayout(false);
- this.PerformLayout();
+ this.btnLogin = new System.Windows.Forms.Button();
+ this.lblOnlineId = new System.Windows.Forms.Label();
+ this.lstFriends = new System.Windows.Forms.ListBox();
+ this.lblFriends = new System.Windows.Forms.Label();
+ this.btnBackgroundColor = new System.Windows.Forms.Button();
+ this.colorBackgroundColor = new System.Windows.Forms.ColorDialog();
+ this.btnBackgroundImage = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // btnLogin
+ //
+ this.btnLogin.Location = new System.Drawing.Point(165, 106);
+ this.btnLogin.Name = "btnLogin";
+ this.btnLogin.Size = new System.Drawing.Size(130, 37);
+ this.btnLogin.TabIndex = 0;
+ this.btnLogin.Text = "Login with PlayStation";
+ this.btnLogin.UseVisualStyleBackColor = true;
+ this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
+ //
+ // lblOnlineId
+ //
+ this.lblOnlineId.AutoSize = true;
+ this.lblOnlineId.Location = new System.Drawing.Point(12, 9);
+ this.lblOnlineId.Name = "lblOnlineId";
+ this.lblOnlineId.Size = new System.Drawing.Size(35, 13);
+ this.lblOnlineId.TabIndex = 1;
+ this.lblOnlineId.Text = "label1";
+ this.lblOnlineId.Visible = false;
+ //
+ // lstFriends
+ //
+ this.lstFriends.FormattingEnabled = true;
+ this.lstFriends.Location = new System.Drawing.Point(361, 28);
+ this.lstFriends.Name = "lstFriends";
+ this.lstFriends.Size = new System.Drawing.Size(138, 238);
+ this.lstFriends.TabIndex = 2;
+ this.lstFriends.Visible = false;
+ this.lstFriends.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lstFriends_MouseDoubleClick);
+ //
+ // lblFriends
+ //
+ this.lblFriends.AutoSize = true;
+ this.lblFriends.Location = new System.Drawing.Point(358, 12);
+ this.lblFriends.Name = "lblFriends";
+ this.lblFriends.Size = new System.Drawing.Size(41, 13);
+ this.lblFriends.TabIndex = 3;
+ this.lblFriends.Text = "Friends";
+ //
+ // btnBackgroundColor
+ //
+ this.btnBackgroundColor.Location = new System.Drawing.Point(12, 243);
+ this.btnBackgroundColor.Name = "btnBackgroundColor";
+ this.btnBackgroundColor.Size = new System.Drawing.Size(151, 23);
+ this.btnBackgroundColor.TabIndex = 4;
+ this.btnBackgroundColor.Text = "Background Color";
+ this.btnBackgroundColor.UseVisualStyleBackColor = true;
+ this.btnBackgroundColor.Visible = false;
+ this.btnBackgroundColor.Click += new System.EventHandler(this.btnBackgroundColor_Click);
+ //
+ // btnBackgroundImage
+ //
+ this.btnBackgroundImage.Location = new System.Drawing.Point(204, 243);
+ this.btnBackgroundImage.Name = "btnBackgroundImage";
+ this.btnBackgroundImage.Size = new System.Drawing.Size(151, 23);
+ this.btnBackgroundImage.TabIndex = 5;
+ this.btnBackgroundImage.Text = "Background Image";
+ this.btnBackgroundImage.UseVisualStyleBackColor = true;
+ this.btnBackgroundImage.Visible = false;
+ this.btnBackgroundImage.Click += new System.EventHandler(this.btnBackgroundImage_Click);
+ //
+ // TestForm
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(511, 278);
+ this.Controls.Add(this.btnBackgroundImage);
+ this.Controls.Add(this.btnBackgroundColor);
+ this.Controls.Add(this.lblFriends);
+ this.Controls.Add(this.lstFriends);
+ this.Controls.Add(this.lblOnlineId);
+ this.Controls.Add(this.btnLogin);
+ this.Name = "TestForm";
+ this.Text = "Form1";
+ this.Load += new System.EventHandler(this.TestForm_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
}
diff --git a/PlayStationSharp.TestApp/TestForm.cs b/PlayStationSharp.TestApp/TestForm.cs
index 54c0a48..db12df1 100644
--- a/PlayStationSharp.TestApp/TestForm.cs
+++ b/PlayStationSharp.TestApp/TestForm.cs
@@ -14,16 +14,24 @@ public TestForm()
InitializeComponent();
}
- private Account Account { get; set; }
+ private Account _account;
+ private Account Account
+ {
+ get => _account;
+ set
+ {
+ btnBackgroundColor.Visible = !(value is null);
+ _account = value;
+ }
+ }
private void btnLogin_Click(object sender, EventArgs e)
{
- var account = Auth.CreateLogin();
-
- if (account == null) return;
+ Account = Auth.CreateLogin();
- this.Account = account;
- TokenHandler.Write(account.Client.Tokens);
+ if (Account == null) return;
+;
+ TokenHandler.Write(Account.Client.Tokens);
SetupLogin(false);
PopulateFields();
From 05175d11d47bc6fef9d43d68c5055b8b812144c4 Mon Sep 17 00:00:00 2001
From: TheBoxyBear <15822255+TheBoxyBear@users.noreply.github.com>
Date: Thu, 4 Mar 2021 16:12:17 -0500
Subject: [PATCH 2/3] Remove unessesary exception
---
PlayStationSharp.TestApp/TestForm.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/PlayStationSharp.TestApp/TestForm.cs b/PlayStationSharp.TestApp/TestForm.cs
index db12df1..6761bfb 100644
--- a/PlayStationSharp.TestApp/TestForm.cs
+++ b/PlayStationSharp.TestApp/TestForm.cs
@@ -62,7 +62,7 @@ private void TestForm_Load(object sender, EventArgs e)
SetupLogin(false);
PopulateFields();
}
- catch (Exception)
+ catch
{
SetupLogin(true);
}
From 8b97b5076492e31a41833581867b17ac9b52bc8d Mon Sep 17 00:00:00 2001
From: TheBoxyBear <15822255+TheBoxyBear@users.noreply.github.com>
Date: Thu, 4 Mar 2021 16:15:29 -0500
Subject: [PATCH 3/3] Add IsOnline property to User copied from UserExtensions
---
PlayStationSharp/API/User.cs | 2 ++
PlayStationSharp/Extensions/UserExtensions.cs | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/PlayStationSharp/API/User.cs b/PlayStationSharp/API/User.cs
index 721fd4d..e39ceec 100644
--- a/PlayStationSharp/API/User.cs
+++ b/PlayStationSharp/API/User.cs
@@ -16,6 +16,8 @@ public class User : AbstractUser
public List MessageThreads => _messageThreads.Value;
+ public bool IsOnline => Profile.Presences != null && Profile.Presences[0].OnlineStatus == "online";
+
[Flags]
public enum RequestType
{
diff --git a/PlayStationSharp/Extensions/UserExtensions.cs b/PlayStationSharp/Extensions/UserExtensions.cs
index 477cae8..9efbda1 100644
--- a/PlayStationSharp/Extensions/UserExtensions.cs
+++ b/PlayStationSharp/Extensions/UserExtensions.cs
@@ -11,7 +11,7 @@ public static class UserExtensions
{
public static List Online(this List users)
{
- return users.Where(a => a.Profile.Presences != null && a.Profile.Presences[0].OnlineStatus == "online").ToList();
+ return users.Where(a => a.IsOnline).ToList();
}
}
}