From 2a7c1c8268630fab6a6c0a2650fcff688da04128 Mon Sep 17 00:00:00 2001 From: Nuclearist Date: Fri, 26 Jan 2024 10:40:23 +0300 Subject: [PATCH] Replaced Path.Combine with Path.Join --- src/AppManager.cs | 58 +++++++++++++++++++++++------------------------ src/CDNClient.cs | 28 +++++++++++------------ 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/AppManager.cs b/src/AppManager.cs index aa63383..ea87e5d 100644 --- a/src/AppManager.cs +++ b/src/AppManager.cs @@ -20,12 +20,12 @@ public AppManager(uint appId, string installationPath, [Optional]string? worksho { AppId = appId; InstallationPath = installationPath; - _scDataPath = Path.Combine(installationPath, "SCData"); - WorkshopContentPath = workshopContentPath ?? Path.Combine(_scDataPath, "Workshop"); + _scDataPath = Path.Join(installationPath, "SCData"); + WorkshopContentPath = workshopContentPath ?? Path.Join(_scDataPath, "Workshop"); CdnClient = new() { - DownloadsDirectory = Path.Combine(_scDataPath, "Downloads"), - ManifestsDirectory = Path.Combine(_scDataPath, "Manifests"), + DownloadsDirectory = Path.Join(_scDataPath, "Downloads"), + ManifestsDirectory = Path.Join(_scDataPath, "Manifests"), CmClient = CmClient }; CdnClient.ProgressInitiated += (type, totalValue, initialValue) => ProgressInitiated?.Invoke(type, totalValue, initialValue); @@ -72,7 +72,7 @@ public AppManager(uint appId, string installationPath, [Optional]string? worksho /// Token to monitor for cancellation requests. private void Commit(ItemState state, DepotManifest? sourceManifest, DepotManifest targetManifest, DepotPatch? patch, DepotDelta delta, CancellationToken cancellationToken) { - string localPath = state.Id.WorkshopItemId is 0 ? InstallationPath : Path.Combine(WorkshopContentPath, state.Id.WorkshopItemId.ToString()); + string localPath = state.Id.WorkshopItemId is 0 ? InstallationPath : Path.Join(WorkshopContentPath, state.Id.WorkshopItemId.ToString()); if (state.Status <= ItemState.ItemStatus.Patching && delta.NumTransferOperations > 0) PatchAndRelocateChunks(state, localPath, sourceManifest!, targetManifest, patch, delta, cancellationToken); if (state.Status <= ItemState.ItemStatus.WritingNewData) @@ -115,7 +115,7 @@ void processDir(in DirectoryEntry.AuxiliaryEntry dir, string path, int recursion return; } var file = targetManifest.FileBuffer[auxiliaryFile.Index]; - string filePath = Path.Combine(path, file.Name); + string filePath = Path.Join(path, file.Name); var attributes = File.GetAttributes(filePath); if (attributes.HasFlag(FileAttributes.ReadOnly)) File.SetAttributes(filePath, attributes & ~FileAttributes.ReadOnly); @@ -272,7 +272,7 @@ void processDir(in DirectoryEntry.AuxiliaryEntry dir, string path, int recursion var subdir = dir.Subdirectories[index]; if (subdir.FilesToRemove.HasValue && subdir.FilesToRemove.Value.Count is 0) continue; - processDir(in subdir, Path.Combine(path, targetManifest.DirectoryBuffer[subdir.Index].Name), recursionLevel + 1); + processDir(in subdir, Path.Join(path, targetManifest.DirectoryBuffer[subdir.Index].Name), recursionLevel + 1); if (cancellationToken.IsCancellationRequested) { state.ProgressIndexStack[recursionLevel] = dir.Files.Count + index; @@ -290,7 +290,7 @@ void processDir(in DirectoryEntry.AuxiliaryEntry dir, string path, int recursion StatusUpdated?.Invoke(Status.Patching); ProgressInitiated?.Invoke(ProgressType.Percentage, delta.NumTransferOperations, state.DisplayProgress); if (delta.IntermediateFileSize > 0) - intermediateFileHandle = File.OpenHandle(Path.Combine(CdnClient.DownloadsDirectory!, $"{state.Id}.screlocpatchcache"), FileMode.OpenOrCreate, FileAccess.ReadWrite, options: FileOptions.SequentialScan); + intermediateFileHandle = File.OpenHandle(Path.Join(CdnClient.DownloadsDirectory!, $"{state.Id}.screlocpatchcache"), FileMode.OpenOrCreate, FileAccess.ReadWrite, options: FileOptions.SequentialScan); processDir(in delta.AuxiliaryTree, localPath, 0); intermediateFileHandle?.Dispose(); if (cancellationToken.IsCancellationRequested) @@ -299,7 +299,7 @@ void processDir(in DirectoryEntry.AuxiliaryEntry dir, string path, int recursion throw new OperationCanceledException(cancellationToken); } if (delta.IntermediateFileSize > 0) - File.Delete(Path.Combine(CdnClient.DownloadsDirectory!, $"{state.Id}.screlocpatchcache")); + File.Delete(Path.Join(CdnClient.DownloadsDirectory!, $"{state.Id}.screlocpatchcache")); } /// Deletes files and directories that have been removed from the target manifest. /// State of the item. @@ -330,7 +330,7 @@ void processDir(in DirectoryEntry.AuxiliaryEntry dir, string path, int recursion state.ProgressIndexStack[recursionLevel] = index; return; } - File.Delete(Path.Combine(path, sourceManifest.FileBuffer[filesToRemove[index]].Name)); + File.Delete(Path.Join(path, sourceManifest.FileBuffer[filesToRemove[index]].Name)); ProgressUpdated?.Invoke(++state.DisplayProgress); } index -= dir.Files.Count; @@ -345,11 +345,11 @@ void processDir(in DirectoryEntry.AuxiliaryEntry dir, string path, int recursion var subdir = dir.Subdirectories[index]; if (subdir.FilesToRemove.HasValue && subdir.FilesToRemove.Value.Count is 0) { - Directory.Delete(Path.Combine(path, sourceManifest.DirectoryBuffer[subdir.Index].Name), true); + Directory.Delete(Path.Join(path, sourceManifest.DirectoryBuffer[subdir.Index].Name), true); ProgressUpdated?.Invoke(++state.DisplayProgress); continue; } - processDir(in subdir, Path.Combine(path, targetManifest.DirectoryBuffer[subdir.Index].Name), recursionLevel + 1); + processDir(in subdir, Path.Join(path, targetManifest.DirectoryBuffer[subdir.Index].Name), recursionLevel + 1); if (cancellationToken.IsCancellationRequested) { state.ProgressIndexStack[recursionLevel] = dir.Files.Count + index; @@ -420,10 +420,10 @@ static long countTotalDirSize(in DirectoryEntry dir) var file = manifest.FileBuffer[acquisitonFile.Index]; if (acquisitonFile.Chunks.Count is 0) { - string destinationFile = Path.Combine(localPath, file.Name); + string destinationFile = Path.Join(localPath, file.Name); if (File.Exists(destinationFile)) File.Delete(destinationFile); - File.Move(Path.Combine(downloadPath, file.Name), destinationFile); + File.Move(Path.Join(downloadPath, file.Name), destinationFile); if (file.Flags is not 0) { var attributes = (FileAttributes)0; @@ -450,7 +450,7 @@ static long countTotalDirSize(in DirectoryEntry dir) state.ProgressIndexStack.Add(0); chunkIndex = 0; } - string filePath = Path.Combine(localPath, file.Name); + string filePath = Path.Join(localPath, file.Name); var attributes = File.GetAttributes(filePath); if (attributes.HasFlag(FileAttributes.ReadOnly)) File.SetAttributes(filePath, attributes & ~FileAttributes.ReadOnly); @@ -479,7 +479,7 @@ static long countTotalDirSize(in DirectoryEntry dir) { var subdir = dir.Subdirectories[index]; string subdirName = manifest.DirectoryBuffer[subdir.Index].Name; - writeDir(in subdir, Path.Combine(downloadPath, subdirName), Path.Combine(localPath, subdirName), recursionLevel + 1); + writeDir(in subdir, Path.Join(downloadPath, subdirName), Path.Join(localPath, subdirName), recursionLevel + 1); if (cancellationToken.IsCancellationRequested) { state.ProgressIndexStack[recursionLevel] = dir.Files.Count + index; @@ -497,19 +497,19 @@ static long countTotalDirSize(in DirectoryEntry dir) StatusUpdated?.Invoke(Status.WritingNewData); ProgressInitiated?.Invoke(ProgressType.Binary, delta.DownloadCacheSize - delta.IntermediateFileSize, state.DisplayProgress); if (delta.ChunkBufferFileSize > 0) - chunkBufferFileHandle = File.OpenHandle(Path.Combine(CdnClient.DownloadsDirectory!, $"{state.Id}.scchunkbuffer"), options: FileOptions.SequentialScan); - writeDir(in delta.AcquisitionTree, Path.Combine(CdnClient.DownloadsDirectory!, state.Id.ToString()), localPath, 0); + chunkBufferFileHandle = File.OpenHandle(Path.Join(CdnClient.DownloadsDirectory!, $"{state.Id}.scchunkbuffer"), options: FileOptions.SequentialScan); + writeDir(in delta.AcquisitionTree, Path.Join(CdnClient.DownloadsDirectory!, state.Id.ToString()), localPath, 0); chunkBufferFileHandle?.Dispose(); if (cancellationToken.IsCancellationRequested) { state.SaveToFile(); throw new OperationCanceledException(cancellationToken); } - string downloadDirPath = Path.Combine(CdnClient.DownloadsDirectory!, state.Id.ToString()); + string downloadDirPath = Path.Join(CdnClient.DownloadsDirectory!, state.Id.ToString()); if (Directory.Exists(downloadDirPath)) Directory.Delete(downloadDirPath, true); if (delta.ChunkBufferFileSize > 0) - File.Delete(Path.Combine(CdnClient.DownloadsDirectory!, $"{state.Id}.scchunkbuffer")); + File.Delete(Path.Join(CdnClient.DownloadsDirectory!, $"{state.Id}.scchunkbuffer")); } /// Computes difference between source and target manifests' contents /// Source manifest to compute difference from. @@ -833,7 +833,7 @@ static void addSubdir(DirectoryEntry.AcquisitionStaging acquisitionDir, in Direc /// Depot delta object containing index tree for missing chunks. private DepotDelta Validate(ItemState state, DepotManifest manifest, CancellationToken cancellationToken) { - string cachePath = Path.Combine(CdnClient.DownloadsDirectory!, $"{manifest.Item}-{manifest.Id}.scvcache"); + string cachePath = Path.Join(CdnClient.DownloadsDirectory!, $"{manifest.Item}-{manifest.Id}.scvcache"); var cache = File.Exists(cachePath) ? new ValidationCache(cachePath) : new(); byte[] buffer = GC.AllocateUninitializedArray(0x100000); void copyDirToStagingAndCount(in DirectoryEntry directory, DirectoryEntry.AcquisitionStaging stagingDir) @@ -892,7 +892,7 @@ void validateDir(in DirectoryEntry directory, DirectoryEntry.AcquisitionStaging } int absFileIndex = dirFileOffset + index; var file = directory.Files[index]; - string filePath = Path.Combine(path, file.Name); + string filePath = Path.Join(path, file.Name); if (!File.Exists(filePath)) { stagingDir.Files.Add(new(absFileIndex)); @@ -957,7 +957,7 @@ void validateDir(in DirectoryEntry directory, DirectoryEntry.AcquisitionStaging int absSubdirIndex = dirSubdirOffset + index; var subdir = directory.Subdirectories[index]; var stagingSubdir = continueType is 2 ? (stagingDir.Subdirectories.Find(sd => sd.Index == absSubdirIndex) ?? new DirectoryEntry.AcquisitionStaging(absSubdirIndex, false)) : new DirectoryEntry.AcquisitionStaging(absSubdirIndex, false); - validateDir(in subdir, stagingSubdir, Path.Combine(path, subdir.Name), recursionLevel + 1); + validateDir(in subdir, stagingSubdir, Path.Join(path, subdir.Name), recursionLevel + 1); if (continueType is 2) continueType = 0; else if (stagingSubdir.IsNew || stagingSubdir.Files.Count > 0 || stagingSubdir.Subdirectories.Count > 0) @@ -971,7 +971,7 @@ void validateDir(in DirectoryEntry directory, DirectoryEntry.AcquisitionStaging state.ProgressIndexStack.RemoveAt(recursionLevel); return; } - string basePath = state.Id.WorkshopItemId is 0 ? InstallationPath : Path.Combine(WorkshopContentPath, state.Id.WorkshopItemId.ToString()); + string basePath = state.Id.WorkshopItemId is 0 ? InstallationPath : Path.Join(WorkshopContentPath, state.Id.WorkshopItemId.ToString()); if (state.Status is not ItemState.ItemStatus.Validating) { state.Status = ItemState.ItemStatus.Validating; @@ -1012,7 +1012,7 @@ public bool Update(ItemIdentifier item, CancellationToken cancellationToken, [Op targetManifestId = CmClient.GetWorkshopItemManifestId(AppId, item.WorkshopItemId); } } - var state = new ItemState(item, Path.Combine(_scDataPath, $"{item}.scitemstate")); + var state = new ItemState(item, Path.Join(_scDataPath, $"{item}.scitemstate")); if (state.CurrentManifestId is 0) return Validate(item, cancellationToken, targetManifestId); //Cannot update when source version is unknown if (state.CurrentManifestId == targetManifestId) @@ -1022,7 +1022,7 @@ public bool Update(ItemIdentifier item, CancellationToken cancellationToken, [Op var patch = CmClient.GetPatchAvailability(AppId, item.DepotId, sourceManifest.Id, targetManifest.Id) ? CdnClient.GetPatch(AppId, item, sourceManifest, targetManifest, cancellationToken) : null; - string deltaFilePath = Path.Combine(CdnClient.DownloadsDirectory!, $"{item}-{sourceManifest.Id}-{targetManifest.Id}.scdelta"); + string deltaFilePath = Path.Join(CdnClient.DownloadsDirectory!, $"{item}-{sourceManifest.Id}-{targetManifest.Id}.scdelta"); DepotDelta delta; if (state.Status < ItemState.ItemStatus.Preallocating) { @@ -1043,7 +1043,7 @@ public bool Update(ItemIdentifier item, CancellationToken cancellationToken, [Op state.SaveToFile(); File.Delete(deltaFilePath); if (patch is not null) - File.Delete(Path.Combine(CdnClient.DownloadsDirectory!, $"{item}-{sourceManifest.Id}-{targetManifest.Id}.scpatch")); + File.Delete(Path.Join(CdnClient.DownloadsDirectory!, $"{item}-{sourceManifest.Id}-{targetManifest.Id}.scpatch")); return false; } /// Verifies item files, downloads and installs missing data. @@ -1067,9 +1067,9 @@ public bool Validate(ItemIdentifier item, CancellationToken cancellationToken, [ manifestId = CmClient.GetWorkshopItemManifestId(AppId, item.WorkshopItemId); } } - var state = new ItemState(item, Path.Combine(_scDataPath, $"{item}.scitemstate")); + var state = new ItemState(item, Path.Join(_scDataPath, $"{item}.scitemstate")); var manifest = CdnClient.GetManifest(AppId, item, manifestId, cancellationToken); - string deltaFilePath = Path.Combine(CdnClient.DownloadsDirectory!, $"{item}-{manifestId}.scdelta"); + string deltaFilePath = Path.Join(CdnClient.DownloadsDirectory!, $"{item}-{manifestId}.scdelta"); DepotDelta delta; if (state.Status <= ItemState.ItemStatus.Validating) { diff --git a/src/CDNClient.cs b/src/CDNClient.cs index 2d685d1..5f0f7df 100644 --- a/src/CDNClient.cs +++ b/src/CDNClient.cs @@ -184,7 +184,7 @@ void downloadDir(in DirectoryEntry.AcquisitionEntry dir, string path, int recurs } if (acquisitonFile.Chunks.Count is 0) { - string filePath = Path.Combine(path, file.Name); + string filePath = Path.Join(path, file.Name); var chunks = file.Chunks; LimitedUseFileHandle? handle; if (numResumedContexts > 0) @@ -336,7 +336,7 @@ void downloadDir(in DirectoryEntry.AcquisitionEntry dir, string path, int recurs for (; index < dir.Subdirectories.Count; index++) { var subdir = dir.Subdirectories[index]; - downloadDir(in subdir, Path.Combine(path, manifest.DirectoryBuffer[subdir.Index].Name), recursionLevel + 1); + downloadDir(in subdir, Path.Join(path, manifest.DirectoryBuffer[subdir.Index].Name), recursionLevel + 1); if (linkedCts.IsCancellationRequested) { state.ProgressIndexStack[recursionLevel] = dir.Files.Count + index; @@ -369,11 +369,11 @@ void downloadDir(in DirectoryEntry.AcquisitionEntry dir, string path, int recurs contexts[i] = new(threadSafeProgress, httpClients[i % httpClients.Length], linkedCts.Token); contexts[i].Aes.Key = decryptionKey; } - string dwContextsFilePath = Path.Combine(DownloadsDirectory!, $"{state.Id}.scdwcontexts"); + string dwContextsFilePath = Path.Join(DownloadsDirectory!, $"{state.Id}.scdwcontexts"); ProgressInitiated?.Invoke(ProgressType.Binary, delta.DownloadSize, state.DisplayProgress); if (delta.ChunkBufferFileSize > 0) { - chunkBufferFilePath = Path.Combine(DownloadsDirectory!, $"{state.Id}.scchunkbuffer"); + chunkBufferFilePath = Path.Join(DownloadsDirectory!, $"{state.Id}.scchunkbuffer"); chunkBufferFileHandle = new(File.OpenHandle(chunkBufferFilePath, FileMode.OpenOrCreate, FileAccess.Write, options: FileOptions.RandomAccess | FileOptions.Asynchronous), int.MaxValue); } if (File.Exists(dwContextsFilePath)) @@ -410,7 +410,7 @@ void downloadDir(in DirectoryEntry.AcquisitionEntry dir, string path, int recurs for (int i = 0; i < numResumedContexts; i++) tasks[i] = Task.Factory.StartNew(AcquireChunk, contexts[i], TaskCreationOptions.DenyChildAttach); } - downloadDir(in delta.AcquisitionTree, Path.Combine(DownloadsDirectory!, state.Id.ToString()), 0); + downloadDir(in delta.AcquisitionTree, Path.Join(DownloadsDirectory!, state.Id.ToString()), 0); foreach (var task in tasks) { if (task is null) @@ -480,7 +480,7 @@ void preallocDir(in DirectoryEntry.AcquisitionEntry dir, string path, int recurs return; } var file = manifest.FileBuffer[acquisitonFile.Index]; - var handle = File.OpenHandle(Path.Combine(path, file.Name), FileMode.Create, FileAccess.Write, preallocationSize: file.Size); + var handle = File.OpenHandle(Path.Join(path, file.Name), FileMode.Create, FileAccess.Write, preallocationSize: file.Size); RandomAccess.SetLength(handle, file.Size); handle.Dispose(); ProgressUpdated?.Invoke(++state.DisplayProgress); @@ -489,7 +489,7 @@ void preallocDir(in DirectoryEntry.AcquisitionEntry dir, string path, int recurs for (; index < dir.Subdirectories.Count; index++) { var subdir = dir.Subdirectories[index]; - preallocDir(in subdir, Path.Combine(path, manifest.DirectoryBuffer[subdir.Index].Name), recursionLevel + 1); + preallocDir(in subdir, Path.Join(path, manifest.DirectoryBuffer[subdir.Index].Name), recursionLevel + 1); if (cancellationToken.IsCancellationRequested) { state.ProgressIndexStack[recursionLevel] = dir.Files.Count + index; @@ -508,7 +508,7 @@ void preallocDir(in DirectoryEntry.AcquisitionEntry dir, string path, int recurs if (new DriveInfo(DownloadsDirectory!).AvailableFreeSpace < delta.DownloadCacheSize) throw new SteamNotEnoughDiskSpaceException(delta.DownloadCacheSize); ProgressInitiated?.Invoke(ProgressType.Numeric, delta.NumDownloadFiles, state.DisplayProgress); - preallocDir(in delta.AcquisitionTree, Path.Combine(DownloadsDirectory!, state.Id.ToString()), 0); + preallocDir(in delta.AcquisitionTree, Path.Join(DownloadsDirectory!, state.Id.ToString()), 0); if (cancellationToken.IsCancellationRequested) { state.SaveToFile(); @@ -516,14 +516,14 @@ void preallocDir(in DirectoryEntry.AcquisitionEntry dir, string path, int recurs } if (delta.ChunkBufferFileSize > 0) { - var handle = File.OpenHandle(Path.Combine(DownloadsDirectory!, $"{state.Id}.scchunkbuffer"), FileMode.Create, FileAccess.Write, preallocationSize: delta.ChunkBufferFileSize); + var handle = File.OpenHandle(Path.Join(DownloadsDirectory!, $"{state.Id}.scchunkbuffer"), FileMode.Create, FileAccess.Write, preallocationSize: delta.ChunkBufferFileSize); RandomAccess.SetLength(handle, delta.ChunkBufferFileSize); handle.Dispose(); ProgressUpdated?.Invoke(++state.DisplayProgress); } if (delta.IntermediateFileSize > 0) { - var handle = File.OpenHandle(Path.Combine(DownloadsDirectory!, $"{state.Id}.screlocpatchcache"), FileMode.Create, FileAccess.Write, preallocationSize: delta.IntermediateFileSize); + var handle = File.OpenHandle(Path.Join(DownloadsDirectory!, $"{state.Id}.screlocpatchcache"), FileMode.Create, FileAccess.Write, preallocationSize: delta.IntermediateFileSize); RandomAccess.SetLength(handle, delta.IntermediateFileSize); handle.Dispose(); ProgressUpdated?.Invoke(++state.DisplayProgress); @@ -540,7 +540,7 @@ public DepotManifest GetManifest(uint appId, ItemIdentifier item, ulong manifest { if (ManifestsDirectory is not null) { - string filePath = Path.Combine(ManifestsDirectory, $"{item}-{manifestId}.scmanifest"); + string filePath = Path.Join(ManifestsDirectory, $"{item}-{manifestId}.scmanifest"); if (File.Exists(filePath)) { StatusUpdated?.Invoke(Status.LoadingManifest); @@ -579,7 +579,7 @@ public DepotManifest GetManifest(uint appId, ItemIdentifier item, ulong manifest StatusUpdated?.Invoke(Status.LoadingManifest); var result = new DepotManifest(buffer, item); if (ManifestsDirectory is not null) - result.WriteToFile(Path.Combine(ManifestsDirectory, $"{item}-{manifestId}.scmanifest")); + result.WriteToFile(Path.Join(ManifestsDirectory, $"{item}-{manifestId}.scmanifest")); return result; } catch (Exception e) @@ -604,7 +604,7 @@ public DepotPatch GetPatch(uint appId, ItemIdentifier item, DepotManifest source { if (DownloadsDirectory is not null) { - string filePath = Path.Combine(DownloadsDirectory, $"{item}-{sourceManifest.Id}-{targetManifest.Id}.scpatch"); + string filePath = Path.Join(DownloadsDirectory, $"{item}-{sourceManifest.Id}-{targetManifest.Id}.scpatch"); if (File.Exists(filePath)) { StatusUpdated?.Invoke(Status.LoadingPatch); @@ -642,7 +642,7 @@ public DepotPatch GetPatch(uint appId, ItemIdentifier item, DepotManifest source StatusUpdated?.Invoke(Status.LoadingPatch); var result = new DepotPatch(buffer, item, sourceManifest, targetManifest); if (DownloadsDirectory is not null) - result.WriteToFile(Path.Combine(DownloadsDirectory, $"{item}-{sourceManifest.Id}-{targetManifest.Id}.scpatch")); + result.WriteToFile(Path.Join(DownloadsDirectory, $"{item}-{sourceManifest.Id}-{targetManifest.Id}.scpatch")); return result; } catch (Exception e)