Exemplo n.º 1
0
        private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case "IsReadOnly":
                if (ViewModel.IsReadOnly)
                {
                    List.ForEach(x => NativeFileOperationsHelper.SetFileAttribute(
                                     x.ItemPath, System.IO.FileAttributes.ReadOnly));
                }
                else
                {
                    List.ForEach(x => NativeFileOperationsHelper.UnsetFileAttribute(
                                     x.ItemPath, System.IO.FileAttributes.ReadOnly));
                }
                break;

            case "IsHidden":
                if (ViewModel.IsHidden)
                {
                    List.ForEach(x => NativeFileOperationsHelper.SetFileAttribute(
                                     x.ItemPath, System.IO.FileAttributes.Hidden));
                }
                else
                {
                    List.ForEach(x => NativeFileOperationsHelper.UnsetFileAttribute(
                                     x.ItemPath, System.IO.FileAttributes.Hidden));
                }
                break;
            }
        }
Exemplo n.º 2
0
        private async void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case "IsReadOnly":
                if (ViewModel.IsReadOnly)
                {
                    NativeFileOperationsHelper.SetFileAttribute(
                        Item.ItemPath, System.IO.FileAttributes.ReadOnly);
                }
                else
                {
                    NativeFileOperationsHelper.UnsetFileAttribute(
                        Item.ItemPath, System.IO.FileAttributes.ReadOnly);
                }
                break;

            case "IsHidden":
                if (ViewModel.IsHidden)
                {
                    NativeFileOperationsHelper.SetFileAttribute(
                        Item.ItemPath, System.IO.FileAttributes.Hidden);
                }
                else
                {
                    NativeFileOperationsHelper.UnsetFileAttribute(
                        Item.ItemPath, System.IO.FileAttributes.Hidden);
                }
                break;

            case "ShortcutItemPath":
            case "ShortcutItemWorkingDir":
            case "ShortcutItemArguments":
                var tmpItem = (ShortcutItem)Item;
                if (string.IsNullOrWhiteSpace(ViewModel.ShortcutItemPath))
                {
                    return;
                }

                var connection = await AppServiceConnectionHelper.Instance;
                if (connection != null)
                {
                    var value = new ValueSet()
                    {
                        { "Arguments", "FileOperation" },
                        { "fileop", "UpdateLink" },
                        { "filepath", Item.ItemPath },
                        { "targetpath", ViewModel.ShortcutItemPath },
                        { "arguments", ViewModel.ShortcutItemArguments },
                        { "workingdir", ViewModel.ShortcutItemWorkingDir },
                        { "runasadmin", tmpItem.RunAsAdmin },
                    };
                    await connection.SendMessageAsync(value);
                }
                break;
            }
        }
Exemplo n.º 3
0
        public static void WriteFileTag(string filePath, string tag)
        {
            var isReadOnly = NativeFileOperationsHelper.HasFileAttribute(filePath, System.IO.FileAttributes.ReadOnly);

            if (isReadOnly) // Unset read-only attribute (#7534)
            {
                NativeFileOperationsHelper.UnsetFileAttribute(filePath, System.IO.FileAttributes.ReadOnly);
            }
            if (tag == null)
            {
                NativeFileOperationsHelper.DeleteFileFromApp($"{filePath}:files");
            }
            else if (ReadFileTag(filePath) != tag)
            {
                NativeFileOperationsHelper.WriteStringToFile($"{filePath}:files", tag);
            }
            if (isReadOnly) // Restore read-only attribute (#7534)
            {
                NativeFileOperationsHelper.SetFileAttribute(filePath, System.IO.FileAttributes.ReadOnly);
            }
        }