2 Commits

Author SHA1 Message Date
Aurélie Delhaie
40645a80a1 Fix download/upload timeout + Fix some warnings 2022-08-08 18:00:11 +02:00
Aurélie Delhaie
e3d33a1af9 License 2022-08-01 22:27:37 +02:00
29 changed files with 78 additions and 52 deletions

7
LICENSE Normal file
View File

@@ -0,0 +1,7 @@
Copyright 2022 Aurélie Delhaie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -20,7 +20,7 @@ namespace OpenSaveCloudClient
public AboutBox() public AboutBox()
{ {
InitializeComponent(); InitializeComponent();
serverConnector = ServerConnector.GetInstance(); serverConnector = ServerConnector.Instance;
} }
private void AboutBox_Load(object sender, EventArgs e) private void AboutBox_Load(object sender, EventArgs e)

View File

@@ -22,7 +22,7 @@ namespace OpenSaveCloudClient
public AddGameForm() public AddGameForm()
{ {
InitializeComponent(); InitializeComponent();
saveManager = SaveManager.GetInstance(); saveManager = SaveManager.Instance;
NoCoverLabel.Text = "IGDB is not configured"; NoCoverLabel.Text = "IGDB is not configured";
} }

View File

@@ -21,8 +21,8 @@ namespace OpenSaveCloudClient
public AddUser() public AddUser()
{ {
InitializeComponent(); InitializeComponent();
serverConnector = ServerConnector.GetInstance(); serverConnector = ServerConnector.Instance;
taskManager = TaskManager.GetInstance(); taskManager = TaskManager.Instance;
} }
private void AddUser_Load(object sender, EventArgs e) private void AddUser_Load(object sender, EventArgs e)

View File

@@ -20,10 +20,16 @@ namespace OpenSaveCloudClient.Core
messages = new List<Log>(); messages = new List<Log>();
} }
public static LogManager GetInstance() public static LogManager Instance
{ {
if (instance == null) { instance = new LogManager(); } get
return instance; {
if (instance == null)
{
instance = new LogManager();
}
return instance;
}
} }
public void AddError(Exception ex) public void AddError(Exception ex)

View File

@@ -22,13 +22,16 @@ namespace OpenSaveCloudClient.Core
ThreadPool.QueueUserWorkItem(delegate { CleanArchiveFolder(); }); ThreadPool.QueueUserWorkItem(delegate { CleanArchiveFolder(); });
} }
public static SaveManager GetInstance() public static SaveManager Instance
{ {
if (instance == null) get
{ {
instance = new SaveManager(); if (instance == null)
{
instance = new SaveManager();
}
return instance;
} }
return instance;
} }
public GameSave Create(string name, string path, string coverHash) public GameSave Create(string name, string path, string coverHash)

View File

@@ -29,7 +29,7 @@ namespace OpenSaveCloudClient.Core
private readonly LogManager logManager; private readonly LogManager logManager;
private readonly TaskManager taskManager; private readonly TaskManager taskManager;
private readonly Configuration configuration; private readonly UserConfiguration configuration;
private readonly SaveManager saveManager; private readonly SaveManager saveManager;
@@ -42,19 +42,21 @@ namespace OpenSaveCloudClient.Core
private ServerConnector() private ServerConnector()
{ {
configuration = Configuration.GetInstance(); configuration = UserConfiguration.Instance;
logManager = LogManager.GetInstance(); logManager = LogManager.Instance;
taskManager = TaskManager.GetInstance(); taskManager = TaskManager.Instance;
saveManager = SaveManager.GetInstance(); saveManager = SaveManager.Instance;
} }
public static ServerConnector GetInstance() public static ServerConnector Instance
{ {
if (instance == null) get {
{ if (instance == null)
instance = new ServerConnector(); {
instance = new ServerConnector();
}
return instance;
} }
return instance;
} }
/// <summary> /// <summary>
@@ -441,6 +443,7 @@ namespace OpenSaveCloudClient.Core
client.DefaultRequestHeaders.Add("X-Upload-Key", uploadToken); client.DefaultRequestHeaders.Add("X-Upload-Key", uploadToken);
client.DefaultRequestHeaders.Add("X-Game-Save-Hash", newHash); client.DefaultRequestHeaders.Add("X-Game-Save-Hash", newHash);
client.DefaultRequestHeaders.Add("X-Hash", hash); client.DefaultRequestHeaders.Add("X-Hash", hash);
client.Timeout = Timeout.InfiniteTimeSpan;
HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/game/upload", host, port), multipartFormContent).Result; HttpResponseMessage response = client.PostAsync(string.Format("{0}:{1}/api/v1/game/upload", host, port), multipartFormContent).Result;
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {
@@ -480,6 +483,7 @@ namespace OpenSaveCloudClient.Core
using HttpClient client = new(); using HttpClient client = new();
client.DefaultRequestHeaders.Add("Authorization", "bearer " + token); client.DefaultRequestHeaders.Add("Authorization", "bearer " + token);
client.DefaultRequestHeaders.Add("X-Upload-Key", uploadToken); client.DefaultRequestHeaders.Add("X-Upload-Key", uploadToken);
client.Timeout = Timeout.InfiniteTimeSpan;
HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/game/download", host, port)).Result; HttpResponseMessage response = client.GetAsync(string.Format("{0}:{1}/api/v1/game/download", host, port)).Result;
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {

View File

@@ -21,7 +21,7 @@ namespace OpenSaveCloudClient.Core
private TaskManager() private TaskManager()
{ {
logManager = LogManager.GetInstance(); logManager = LogManager.Instance;
_tasks = new Dictionary<string, AsyncTaskInformation>(); _tasks = new Dictionary<string, AsyncTaskInformation>();
mut = new Mutex(); mut = new Mutex();
timer = new System.Timers.Timer timer = new System.Timers.Timer
@@ -32,13 +32,16 @@ namespace OpenSaveCloudClient.Core
timer.Start(); timer.Start();
} }
public static TaskManager GetInstance() public static TaskManager Instance
{ {
if (instance == null) get
{ {
instance = new TaskManager(); if (instance == null)
{
instance = new TaskManager();
}
return instance;
} }
return instance;
} }
public string StartTask(string label, bool undefined, int progressMax) public string StartTask(string label, bool undefined, int progressMax)

View File

@@ -28,8 +28,8 @@ namespace OpenSaveCloudClient
{ {
InitializeComponent(); InitializeComponent();
result = new List<GameSave>(); result = new List<GameSave>();
serverConnector = ServerConnector.GetInstance(); serverConnector = ServerConnector.Instance;
saveManager = SaveManager.GetInstance(); saveManager = SaveManager.Instance;
} }
private void DownloadGameForm_Load(object sender, EventArgs e) private void DownloadGameForm_Load(object sender, EventArgs e)

View File

@@ -7,7 +7,7 @@ namespace OpenSaveCloudClient
public partial class GameLibrary : Form public partial class GameLibrary : Form
{ {
private readonly Configuration _configuration; private readonly UserConfiguration _configuration;
private readonly SaveManager saveManager; private readonly SaveManager saveManager;
private readonly TaskManager taskManager; private readonly TaskManager taskManager;
private readonly ServerConnector serverConnector; private readonly ServerConnector serverConnector;
@@ -17,11 +17,11 @@ namespace OpenSaveCloudClient
public GameLibrary() public GameLibrary()
{ {
InitializeComponent(); InitializeComponent();
saveManager = SaveManager.GetInstance(); saveManager = SaveManager.Instance;
taskManager = TaskManager.GetInstance(); taskManager = TaskManager.Instance;
serverConnector = ServerConnector.GetInstance(); serverConnector = ServerConnector.Instance;
_configuration = Configuration.GetInstance(); _configuration = UserConfiguration.Instance;
logManager = LogManager.GetInstance(); logManager = LogManager.Instance;
listViewContextMenu = new ContextMenuStrip(); listViewContextMenu = new ContextMenuStrip();
listViewContextMenu.Items.Add("Delete from server").Click += contextMenuDeleteFromServer_Click; listViewContextMenu.Items.Add("Delete from server").Click += contextMenuDeleteFromServer_Click;

View File

@@ -19,7 +19,7 @@ namespace OpenSaveCloudClient
public LoginForm() public LoginForm()
{ {
InitializeComponent(); InitializeComponent();
serverConnector = ServerConnector.GetInstance(); serverConnector = ServerConnector.Instance;
} }
private void LoginButton_Click(object sender, EventArgs e) private void LoginButton_Click(object sender, EventArgs e)

View File

@@ -19,7 +19,7 @@ namespace OpenSaveCloudClient
public LogsForm() public LogsForm()
{ {
InitializeComponent(); InitializeComponent();
logManager = LogManager.GetInstance(); logManager = LogManager.Instance;
logManager.NewMessage += logManager_NewError; logManager.NewMessage += logManager_NewError;
} }

View File

@@ -7,24 +7,27 @@ using System.Text.Json;
namespace OpenSaveCloudClient.Models namespace OpenSaveCloudClient.Models
{ {
public class Configuration public class UserConfiguration
{ {
private static Configuration? instance; private static UserConfiguration? instance;
private Dictionary<string, string> _values; private Dictionary<string, string> _values;
private Configuration() private UserConfiguration()
{ {
_values = new Dictionary<string, string>(); _values = new Dictionary<string, string>();
Load(); Load();
} }
public static Configuration GetInstance() public static UserConfiguration Instance
{ {
if (instance == null) get
{ {
instance = new Configuration(); if (instance == null)
{
instance = new UserConfiguration();
}
return instance;
} }
return instance;
} }
private void Load() private void Load()

View File

@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using System.IO.Compression; using System.IO.Compression;
using System.Security.Cryptography; using System.Security.Cryptography;
using OpenSaveCloudClient.Core; using OpenSaveCloudClient.Core;
using System.Globalization;
namespace OpenSaveCloudClient.Models namespace OpenSaveCloudClient.Models
{ {
@@ -96,7 +97,7 @@ namespace OpenSaveCloudClient.Models
byte[]? hashBytes = HashTool.HashDirectory(FolderPath); byte[]? hashBytes = HashTool.HashDirectory(FolderPath);
if (hashBytes == null) if (hashBytes == null)
{ {
throw new Exception(String.Format("failed to get hash of directory '{0}'", FolderPath)); throw new Exception(message: string.Format(CultureInfo.CurrentCulture, "failed to get hash of directory '{0}'", FolderPath));
} }
currentHash = BitConverter.ToString(hashBytes).Replace("-", ""); currentHash = BitConverter.ToString(hashBytes).Replace("-", "");
if (currentHash != hash) if (currentHash != hash)

View File

@@ -14,7 +14,7 @@
<SignAssembly>True</SignAssembly> <SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>D:\keyPair.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>D:\keyPair.snk</AssemblyOriginatorKeyFile>
<AnalysisLevel>6.0-all</AnalysisLevel> <AnalysisLevel>6.0-all</AnalysisLevel>
<Version>1.0.1</Version> <Version>1.0.2</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@@ -14,12 +14,12 @@ namespace OpenSaveCloudClient
public partial class SettingsForm : Form public partial class SettingsForm : Form
{ {
private readonly Configuration _configuration; private readonly UserConfiguration _configuration;
public SettingsForm() public SettingsForm()
{ {
InitializeComponent(); InitializeComponent();
_configuration = Configuration.GetInstance(); _configuration = UserConfiguration.Instance;
InitAndFillFields(); InitAndFillFields();
} }

View File

@@ -19,7 +19,7 @@ namespace OpenSaveCloudClient
public TasksForm() public TasksForm()
{ {
InitializeComponent(); InitializeComponent();
taskManager = TaskManager.GetInstance(); taskManager = TaskManager.Instance;
} }
private void AddLVItem(string key, string name, string status, bool undefined, int value, int max) private void AddLVItem(string key, string name, string status, bool undefined, int value, int max)

View File

@@ -20,7 +20,7 @@ namespace OpenSaveCloudClient
public UserForm() public UserForm()
{ {
InitializeComponent(); InitializeComponent();
serverConnector = ServerConnector.GetInstance(); serverConnector = ServerConnector.Instance;
} }
private void UserForm_Load(object sender, EventArgs e) private void UserForm_Load(object sender, EventArgs e)

View File

@@ -20,7 +20,7 @@ namespace OpenSaveCloudClient
public UserManagementForm() public UserManagementForm()
{ {
InitializeComponent(); InitializeComponent();
serverConnector = ServerConnector.GetInstance(); serverConnector = ServerConnector.Instance;
} }
private void UserSettingsButton_Click(object sender, EventArgs e) private void UserSettingsButton_Click(object sender, EventArgs e)

View File

@@ -82,6 +82,5 @@
private Label label1; private Label label1;
private PictureBox LoadingIndicator; private PictureBox LoadingIndicator;
private System.Windows.Forms.Timer timer1;
} }
} }

View File

@@ -19,7 +19,7 @@ namespace OpenSaveCloudClient
public WaitingForm() public WaitingForm()
{ {
InitializeComponent(); InitializeComponent();
taskManager = TaskManager.GetInstance(); taskManager = TaskManager.Instance;
taskManager.TaskChanged += OnTaskChanged; taskManager.TaskChanged += OnTaskChanged;
} }