Switching project to C# (because why not)

This commit is contained in:
Aurélie Delhaie
2022-05-19 18:49:04 +02:00
commit b013815a96
44 changed files with 18946 additions and 0 deletions

264
OpenSaveCloudClient/AboutBox.Designer.cs generated Normal file
View File

@@ -0,0 +1,264 @@
namespace OpenSaveCloudClient
{
partial class AboutBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutBox));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.VersionLabel = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.ClientInfoLabel = new System.Windows.Forms.Label();
this.ServerInfoLabel = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.ApiVersionLabel = new System.Windows.Forms.Label();
this.ServerVersionLabel = new System.Windows.Forms.Label();
this.AllowRegisterLabel = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(507, 154);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// label1
//
this.label1.Dock = System.Windows.Forms.DockStyle.Top;
this.label1.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.label1.Location = new System.Drawing.Point(0, 154);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(507, 50);
this.label1.TabIndex = 1;
this.label1.Text = "Open Save Cloud";
this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// VersionLabel
//
this.VersionLabel.Dock = System.Windows.Forms.DockStyle.Top;
this.VersionLabel.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.VersionLabel.Location = new System.Drawing.Point(0, 204);
this.VersionLabel.Name = "VersionLabel";
this.VersionLabel.Size = new System.Drawing.Size(507, 37);
this.VersionLabel.TabIndex = 2;
this.VersionLabel.Text = "0.0.0.0";
this.VersionLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// label2
//
this.label2.Dock = System.Windows.Forms.DockStyle.Top;
this.label2.Location = new System.Drawing.Point(0, 241);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(507, 114);
this.label2.TabIndex = 3;
this.label2.Text = "Made by Aurélie Delhaie\r\nThis project exist because all games \r\ndon\'t have the cl" +
"oud save feature\r\n(Like The Sims 4)";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(15, 36);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(60, 25);
this.label4.TabIndex = 5;
this.label4.Text = "Client:";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(15, 61);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(65, 25);
this.label5.TabIndex = 6;
this.label5.Text = "Server:";
//
// ClientInfoLabel
//
this.ClientInfoLabel.AutoSize = true;
this.ClientInfoLabel.Location = new System.Drawing.Point(86, 36);
this.ClientInfoLabel.Name = "ClientInfoLabel";
this.ClientInfoLabel.Size = new System.Drawing.Size(24, 25);
this.ClientInfoLabel.TabIndex = 7;
this.ClientInfoLabel.Text = "...";
//
// ServerInfoLabel
//
this.ServerInfoLabel.AutoSize = true;
this.ServerInfoLabel.Location = new System.Drawing.Point(86, 61);
this.ServerInfoLabel.Name = "ServerInfoLabel";
this.ServerInfoLabel.Size = new System.Drawing.Size(24, 25);
this.ServerInfoLabel.TabIndex = 8;
this.ServerInfoLabel.Text = "...";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.ServerInfoLabel);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.ClientInfoLabel);
this.groupBox1.Location = new System.Drawing.Point(12, 378);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(483, 242);
this.groupBox1.TabIndex = 9;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Geek informations";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.ApiVersionLabel);
this.groupBox2.Controls.Add(this.ServerVersionLabel);
this.groupBox2.Controls.Add(this.AllowRegisterLabel);
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Location = new System.Drawing.Point(6, 93);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(471, 143);
this.groupBox2.TabIndex = 9;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "API";
//
// ApiVersionLabel
//
this.ApiVersionLabel.AutoSize = true;
this.ApiVersionLabel.Location = new System.Drawing.Point(231, 90);
this.ApiVersionLabel.Name = "ApiVersionLabel";
this.ApiVersionLabel.Size = new System.Drawing.Size(24, 25);
this.ApiVersionLabel.TabIndex = 5;
this.ApiVersionLabel.Text = "...";
//
// ServerVersionLabel
//
this.ServerVersionLabel.AutoSize = true;
this.ServerVersionLabel.Location = new System.Drawing.Point(231, 65);
this.ServerVersionLabel.Name = "ServerVersionLabel";
this.ServerVersionLabel.Size = new System.Drawing.Size(50, 25);
this.ServerVersionLabel.TabIndex = 4;
this.ServerVersionLabel.Text = "0.0.0";
//
// AllowRegisterLabel
//
this.AllowRegisterLabel.AutoSize = true;
this.AllowRegisterLabel.Location = new System.Drawing.Point(231, 40);
this.AllowRegisterLabel.Name = "AllowRegisterLabel";
this.AllowRegisterLabel.Size = new System.Drawing.Size(24, 25);
this.AllowRegisterLabel.TabIndex = 3;
this.AllowRegisterLabel.Text = "...";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(10, 90);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(159, 25);
this.label7.TabIndex = 2;
this.label7.Text = "API Server version:";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(10, 65);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(127, 25);
this.label6.TabIndex = 1;
this.label6.Text = "Server version:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(10, 40);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(215, 25);
this.label3.TabIndex = 0;
this.label3.Text = "Allow registration of user:";
//
// AboutBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(507, 632);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.VersionLabel);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(529, 688);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(529, 688);
this.Name = "AboutBox";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "About OSC";
this.Load += new System.EventHandler(this.AboutBox_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private PictureBox pictureBox1;
private Label label1;
private Label VersionLabel;
private Label label2;
private Label label4;
private Label label5;
private Label ClientInfoLabel;
private Label ServerInfoLabel;
private GroupBox groupBox1;
private GroupBox groupBox2;
private Label ApiVersionLabel;
private Label ServerVersionLabel;
private Label AllowRegisterLabel;
private Label label7;
private Label label6;
private Label label3;
}
}

View File

@@ -0,0 +1,54 @@
using OpenSaveCloudClient.Core;
using OpenSaveCloudClient.Models.Remote;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OpenSaveCloudClient
{
public partial class AboutBox : Form
{
private ServerConnector serverConnector;
public AboutBox()
{
InitializeComponent();
serverConnector = ServerConnector.GetInstance();
}
private void AboutBox_Load(object sender, EventArgs e)
{
if (serverConnector != null)
{
ServerInformation? si = serverConnector.ServerInformation;
if (si != null)
{
string serverInfo = "Go [{0} {1}/{2}]";
serverInfo = string.Format(serverInfo, si.GoVersion, si.OsName, si.OsArchitecture);
ServerInfoLabel.Text = serverInfo;
AllowRegisterLabel.Text = (si.AllowRegister) ? "Yes" : "No";
ServerVersionLabel.Text = si.Version;
ApiVersionLabel.Text = Convert.ToString(si.ApiVersion);
}
}
Assembly a = Assembly.GetExecutingAssembly();
Version? v = a.GetName().Version;
if (v != null)
{
VersionLabel.Text = v.ToString();
}
string clientInfo = "C# [Core .NET {0}/{1}]";
Version dotNetVersion = Environment.Version;
string? clrArch = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
clientInfo = string.Format(clientInfo, dotNetVersion, clrArch);
ClientInfoLabel.Text = clientInfo;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,222 @@
namespace OpenSaveCloudClient
{
partial class AddGameForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddGameForm));
this.label1 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.pathButton = new System.Windows.Forms.Button();
this.LocationBox = new System.Windows.Forms.TextBox();
this.NameBox = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.NoCoverLabel = new System.Windows.Forms.Label();
this.CoverPicture = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.CoverPicture)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.label1.ForeColor = System.Drawing.SystemColors.Highlight;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(212, 48);
this.label1.TabIndex = 0;
this.label1.Text = "Add a game";
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.pathButton);
this.groupBox1.Controls.Add(this.LocationBox);
this.groupBox1.Controls.Add(this.NameBox);
this.groupBox1.Location = new System.Drawing.Point(12, 80);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(634, 417);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Game information";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(15, 132);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(169, 25);
this.label3.TabIndex = 4;
this.label3.Text = "Save folder location";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(15, 51);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(59, 25);
this.label2.TabIndex = 3;
this.label2.Text = "Name";
//
// pathButton
//
this.pathButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.pathButton.Location = new System.Drawing.Point(571, 157);
this.pathButton.Name = "pathButton";
this.pathButton.Size = new System.Drawing.Size(47, 34);
this.pathButton.TabIndex = 2;
this.pathButton.Text = "...";
this.pathButton.UseVisualStyleBackColor = true;
this.pathButton.Click += new System.EventHandler(this.pathButton_Click);
//
// LocationBox
//
this.LocationBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.LocationBox.Location = new System.Drawing.Point(15, 160);
this.LocationBox.Name = "LocationBox";
this.LocationBox.ReadOnly = true;
this.LocationBox.Size = new System.Drawing.Size(550, 31);
this.LocationBox.TabIndex = 1;
//
// NameBox
//
this.NameBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.NameBox.Location = new System.Drawing.Point(15, 79);
this.NameBox.Name = "NameBox";
this.NameBox.Size = new System.Drawing.Size(603, 31);
this.NameBox.TabIndex = 0;
this.NameBox.TextChanged += new System.EventHandler(this.NameBox_TextChanged);
//
// groupBox2
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox2.Controls.Add(this.NoCoverLabel);
this.groupBox2.Controls.Add(this.CoverPicture);
this.groupBox2.Location = new System.Drawing.Point(652, 80);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(403, 417);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Cover";
//
// NoCoverLabel
//
this.NoCoverLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.NoCoverLabel.Location = new System.Drawing.Point(54, 56);
this.NoCoverLabel.Name = "NoCoverLabel";
this.NoCoverLabel.Size = new System.Drawing.Size(311, 305);
this.NoCoverLabel.TabIndex = 0;
this.NoCoverLabel.Text = "...";
this.NoCoverLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// CoverPicture
//
this.CoverPicture.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.CoverPicture.Location = new System.Drawing.Point(54, 56);
this.CoverPicture.Name = "CoverPicture";
this.CoverPicture.Size = new System.Drawing.Size(311, 305);
this.CoverPicture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.CoverPicture.TabIndex = 1;
this.CoverPicture.TabStop = false;
this.CoverPicture.Visible = false;
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(943, 508);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 34);
this.button1.TabIndex = 3;
this.button1.Text = "Add";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// timer1
//
this.timer1.Interval = 350;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// AddGameForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(1067, 554);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimumSize = new System.Drawing.Size(1089, 610);
this.Name = "AddGameForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Add a game";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.CoverPicture)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label label1;
private GroupBox groupBox1;
private GroupBox groupBox2;
private Button button1;
private TextBox LocationBox;
private TextBox NameBox;
private Button pathButton;
private Label label3;
private Label label2;
private Label NoCoverLabel;
private PictureBox CoverPicture;
private System.Windows.Forms.Timer timer1;
}
}

View File

@@ -0,0 +1,134 @@
using IGDB;
using IGDB.Models;
using OpenSaveCloudClient.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OpenSaveCloudClient
{
public partial class AddGameForm : Form
{
private readonly IGDBClient? _client;
private GameSave result;
public GameSave Result { get { return result; } }
public AddGameForm(IGDBClient? iGDBClient)
{
InitializeComponent();
_client = iGDBClient;
if (_client == null)
{
NoCoverLabel.Text = "IGDB is not configured";
}
else
{
NoCoverLabel.Visible = false;
}
}
private async void timer1_Tick(object sender, EventArgs e)
{
timer1.Stop();
if (_client != null)
{
NoCoverLabel.Visible = false;
CoverPicture.Visible = true;
if (!string.IsNullOrWhiteSpace(NameBox.Text))
{
try
{
string query = string.Format("fields *; search \"{0}\";", NameBox.Text.Replace("\"", ""));
Game[] games = await _client.QueryAsync<Game>(IGDBClient.Endpoints.Games, query: query);
games = games.Where(g => g.Cover != null && g.Cover.Value != null).ToArray();
if (games.Length > 0)
{
Game game = games.First();
CoverPicture.LoadAsync(game.Cover.Value.Url);
}
else
{
CoverPicture.Visible = false;
NoCoverLabel.Text = "No cover found";
NoCoverLabel.Visible = true;
}
}
catch (Exception ex)
{
CoverPicture.Visible = false;
NoCoverLabel.Text = ex.Message;
NoCoverLabel.Visible = true;
}
}
}
}
private void NameBox_TextChanged(object sender, EventArgs e)
{
if (_client != null)
{
timer1.Stop();
timer1.Start();
}
}
private void pathButton_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
string path = dialog.SelectedPath;
LocationBox.Text = path;
if (string.IsNullOrWhiteSpace(NameBox.Text))
{
NameBox.Text = path.Split(Path.DirectorySeparatorChar).Last();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
LockControls(true);
try
{
if (string.IsNullOrWhiteSpace(LocationBox.Text))
{
MessageBox.Show("File folder cannot be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!Directory.Exists(LocationBox.Text))
{
MessageBox.Show("This directory does not exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrWhiteSpace(NameBox.Text))
{
NameBox.Text = LocationBox.Text.Split(Path.DirectorySeparatorChar).Last();
}
result = new GameSave(NameBox.Text, "", LocationBox.Text, null, 0);
DialogResult = DialogResult.OK;
Close();
} finally
{
LockControls(false);
}
}
private void LockControls(bool value)
{
value = !value;
button1.Enabled = value;
NameBox.Enabled = value;
LocationBox.Enabled = value;
pathButton.Enabled = value;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using OpenSaveCloudClient.Models;
namespace OpenSaveCloudClient.Core
{
public class SaveManager
{
private static SaveManager? instance;
private List<GameSave> saves;
public List<GameSave> Saves { get { return saves; } }
private SaveManager()
{
saves = new List<GameSave>();
Load();
new Thread(() => CleanArchiveFolder()).Start();
}
public static SaveManager GetInstance()
{
if (instance == null)
{
instance = new SaveManager();
}
return instance;
}
public GameSave Create(string name, string path, string coverHash)
{
GameSave gameSave = new GameSave(name, "", path, "", 0);
return gameSave;
}
private void Load()
{
string appdata = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "osc");
string path = Path.Combine(appdata, "games.json");
if (!File.Exists(appdata))
{
Directory.CreateDirectory(appdata);
}
if (File.Exists(path))
{
string json = File.ReadAllText(path);
var res = JsonSerializer.Deserialize<List<GameSave>>(json);
if (res != null)
{
saves = res;
}
}
}
public void Save()
{
string appdata = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "osc");
string path = Path.Combine(appdata, "games.json");
if (!File.Exists(appdata))
{
Directory.CreateDirectory(appdata);
}
string json = JsonSerializer.Serialize(saves);
File.WriteAllText(path, json);
}
private void CleanArchiveFolder()
{
string appdata = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "osc");
string cachePath = Path.Combine(appdata, "cache");
if (Directory.Exists(cachePath))
{
string[] files = Directory.GetFiles(cachePath);
foreach (string file in files)
{
bool exist = false;
foreach (GameSave save in saves)
{
if (save.Uuid == Path.GetFileNameWithoutExtension(file))
{
exist = true;
break;
}
}
if (!exist)
{
File.Delete(Path.Combine(cachePath, file));
}
}
}
}
}
}

View File

@@ -0,0 +1,180 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
using OpenSaveCloudClient.Models.Remote;
using OpenSaveCloudClient.Models;
namespace OpenSaveCloudClient.Core
{
public class ServerConnector
{
private static ServerConnector? instance;
private string? token;
private string? host;
private int port;
private bool bind;
private bool connected;
private ServerInformation? serverInformation;
private Configuration configuration;
public string? Host { get { return host; } }
public int Port { get { return port; } }
public bool Bind { get { return bind; } }
public bool Connected { get { return connected; } }
public ServerInformation? ServerInformation { get { return serverInformation; } }
private ServerConnector()
{
configuration = Configuration.GetInstance();
}
public static ServerConnector GetInstance()
{
if (instance == null)
{
instance = new ServerConnector();
}
return instance;
}
public void BindNewServer(string host, int port)
{
Logout();
if (!host.StartsWith("http://") && !host.StartsWith("https://"))
{
host = "http://" + host;
}
this.host = host;
this.port = port;
GetServerInformation();
}
private void GetServerInformation()
{
try
{
HttpClient client = new();
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/system/information", host, port)).Result;
if (response.IsSuccessStatusCode)
{
string responseText = response.Content.ReadAsStringAsync().Result;
serverInformation = JsonSerializer.Deserialize<ServerInformation>(responseText);
if (serverInformation != null)
{
bind = true;
}
}
}
catch (Exception)
{ }
}
public void Login(string username, string password)
{
try
{
HttpClient client = new HttpClient();
string json = JsonSerializer.Serialize(new Credential { Username = username, Password = password });
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/login", host, port), content).Result;
if (response.IsSuccessStatusCode)
{
string responseText = response.Content.ReadAsStringAsync().Result;
AccessToken? accessToken = JsonSerializer.Deserialize<AccessToken>(responseText);
if (accessToken != null)
{
token = accessToken.Token;
connected = true;
SaveToConfig();
}
}
}
catch (Exception)
{ }
}
public void Reconnect()
{
try
{
if (ReloadFromConfiguration())
{
HttpClient client = new HttpClient();
string json = JsonSerializer.Serialize(new AccessToken { Token = token });
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/check/token", host, port), content).Result;
if (response.IsSuccessStatusCode)
{
string responseText = response.Content.ReadAsStringAsync().Result;
TokenValidation? accessToken = JsonSerializer.Deserialize<TokenValidation>(responseText);
if (accessToken != null && accessToken.Valid)
{
connected = true;
SaveToConfig();
}
else
{
Logout();
}
}
}
}
catch (Exception)
{ }
}
private bool ReloadFromConfiguration()
{
string newHost = configuration.GetString("authentication.host", "");
int newPort = configuration.GetInt("authentication.port", 443);
if (string.IsNullOrWhiteSpace(newHost))
{
return false;
}
try
{
string oldToken = configuration.GetString("authentication.token", "");
BindNewServer(newHost, newPort);
if (!bind)
{
return false;
}
if (string.IsNullOrWhiteSpace(oldToken))
{
return false;
}
token = oldToken;
}
catch (Exception)
{
return false;
}
return true;
}
public void Logout()
{
serverInformation = null;
bind = false;
connected = false;
token = "";
configuration.SetValue("authentication.host", null);
configuration.SetValue("authentication.port", null);
configuration.SetValue("authentication.token", null);
configuration.Flush();
}
private void SaveToConfig()
{
configuration.SetValue("authentication.host", host);
configuration.SetValue("authentication.port", port);
configuration.SetValue("authentication.token", token);
configuration.Flush();
}
}
}

View File

@@ -0,0 +1,77 @@
using OpenSaveCloudClient.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenSaveCloudClient.Core
{
public class TaskManager
{
private static TaskManager instance;
private readonly System.Timers.Timer timer;
private readonly Dictionary<string, AsyncTaskInformation> _tasks;
private readonly Mutex mut;
private TaskManager()
{
_tasks = new Dictionary<string, AsyncTaskInformation>();
mut = new Mutex();
timer = new System.Timers.Timer
{
Interval = 2000
};
timer.Elapsed += timer_Tick;
timer.Start();
}
public static TaskManager GetInstance()
{
if (instance == null)
{
instance = new TaskManager();
}
return instance;
}
public string StartTask(string label, int progressMax)
{
string uuid = Guid.NewGuid().ToString();
_tasks.Add(uuid, new AsyncTaskInformation(label, progressMax));
return uuid;
}
public AsyncTaskInformation GetTask(string uuid)
{
return _tasks[uuid];
}
private void timer_Tick(object? sender, EventArgs e)
{
mut.WaitOne();
try
{
List<string> toDelete = new();
foreach (KeyValuePair<string, AsyncTaskInformation> task in _tasks)
{
if (task.Value.Status == AsyncTaskStatus.Ended)
{
toDelete.Add(task.Key);
}
}
foreach (string uuid in toDelete)
{
_tasks.Remove(uuid);
}
}
finally
{
mut.ReleaseMutex();
}
}
}
}

View File

@@ -0,0 +1,206 @@
namespace OpenSaveCloudClient
{
partial class GameLibrary
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GameLibrary));
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.AddButton = new System.Windows.Forms.ToolStripButton();
this.SyncButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.ConfigButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.LogoutButton = new System.Windows.Forms.ToolStripButton();
this.listView1 = new System.Windows.Forms.ListView();
this.coverList = new System.Windows.Forms.ImageList(this.components);
this.AboutButton = new System.Windows.Forms.ToolStripButton();
this.statusStrip1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
//
// statusStrip1
//
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel1});
this.statusStrip1.Location = new System.Drawing.Point(0, 803);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(1428, 32);
this.statusStrip1.TabIndex = 0;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(60, 25);
this.toolStripStatusLabel1.Text = "Ready";
//
// toolStrip1
//
this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
this.toolStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.AddButton,
this.SyncButton,
this.toolStripSeparator1,
this.ConfigButton,
this.toolStripSeparator2,
this.LogoutButton,
this.AboutButton});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(1428, 33);
this.toolStrip1.TabIndex = 1;
this.toolStrip1.Text = "toolStrip1";
//
// AddButton
//
this.AddButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.AddButton.Image = ((System.Drawing.Image)(resources.GetObject("AddButton.Image")));
this.AddButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.AddButton.Name = "AddButton";
this.AddButton.Size = new System.Drawing.Size(34, 28);
this.AddButton.Text = "Add a game";
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
//
// SyncButton
//
this.SyncButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.SyncButton.Image = ((System.Drawing.Image)(resources.GetObject("SyncButton.Image")));
this.SyncButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.SyncButton.Name = "SyncButton";
this.SyncButton.Size = new System.Drawing.Size(34, 28);
this.SyncButton.Text = "Synchronize";
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 33);
//
// ConfigButton
//
this.ConfigButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.ConfigButton.Image = ((System.Drawing.Image)(resources.GetObject("ConfigButton.Image")));
this.ConfigButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.ConfigButton.Name = "ConfigButton";
this.ConfigButton.Size = new System.Drawing.Size(34, 28);
this.ConfigButton.Text = "Settings";
this.ConfigButton.Click += new System.EventHandler(this.ConfigButton_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(6, 33);
//
// LogoutButton
//
this.LogoutButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.LogoutButton.Image = ((System.Drawing.Image)(resources.GetObject("LogoutButton.Image")));
this.LogoutButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.LogoutButton.Name = "LogoutButton";
this.LogoutButton.Size = new System.Drawing.Size(34, 28);
this.LogoutButton.Text = "Logout";
this.LogoutButton.Click += new System.EventHandler(this.LogoutButton_Click);
//
// listView1
//
this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.LargeImageList = this.coverList;
this.listView1.Location = new System.Drawing.Point(0, 36);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.ShowGroups = false;
this.listView1.ShowItemToolTips = true;
this.listView1.Size = new System.Drawing.Size(1428, 764);
this.listView1.TabIndex = 2;
this.listView1.UseCompatibleStateImageBehavior = false;
//
// coverList
//
this.coverList.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
this.coverList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("coverList.ImageStream")));
this.coverList.TransparentColor = System.Drawing.Color.Transparent;
this.coverList.Images.SetKeyName(0, "unknown_cover.png");
//
// AboutButton
//
this.AboutButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.AboutButton.Image = ((System.Drawing.Image)(resources.GetObject("AboutButton.Image")));
this.AboutButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.AboutButton.Name = "AboutButton";
this.AboutButton.Size = new System.Drawing.Size(34, 28);
this.AboutButton.Text = "toolStripButton1";
this.AboutButton.Click += new System.EventHandler(this.AboutButton_Click);
//
// GameLibrary
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(1428, 835);
this.Controls.Add(this.listView1);
this.Controls.Add(this.toolStrip1);
this.Controls.Add(this.statusStrip1);
this.DoubleBuffered = true;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MinimumSize = new System.Drawing.Size(1450, 891);
this.Name = "GameLibrary";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Game Library";
this.Load += new System.EventHandler(this.GameLibrary_Load);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private StatusStrip statusStrip1;
private ToolStripStatusLabel toolStripStatusLabel1;
private ToolStrip toolStrip1;
private ToolStripButton AddButton;
private ToolStripButton SyncButton;
private ToolStripSeparator toolStripSeparator1;
private ToolStripButton LogoutButton;
private ListView listView1;
private ToolStripButton ConfigButton;
private ToolStripSeparator toolStripSeparator2;
private ImageList coverList;
private ToolStripButton AboutButton;
}
}

View File

@@ -0,0 +1,165 @@
using OpenSaveCloudClient.Models;
using OpenSaveCloudClient.Core;
using IGDB;
namespace OpenSaveCloudClient
{
public partial class GameLibrary : Form
{
private readonly Configuration _configuration;
private readonly IGDBClient? _client;
private readonly SaveManager saveManager;
private readonly TaskManager taskManager;
private readonly ServerConnector serverConnector;
public GameLibrary()
{
InitializeComponent();
saveManager = SaveManager.GetInstance();
taskManager = TaskManager.GetInstance();
serverConnector = ServerConnector.GetInstance();
_configuration = Configuration.GetInstance();
if (_configuration.GetBoolean("igdb.enabled", false))
{
string clientId = _configuration.GetString("igdb.client_id", "");
string clientSecret = _configuration.GetString("igdb.client_secret", "");
_client = new IGDBClient(clientId, clientSecret);
}
}
private void GameLibrary_Load(object sender, EventArgs e)
{
new Thread(() =>
{
serverConnector.Reconnect();
if (!serverConnector.Connected)
{
this.Invoke((MethodInvoker)delegate {
ShowLoginForm();
});
}
}).Start();
RefreshList();
}
private void ShowLoginForm()
{
Enabled = false;
LoginForm loginForm = new LoginForm();
loginForm.FormClosed += LoginForm_Close;
loginForm.Show();
}
private void LoginForm_Close(object? sender, EventArgs e)
{
if (!serverConnector.Connected)
{
Close();
} else
{
Enabled = true;
}
}
private void AddButton_Click(object sender, EventArgs e)
{
AddGameForm form = new(_client);
if (form.ShowDialog() == DialogResult.OK) {
GameSave newGame = form.Result;
new Thread(() => AddGameToLibrary(newGame)).Start();
}
}
private void AddGameToLibrary(GameSave newGame)
{
string taskUuid = "";
try
{
this.Invoke((MethodInvoker)delegate {
taskUuid = StartTask(String.Format("Archiving \"{0}\"", newGame.Name), 1);
});
newGame.Archive();
saveManager.Saves.Add(newGame);
saveManager.Save();
this.Invoke((MethodInvoker)delegate {
RefreshList();
SetTaskEnded(taskUuid);
});
}
catch (Exception)
{
this.statusStrip1.Invoke((MethodInvoker)delegate {
this.Invoke((MethodInvoker)delegate {
SetTaskFailed(taskUuid);
});
});
}
}
private void ConfigButton_Click(object sender, EventArgs e)
{
SettingsForm form = new();
form.ShowDialog();
}
private void RefreshList()
{
listView1.Clear();
foreach (GameSave game in saveManager.Saves)
{
ListViewItem itm = listView1.Items.Add(game.Name);
itm.ImageKey = "unknown_cover.png";
}
}
private string StartTask(string label, int maxProgress)
{
toolStripStatusLabel1.Text = string.Format("{0}...", label);
return taskManager.StartTask(label, maxProgress);
}
private void SetTaskEnded(string uuid)
{
try
{
var task = taskManager.GetTask(uuid);
task.Progress = task.Max;
task.Status = AsyncTaskStatus.Ended;
toolStripStatusLabel1.Text = string.Format("{0} finished", task.Label);
}
catch (Exception ex)
{
//todo: catch exception
}
}
private void SetTaskFailed(string uuid)
{
try
{
var task = taskManager.GetTask(uuid);
task.Status = AsyncTaskStatus.Failed;
toolStripStatusLabel1.Text = string.Format("{0} failed", task.Label);
}
catch (Exception ex)
{
//todo: catch exception
}
}
private void LogoutButton_Click(object sender, EventArgs e)
{
serverConnector.Logout();
ShowLoginForm();
}
private void AboutButton_Click(object sender, EventArgs e)
{
AboutBox aboutBox = new();
aboutBox.ShowDialog();
}
}
}

File diff suppressed because it is too large Load Diff

199
OpenSaveCloudClient/LoginForm.Designer.cs generated Normal file
View File

@@ -0,0 +1,199 @@
namespace OpenSaveCloudClient
{
partial class LoginForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LoginForm));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.ServerTextBox = new System.Windows.Forms.TextBox();
this.UsernameTextBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.PasswordTextBox = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.PortNumericBox = new System.Windows.Forms.NumericUpDown();
this.LoginButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.PortNumericBox)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(1061, 135);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// ServerTextBox
//
this.ServerTextBox.Location = new System.Drawing.Point(283, 213);
this.ServerTextBox.Name = "ServerTextBox";
this.ServerTextBox.PlaceholderText = "myserver.com";
this.ServerTextBox.Size = new System.Drawing.Size(392, 31);
this.ServerTextBox.TabIndex = 1;
//
// UsernameTextBox
//
this.UsernameTextBox.Location = new System.Drawing.Point(283, 301);
this.UsernameTextBox.Name = "UsernameTextBox";
this.UsernameTextBox.Size = new System.Drawing.Size(514, 31);
this.UsernameTextBox.TabIndex = 3;
//
// label1
//
this.label1.AutoSize = true;
this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
this.label1.Location = new System.Drawing.Point(283, 185);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(61, 25);
this.label1.TabIndex = 0;
this.label1.Text = "Server";
//
// label2
//
this.label2.AutoSize = true;
this.label2.ForeColor = System.Drawing.SystemColors.ControlText;
this.label2.Location = new System.Drawing.Point(283, 273);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(91, 25);
this.label2.TabIndex = 0;
this.label2.Text = "Username";
//
// label3
//
this.label3.AutoSize = true;
this.label3.ForeColor = System.Drawing.SystemColors.ControlText;
this.label3.Location = new System.Drawing.Point(283, 342);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(87, 25);
this.label3.TabIndex = 0;
this.label3.Text = "Password";
//
// PasswordTextBox
//
this.PasswordTextBox.Location = new System.Drawing.Point(283, 370);
this.PasswordTextBox.Name = "PasswordTextBox";
this.PasswordTextBox.Size = new System.Drawing.Size(514, 31);
this.PasswordTextBox.TabIndex = 4;
this.PasswordTextBox.UseSystemPasswordChar = true;
//
// label4
//
this.label4.AutoSize = true;
this.label4.ForeColor = System.Drawing.SystemColors.ControlText;
this.label4.Location = new System.Drawing.Point(681, 185);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(44, 25);
this.label4.TabIndex = 0;
this.label4.Text = "Port";
//
// PortNumericBox
//
this.PortNumericBox.InterceptArrowKeys = false;
this.PortNumericBox.Location = new System.Drawing.Point(681, 213);
this.PortNumericBox.Maximum = new decimal(new int[] {
65535,
0,
0,
0});
this.PortNumericBox.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.PortNumericBox.Name = "PortNumericBox";
this.PortNumericBox.Size = new System.Drawing.Size(116, 31);
this.PortNumericBox.TabIndex = 2;
this.PortNumericBox.Value = new decimal(new int[] {
443,
0,
0,
0});
//
// LoginButton
//
this.LoginButton.Location = new System.Drawing.Point(685, 439);
this.LoginButton.Name = "LoginButton";
this.LoginButton.Size = new System.Drawing.Size(112, 34);
this.LoginButton.TabIndex = 5;
this.LoginButton.Text = "Login";
this.LoginButton.UseVisualStyleBackColor = true;
this.LoginButton.Click += new System.EventHandler(this.LoginButton_Click);
//
// LoginForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(1061, 508);
this.Controls.Add(this.LoginButton);
this.Controls.Add(this.PortNumericBox);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.PasswordTextBox);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.UsernameTextBox);
this.Controls.Add(this.ServerTextBox);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(1083, 564);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(1083, 564);
this.Name = "LoginForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Login to a server";
this.TopMost = true;
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.PortNumericBox)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBox1;
private TextBox ServerTextBox;
private TextBox UsernameTextBox;
private Label label1;
private Label label2;
private Label label3;
private TextBox PasswordTextBox;
private Label label4;
private NumericUpDown PortNumericBox;
private Button LoginButton;
}
}

View File

@@ -0,0 +1,79 @@
using OpenSaveCloudClient.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OpenSaveCloudClient
{
public partial class LoginForm : Form
{
private ServerConnector serverConnector;
public LoginForm()
{
InitializeComponent();
serverConnector = ServerConnector.GetInstance();
}
private void LoginButton_Click(object sender, EventArgs e)
{
LockControls(true);
try
{
if (string.IsNullOrWhiteSpace(ServerTextBox.Text))
{
MessageBox.Show("The server hostname or IP is empty, cannot login to an unknown server", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrWhiteSpace(UsernameTextBox.Text) || string.IsNullOrWhiteSpace(PasswordTextBox.Text))
{
MessageBox.Show("Password or username cannot be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
decimal port = PortNumericBox.Value;
serverConnector.BindNewServer(ServerTextBox.Text, (int)port);
if (serverConnector.Bind)
{
serverConnector.Login(UsernameTextBox.Text, PasswordTextBox.Text);
if (serverConnector.Connected)
{
Close();
}
else
{
MessageBox.Show("Wrong username or password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Failed to find the server, check the hostname or the port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
LockControls(false);
}
}
private void LockControls(bool value)
{
value = !value;
ServerTextBox.Enabled = value;
PortNumericBox.Enabled = value;
UsernameTextBox.Enabled = value;
PasswordTextBox.Enabled = value;
LoginButton.Enabled = value;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenSaveCloudClient.Models
{
public class AsyncTaskInformation
{
private readonly string label;
private readonly int max;
private int progress;
private AsyncTaskStatus status;
public string Label { get { return label; } }
public int Max { get { return max; } }
public int Progress { get { return progress; } set { progress = value; } }
public AsyncTaskStatus Status { get { return status; } set { status = value; } }
public AsyncTaskInformation(string label, int max)
{
this.label = label;
this.max = max;
this.progress = 0;
status = AsyncTaskStatus.Running;
}
public int Add(int progress)
{
this.progress += progress;
return progress;
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenSaveCloudClient.Models
{
public enum AsyncTaskStatus
{
Running,
Failed,
Stopped,
Ended
}
}

View File

@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
namespace OpenSaveCloudClient.Models
{
public class Configuration
{
private static Configuration? instance;
private Dictionary<string, string> _values;
private Configuration()
{
_values = new Dictionary<string, string>();
Load();
}
public static Configuration GetInstance()
{
if (instance == null)
{
instance = new Configuration();
}
return instance;
}
private void Load()
{
string appdata = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "osc");
string path = Path.Combine(appdata, "settings.json");
if (!File.Exists(appdata))
{
Directory.CreateDirectory(appdata);
}
if (File.Exists(path))
{
string json = File.ReadAllText(path);
var res = JsonSerializer.Deserialize<Dictionary<string, string>>(json);
if (res != null)
{
_values = res;
}
}
}
private void Save()
{
string appdata = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "osc");
string path = Path.Combine(appdata, "settings.json");
if (!File.Exists(appdata))
{
Directory.CreateDirectory(appdata);
}
string json = JsonSerializer.Serialize<Dictionary<string, string>>(_values);
File.WriteAllText(path, json);
}
public string GetString(string key, string defaultValue)
{
try
{
return _values[key];
}
catch (KeyNotFoundException)
{
return defaultValue;
}
}
public int GetInt(string key, int defaultValue)
{
try
{
string value = _values[key];
if (!Int32.TryParse(value, out int result))
{
throw new Exception("This value is not an Int32");
}
return result;
}
catch (KeyNotFoundException)
{
return defaultValue;
}
}
public Boolean GetBoolean(string key, bool defaultValue)
{
try
{
string value = _values[key];
if (!Boolean.TryParse(value, out bool result))
{
throw new Exception("This value is not a Boolean");
}
return result;
} catch (KeyNotFoundException)
{
return defaultValue;
}
}
public void SetValue(string key, object? value, bool autoFlush = false)
{
if (value == null)
{
_values.Remove(key);
}
else
{
_values[key] = value.ToString();
}
if (autoFlush)
{
Save();
}
}
public void Flush()
{
Save();
}
}
}

View File

@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.IO.Compression;
using System.Security.Cryptography;
namespace OpenSaveCloudClient.Models
{
public class GameSave
{
private int id;
private string uuid;
private readonly string name;
private readonly string folderPath;
private readonly string description;
private string hash;
private readonly string? coverPath;
private readonly int revision;
private bool synced;
private bool localOnly;
public int Id { get { return id; } set { id = value; } }
public string Uuid { get { return uuid; } }
public string Name { get { return name; } }
public string Description { get { return description; } }
public string FolderPath { get { return folderPath; } }
public string Hash { get { return hash; } }
public string? CoverPath { get { return coverPath; } }
public int Revision { get { return revision; } }
public bool Synced { get { return synced; } set { synced = value; } }
public bool LocalOnly { get { return localOnly; } set { localOnly = value; } }
public GameSave(string name, string description, string folderPath, string? coverPath, int revision)
{
Guid guid = Guid.NewGuid();
this.name = name;
this.uuid = guid.ToString();
this.description = description;
this.hash = "";
this.folderPath = folderPath;
this.coverPath = coverPath;
this.revision = revision;
synced = false;
localOnly = true;
}
[JsonConstructor]
public GameSave(int id, string uuid, string name, string folderPath, string description, string hash, string? coverPath, int revision, bool synced, bool localOnly)
{
this.id = id;
this.uuid = uuid;
this.name = name;
this.folderPath = folderPath;
this.description = description;
this.hash = hash;
this.coverPath = coverPath;
this.revision = revision;
this.synced = synced;
this.localOnly = localOnly;
}
public void Archive()
{
string appdata = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "osc");
string cachePath = Path.Combine(appdata, "cache");
string archivePath = Path.Combine(cachePath, uuid + ".bin");
if (!File.Exists(appdata))
{
Directory.CreateDirectory(appdata);
}
if (!File.Exists(cachePath))
{
Directory.CreateDirectory(cachePath);
}
ZipFile.CreateFromDirectory(folderPath, archivePath, CompressionLevel.SmallestSize, true);
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(archivePath))
{
var h = md5.ComputeHash(stream);
hash = BitConverter.ToString(h).Replace("-", "").ToLowerInvariant();
}
}
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace OpenSaveCloudClient.Models.Remote
{
public class AccessToken
{
[JsonPropertyName("token")]
public string Token { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace OpenSaveCloudClient.Models.Remote
{
public class Credential
{
[JsonPropertyName("username")]
public string Username { get; set; }
[JsonPropertyName("password")]
public string Password { get; set; }
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace OpenSaveCloudClient.Models.Remote
{
public class ServerInformation
{
[JsonPropertyName("allow_register")]
public bool AllowRegister { get; set; }
[JsonPropertyName("version")]
public string Version { get; set; }
[JsonPropertyName("api_version")]
public int ApiVersion { get; set; }
[JsonPropertyName("go_version")]
public string GoVersion { get; set; }
[JsonPropertyName("os_name")]
public string OsName { get; set; }
[JsonPropertyName("os_architecture")]
public string OsArchitecture { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace OpenSaveCloudClient.Models.Remote
{
public class TokenValidation
{
[JsonPropertyName("valid")]
public bool Valid { get; set; }
}
}

View File

@@ -0,0 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<SupportedOSPlatformVersion>8.0</SupportedOSPlatformVersion>
<PlatformTarget>x64</PlatformTarget>
<PackageIcon>logo.png</PackageIcon>
<ApplicationIcon>logo.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Content Include="logo.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IGDB" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="logo.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,17 @@
namespace OpenSaveCloudClient
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new GameLibrary());
}
}
}

View File

@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace OpenSaveCloudClient.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OpenSaveCloudClient.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,197 @@
namespace OpenSaveCloudClient
{
partial class SettingsForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingsForm));
this.label1 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.IgdbClientSecret = new System.Windows.Forms.TextBox();
this.IgdbClientID = new System.Windows.Forms.TextBox();
this.IgdbCheckBox = new System.Windows.Forms.CheckBox();
this.label3 = new System.Windows.Forms.Label();
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.label1.ForeColor = System.Drawing.SystemColors.Highlight;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(147, 48);
this.label1.TabIndex = 0;
this.label1.Text = "Settings";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.IgdbClientSecret);
this.groupBox1.Controls.Add(this.IgdbClientID);
this.groupBox1.Controls.Add(this.IgdbCheckBox);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.linkLabel1);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Location = new System.Drawing.Point(12, 80);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(483, 478);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "IGDB";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(6, 403);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(109, 25);
this.label5.TabIndex = 8;
this.label5.Text = "Client Secret";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 330);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(79, 25);
this.label4.TabIndex = 7;
this.label4.Text = "Client ID";
//
// IgdbClientSecret
//
this.IgdbClientSecret.Enabled = false;
this.IgdbClientSecret.Location = new System.Drawing.Point(6, 431);
this.IgdbClientSecret.Name = "IgdbClientSecret";
this.IgdbClientSecret.Size = new System.Drawing.Size(471, 31);
this.IgdbClientSecret.TabIndex = 6;
//
// IgdbClientID
//
this.IgdbClientID.Enabled = false;
this.IgdbClientID.Location = new System.Drawing.Point(6, 358);
this.IgdbClientID.Name = "IgdbClientID";
this.IgdbClientID.Size = new System.Drawing.Size(471, 31);
this.IgdbClientID.TabIndex = 5;
//
// IgdbCheckBox
//
this.IgdbCheckBox.AutoSize = true;
this.IgdbCheckBox.Location = new System.Drawing.Point(6, 293);
this.IgdbCheckBox.Name = "IgdbCheckBox";
this.IgdbCheckBox.Size = new System.Drawing.Size(135, 29);
this.IgdbCheckBox.TabIndex = 4;
this.IgdbCheckBox.Text = "Enable IGDB";
this.IgdbCheckBox.UseVisualStyleBackColor = true;
this.IgdbCheckBox.CheckedChanged += new System.EventHandler(this.IgdbCheckBox_CheckedChanged);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 222);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(402, 25);
this.label3.TabIndex = 3;
this.label3.Text = "Hint: OAuth Redirect URLs can be http://localhost";
//
// linkLabel1
//
this.linkLabel1.AutoSize = true;
this.linkLabel1.Location = new System.Drawing.Point(6, 256);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(177, 25);
this.linkLabel1.TabIndex = 2;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "https://dev.twitch.tv/";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 36);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(443, 175);
this.label2.TabIndex = 0;
this.label2.Text = resources.GetString("label2.Text");
//
// button1
//
this.button1.Location = new System.Drawing.Point(383, 582);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 34);
this.button1.TabIndex = 2;
this.button1.Text = "Save";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Settings
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(507, 628);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(529, 684);
this.MinimumSize = new System.Drawing.Size(529, 684);
this.Name = "Settings";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Settings";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label label1;
private GroupBox groupBox1;
private Label label2;
private Label label5;
private Label label4;
private TextBox IgdbClientSecret;
private TextBox IgdbClientID;
private CheckBox IgdbCheckBox;
private Label label3;
private LinkLabel linkLabel1;
private Button button1;
}
}

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenSaveCloudClient.Models;
namespace OpenSaveCloudClient
{
public partial class SettingsForm : Form
{
private readonly Configuration _configuration;
public SettingsForm()
{
InitializeComponent();
_configuration = Configuration.GetInstance();
InitAndFillFields();
}
private void InitAndFillFields()
{
IgdbCheckBox.Checked = _configuration.GetBoolean("igdb.enabled", false);
IgdbClientID.Text = _configuration.GetString("igdb.client_id", "");
IgdbClientSecret.Text = _configuration.GetString("igdb.client_secret", "");
}
private void IgdbCheckBox_CheckedChanged(object sender, EventArgs e)
{
IgdbClientID.Enabled = IgdbCheckBox.Checked;
IgdbClientSecret.Enabled = IgdbCheckBox.Checked;
}
private void Save()
{
_configuration.SetValue("igdb.enabled", IgdbCheckBox.Checked);
_configuration.SetValue("igdb.client_id", IgdbClientID.Text);
_configuration.SetValue("igdb.client_secret", IgdbClientSecret.Text);
_configuration.Flush();
}
private void button1_Click(object sender, EventArgs e)
{
Save();
Close();
}
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB