private void AddFile(string fileName, string packageDirPath, string suffix, CancellationToken cancellationToken) { _logger.LogDebug(string.Format("Processing add file entry {0}", fileName)); var filePath = _localData.Path.PathCombine(fileName); _logger.LogTrace("filePath = " + filePath); var sourceFilePath = Path.Combine(packageDirPath, fileName + suffix); _logger.LogTrace("sourceFilePath = " + sourceFilePath); if (!File.Exists(sourceFilePath)) { throw new MissingFileFromPackageException(string.Format("Cannot find file {0} in diff package.", fileName)); } _logger.LogDebug("Creating file parent directories in local data..."); var fileParentDirPath = Path.GetDirectoryName(filePath); _logger.LogTrace("fileParentDirPath = " + fileParentDirPath); //TODO: Assert that fileParentDirPath is not null // ReSharper disable once AssignNullToNotNullAttribute DirectoryOperations.CreateDirectory(fileParentDirPath, cancellationToken); _logger.LogDebug("File parent directories created in local data."); _logger.LogDebug("Copying file to local data (overwriting if needed)..."); FileOperations.Copy(sourceFilePath, filePath, true, cancellationToken); _logger.LogDebug("File copied to local data."); _localMetaData.RegisterEntry(fileName, _versionId); _logger.LogDebug("Add file entry processed."); }
private void ProcessAddedFiles(string packageDirPath, string suffix, CancellationToken cancellationToken) { DebugLogger.Log("Processing added files."); _addFilesStatusReporter.OnProgressChanged(0.0, "Installing package..."); for (int i = 0; i < _versionDiffSummary.AddedFiles.Length; i++) { cancellationToken.ThrowIfCancellationRequested(); var entryName = _versionDiffSummary.AddedFiles[i]; string entryPath = _localData.Path.PathCombine(entryName); if (entryName.EndsWith("/")) { DirectoryOperations.CreateDirectory(entryPath); // TODO: Uncomment this after fixing directory registration in install content command //_localMetaData.RegisterEntry(entryName, _versionId); } else { string sourceFilePath = Path.Combine(packageDirPath, entryName + suffix); if (!File.Exists(sourceFilePath)) { throw new InstallerException(string.Format("Cannot find file <{0}> in content package.", entryName)); } DebugLogger.LogFormat("Copying {0} -> {1}", sourceFilePath, entryName); DirectoryOperations.CreateParentDirectory(entryPath); FileOperations.Copy(sourceFilePath, entryPath, true); _localMetaData.RegisterEntry(entryName, _versionId); } _addFilesStatusReporter.OnProgressChanged((i + 1) / (double)_versionDiffSummary.AddedFiles.Length, "Installing package..."); } _addFilesStatusReporter.OnProgressChanged(1.0, "Installing package..."); }
private void InstallFile(string fileName, string packageDirPath) { DebugLogger.Log(string.Format("Installing file {0}", fileName)); string sourceFilePath = Path.Combine(packageDirPath, fileName); if (!File.Exists(sourceFilePath)) { throw new InstallerException(string.Format("Cannot find file {0} in content package.", fileName)); } string destinationFilePath = _localData.Path.PathCombine(fileName); DirectoryOperations.CreateParentDirectory(destinationFilePath); if (File.Exists(destinationFilePath)) { DebugLogger.LogFormat("Destination file {0} already exists, removing it.", destinationFilePath); FileOperations.Delete(destinationFilePath); } FileOperations.Move(sourceFilePath, destinationFilePath); _localMetaData.RegisterEntry(fileName, _versionId); }