Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Files.Launcher/Files.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
<LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>
<Content Include="Assets\FilesOpenDialog\FilesLauncher.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\FilesOpenDialog\SetFilesAsDefault.reg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\FilesOpenDialog\UnsetFilesAsDefault.reg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
Expand Down
99 changes: 14 additions & 85 deletions src/Files.Uwp/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;
using static Files.Uwp.Helpers.PathNormalization;
using System.Collections.Specialized;
using System.Runtime.InteropServices;
using Windows.Storage.FileProperties;

namespace Files.Uwp
{
Expand Down Expand Up @@ -376,7 +379,7 @@ public virtual void ResetItemOpacity()
}
}

protected ListedItem GetItemFromElement(object element)
protected ListedItem GetItemFromElement(object element)
{
var item = element as ContentControl;
if (item == null || !CanGetItemFromElement(element))
Expand Down Expand Up @@ -858,95 +861,21 @@ protected virtual void Page_CharacterReceived(CoreWindow sender, CharacterReceiv

protected async void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
ConcurrentBag<IStorageItem> selectedStorageItems = new ConcurrentBag<IStorageItem>();

// Only support IStorageItem capable paths
e.Items.OfType<ListedItem>().ForEach(item => SelectedItems.Add(item));

var itemsCount = e.Items.Count;
PostedStatusBanner banner = itemsCount > 50 ? App.OngoingTasksViewModel.PostOperationBanner(
string.Empty,
string.Format("StatusPreparingItemsDetails_Plural".GetLocalized(), itemsCount),
0,
ReturnResult.InProgress,
FileOperationType.Prepare, new CancellationTokenSource()) : null;

try
{
await e.Items.OfType<ListedItem>().ParallelForEachAsync(async item =>
{
if (banner != null)
{
((IProgress<float>)banner.Progress).Report(selectedStorageItems.Count / (float)itemsCount * 100);
}

if (item is FtpItem ftpItem)
{
if (item.PrimaryItemAttribute is StorageItemTypes.File or StorageItemTypes.Folder)
{
selectedStorageItems.Add(await ftpItem.ToStorageItem());
}
}
else if (item.PrimaryItemAttribute == StorageItemTypes.File || item is ZipItem)
{
var result = await ParentShellPageInstance.FilesystemViewModel.GetFileFromPathAsync(item.ItemPath)
.OnSuccess(t => selectedStorageItems.Add(t));
if (!result)
{
throw new IOException($"Failed to process {item.ItemPath}.", (int)result.ErrorCode);
}
}
else if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
{
var result = await ParentShellPageInstance.FilesystemViewModel.GetFolderFromPathAsync(item.ItemPath)
.OnSuccess(t => selectedStorageItems.Add(t));
if (!result)
{
throw new IOException($"Failed to process {item.ItemPath}.", (int)result.ErrorCode);
}
}
}, 10, banner?.CancellationToken ?? default);
}
catch (Exception ex)
{
if (ex.HResult == (int)FileSystemStatusCode.Unauthorized)
{
var itemList = e.Items.OfType<ListedItem>().Select(x => StorageHelpers.FromPathAndType(
x.ItemPath, x.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
e.Data.Properties["FileDrop"] = itemList.ToList();
}
else
{
e.Cancel = true;
}
banner?.Remove();
return;
}

banner?.Remove();

var onlyStandard = selectedStorageItems.All(x => x is StorageFile || x is StorageFolder || x is SystemStorageFile || x is SystemStorageFolder);
if (onlyStandard)
{
selectedStorageItems = new ConcurrentBag<IStorageItem>(await selectedStorageItems.ToStandardStorageItemsAsync());
// Get the log file to use its properties. For some reason the drag and drop operation
// requires a BasicProperties object even though does not seem to be used.
// We supply it regardless for every VirtualStorageItem because it is checked for
var fakeFilePropsItem = await StorageFile.GetFileFromPathAsync(Path.Combine(ApplicationData.Current.LocalFolder.Path, "debug.log"));
var props = await fakeFilePropsItem.GetBasicPropertiesAsync();
var itemList = e.Items.OfType<ListedItem>().Where(x => !(x.IsHiddenItem && x.IsLinkItem && x.IsRecycleBinItem && x.IsShortcutItem)).Select(x => new VirtualStorageItem(x, props));
e.Data.SetStorageItems(itemList, false);
//e.Data.RequestedOperation = DataPackageOperation.Move;
}
if (selectedStorageItems.Count == 1)
{
if (selectedStorageItems.Single() is IStorageFile file)
{
var itemExtension = Path.GetExtension(file.Name);
if (ImagePreviewViewModel.Extensions.Any((ext) => ext.Equals(itemExtension, StringComparison.OrdinalIgnoreCase)))
{
var streamRef = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(file);
e.Data.SetBitmap(streamRef);
}
}
e.Data.SetStorageItems(selectedStorageItems, false);
}
else if (selectedStorageItems.Count > 1)
{
e.Data.SetStorageItems(selectedStorageItems, false);
}
else
catch (Exception)
{
e.Cancel = true;
}
Expand Down
1 change: 1 addition & 0 deletions src/Files.Uwp/Files.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<Compile Include="Filesystem\StorageItems\StreamWithContentType.cs" />
<Compile Include="Filesystem\StorageItems\SystemStorageFile.cs" />
<Compile Include="Filesystem\StorageItems\SystemStorageFolder.cs" />
<Compile Include="Filesystem\StorageItems\VirtualStorageItem.cs" />
<Compile Include="Filesystem\StorageItems\ZipStorageFile.cs" />
<Compile Include="Filesystem\StorageItems\ZipStorageFolder.cs" />
<Compile Include="Filesystem\BaseStorage\BaseBasicProperties.cs" />
Expand Down
63 changes: 63 additions & 0 deletions src/Files.Uwp/Filesystem/StorageItems/VirtualStorageItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Storage;
using Windows.Storage.FileProperties;

namespace Files.Uwp.Filesystem.StorageItems
{
/// <summary>
/// Implements IStorageItem, allowing us to get an instance of IStorageItem for a ListedItem
/// representing a standard filesystem item. As such, VirtualStorageItem does not support hidden,
/// shortcut, or link items.
/// </summary>
public class VirtualStorageItem : IStorageItem
{
private readonly ListedItem item;
private readonly BasicProperties props;

public VirtualStorageItem(ListedItem item, BasicProperties props)
{
this.item = item;
this.props = props;
}

public IAsyncAction RenameAsync(string desiredName)
{
throw new NotImplementedException();
}

public IAsyncAction RenameAsync(string desiredName, NameCollisionOption option)
{
throw new NotImplementedException();
}

public IAsyncAction DeleteAsync()
{
throw new NotImplementedException();
}

public IAsyncAction DeleteAsync(StorageDeleteOption option)
{
throw new NotImplementedException();
}

public IAsyncOperation<BasicProperties> GetBasicPropertiesAsync()
{
return Task.FromResult(props).AsAsyncOperation();
}

public bool IsOfType(StorageItemTypes type)
{
return item.PrimaryItemAttribute == type;
}

public FileAttributes Attributes => item.PrimaryItemAttribute == StorageItemTypes.File ? FileAttributes.Normal : FileAttributes.Directory;

public DateTimeOffset DateCreated => item.ItemDateCreatedReal;

public string Name => item.ItemName;

public string Path => item.ItemPath;
}
}