public void DisplayResource(IResource resource) { _displayedResource = resource; string path = null; try { path = Core.FileResourceManager.GetSourceFile(resource); } catch (Exception e) { Utils.DisplayException(e, "Error"); } if (path != null && path.Length > 0) { string fileType = FileSystemTypes.GetFileType(Path.GetExtension(path)); if (fileType == null || fileType.Length == 0) { fileType = Path.GetExtension(path); } _infoLabel.Text = Core.ProductName + " is unable to process files of type \"" + fileType + "\". To open this resource in associated application, click the button below."; _openButton.Visible = true; return; } _infoLabel.Text = Core.ProductName + " failed to determine type of this resource, it cannot be displayed :("; _openButton.Visible = false; }
/** * finds or creates resource for a file * for the UnknowFile type creates transient resources */ public IResource FindOrCreateFile(FileInfo fileInfo, bool createTransient) { string resourceType; bool indexIt = false; DateTime lastWriteTime = IOTools.GetLastWriteTime(fileInfo); string extension = IOTools.GetExtension(fileInfo); int size = (int)IOTools.GetLength(fileInfo); string name = IOTools.GetName(fileInfo); IResource file = FindFile(fileInfo); if (file != null) { if (!Core.ResourceStore.IsOwnerThread()) { return((IResource)_resourceAP.RunUniqueJob(_cUpdatingFileJob, _findOrCreateFileDelegate, fileInfo, createTransient)); } file.BeginUpdate(); if (file.Type == FileProxy._unknownFileResourceType && (resourceType = _ftm.GetResourceTypeByExtension(extension)) != null) { file.ChangeType(resourceType); indexIt = true; } if (name != file.GetPropText(Core.Props.Name)) { file.SetProp(Core.Props.Name, name); indexIt = true; } if (lastWriteTime != file.GetDateProp(Core.Props.Date)) { file.SetProp(Core.Props.Date, lastWriteTime); indexIt = true; } indexIt = indexIt || (!file.IsTransient && !file.HasProp("InTextIndex")); file.SetProp(FileProxy._propSize, size); string filetype = FileSystemTypes.GetFileType(extension); file.SetProp(FileProxy._propFileType, filetype ?? "Unknown"); } else { string directoryName = IOTools.GetDirectoryName(fileInfo); IResource folder = FindOrCreateDirectory(directoryName); if (folder == null) { return(null); } resourceType = _ftm.GetResourceTypeByExtension(extension); /** * look through pending file deletions */ IResourceList deletedFiles = Core.ResourceStore.FindResourcesWithProp(resourceType, FileProxy._propDeletedFile); deletedFiles = deletedFiles.Intersect( Core.ResourceStore.FindResources(null, FileProxy._propSize, size), true); deletedFiles = deletedFiles.Intersect( Core.ResourceStore.FindResources(null, Core.Props.Name, name), true); if (deletedFiles.Count > 0) { file = deletedFiles[0]; if (!file.IsTransient) { if (!Core.ResourceStore.IsOwnerThread()) { return((IResource)_resourceAP.RunUniqueJob( _cUpdatingFileJob, _findOrCreateFileDelegate, fileInfo, createTransient)); } file.BeginUpdate(); } } if (file == null) { if (resourceType != null && !createTransient) { if (!Core.ResourceStore.IsOwnerThread()) { return((IResource)_resourceAP.RunUniqueJob( _cUpdatingFileJob, _findOrCreateFileDelegate, fileInfo, createTransient)); } file = Core.ResourceStore.BeginNewResource(resourceType); indexIt = true; } else { if (!createTransient) { return(null); } if (resourceType == null) { resourceType = FileProxy._unknownFileResourceType; } file = Core.ResourceStore.NewResourceTransient(resourceType); } } file.SetProp(FileProxy._propParentFolder, folder); file.SetProp(FileProxy._propDirectory, directoryName); file.SetProp(Core.Props.Name, name); file.SetProp(Core.Props.Date, lastWriteTime); file.SetProp(FileProxy._propSize, size); string filetype = FileSystemTypes.GetFileType(extension); file.SetProp(FileProxy._propFileType, filetype ?? "Unknown"); } file.SetProp(FileProxy._propDeletedFile, false); if (!file.IsTransient) { file.EndUpdate(); if (indexIt) { Core.TextIndexManager.QueryIndexing(file.Id); } } return(file); }