Skip to content

Commit 75ade31

Browse files
committed
switched from md5 to sha256
1 parent 45eed30 commit 75ade31

File tree

18 files changed

+213
-239
lines changed

18 files changed

+213
-239
lines changed

src/Avalonia.Desktop/UserControls/Editor/EditorFileFixControl.axaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@
286286
Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
287287
</Grid>
288288

289-
<!--File MD5-->
289+
<!--File hash-->
290290
<Grid>
291291
<Grid.ColumnDefinitions>
292292
<ColumnDefinition Width="auto" SharedSizeGroup="MySizeGroup" />
@@ -296,10 +296,10 @@
296296
<TextBlock VerticalAlignment="Center"
297297
Grid.Column="0"
298298
Margin="5">
299-
MD5
299+
Hash
300300
</TextBlock>
301301

302-
<TextBox Text="{Binding SelectedFixMD5, Mode=TwoWay}"
302+
<TextBox Text="{Binding SelectedFixHash, Mode=TwoWay}"
303303
Margin="0,3"
304304
Grid.Column="1"
305305
IsEnabled="{Binding #LinkToFile.Text,

src/Avalonia.Desktop/ViewModels/Editor/FileFixViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ public string? SelectedFixFileSize
159159
}
160160
}
161161

162-
public string? SelectedFixMD5
162+
public string? SelectedFixHash
163163
{
164-
get => SelectedFix.MD5;
164+
get => SelectedFix.Sha256;
165165
set
166166
{
167-
SelectedFix.MD5 = string.IsNullOrWhiteSpace(value) ? null : value;
167+
SelectedFix.Sha256 = string.IsNullOrWhiteSpace(value) ? null : value;
168168
OnPropertyChanged();
169169
}
170170
}

src/Avalonia.Desktop/ViewModels/MainViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ Do you want to install them?
965965
result = await _fixManager.InstallFixAsync(fixesList.Game, fix, fixVariant, false, _cancellationTokenSource.Token).ConfigureAwait(true);
966966
}
967967

968-
if (result == ResultEnum.MD5Error)
968+
if (result == ResultEnum.HashError)
969969
{
970970
var popupResult = await _popupMessage.ShowAndGetResultAsync(
971971
"Warning",

src/Common.Axiom/Entities/Fixes/FileFix/FileFixEntity.cs

Lines changed: 81 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,65 +10,6 @@ namespace Common.Axiom.Entities.Fixes.FileFix;
1010
/// </summary>
1111
public sealed class FileFixEntity : BaseFixEntity
1212
{
13-
public FileFixEntity()
14-
{
15-
}
16-
17-
[SetsRequiredMembers]
18-
public FileFixEntity(bool _)
19-
{
20-
Name = string.Empty;
21-
Version = "1.0";
22-
Guid = Guid.NewGuid();
23-
Description = null;
24-
Changelog = null;
25-
Dependencies = null;
26-
Tags = null;
27-
SupportedOSes = OSEnum.Windows;
28-
IsDisabled = false;
29-
30-
Url = null;
31-
FileSize = null;
32-
InstallFolder = null;
33-
ConfigFile = null;
34-
FilesToDelete = null;
35-
FilesToBackup = null;
36-
FilesToPatch = null;
37-
RunAfterInstall = null;
38-
MD5 = null;
39-
SharedFixGuid = null;
40-
SharedFix = null;
41-
SharedFixInstallFolder = null;
42-
WineDllOverrides = null;
43-
}
44-
45-
[SetsRequiredMembers]
46-
public FileFixEntity(BaseFixEntity fix)
47-
{
48-
Name = fix.Name;
49-
Version = fix.Version;
50-
Guid = fix.Guid;
51-
Description = fix.Description;
52-
Changelog = fix.Changelog;
53-
Dependencies = fix.Dependencies;
54-
Tags = fix.Tags;
55-
SupportedOSes = fix.SupportedOSes;
56-
IsDisabled = fix.IsDisabled;
57-
58-
Url = null;
59-
FileSize = null;
60-
InstallFolder = null;
61-
ConfigFile = null;
62-
FilesToDelete = null;
63-
FilesToBackup = null;
64-
RunAfterInstall = null;
65-
MD5 = null;
66-
SharedFixGuid = null;
67-
SharedFix = null;
68-
SharedFixInstallFolder = null;
69-
WineDllOverrides = null;
70-
}
71-
7213
/// <summary>
7314
/// Download URL
7415
/// </summary>
@@ -141,8 +82,14 @@ public string? RunAfterInstall
14182
/// <summary>
14283
/// Zip archive MD5
14384
/// </summary>
85+
[Obsolete]
14486
public string? MD5 { get; set; }
14587

88+
/// <summary>
89+
/// Zip archive MD5
90+
/// </summary>
91+
public string? Sha256 { get; set; }
92+
14693
/// <summary>
14794
/// List of files that will be backed up and patched with filename.octodiff patch
14895
/// </summary>
@@ -205,6 +152,73 @@ public override bool IsOutdated
205152
}
206153
}
207154

155+
156+
public FileFixEntity()
157+
{
158+
}
159+
160+
161+
[SetsRequiredMembers]
162+
public FileFixEntity(BaseFixEntity fix)
163+
{
164+
Name = fix.Name;
165+
Version = fix.Version;
166+
Guid = fix.Guid;
167+
Description = fix.Description;
168+
Changelog = fix.Changelog;
169+
Dependencies = fix.Dependencies;
170+
Tags = fix.Tags;
171+
SupportedOSes = fix.SupportedOSes;
172+
IsDisabled = fix.IsDisabled;
173+
174+
Url = null;
175+
FileSize = null;
176+
InstallFolder = null;
177+
ConfigFile = null;
178+
FilesToDelete = null;
179+
FilesToBackup = null;
180+
RunAfterInstall = null;
181+
MD5 = null;
182+
Sha256 = null;
183+
SharedFixGuid = null;
184+
SharedFix = null;
185+
SharedFixInstallFolder = null;
186+
WineDllOverrides = null;
187+
}
188+
189+
190+
public static FileFixEntity CreateBlank()
191+
{
192+
return new()
193+
{
194+
Name = string.Empty,
195+
Version = "1.0",
196+
Guid = Guid.NewGuid(),
197+
Description = null,
198+
Changelog = null,
199+
Dependencies = null,
200+
Tags = null,
201+
SupportedOSes = OSEnum.Windows,
202+
IsDisabled = false,
203+
204+
Url = null,
205+
FileSize = null,
206+
InstallFolder = null,
207+
ConfigFile = null,
208+
FilesToDelete = null,
209+
FilesToBackup = null,
210+
FilesToPatch = null,
211+
RunAfterInstall = null,
212+
MD5 = null,
213+
Sha256 = null,
214+
SharedFixGuid = null,
215+
SharedFix = null,
216+
SharedFixInstallFolder = null,
217+
WineDllOverrides = null
218+
};
219+
}
220+
221+
208222
public FileFixEntity Clone()
209223
{
210224
return new()
@@ -213,21 +227,22 @@ public FileFixEntity Clone()
213227
Version = this.Version,
214228
Guid = this.Guid,
215229
Description = this.Description,
216-
Dependencies = this.Dependencies,
217-
Tags = this.Tags,
230+
Dependencies = this.Dependencies?.ToList(),
231+
Tags = this.Tags?.ToList(),
218232
SupportedOSes = this.SupportedOSes,
219233
Url = this.Url,
220234
InstallFolder = this.InstallFolder,
221235
ConfigFile = this.ConfigFile,
222-
FilesToDelete = this.FilesToDelete,
223-
FilesToBackup = this.FilesToBackup,
224-
FilesToPatch = this.FilesToPatch,
236+
FilesToDelete = this.FilesToDelete?.ToList(),
237+
FilesToBackup = this.FilesToBackup?.ToList(),
238+
FilesToPatch = this.FilesToPatch?.ToList(),
225239
RunAfterInstall = this.RunAfterInstall,
226240
MD5 = this.MD5,
241+
Sha256 = this.Sha256,
227242
SharedFixGuid = this.SharedFixGuid,
228-
SharedFix = this.SharedFix,
243+
SharedFix = this.SharedFix?.Clone(),
229244
SharedFixInstallFolder = this.SharedFixInstallFolder,
230-
WineDllOverrides = this.WineDllOverrides,
245+
WineDllOverrides = this.WineDllOverrides?.ToList(),
231246
FileSize = this.FileSize
232247
};
233248
}

src/Common.Axiom/Helpers/CommonConstants.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ namespace Common.Axiom.Helpers;
22

33
public static class CommonConstants
44
{
5-
public const string S3Endpoint = "https://s3.firstvds.ru/";
5+
public const string S3Endpoint = "https://s3-nl.hostkey.com";
66

7-
/// <summary>
8-
/// Path to the files repository
9-
/// </summary>
10-
public const string BucketAddress = $"{S3Endpoint}superheater/";
7+
public const string S3Bucket = "b8743306-fgsfds";
118

12-
/// <summary>
13-
/// Path to the uploads repository
14-
/// </summary>
15-
public const string UploadsFolder = $"{S3Endpoint}uploads/superheater/";
9+
public const string S3Folder = "superheater";
1610

1711
public const string FixesJsonUrl = "https://raw.githubusercontent.com/fgsfds/Steam-Superheater/refs/heads/master/db/fixes.json";
1812

src/Common.Axiom/Result.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ public enum ResultEnum : byte
138138
/// </summary>
139139
Success,
140140
/// <summary>
141-
/// Error while validating MD5
141+
/// Error while validating hash
142142
/// </summary>
143-
MD5Error,
143+
HashError,
144144
/// <summary>
145145
/// Something not found
146146
/// </summary>

src/Common.Client/AppUpdateInstaller.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public async Task DownloadAndUnpackLatestRelease(CancellationToken cancellationT
7171
File.Delete(fileName);
7272
}
7373

74-
_ = await _filesDownloader.CheckAndDownloadFileAsync(updateUrl, fileName, cancellationToken).ConfigureAwait(false);
74+
_ = await _filesDownloader.DownloadFileAsync(updateUrl, fileName, cancellationToken).ConfigureAwait(false);
7575

7676
ZipFile.ExtractToDirectory(fileName, Path.Combine(ClientProperties.WorkingFolder, ClientConstants.UpdateFolder), true);
7777

src/Common.Client/FilesTools/FilesDownloader.cs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Net.Http.Headers;
2-
using System.Security.Cryptography;
32
using Common.Axiom;
43
using Common.Client.FilesTools.Interfaces;
54
using Microsoft.Extensions.Logging;
@@ -24,15 +23,14 @@ ILogger logger
2423
}
2524

2625
/// <inheritdoc/>
27-
public async Task<Result> CheckAndDownloadFileAsync(
26+
public async Task<Result> DownloadFileAsync(
2827
Uri url,
2928
string filePath,
3029
CancellationToken cancellationToken
3130
)
3231
{
3332
_logger.LogInformation($"Started downloading file {url}");
3433

35-
IProgress<float> progress = _progressReport.Progress;
3634
var tempFile = filePath + ".temp";
3735

3836
if (File.Exists(tempFile))
@@ -113,47 +111,6 @@ CancellationToken cancellationToken
113111
return new(ResultEnum.Success, string.Empty);
114112
}
115113

116-
public async Task<Result> CheckFileHashAsync(string filePath, string hash, CancellationToken cancellationToken)
117-
{
118-
FileInfo fileInfo = new(filePath);
119-
var contentLength = fileInfo.Length;
120-
121-
if (contentLength > 1e+9)
122-
{
123-
_progressReport.OperationMessage = "Checking hash... This may take a while. Press Cancel to skip.";
124-
}
125-
else
126-
{
127-
_progressReport.OperationMessage = "Checking hash...";
128-
}
129-
130-
try
131-
{
132-
using var md5 = MD5.Create();
133-
await using var stream = File.OpenRead(filePath);
134-
135-
var fileHash = Convert.ToHexString(await md5.ComputeHashAsync(stream, cancellationToken).ConfigureAwait(false));
136-
137-
if (!hash.Equals(fileHash, StringComparison.OrdinalIgnoreCase))
138-
{
139-
return new(ResultEnum.MD5Error, "File's hash doesn't match the database");
140-
}
141-
}
142-
catch (OperationCanceledException)
143-
{
144-
_logger.LogInformation("Hash checking cancelled");
145-
//do nothing
146-
}
147-
catch (Exception ex)
148-
{
149-
_progressReport.OperationMessage = string.Empty;
150-
return new(ResultEnum.Error, ex.ToString());
151-
}
152-
153-
_progressReport.OperationMessage = string.Empty;
154-
return new(ResultEnum.Success, string.Empty);
155-
}
156-
157114

158115
/// <summary>
159116
/// Continue download after network error

src/Common.Client/FilesTools/Interfaces/IFilesDownloader.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ public interface IFilesDownloader
1010
/// <param name="url">Link to file download</param>
1111
/// <param name="filePath">Absolute path to destination file</param>
1212
/// <param name="cancellationToken"></param>
13-
Task<Result> CheckAndDownloadFileAsync(Uri url, string filePath, CancellationToken cancellationToken);
14-
Task<Result> CheckFileHashAsync(string filePath, string hash, CancellationToken cancellationToken);
13+
Task<Result> DownloadFileAsync(Uri url, string filePath, CancellationToken cancellationToken);
1514
}

0 commit comments

Comments
 (0)