public string GenerateFullName(string filePath)
        {
            var initialName = _pathService.GetFileName(filePath);
            var directory   = _pathService.GetParentDirectory(filePath);
            var newName     = GenerateName(initialName, directory);

            return(_pathService.Combine(directory, newName));
        }
        private string GenerateNewName(string currentName, int i)
        {
            var fileName  = _pathService.GetFileName(currentName);
            var extension = _pathService.GetExtension(currentName);

            return(string.IsNullOrEmpty(extension) ? $"{fileName} ({i})" : $"{fileName} ({i}).{extension}");
        }
Beispiel #3
0
        public IFileSystemNodeViewModel Create(FileModel fileModel)
        {
            var fileViewModel = new FileViewModel(
                _fileOpeningBehavior,
                _operationsService,
                _clipboardOperationsService,
                _filesOperationsMediator,
                _fileSizeFormatter,
                _filePropertiesBehavior,
                _dialogService,
                _trashCanService,
                _archiveService,
                _systemDialogService,
                _openWithApplicationService,
                _pathService)
            {
                FullPath             = fileModel.FullPath,
                Size                 = fileModel.SizeBytes,
                LastModifiedDateTime = fileModel.LastModifiedDateTime,
                Name                 = _pathService.GetFileNameWithoutExtension(fileModel.Name),
                Extension            = _pathService.GetExtension(fileModel.Name),
                FullName             = _pathService.GetFileName(fileModel.Name)
            };

            return(fileViewModel);
        }
Beispiel #4
0
        private async Task WriteMetaDataAsync(string oldFilePath, string newFilePath,
                                              string trashCanMetadataLocation, DateTime dateTime)
        {
            var fileName         = _pathService.GetFileName(newFilePath);
            var metadataFullPath = _pathService.Combine(trashCanMetadataLocation, fileName + ".trashinfo");
            var metadata         = GetMetadata(oldFilePath, dateTime);

            await _fileService.WriteTextAsync(metadataFullPath, metadata);
        }
    private async Task <List <LinuxApplicationModel> > GetDesktopEntriesAsync()
    {
        var desktopEntryFiles = new List <LinuxApplicationModel>();

        var specification      = GetSpecification();
        var globalDesktopFiles = GetGlobalDesktopFiles(specification);
        var localDesktopFiles  = GetLocalDesktopFiles(specification);
        var desktopFilePaths   = globalDesktopFiles.Concat(localDesktopFiles).Select(f => f.FullPath);

        var mimeTypesExtensions = await GetMimeTypesAsync();

        var defaultApplications = await GetDefaultApplicationsAsync(mimeTypesExtensions);

        foreach (var desktopFilePath in desktopFilePaths)
        {
            var desktopEntry = await GetDesktopEntryAsync(desktopFilePath);

            var desktopType = desktopEntry.GetValueOrDefault("Desktop Entry:Type");
            if (desktopType is null || !desktopType.Equals("Application", StringComparison.OrdinalIgnoreCase))
            {
                continue;
            }

            var displayName  = desktopEntry.GetValueOrDefault("Desktop Entry:Name");
            var startCommand = desktopEntry.GetValueOrDefault("Desktop Entry:Exec");

            if (string.IsNullOrWhiteSpace(displayName) || string.IsNullOrWhiteSpace(startCommand))
            {
                continue;
            }

            var(executePath, arguments) = ExtractExecutePathAndArguments(startCommand);
            if (string.IsNullOrWhiteSpace(executePath))
            {
                continue;
            }

            var extensions = GetExtensions(desktopEntry, mimeTypesExtensions);

            var desktopFileName      = _pathService.GetFileName(desktopFilePath);
            var isDefaultApplication = defaultApplications.ContainsKey(desktopFileName) &&
                                       defaultApplications[desktopFileName].IsSubsetOf(extensions);

            desktopEntryFiles.Add(new LinuxApplicationModel
            {
                DisplayName          = displayName,
                ExecutePath          = executePath,
                Arguments            = arguments,
                Extensions           = extensions,
                IsDefaultApplication = isDefaultApplication
            });
        }

        return(desktopEntryFiles);
    }
Beispiel #6
0
        protected override async Task WriteMetaDataAsync(IDictionary <string, string> files, string trashCanLocation)
        {
            var deleteTime = _environmentService.Now;

            foreach (var(originalFilePath, trashCanFilePath) in files)
            {
                var metadataBytes    = GetMetadataBytes(originalFilePath, trashCanFilePath, deleteTime);
                var metadataFileName = _pathService.GetFileName(trashCanFilePath).Replace(FilePrefix, MetadataPrefix);
                var metadataPath     = _pathService.Combine(trashCanLocation, metadataFileName);

                await _fileService.WriteBytesAsync(metadataPath, metadataBytes);
            }
        }
Beispiel #7
0
        protected override string GetUniqueFilePath(string file, HashSet <string> filesSet, string directory)
        {
            var filePath = _pathService.Combine(directory, _pathService.GetFileName(file));

            if (!filesSet.Contains(filePath))
            {
                return(filePath);
            }

            var fileName = _pathService.GetFileName(file);

            string result;
            var    i = 1;

            do
            {
                var newFileName = $"{fileName} ({i})";
                result = _pathService.Combine(directory, newFileName);
                i++;
            } while (filesSet.Contains(result) || _fileService.CheckIfExists(result));

            return(result);
        }
 public IFileSystemNodeViewModel Create(FileModel fileModel) =>
 new FileViewModel(
     _fileOpeningBehavior,
     _filePropertiesBehavior,
     _fileSystemNodeFacade,
     false,
     _fileSizeFormatter,
     _fileTypeMapper)
 {
     FullPath             = fileModel.FullPath,
     Size                 = fileModel.SizeBytes,
     LastModifiedDateTime = fileModel.LastModifiedDateTime,
     Name                 = _pathService.GetFileNameWithoutExtension(fileModel.Name),
     Extension            = _pathService.GetExtension(fileModel.Name),
     FullName             = _pathService.GetFileName(fileModel.Name)
 };
Beispiel #9
0
        private IDictionary <string, string> GetFilesTrashCanPathsMapping(IReadOnlyCollection <string> files,
                                                                          string filesTrashCanLocation)
        {
            var fileNames  = new HashSet <string>();
            var dictionary = new Dictionary <string, string>();

            foreach (var file in files)
            {
                var fileName    = _pathService.GetFileName(file);
                var newFilePath = GetUniqueFilePath(fileName, fileNames, filesTrashCanLocation);
                fileNames.Add(newFilePath);

                dictionary.Add(file, newFilePath);
            }

            return(dictionary);
        }
Beispiel #10
0
        public override void Activate(OverwriteOptionsNavigationParameter parameter)
        {
            var sourceFileModel = _fileService.GetFile(parameter.SourceFilePath);

            ReplaceWithFileViewModel = CreateFrom(sourceFileModel);

            var destinationFileModel = _fileService.GetFile(parameter.DestinationFilePath);

            OriginalFileViewModel = CreateFrom(destinationFileModel);

            var destinationDirectory = _pathService.GetParentDirectory(destinationFileModel.FullPath);

            NewFileName = _fileNameGenerationService.GenerateName(sourceFileModel.Name, destinationDirectory);
            DestinationDirectoryName = _pathService.GetFileName(destinationDirectory);

            AreMultipleFilesAvailable = parameter.AreMultipleFilesAvailable;
        }
    protected override async Task WriteMetaDataAsync(IReadOnlyDictionary <string, string> filePathsDictionary,
                                                     string trashCanLocation)
    {
        var deleteTime = _dateTimeProvider.Now;

        foreach (var(originalFilePath, trashCanFilePath) in filePathsDictionary)
        {
            var fileSize = _fileSizesDictionary.ContainsKey(originalFilePath)
                ? _fileSizesDictionary[originalFilePath]
                : 0;
            var metadataBytes    = GetMetadataBytes(originalFilePath, fileSize, deleteTime);
            var metadataFileName = _pathService
                                   .GetFileName(trashCanFilePath)
                                   .Replace(FilePrefix, MetadataPrefix);
            var metadataPath = _pathService.Combine(trashCanLocation, metadataFileName);

            await _fileService.WriteBytesAsync(metadataPath, metadataBytes);
        }
    }
Beispiel #12
0
        public IFileSystemNodeViewModel Create(FileModel fileModel)
        {
            var fileViewModel = new FileViewModel(
                _fileOpeningBehavior,
                _operationsService,
                _clipboardOperationsService,
                _filesOperationsMediator,
                _fileSizeFormatter)
            {
                FullPath             = fileModel.FullPath,
                Size                 = fileModel.SizeBytes,
                LastModifiedDateTime = fileModel.LastWriteTime.ToString(CultureInfo.CurrentCulture),
                Name                 = _pathService.GetFileNameWithoutExtension(fileModel.Name),
                Extension            = _pathService.GetExtension(fileModel.Name),
                FullName             = _pathService.GetFileName(fileModel.Name)
            };

            return(fileViewModel);
        }
Beispiel #13
0
        public void DisplayDeferredProjectStartedEvent(BuildEventContext e)
        {
            if (_context.Parameters.ShowOnlyErrors || _context.Parameters.ShowOnlyWarnings || _context.SkipProjectStartedText)
            {
                return;
            }

            var projectStartedEvent = _buildEventManager.GetProjectStartedEvent(e);

            if (projectStartedEvent == null || projectStartedEvent.ShowProjectFinishedEvent)
            {
                return;
            }

            projectStartedEvent.ShowProjectFinishedEvent = true;
            var parentProjectStartedEvent = projectStartedEvent.ParentProjectStartedEvent;

            if (parentProjectStartedEvent != null)
            {
                DisplayDeferredStartedEvents(parentProjectStartedEvent.ProjectBuildEventContext);
            }

            var projectFile       = projectStartedEvent.ProjectFile ?? string.Empty;
            var parentProjectFile = parentProjectStartedEvent?.ProjectFile;
            var targetNames       = projectStartedEvent.TargetNames;
            var nodeId            = projectStartedEvent.ProjectBuildEventContext.NodeId;
            var shortProjectFile  = _pathService.GetFileName(projectFile);

            if (parentProjectFile == null)
            {
                string message;
                string shortName;
                if (string.IsNullOrEmpty(targetNames))
                {
                    message   = _stringService.FormatResourceString("ProjectStartedTopLevelProjectWithDefaultTargets", projectFile, nodeId);
                    shortName = $"Project \"{shortProjectFile}\"";
                }
                else
                {
                    message   = _stringService.FormatResourceString("ProjectStartedTopLevelProjectWithTargetNames", projectFile, nodeId, targetNames);
                    shortName = $"Project \"{shortProjectFile}\": {targetNames}";
                }

                _hierarchicalMessageWriter.StartBlock(shortName);

                _messageWriter.WriteLinePrefix(projectStartedEvent.FullProjectKey, projectStartedEvent.TimeStamp, false);
                _logWriter.SetColor(Color.BuildStage);
                _messageWriter.WriteMessageAligned(message, true);
                _logWriter.ResetColor();
            }
            else
            {
                if (string.IsNullOrEmpty(targetNames))
                {
                    var shortName = $"Project \"{shortProjectFile}\"";
                    _hierarchicalMessageWriter.StartBlock(shortName);

                    _messageWriter.WriteLinePrefix(parentProjectStartedEvent.FullProjectKey, parentProjectStartedEvent.TimeStamp, false);
                    _logWriter.SetColor(Color.BuildStage);
                    _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("ProjectStartedWithDefaultTargetsMultiProc", parentProjectFile, parentProjectStartedEvent.FullProjectKey, projectFile, projectStartedEvent.FullProjectKey, nodeId), true);
                }
                else
                {
                    var shortName = $"Project \"{shortProjectFile}\": {targetNames}";
                    _hierarchicalMessageWriter.StartBlock(shortName);

                    _messageWriter.WriteLinePrefix(parentProjectStartedEvent.FullProjectKey, parentProjectStartedEvent.TimeStamp, false);
                    _logWriter.SetColor(Color.BuildStage);
                    _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("ProjectStartedWithTargetsMultiProc", parentProjectFile, parentProjectStartedEvent.FullProjectKey, projectFile, projectStartedEvent.FullProjectKey, nodeId, targetNames), true);
                }

                _logWriter.ResetColor();
            }

            ShownBuildEventContext(null);
        }
Beispiel #14
0
    public string GenerateFullName(string filePath)
    {
        var initialName = _pathService.GetFileName(filePath);

        return(GenerateByInitialName(filePath, initialName));
    }
 public override void Activate(RenameNodeNavigationParameter parameter)
 {
     _directory = _pathService.GetParentDirectory(parameter.NodePath);
     NodeName   = _pathService.GetFileName(parameter.NodePath);
 }
Beispiel #16
0
        private static void AddContentToSyncList(string sourceBasePath, IFileHandler outputFileHandler, IList <Package> packages,
                                                 string contentFolderName, SyncType syncType, List <Sync> syncList, AliasService aliasService)
        {
            int packageCnt = 0;

            foreach (var package in packages)
            {
                ProgressBar.DrawProgressBar($"AddContentToSyncList [{contentFolderName}]", packageCnt++, packages.Count);

                var packageContentFolderBasePath = _pathService.Combine(sourceBasePath, package.Path, contentFolderName);
                var packageContentLhaBasePath    = _pathService.Combine(sourceBasePath, package.Path, contentFolderName + ".lha");
                if (Directory.Exists(packageContentFolderBasePath) && File.Exists(packageContentLhaBasePath))
                {
                    throw new Exception($"Package [{package.Path}] has both [content] folder and [content.lha].");
                }

                string packageContentBasePath;
                if (File.Exists(packageContentLhaBasePath))
                {
                    packageContentBasePath = packageContentLhaBasePath;
                }
                else if (Directory.Exists(packageContentFolderBasePath))
                {
                    packageContentBasePath = packageContentFolderBasePath;
                }
                else
                {
                    continue;
                }

                using (var contentFileHandler = FileHandlerFactory.Create(_logger, packageContentBasePath))
                {
                    var packageOutputPath = "";
                    var sourcePath        = "";
                    var packageEntries    = contentFileHandler.DirectoryGetFileSystemEntriesRecursive(sourcePath);
                    foreach (var packageEntry in packageEntries)
                    {
                        var outputPath = aliasService.TargetAliasToOutputPath(packageEntry);

                        var packageEntryFileName = _pathService.GetFileName(outputPath);
                        if (ShouldContentReverseAll(packageEntryFileName))
                        {
                            var contentReversePackageEntryPath = _pathService.GetDirectoryName(outputPath);
                            var contentReversePackageSubPath   = RemoveRoot(sourcePath, contentReversePackageEntryPath);
                            var contentReverseFileOutputPath   = _pathService.Combine(packageOutputPath, contentReversePackageSubPath);
                            if (outputFileHandler.DirectoryExists(contentReverseFileOutputPath))
                            {
                                var innerContentReversePackageEntries = outputFileHandler.DirectoryGetFileSystemEntriesRecursive(contentReverseFileOutputPath);
                                foreach (var innerContentReversePackageEntry in innerContentReversePackageEntries)
                                {
                                    var innerContentReversePackageSubPath = RemoveRoot(packageOutputPath, innerContentReversePackageEntry);
                                    var innerContentReverseSourcePath     = _pathService.Combine(sourcePath, innerContentReversePackageSubPath);

                                    var innerSync = new Sync
                                    {
                                        PackageContentBasePath = packageContentBasePath,
                                        SourcePath             = innerContentReverseSourcePath,
                                        TargetPath             = innerContentReversePackageEntry,
                                        SyncType = syncType,
                                        FileType = outputFileHandler.GetFileType(innerContentReversePackageEntry)
                                    };

                                    syncList.Add(innerSync);
                                }
                            }
                        }
                        else
                        {
                            var packageSubPath = RemoveRoot(sourcePath, outputPath);
                            var fileOutputPath = _pathService.Combine(packageOutputPath, packageSubPath);
                            var sync           = new Sync
                            {
                                PackageContentBasePath = packageContentBasePath,
                                SourcePath             = packageEntry,
                                TargetPath             = fileOutputPath,
                                SyncType = syncType,
                                FileType = contentFileHandler.GetFileType(packageEntry)
                            };

                            syncList.Add(sync);
                        }
                    }
                }
            }
        }