Skip to content

Commit 66faf29

Browse files
committed
[GI Repair] Fix repair FileNotFoundException
1. Iterate between StreamingAssets and Persistent 2. If not found in both, add asset as "Missing" 3. If found in one but asked for other path, then move the asset to the correct path
1 parent 4037146 commit 66faf29

File tree

1 file changed

+43
-31
lines changed
  • CollapseLauncher/Classes/RepairManagement/Genshin

1 file changed

+43
-31
lines changed

CollapseLauncher/Classes/RepairManagement/Genshin/Check.cs

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -200,44 +200,28 @@ private async ValueTask CheckAssetAllType(PkgVersionProperties asset, List<PkgVe
200200
// Check if the persistent or streaming file doesn't exist
201201
if ((UsePersistent && !IsPersistentExist) || (!IsStreamingExist && !IsPersistentExist))
202202
{
203-
// Update the total progress and found counter
204-
_progressAllSizeFound += asset.fileSize;
205-
_progressAllCountFound++;
206-
207-
// Set the per size progress
208-
_progressPerFileSizeCurrent = asset.fileSize;
209-
210-
// Increment the total current progress
211-
_progressAllSizeCurrent += asset.fileSize;
212-
213-
Dispatch(() => AssetEntry.Add(
214-
new AssetProperty<RepairAssetType>(
215-
Path.GetFileName(repairFile),
216-
RepairAssetType.Generic,
217-
Path.GetDirectoryName(repairFile),
218-
asset.fileSize,
219-
null,
220-
HexTool.HexToBytesUnsafe(asset.md5)
221-
)
222-
));
223-
targetAssetIndex.Add(asset);
224-
225-
LogWriteLine($"File [T: {RepairAssetType.Generic}]: {(string.IsNullOrEmpty(repairFile) ? asset.localName : repairFile)} is not found or has unmatched size", LogType.Warning, true);
226-
return;
203+
AddNotFoundOrMismatchAsset(asset);
204+
}
205+
206+
// Iterate between Persistent and StreamingAssets folder if it sees the file is not exist
207+
var file = UsePersistent ? fileInfoPersistent : fileInfoStreaming;
208+
if (!file!.Exists)
209+
{
210+
file = !UsePersistent ? fileInfoPersistent! : fileInfoStreaming;
211+
if (!file.Exists) AddNotFoundOrMismatchAsset(asset);
212+
213+
var origFilePath = UsePersistent ? fileInfoPersistent.FullName : fileInfoStreaming.FullName;
214+
file.MoveTo(origFilePath); // Move the file to the correct path
215+
LogWriteLine($"[CheckAssetAllType] Moving files to their correct path\r\n\t" +
216+
$"Current path: {file.FullName}\r\n\t" +
217+
$"Target path : {origFilePath}", LogType.Default, true);
227218
}
228219

229220
// Skip CRC check if fast method is used
230221
if (_useFastMethod)
231222
{
232223
return;
233224
}
234-
235-
var file = UsePersistent ? fileInfoPersistent : fileInfoStreaming;
236-
if (!file.Exists)
237-
{
238-
file = !UsePersistent ? fileInfoPersistent! : fileInfoStreaming;
239-
if (file.Exists) throw new FileNotFoundException(file.FullName);
240-
}
241225

242226
try
243227
{
@@ -309,6 +293,34 @@ await NaivelyOpenFileStreamAsync(file,
309293
targetAssetIndex.Add(asset);
310294
LogWriteLine($"File [T: {asset.type}]: {repairFile} is not found or has unmatched size", LogType.Warning, true);
311295
}
296+
297+
void AddNotFoundOrMismatchAsset(PkgVersionProperties assetInner)
298+
{
299+
// Update the total progress and found counter
300+
_progressAllSizeFound += assetInner.fileSize;
301+
_progressAllCountFound++;
302+
303+
// Set the per size progress
304+
_progressPerFileSizeCurrent = assetInner.fileSize;
305+
306+
// Increment the total current progress
307+
_progressAllSizeCurrent += assetInner.fileSize;
308+
309+
Dispatch(() => AssetEntry.Add(
310+
new AssetProperty<RepairAssetType>(
311+
Path.GetFileName(repairFile),
312+
RepairAssetType.Generic,
313+
Path.GetDirectoryName(repairFile),
314+
assetInner.fileSize,
315+
null,
316+
HexTool.HexToBytesUnsafe(assetInner.md5)
317+
)
318+
));
319+
targetAssetIndex.Add(assetInner);
320+
321+
LogWriteLine($"File [T: {RepairAssetType.Generic}]: {(string.IsNullOrEmpty(repairFile) ? assetInner.localName : repairFile)} is not found or has unmatched size",
322+
LogType.Warning, true);
323+
}
312324
}
313325

314326
#region UnusedFiles

0 commit comments

Comments
 (0)