/// <summary> /// We follow this algorithm for looking up files: /// /// if (not asked to create) /// Look in AppDesigner folder /// Look in root folder /// /// if (asked to create) /// Look in AppDesigner folder /// Look in root folder /// Force-create in app-designer folder unless that file is not created there by default. /// In that case create under the root node. /// </summary> public async Task <string> GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags, CancellationToken cancellationToken = default(CancellationToken)) { // Search for the file in the app designer and root folders. IProjectTree specialFileNode = await FindFileAsync(Name).ConfigureAwait(false); if (specialFileNode != null) { if (await IsNodeInSyncWithDiskAsync(specialFileNode, forceSync: flags.HasFlag(SpecialFileFlags.CreateIfNotExist), cancellationToken: cancellationToken).ConfigureAwait(false)) { return(specialFileNode.FilePath); } } // File doesn't exist. Create it if we've been asked to. if (flags.HasFlag(SpecialFileFlags.CreateIfNotExist)) { string createdFilePath = await CreateFileAsync(fileId, Name).ConfigureAwait(false); if (createdFilePath != null) { return(createdFilePath); } } // We haven't found the file but return the default file path as that's the contract. IProjectTree rootNode = _projectTree.CurrentTree; string rootFilePath = _projectTree.TreeProvider.GetPath(rootNode); string fullPath = Path.Combine(Path.GetDirectoryName(rootFilePath), Name); return(fullPath); }
private Task <string?> GetAppDesignerFolderPathAsync(bool createIfNotExists = false) { SpecialFileFlags flags = SpecialFileFlags.FullPath; if (createIfNotExists) { flags |= SpecialFileFlags.CreateIfNotExist; } return(_specialFilesManager.GetFileAsync(SpecialFiles.AppDesigner, flags)); }
public virtual async Task <string?> GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags, CancellationToken cancellationToken = default) { // Make sure at least have a tree before we start searching it IProjectTreeServiceState state = await _treeService.PublishAnyNonLoadingTreeAsync(cancellationToken); // Attempt to find an existing file/folder first string?path = await FindFileAsync(state.TreeProvider, state.Tree, flags); if (path == null) { // Otherwise, fall back and create it path = await CreateDefaultFileAsync(state.TreeProvider, state.Tree, flags); } return(path); }
public async Task <string?> GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags) { await _projectVsServices.ThreadingService.SwitchToUIThread(); var files = (IVsProjectSpecialFiles)_projectVsServices.VsHierarchy; HResult result = files.GetFile((int)fileId, (uint)flags, out _, out string fileName); if (result.IsOK) { return(fileName); } if (result.IsNotImplemented) { return(null); // Not handled } throw result.Exception !; }
private async Task <IProjectTree?> GetAppDesignerFolderAsync(bool createIfNotExists) { SpecialFileFlags flags = SpecialFileFlags.FullPath; if (createIfNotExists) { flags |= SpecialFileFlags.CreateIfNotExist; } string?path = await _specialFilesManager.GetFileAsync(SpecialFiles.AppDesigner, flags); if (path == null) { return(null); } return(_projectTree.TreeProvider.FindByPath(_projectTree.CurrentTree, path)); }
public async Task <string> GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags, CancellationToken cancellationToken = default(CancellationToken)) { string path = FindAppDesignerFolder(); if (path == null) { // Not found, let's find the default path and create it if needed path = await GetDefaultAppDesignerFolderPathAsync().ConfigureAwait(false); if (path != null && (flags & SpecialFileFlags.CreateIfNotExist) == SpecialFileFlags.CreateIfNotExist) { await _projectTree.Value.TreeStorage.CreateFolderAsync(path) .ConfigureAwait(false); } } // We always return the default path, regardless of whether we created it or it exists, as per contract return(path); }
public virtual async Task <string> GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags, CancellationToken cancellationToken = default) { // Make sure at least have a tree before we start searching it await _projectTree.Value.TreeService.PublishAnyNonLoadingTreeAsync(cancellationToken); string path = FindAppDesignerFolder(); if (path == null) { // Not found, let's find the default path and create it if needed path = await GetDefaultAppDesignerFolderPathAsync(); if (path != null && (flags & SpecialFileFlags.CreateIfNotExist) == SpecialFileFlags.CreateIfNotExist) { await _projectTree.Value.TreeStorage.CreateFolderAsync(path); } } // We always return the default path, regardless of whether we created it or it exists, as per contract return(path); }
private async Task <string?> CreateDefaultFileAsync(IProjectTreeProvider provider, IProjectTree root, SpecialFileFlags flags) { string?path = await GetDefaultFileAsync(provider, root); if (path != null && flags.HasFlag(SpecialFileFlags.CreateIfNotExist)) { await CreateFileAsync(path); } // We always return the default path, regardless of whether we created it or it exists, as per contract return(path); }
private async Task <string?> FindFileAsync(IProjectTreeProvider provider, IProjectTree root, SpecialFileFlags flags) { IProjectTree?node = await FindFileAsync(provider, root); if (node == null) { return(null); } string?path = GetFilePath(provider, node); if (path != null && flags.HasFlag(SpecialFileFlags.CreateIfNotExist)) { // Similar to legacy, we only verify state if we've been asked to create it await VerifyStateAsync(node, path); } return(path); }