private void RemoveDir(string dirName, CancellationToken cancellationToken) { _logger.LogDebug(string.Format("Processing remove directory entry {0}", dirName)); string dirPath = _localData.Path.PathCombine(dirName); _logger.LogTrace("dirPath = " + dirPath); _logger.LogDebug("Deleting directory in local data. Checking whether it actually exists..."); if (Directory.Exists(dirPath)) { _logger.LogDebug("Directory exists. Checking whether directory is empty..."); if (IsDirectoryEmpty(dirPath)) { _logger.LogDebug("Directory is empty. Deleting it..."); DirectoryOperations.Delete(dirPath, cancellationToken); _logger.LogDebug("Directory deleted."); } else { _logger.LogDebug("Directory is not empty. Couldn't delete it."); } } _logger.LogDebug("Remove directory entry processed."); // TODO: Uncomment this after fixing directory registration in install content command //_localMetaData.UnregisterEntry(dirName); }
private void ReleaseUnmanagedResources() { if (!_keep && Directory.Exists(Path)) { DirectoryOperations.Delete(Path, CancellationToken.Empty, true); } }
public override void Execute(CancellationToken cancellationToken) { base.Execute(cancellationToken); Checks.FileExists(_packagePath); if (_versionDiffSummary.CompressionMethod == "pack1") { Assert.IsTrue(File.Exists(_packageMetaPath), "Compression method is pack1, but meta file does not exist"); DebugLogger.Log("Parsing package meta file"); _pack1Meta = Pack1Meta.ParseFromFile(_packageMetaPath); DebugLogger.Log("Package meta file parsed succesfully"); } DebugLogger.Log("Installing diff."); var packageDirPath = _temporaryData.GetUniquePath(); DebugLogger.LogVariable(packageDirPath, "packageDirPath"); DebugLogger.Log("Creating package directory."); DirectoryOperations.CreateDirectory(packageDirPath); try { DebugLogger.Log("Unarchiving files."); string usedSuffix; IUnarchiver unarchiver = CreateUnrachiver(packageDirPath, out usedSuffix); _unarchivePackageStatusReporter.OnProgressChanged(0.0, "Unarchiving package..."); unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount, entryProgress) => { var entryMinProgress = Mathf.Max(0, entry - 1) / (double)amount; // entry could be zero var entryMaxProgress = entry / (double)amount; var progress = entryMinProgress + (entryMaxProgress - entryMinProgress) * entryProgress; _unarchivePackageStatusReporter.OnProgressChanged(progress, "Unarchiving package..."); }; unarchiver.Unarchive(cancellationToken); _unarchivePackageStatusReporter.OnProgressChanged(1.0, string.Empty); ProcessAddedFiles(packageDirPath, usedSuffix, cancellationToken); ProcessRemovedFiles(cancellationToken); ProcessModifiedFiles(packageDirPath, usedSuffix, cancellationToken); DeleteEmptyMacAppDirectories(); } finally { DebugLogger.Log("Deleting package directory."); if (Directory.Exists(packageDirPath)) { DirectoryOperations.Delete(packageDirPath, true); } } }
public void Clear() { DebugLogger.Log("Clearing download data."); if (Directory.Exists(Path)) { DirectoryOperations.Delete(Path, true); DirectoryOperations.CreateDirectory(Path); } }
public override void Execute(CancellationToken cancellationToken) { base.Execute(cancellationToken); Checks.FileExists(_packagePath); if (_versionDiffSummary.CompressionMethod == "pack1") { Assert.IsTrue(File.Exists(_packageMetaPath), "Compression method is pack1, but meta file does not exist"); DebugLogger.Log("Parsing package meta file"); _pack1Meta = Pack1Meta.ParseFromFile(_packageMetaPath); DebugLogger.Log("Package meta file parsed succesfully"); } DebugLogger.Log("Installing diff."); var packageDirPath = _temporaryData.GetUniquePath(); DebugLogger.LogVariable(packageDirPath, "packageDirPath"); DebugLogger.Log("Creating package directory."); DirectoryOperations.CreateDirectory(packageDirPath); try { DebugLogger.Log("Unarchiving files."); IUnarchiver unarchiver = CreateUnrachiver(packageDirPath); unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount) => { _unarchivePackageStatusReporter.OnProgressChanged(entry / (double)amount); }; unarchiver.Unarchive(cancellationToken); _unarchivePackageStatusReporter.OnProgressChanged(1.0); ProcessAddedFiles(packageDirPath, cancellationToken); ProcessRemovedFiles(cancellationToken); ProcessModifiedFiles(packageDirPath, cancellationToken); } finally { DebugLogger.Log("Deleting package directory."); if (Directory.Exists(packageDirPath)) { DirectoryOperations.Delete(packageDirPath, true); } } }
private void DeleteOldTmpDirectories() { DebugLogger.Log("TemporaryDirectory: ParentFullName: " + Directory.GetParent(Path).FullName); DirectoryInfo[] tmpDirs = Directory.GetParent(Path).GetDirectories(_prefix + "*"); for (int i = 0; i < tmpDirs.Length; i++) { if (tmpDirs[i].CreationTime < _createdAt) { DebugLogger.LogFormat("TemporaryDirectory: Deleting old tmp directory[{0}/{1}]: {2}", (i + 1), tmpDirs.Length, tmpDirs[i].FullName); DirectoryOperations.Delete(tmpDirs[i].FullName, true); } } }
private void ProcessRemovedFiles(CancellationToken cancellationToken) { DebugLogger.Log("Processing removed files."); var files = _versionDiffSummary.RemovedFiles.Where(s => !s.EndsWith("/")); var directories = _versionDiffSummary.RemovedFiles.Where(s => s.EndsWith("/")); int counter = 0; _removeFilesStatusReporter.OnProgressChanged(0.0, "Installing package..."); foreach (var fileName in files) { cancellationToken.ThrowIfCancellationRequested(); string filePath = _localData.Path.PathCombine(fileName); if (File.Exists(filePath)) { FileOperations.Delete(filePath); } _localMetaData.UnregisterEntry(fileName); counter++; _removeFilesStatusReporter.OnProgressChanged(counter / (double)_versionDiffSummary.RemovedFiles.Length, "Installing package..."); } foreach (var dirName in directories) { cancellationToken.ThrowIfCancellationRequested(); string dirPath = _localData.Path.PathCombine(dirName); if (Directory.Exists(dirPath) && DirectoryOperations.IsDirectoryEmpty(dirPath)) { DirectoryOperations.Delete(dirPath, false); } // TODO: Uncomment this after fixing directory registration in install content command //_localMetaData.UnregisterEntry(dirName); counter++; _removeFilesStatusReporter.OnProgressChanged(counter / (double)_versionDiffSummary.RemovedFiles.Length, "Installing package..."); } _removeFilesStatusReporter.OnProgressChanged(1.0, string.Empty); }
private TemporaryDirectory([NotNull] string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentException("Value cannot be null or empty.", "path"); } Path = path; if (Directory.Exists(Path)) { DirectoryOperations.Delete(Path, CancellationToken.Empty, true); } DirectoryOperations.CreateDirectory(Path, CancellationToken.Empty); }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } DebugLogger.LogDispose(); if (Directory.Exists(Path)) { DirectoryOperations.Delete(Path, true); } _disposed = true; }
// TODO: Temporary solution for situation when .app directory is not deleted private void DeleteEmptyMacAppDirectories(CancellationToken cancellationToken) { if (!Platform.IsOSX()) { return; } _logger.LogDebug("Deleting empty Mac OSX '.app' directories..."); foreach (var dir in FindEmptyMacAppDirectories()) { _logger.LogDebug(string.Format("Deleting {0}", dir)); DirectoryOperations.Delete(dir, cancellationToken, true); _logger.LogDebug("Directory deleted."); } _logger.LogDebug("Empty Mac OSX '.app' directories deleted."); }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } DebugLogger.Log("TemporaryDirectory: Deleting: " + Path); if (Directory.Exists(Path)) { DirectoryOperations.Delete(Path, true); } DeleteOldTmpDirectories(); DebugLogger.LogDispose(); _disposed = true; }
private void Cleanup() { DebugLogger.Log("Cleaning up..."); if (Directory.Exists(DownloadDirectoryPath)) { SafeInvoker.Invoke(() => DirectoryOperations.Delete(DownloadDirectoryPath, true), null, _ => { DebugLogger.LogWarning("Unable to cleanup torrent download directory."); }); } if (File.Exists(TorrentFilePath)) { SafeInvoker.Invoke(() => FileOperations.Delete(TorrentFilePath), null, _ => { DebugLogger.LogWarning("Unable to cleanup torrent file."); }); } DebugLogger.Log("Cleanup completed."); }
// TODO: Temporary solution for situation when .app directory is not deleted private void DeleteEmptyMacAppDirectories() { if (Platform.IsOSX()) { DebugLogger.Log("Deleting empty Mac OSX '.app' directories..."); var appDirectories = Directory .GetFileSystemEntries(_localData.Path) .Where(s => Directory.Exists(s) && s.EndsWith(".app") && Directory.GetFiles(s, "*", SearchOption.AllDirectories).Length == 0); foreach (var dir in appDirectories) { if (Directory.Exists(dir)) { DirectoryOperations.Delete(dir, true); } } DebugLogger.Log("Empty Mac OSX '.app' directories has been deleted."); } }
public override void Execute(CancellationToken cancellationToken) { base.Execute(cancellationToken); Checks.FileExists(_packagePath); Assert.IsTrue(_localMetaData.GetRegisteredEntries().Length == 0, "Cannot install content if previous version is still present."); if (_versionContentSummary.CompressionMethod == "pack1") { Assert.IsTrue(File.Exists(_packageMetaPath), "Compression method is pack1, but meta file does not exist"); DebugLogger.Log("Parsing package meta file"); _pack1Meta = Pack1Meta.ParseFromFile(_packageMetaPath); DebugLogger.Log("Package meta file parsed succesfully"); } DebugLogger.Log("Installing content."); var packageDirPath = _temporaryData.GetUniquePath(); DebugLogger.LogVariable(packageDirPath, "destinationDir"); DebugLogger.Log("Creating package directory."); DirectoryOperations.CreateDirectory(packageDirPath); try { DebugLogger.Log("Unarchiving package."); IUnarchiver unarchiver = CreateUnrachiver(packageDirPath); unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount) => { _unarchivePackageStatusReporter.OnProgressChanged(entry / (double)amount); }; unarchiver.Unarchive(cancellationToken); _unarchivePackageStatusReporter.OnProgressChanged(1.0); DebugLogger.Log("Copying files."); for (int i = 0; i < _versionContentSummary.Files.Length; i++) { cancellationToken.ThrowIfCancellationRequested(); InstallFile(_versionContentSummary.Files[i].Path, packageDirPath); _copyFilesStatusReporter.OnProgressChanged((i + 1) / (double)_versionContentSummary.Files.Length); } _copyFilesStatusReporter.OnProgressChanged(1.0); } finally { DebugLogger.Log("Deleting package directory."); if (Directory.Exists(packageDirPath)) { DirectoryOperations.Delete(packageDirPath, true); } } }
public override void Execute(CancellationToken cancellationToken) { base.Execute(cancellationToken); DebugLogger.Log("Uninstalling."); var entries = _localMetaData.GetRegisteredEntries(); var files = entries.Where(s => !s.EndsWith("/")).ToArray(); // TODO: Uncomment this after fixing directory registration in install content command //var directories = entries.Where(s => s.EndsWith("/")); int counter = 0; foreach (var fileName in files) { cancellationToken.ThrowIfCancellationRequested(); var filePath = _localData.Path.PathCombine(fileName); if (File.Exists(filePath)) { FileOperations.Delete(filePath); } _localMetaData.UnregisterEntry(fileName); counter++; _statusReporter.OnProgressChanged(counter / (double)entries.Length); } // TODO: Delete this after fixing directory registration in install content command // Temporary solution for deleting directories during uninstallation. foreach (var fileName in files) { cancellationToken.ThrowIfCancellationRequested(); string parentDirName = fileName; do { parentDirName = Path.GetDirectoryName(parentDirName); var parentDirPath = _localData.Path.PathCombine(parentDirName); if (Directory.Exists(parentDirPath)) { if (DirectoryOperations.IsDirectoryEmpty(parentDirPath)) { DirectoryOperations.Delete(parentDirPath, false); } else { break; } } } while (parentDirName != null); } // TODO: Uncomment this after fixing directory registration in install content command /* * foreach (var dirName in directories) * { * cancellationToken.ThrowIfCancellationRequested(); * * var dirPath = _localData.Path.PathCombine(dirName); * * if (Directory.Exists(dirPath) && DirectoryOperations.IsDirectoryEmpty(dirPath)) * { * DirectoryOperations.Delete(dirPath, false); * } * * _localMetaData.UnregisterEntry(dirName); * * counter++; * _statusReporter.OnProgressChanged(counter / (double)entries.Length); * }*/ }