/// <summary>
        /// Displays custom columns in Windows file mnager.
        /// </summary>
        /// <param name="customColumnsData">list of columns to display.</param>
        private async Task ShowCustomColumnsAsync(IEnumerable <FileSystemItemPropertyData> customColumnsData)
        {
            List <StorageProviderItemProperty> customColumns = new List <StorageProviderItemProperty>();

            if (customColumnsData != null)
            {
                foreach (FileSystemItemPropertyData column in customColumnsData)
                {
                    customColumns.Add(new StorageProviderItemProperty()
                    {
                        Id = column.Id,
                        // If value is empty Windows File Manager crushes.
                        Value = string.IsNullOrEmpty(column.Value) ? "-" : column.Value,
                        // If icon is not set Windows File Manager crushes.
                        IconResource = column.IconResource ?? Path.Combine(iconsFolderPath, "Blank.ico")
                    });
                }
            }

            // This method may be called on temp files, typically created by MS Office, that exist for a short period of time.
            IStorageItem storageItem = await FsPath.GetStorageItemAsync(userFileSystemPath);

            if (storageItem == null)
            {
                // This method may be called on temp files, typically created by MS Office, that exist for a short period of time.
                // StorageProviderItemProperties.SetAsync(null,) causes AccessViolationException
                // which is not handled by .NET (nor handled by HandleProcessCorruptedStateExceptions) and causes a fatal crush.
                return;
            }

            FileInfo file = new FileInfo(userFileSystemPath);

            // Can not set provider properties on read-only files.
            // Changing read-only attribute on folders triggers folders listing. Changing on files only.
            bool readOnly = file.IsReadOnly;

            // Remove read-only attribute.
            if (readOnly && ((file.Attributes & System.IO.FileAttributes.Directory) == 0))
            {
                file.IsReadOnly = false;
                //new FileInfo(userFileSystemPath).Attributes &= ~System.IO.FileAttributes.ReadOnly;
            }

            // Update columns data.
            await StorageProviderItemProperties.SetAsync(storageItem, customColumns);

            // Set read-only attribute.
            if (readOnly && ((file.Attributes & System.IO.FileAttributes.Directory) == 0))
            {
                file.IsReadOnly = true;
                //new FileInfo(userFileSystemPath).Attributes |= System.IO.FileAttributes.ReadOnly;
            }
        }
Exemple #2
0
        /// <summary>
        /// Sets or removes icon.
        /// </summary>
        /// <param name="set">True to display the icon. False - to remove the icon.</param>
        private async Task SetIconAsync(bool set, int?id = null, string iconFile = null, string description = null)
        {
            IStorageItem storageItem = await FsPath.GetStorageItemAsync(userFileSystemPath);

            if (storageItem == null)
            {
                // This method may be called on temp files, typically created by MS Office, that exist for a short period of time.
                // StorageProviderItemProperties.SetAsync(null,) causes AccessViolationException
                // which is not handled by .NET (or handled by HandleProcessCorruptedStateExceptions) and causes a fatal crush.
                return;
            }

            try
            {
                if (set)
                {
                    StorageProviderItemProperty propState = new StorageProviderItemProperty()
                    {
                        Id           = id.Value,
                        Value        = description,
                        IconResource = Path.Combine(virtualDrive.Settings.IconsFolderPath, iconFile)
                    };
                    await StorageProviderItemProperties.SetAsync(storageItem, new StorageProviderItemProperty[] { propState });
                }
                else
                {
                    await StorageProviderItemProperties.SetAsync(storageItem, new StorageProviderItemProperty[] { });
                }
            }

            // Setting status icon failes for blocked files.
            catch (FileNotFoundException)
            {
            }
            catch (COMException)
            {
                // "Error HRESULT E_FAIL has been returned from a call to a COM component."
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147024499)
                {
                    // "The operation failed due to a conflicting cloud file property lock. (0x8007018D)"
                }
                else
                {
                    // Rethrow the exception preserving stack trace of the original exception.
                    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Sets or removes icon.
        /// </summary>
        /// <param name="set">True to display the icon. False - to remove the icon.</param>
        private async Task SetIconAsync(bool set, int?id = null, string iconFile = null, string description = null)
        {
            IStorageItem storageItem = await FsPath.GetStorageItemAsync(userFileSystemPath);

            if (storageItem == null)
            {
                return; // Item does not exists.
            }

            try
            {
                if (set)
                {
                    StorageProviderItemProperty propState = new StorageProviderItemProperty()
                    {
                        Id           = id.Value,
                        Value        = description,
                        IconResource = Path.Combine(Program.Settings.IconsFolderPath, iconFile)
                    };
                    await StorageProviderItemProperties.SetAsync(storageItem, new StorageProviderItemProperty[] { propState });
                }
                else
                {
                    await StorageProviderItemProperties.SetAsync(storageItem, new StorageProviderItemProperty[] { });
                }
            }

            // Setting status icon failes for blocked files.
            catch (FileNotFoundException)
            {
            }
            catch (COMException)
            {
                // "Error HRESULT E_FAIL has been returned from a call to a COM component."
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147024499)
                {
                    // "The operation failed due to a conflicting cloud file property lock. (0x8007018D)"
                }
                else
                {
                    // Rethrow the exception preserving stack trace of the original exception.
                    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw();
                }
            }
        }
Exemple #4
0
        public static async void ApplyCustomStateToPlaceholderFile(string path, string filename, StorageProviderItemProperty prop)
        {
            try
            {
                var fullPath = Path.Combine(path, filename);

                var customProperties = new StorageProviderItemProperty[] { prop };

                var item = await StorageFile.GetFileFromPathAsync(fullPath);

                await StorageProviderItemProperties.SetAsync(item, customProperties);
            }
            catch (Exception ex)
            {
                // winrt.to_hresult() will eat the exception if it is a result of winrt.check_hresult, otherwise the exception will get
                // rethrown and this method will crash out as it should
                Console.Write("Failed to set custom state with {0:X8}\n", ex.HResult);
            }
        }
Exemple #5
0
        internal async Task SetCustomColumnsDataAsync(IEnumerable <FileSystemItemPropertyData> customColumnsData)
        {
            List <StorageProviderItemProperty> customColumns = new List <StorageProviderItemProperty>();

            if (customColumnsData != null)
            {
                foreach (FileSystemItemPropertyData column in customColumnsData)
                {
                    customColumns.Add(new StorageProviderItemProperty()
                    {
                        Id = column.Id,
                        // If value is empty Windows File Manager crushes.
                        Value = string.IsNullOrEmpty(column.Value) ? "-" : column.Value,
                        // If icon is not set Windows File Manager crushes.
                        IconResource = column.IconResource ?? Path.Combine(Config.Settings.IconsFolderPath, "Blank.ico")
                    });
                }
            }

            // Can not set provider properties on read-only files.
            // Changing read-only attribute on folders triggers folders listing. Changing it on files only.
            FileInfo file     = new FileInfo(userFileSystemPath);
            bool     readOnly = file.IsReadOnly;

            // Remove read-only attribute.
            if (readOnly && ((file.Attributes & System.IO.FileAttributes.Directory) == 0))
            {
                file.IsReadOnly = false;
                //new FileInfo(userFileSystemPath).Attributes &= ~System.IO.FileAttributes.ReadOnly;
            }

            // Update columns data.
            IStorageItem storageItem = await FsPath.GetStorageItemAsync(userFileSystemPath);

            await StorageProviderItemProperties.SetAsync(storageItem, customColumns);

            // Set read-only attribute.
            if (readOnly && ((file.Attributes & System.IO.FileAttributes.Directory) == 0))
            {
                file.IsReadOnly = true;
                //new FileInfo(userFileSystemPath).Attributes |= System.IO.FileAttributes.ReadOnly;
            }
        }
        /// <summary>
        /// Sets or removes "Download pending" icon.
        /// </summary>
        /// <param name="set">True to display the icon. False - to remove the icon.</param>
        private async Task SetDownloadPendingIconAsync(bool set)
        {
            IStorageItem storageItem = await FsPath.GetStorageItemAsync(userFileSystemPath);

            if (set)
            {
                // Set upload pending icon.

                // Set download pending icon.
                StorageProviderItemProperty propState = new StorageProviderItemProperty()
                {
                    Id           = 2,
                    Value        = "Download from server pending", // "@propsys.dll,-42291",
                    IconResource = "%systemroot%\\system32\\imageres.dll,-1402"
                };
                await StorageProviderItemProperties.SetAsync(storageItem, new[] { propState });
            }
            else
            {
                await StorageProviderItemProperties.SetAsync(storageItem, new StorageProviderItemProperty[] { });
            }
        }