Skip to content

Commit 2e17a52

Browse files
committed
Add my Local Commit
1 parent 1db8428 commit 2e17a52

File tree

9 files changed

+267
-153
lines changed

9 files changed

+267
-153
lines changed

Hi3HelperGUI/Classes/Data/BlockData.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class BlockData : XMFDictionaryClasses
2828

2929
#if DEBUG
3030
// 4 KiB buffer
31-
readonly byte[] buffer = new byte[4096];
31+
byte[] buffer = new byte[4096];
3232
#else
3333
// 512 KiB buffer
3434
readonly byte[] buffer = new byte[524288];
@@ -94,20 +94,18 @@ public void CheckIntegrity(PresetConfigClasses input, CancellationToken token)
9494
FileMode.Open,
9595
FileAccess.Read))
9696
{
97+
OnProgressChanged(new CheckingBlockProgressChangedStatus()
98+
{
99+
BlockHash = i.BlockHash,
100+
CurrentBlockPos = z,
101+
BlockCount = y
102+
});
103+
97104
foreach (XMFFileProperty j in i.BlockContent)
98105
{
99106
chunkSize = (int)j.FileSize;
100107
chunkBuffer = new MemoryStream();
101108

102-
OnProgressChanged(new CheckingBlockProgressChangedStatus()
103-
{
104-
BlockHash = i.BlockHash,
105-
ChunkHash = j.FileHash,
106-
ChunkName = j.FileName,
107-
CurrentBlockPos = z,
108-
BlockCount = y
109-
});
110-
111109
while (chunkSize > 0)
112110
{
113111
token.ThrowIfCancellationRequested();
@@ -117,7 +115,13 @@ public void CheckIntegrity(PresetConfigClasses input, CancellationToken token)
117115
chunkSize -= byteSize;
118116
}
119117

118+
/*
119+
token.ThrowIfCancellationRequested();
120+
_ = fileStream.Read(buffer = new byte[chunkSize], 0, chunkSize);
121+
*/
122+
120123
totalRead += j.FileSize;
124+
// totalRead += chunkSize;
121125

122126
chunkBuffer.Position = 0;
123127

@@ -217,7 +221,7 @@ public void BlockRepair(List<PresetConfigClasses> i, CancellationToken token)
217221
currentChunkPos = 0;
218222
currentBlockPos++;
219223
chunkCount = b.BlockContent.Count;
220-
downloadSize = b.BlockSize < b.BlockExistingSize ? b.BlockSize : (b.BlockSize - b.BlockExistingSize);
224+
downloadSize = b.BlockSize;
221225
blockHash = b.BlockHash;
222226
remotePath = $"{remoteAddress}{blockHash.ToLowerInvariant()}";
223227
localPath = Path.Combine(a.ActualGameDataLocation,
@@ -257,7 +261,7 @@ void RepairCorruptedBlock(in XMFBlockList blockProp, in FileInfo blockInfo, in C
257261
currentChunkPos++;
258262
chunkBuffer = new MemoryStream();
259263
fileStream.Position = chunkProp.StartOffset;
260-
DownloadContent($"{remotePath}.c/{chunkProp.FileName}", chunkBuffer, chunkProp, -1, -1, token,
264+
DownloadContent($"{remotePath}.wmv", chunkBuffer, chunkProp, chunkProp.StartOffset, chunkProp.StartOffset + chunkProp.FileSize, token,
261265
$"Down: {blockProp.BlockHash} Offset {NumberToHexString(chunkProp.StartOffset)} Size {NumberToHexString(chunkProp.FileSize)}");
262266

263267
OnProgressChanged(new RepairingBlockProgressChangedStatus()
@@ -377,8 +381,6 @@ private void DownloadEventConverter(object sender, DownloadProgressChanged e)
377381
public class CheckingBlockProgressChangedStatus : EventArgs
378382
{
379383
public string BlockHash { get; set; }
380-
public string ChunkName { get; set; }
381-
public string ChunkHash { get; set; }
382384
public int CurrentBlockPos { get; set; }
383385
public int BlockCount { get; set; }
384386
}
@@ -389,7 +391,6 @@ public class CheckingBlockProgressChanged : EventArgs
389391
public long ChunkSize { get; set; }
390392
public long BytesRead { get; set; }
391393
public long TotalBlockSize { get; set; }
392-
public float ProgressPercentage { get => ((float)BytesRead / (float)TotalBlockSize) * 100; }
393394
}
394395

395396
public class RepairingBlockProgressChangedStatus : EventArgs

Hi3HelperGUI/Classes/Data/Tools/HttpClientTool.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ void UseStream(string input, string output, long startOffset, long endOffset, st
116116
{
117117
token.ThrowIfCancellationRequested();
118118
long existingLength;
119+
long contentLength;
119120
FileInfo fileinfo = new(output);
120121

121122
if (isStream)
@@ -131,7 +132,12 @@ void UseStream(string input, string output, long startOffset, long endOffset, st
131132
request.Headers.Range = new RangeHeaderValue(existingLength, null);
132133

133134
using HttpResponseMessage response = httpClient.Send(request, HttpCompletionOption.ResponseHeadersRead, token);
134-
long contentLength = existingLength + (response.Content.Headers.ContentRange.Length - response.Content.Headers.ContentRange.From) ?? 0;
135+
136+
if (startOffset != -1 && endOffset != -1)
137+
contentLength = endOffset - startOffset;
138+
else
139+
contentLength = existingLength + (response.Content.Headers.ContentRange.Length - response.Content.Headers.ContentRange.From) ?? 0;
140+
135141
resumabilityStatus = new DownloadStatusChanged((int)response.StatusCode == 206);
136142

137143
if (!isStream)

Hi3HelperGUI/Classes/GUI/BlockSection.cs

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Windows.Threading;
34
using System.Threading;
45
using System.Threading.Tasks;
56
using System.IO;
67
using System.Windows;
8+
using Newtonsoft.Json;
79
using Hi3HelperGUI.Preset;
810
using Hi3HelperGUI.Data;
911

@@ -30,6 +32,7 @@ private void BlockCheckCancel(object sender, RoutedEventArgs e)
3032

3133
public async void DoBlockCheck()
3234
{
35+
ToggleBlockPlaceholder(false);
3336
BlockCheckTokenSource = new CancellationTokenSource();
3437
CancellationToken token = BlockCheckTokenSource.Token;
3538

@@ -41,11 +44,13 @@ public async void DoBlockCheck()
4144
{
4245
LogWriteLine($"Block Checking Cancelled!", LogType.Warning, true);
4346
ChangeBlockRepairStatus($"Block Checking Cancelled!", true);
47+
ToggleBlockPlaceholder(true);
4448
}
4549
}
4650

4751
public async void DoBlockRepair()
4852
{
53+
ToggleBlockPlaceholder(false);
4954
BlockCheckTokenSource = new CancellationTokenSource();
5055
CancellationToken token = BlockCheckTokenSource.Token;
5156

@@ -58,6 +63,9 @@ public async void DoBlockRepair()
5863
{
5964
LogWriteLine($"Block Repairing Cancelled!", LogType.Warning, true);
6065
ChangeBlockRepairStatus($"Block Repairing Cancelled!", true, false);
66+
blockData.DisposeAll();
67+
RefreshBlockTreeView();
68+
ToggleBlockPlaceholder(true);
6169
}
6270
}
6371

@@ -69,10 +77,8 @@ public async Task FetchBlockDictionary(CancellationToken token)
6977
await Task.Run(() =>
7078
{
7179
blockData.DisposeAll();
72-
Dispatcher.Invoke(() =>
73-
{
74-
BlockChunkTreeView.ItemsSource = blockData.BrokenBlocksRegion;
75-
});
80+
RefreshBlockTreeView();
81+
7682
foreach (PresetConfigClasses i in ConfigStore.Config)
7783
{
7884
blockDictStream = new MemoryStream();
@@ -109,17 +115,50 @@ await Task.Run(() =>
109115
blockData.CheckingProgressChangedStatus -= BlockProgressChanged;
110116

111117
blockDictStream.Dispose();
118+
119+
// File.WriteAllText(@"C:\Users\neon-nyan\Documents\git\myApp\Hi3Helper\test.json", JsonConvert.SerializeObject(blockData.BrokenBlocksRegion));
112120
}
113121

114122
blockData.DisposeAssets();
115123

116-
Dispatcher.Invoke(() =>
124+
RefreshBlockTreeView();
125+
});
126+
}
127+
128+
List<GameZoneName> BlockGenerateTreeView()
129+
{
130+
List<GameZoneName> zoneName = new();
131+
List<BlockName> blockName;
132+
List<ChunkProperties> chunkProperties;
133+
134+
foreach (KeyValuePair<string, List<XMFDictionaryClasses.XMFBlockList>> i in blockData.BrokenBlocksRegion)
135+
{
136+
blockName = new();
137+
foreach (XMFDictionaryClasses.XMFBlockList j in i.Value)
117138
{
118-
BlockChunkTreeView.ItemsSource = blockData.BrokenBlocksRegion;
139+
chunkProperties = new();
140+
foreach (XMFDictionaryClasses.XMFFileProperty k in j.BlockContent)
141+
{
142+
chunkProperties.Add(new ChunkProperties { ChunkOffset = $"0x{NumberToHexString(k.StartOffset)}", ChunkSize = $"0x{NumberToHexString(k.FileSize)}" });
143+
}
144+
blockName.Add(new BlockName {
145+
BlockHash = j.BlockHash,
146+
BlockStatus = $" [{(j.BlockMissing ? "Missing" : j.BlockExistingSize > 0 && j.BlockContent.Count == 0 ? "Incomplete" : $"{j.BlockContent.Count} Chunk(s)")}]",
147+
ChunkItems = chunkProperties
148+
});
149+
}
150+
zoneName.Add(new GameZoneName {
151+
ZoneName = i.Key,
152+
ZoneStatus = $" [{blockName.Count} Blocks]",
153+
BlockItems = blockName
119154
});
120-
});
155+
}
156+
157+
return zoneName;
121158
}
122159

160+
void RefreshBlockTreeView() => Dispatcher.Invoke(() => { BlockChunkTreeView.ItemsSource = BlockGenerateTreeView(); });
161+
123162
public async Task RunBlockRepair(CancellationToken token)
124163
{
125164
await Task.Run(() =>
@@ -131,6 +170,8 @@ await Task.Run(() =>
131170

132171
blockData.RepairingProgressChanged -= BlockProgressChanged;
133172
blockData.RepairingProgressChangedStatus -= BlockProgressChanged;
173+
blockData.DisposeAll();
174+
RefreshBlockTreeView();
134175
});
135176
}
136177
private void BlockProgressChanged(object sender, CheckingBlockProgressChangedStatus e)
@@ -176,6 +217,8 @@ private void BlockProgressChanged(object sender, RepairingBlockProgressChanged e
176217
}, DispatcherPriority.Background);
177218
}
178219

220+
private void ToggleBlockPlaceholder(bool a) => Dispatcher.Invoke(() => BlockSectionPlaceHolder.Visibility = a ? Visibility.Visible : Visibility.Collapsed);
221+
179222
private void RefreshBlockCheckProgressBar(double cur = 0, double max = 100)
180223
{
181224
Dispatcher.Invoke(() => {

Hi3HelperGUI/Classes/GUI/UpdateSection.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private async void FetchUpdateData()
3434
await Task.Run(() =>
3535
{
3636
(ConfigStore.UpdateFilesTotalSize, ConfigStore.UpdateFilesTotalDownloaded) = (0, 0);
37+
ToggleUpdatePlaceholder(false);
3738
RefreshUpdateProgressBar();
3839
ConfigStore.UpdateFiles = new List<UpdateDataProperties>();
3940
RefreshUpdateProgressLabel();
@@ -53,6 +54,7 @@ await Task.Run(() =>
5354
if (!(ConfigStore.UpdateFilesTotalSize > 0))
5455
{
5556
ChangeUpdateStatus($"Your files are already up-to-date!", true);
57+
ToggleUpdatePlaceholder(true);
5658
return;
5759
}
5860
ChangeUpdateStatus($"{ConfigStore.UpdateFiles.Count} files ({SummarizeSizeSimple(ConfigStore.UpdateFilesTotalSize)}) are ready to be updated. Click Download to start the update!", true);
@@ -124,6 +126,8 @@ await Task.Run(() => {
124126
return false;
125127
}
126128

129+
private void ToggleUpdatePlaceholder(bool a) => Dispatcher.Invoke(() => UpdateSectionPlaceHolder.Visibility = a ? Visibility.Visible : Visibility.Collapsed);
130+
127131
private void RefreshUpdateProgressLabel(string i = "none") => Dispatcher.Invoke(() => UpdateProgressLabel.Content = i);
128132

129133
// private void RefreshUpdateListView() => Dispatcher.Invoke(() => UpdateListView.Items.Refresh());

Hi3HelperGUI/Classes/Preset/Classes/XMFDictionaryClasses.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33

44
namespace Hi3HelperGUI.Preset
55
{
6+
public class ChunkProperties
7+
{
8+
public string ChunkOffset { get; set; }
9+
public string ChunkSize { get; set; }
10+
}
11+
12+
public class BlockName
13+
{
14+
public string BlockHash { get; set; }
15+
public string BlockStatus { get; set; }
16+
public List<ChunkProperties> ChunkItems { get; set; }
17+
}
18+
19+
public class GameZoneName
20+
{
21+
public string ZoneName { get; set; }
22+
public string ZoneStatus { get; set; }
23+
public List<BlockName> BlockItems { get; set; }
24+
}
25+
626
public class XMFDictionaryClasses
727
{
828
public class VersionFile

0 commit comments

Comments
 (0)