@@ -289,23 +289,18 @@ await EnsureDiskSpaceSufficiencyAsync(
289289 long sophonAssetLen = sophonAsset . AssetSize ;
290290 FileInfo filePath = new FileInfo ( assetFullPath + "_tempSophon" ) ;
291291 FileInfo origFilePath = new FileInfo ( assetFullPath ) ;
292-
292+
293293 // If the original file path exist and the length is the same as the asset size
294- // (means the file has already been downloaded, then return 0)
295- if ( origFilePath . Exists && origFilePath . Length == sophonAssetLen )
296- {
297- return 0L ;
298- }
299-
300- // If the temp file path exist and the length is the same as the asset size
301- // (means the file has already been downloaded, then return 0)
302- if ( filePath . Exists && filePath . Length == sophonAssetLen )
294+ // or if the temp file path exist and the length is the same as the asset size
295+ // (means the file has already been downloaded, then return sophonAssetLen)
296+ if ( ( origFilePath . Exists && origFilePath . Length == sophonAssetLen )
297+ || ( filePath . Exists && filePath . Length == sophonAssetLen ) )
303298 {
304- return 0L ;
299+ return sophonAssetLen ;
305300 }
306301
307- // If both orig and temp file don't exist or has different size, then return the asset size
308- return sophonAsset . AssetSize ;
302+ // If both orig and temp file don't exist or has different size, then return 0 as it doesn't exist
303+ return 0L ;
309304 } , ctx ,
310305 TaskCreationOptions . DenyChildAttach ,
311306 TaskScheduler . Default ) ;
@@ -362,21 +357,25 @@ await Task.Run(() =>
362357 token . ThrowIfCancellationRequested ( ) ;
363358
364359 // Get the file path and start the write process
365- string assetName = asset . AssetName ;
366- string assetFullPath = Path . Combine ( gameInstallPath , assetName ) ;
367- FileInfo filePath = new FileInfo ( assetFullPath + "_tempSophon" )
368- . EnsureCreationOfDirectory ( )
369- . EnsureNoReadOnly ( ) ;
370- FileInfo origFilePath = new FileInfo ( assetFullPath )
371- . EnsureNoReadOnly ( out bool isExist ) ;
372-
373- if ( ! isExist )
360+ var assetName = asset . AssetName ;
361+ var assetFullPath = Path . Combine ( gameInstallPath , assetName ) ;
362+ var tempFilePath = new FileInfo ( assetFullPath + "_tempSophon" )
363+ . EnsureCreationOfDirectory ( )
364+ . EnsureNoReadOnly ( out bool isExistTemp ) ;
365+
366+ // If the temp file is not exist, then return (ignore)
367+ if ( ! isExistTemp )
374368 {
375369 return ;
376370 }
377371
378- filePath . MoveTo ( origFilePath . FullName , true ) ;
379- filePath . Refresh ( ) ;
372+ // Get the original file path, ensure the existing file is not read only,
373+ // then move the temp file to the original file path
374+ var origFilePath = new FileInfo ( assetFullPath )
375+ . EnsureNoReadOnly ( ) ;
376+
377+ // Move the thing
378+ tempFilePath . MoveTo ( origFilePath . FullName , true ) ;
380379 origFilePath . Refresh ( ) ;
381380 } , token ) ;
382381 }
0 commit comments