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
97 changes: 66 additions & 31 deletions Files/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel.DataTransfer;
using Windows.Graphics.Imaging;
using Windows.Storage;
using Windows.Storage.Streams;
using static Files.Helpers.NativeFindStorageItemHelper;
using FileAttributes = System.IO.FileAttributes;
using Microsoft.Toolkit.Uwp.Extensions;
using static Files.Helpers.NativeFindStorageItemHelper;

namespace Files.Filesystem
{
Expand Down Expand Up @@ -68,8 +67,8 @@ public FilesystemHelpers(IShellPage associatedInstance, CancellationToken cancel

public async Task<ReturnResult> CreateAsync(IStorageItemWithPath source, bool registerHistory)
{
FileSystemStatusCode returnCode = FileSystemStatusCode.InProgress;
Progress<FileSystemStatusCode> errorCode = new Progress<FileSystemStatusCode>();
var returnCode = FileSystemStatusCode.InProgress;
var errorCode = new Progress<FileSystemStatusCode>();
errorCode.ProgressChanged += (s, e) => returnCode = e;

IStorageHistory history = await filesystemOperations.CreateAsync(source, errorCode, cancellationToken);
Expand Down Expand Up @@ -106,7 +105,7 @@ public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPat
FileOperationType.Recycle);
}

ReturnResult returnStatus = ReturnResult.InProgress;
var returnStatus = ReturnResult.InProgress;
banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus();

var pathsUnderRecycleBin = GetPathsUnderRecycleBin(source);
Expand Down Expand Up @@ -137,7 +136,7 @@ public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPat
permanently = dialog.PermanentlyDelete;
}

Stopwatch sw = new Stopwatch();
var sw = new Stopwatch();
sw.Start();

IStorageHistory history;
Expand Down Expand Up @@ -214,7 +213,7 @@ public async Task<ReturnResult> DeleteItemAsync(IStorageItemWithPath source, boo
FileOperationType.Recycle);
}

ReturnResult returnStatus = ReturnResult.InProgress;
var returnStatus = ReturnResult.InProgress;
banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus();

if (App.AppSettings.ShowConfirmDeleteDialog && showDialog) // Check if the setting to show a confirmation dialog is on
Expand All @@ -241,7 +240,7 @@ public async Task<ReturnResult> DeleteItemAsync(IStorageItemWithPath source, boo
permanently = dialog.PermanentlyDelete;
}

Stopwatch sw = new Stopwatch();
var sw = new Stopwatch();
sw.Start();

IStorageHistory history = await filesystemOperations.DeleteAsync(source, banner.Progress, banner.ErrorCode, permanently, cancellationToken);
Expand Down Expand Up @@ -292,7 +291,7 @@ public async Task<ReturnResult> DeleteItemAsync(IStorageItem source, bool showDi
FileOperationType.Recycle);
}

ReturnResult returnStatus = ReturnResult.InProgress;
var returnStatus = ReturnResult.InProgress;
banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus();

if (App.AppSettings.ShowConfirmDeleteDialog && showDialog) // Check if the setting to show a confirmation dialog is on
Expand All @@ -319,7 +318,7 @@ public async Task<ReturnResult> DeleteItemAsync(IStorageItem source, bool showDi
permanently = dialog.PermanentlyDelete;
}

Stopwatch sw = new Stopwatch();
var sw = new Stopwatch();
sw.Start();

IStorageHistory history = await filesystemOperations.DeleteAsync(source, banner.Progress, banner.ErrorCode, permanently, cancellationToken);
Expand All @@ -342,8 +341,8 @@ public async Task<ReturnResult> DeleteItemAsync(IStorageItem source, bool showDi

public async Task<ReturnResult> RestoreFromTrashAsync(IStorageItemWithPath source, string destination, bool registerHistory)
{
FileSystemStatusCode returnCode = FileSystemStatusCode.InProgress;
Progress<FileSystemStatusCode> errorCode = new Progress<FileSystemStatusCode>();
var returnCode = FileSystemStatusCode.InProgress;
var errorCode = new Progress<FileSystemStatusCode>();
errorCode.ProgressChanged += (s, e) => returnCode = e;

IStorageHistory history = await filesystemOperations.RestoreFromTrashAsync(source, destination, null, errorCode, cancellationToken);
Expand Down Expand Up @@ -412,10 +411,10 @@ public async Task<ReturnResult> CopyItemsAsync(IEnumerable<IStorageItemWithPath>
ReturnResult.InProgress,
FileOperationType.Copy);

ReturnResult returnStatus = ReturnResult.InProgress;
var returnStatus = ReturnResult.InProgress;
banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus();

Stopwatch sw = new Stopwatch();
var sw = new Stopwatch();
sw.Start();

IStorageHistory history;
Expand All @@ -432,7 +431,7 @@ public async Task<ReturnResult> CopyItemsAsync(IEnumerable<IStorageItemWithPath>
banner.ErrorCode,
cancellationToken));

progress = ((float)i / (float)source.Count()) * 100.0f;
progress = i / (float)source.Count() * 100.0f;
((IProgress<float>)banner.Progress).Report(progress);
}

Expand Down Expand Up @@ -474,10 +473,10 @@ public async Task<ReturnResult> CopyItemAsync(IStorageItemWithPath source, strin
ReturnResult.InProgress,
FileOperationType.Copy);

ReturnResult returnStatus = ReturnResult.InProgress;
var returnStatus = ReturnResult.InProgress;
banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus();

Stopwatch sw = new Stopwatch();
var sw = new Stopwatch();
sw.Start();

associatedInstance.ContentPage.ClearSelection();
Expand Down Expand Up @@ -525,7 +524,7 @@ public async Task<ReturnResult> CopyItemsFromClipboard(DataPackageView packageVi
}
ReturnResult returnStatus = ReturnResult.InProgress;

List<string> destinations = new List<string>();
var destinations = new List<string>();
foreach (IStorageItem item in source)
{
destinations.Add(Path.Combine(destination, item.Name));
Expand Down Expand Up @@ -584,14 +583,14 @@ public async Task<ReturnResult> MoveItemsAsync(IEnumerable<IStorageItemWithPath>
ReturnResult.InProgress,
FileOperationType.Move);

ReturnResult returnStatus = ReturnResult.InProgress;
var returnStatus = ReturnResult.InProgress;
banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus();

Stopwatch sw = new Stopwatch();
var sw = new Stopwatch();
sw.Start();

IStorageHistory history;
List<IStorageHistory> rawStorageHistory = new List<IStorageHistory>();
var rawStorageHistory = new List<IStorageHistory>();

associatedInstance.ContentPage.ClearSelection();
float progress;
Expand All @@ -604,7 +603,7 @@ public async Task<ReturnResult> MoveItemsAsync(IEnumerable<IStorageItemWithPath>
banner.ErrorCode,
cancellationToken));

progress = ((float)i / (float)source.Count()) * 100.0f;
progress = i / (float)source.Count() * 100.0f;
((IProgress<float>)banner.Progress).Report(progress);
}

Expand Down Expand Up @@ -646,10 +645,10 @@ public async Task<ReturnResult> MoveItemAsync(IStorageItemWithPath source, strin
ReturnResult.InProgress,
FileOperationType.Move);

ReturnResult returnStatus = ReturnResult.InProgress;
var returnStatus = ReturnResult.InProgress;
banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus();

Stopwatch sw = new Stopwatch();
var sw = new Stopwatch();
sw.Start();

associatedInstance.ContentPage.ClearSelection();
Expand Down Expand Up @@ -702,7 +701,7 @@ public async Task<ReturnResult> MoveItemsFromClipboard(DataPackageView packageVi
}
ReturnResult returnStatus = ReturnResult.InProgress;

List<string> destinations = new List<string>();
var destinations = new List<string>();
foreach (IStorageItem item in source)
{
destinations.Add(Path.Combine(destination, item.Name));
Expand All @@ -719,8 +718,8 @@ public async Task<ReturnResult> MoveItemsFromClipboard(DataPackageView packageVi

public async Task<ReturnResult> RenameAsync(IStorageItem source, string newName, NameCollisionOption collision, bool registerHistory)
{
FileSystemStatusCode returnCode = FileSystemStatusCode.InProgress;
Progress<FileSystemStatusCode> errorCode = new Progress<FileSystemStatusCode>();
var returnCode = FileSystemStatusCode.InProgress;
var errorCode = new Progress<FileSystemStatusCode>();
errorCode.ProgressChanged += (s, e) => returnCode = e;

IStorageHistory history = await filesystemOperations.RenameAsync(source, newName, collision, errorCode, cancellationToken);
Expand All @@ -735,11 +734,47 @@ public async Task<ReturnResult> RenameAsync(IStorageItem source, string newName,

public async Task<ReturnResult> RenameAsync(IStorageItemWithPath source, string newName, NameCollisionOption collision, bool registerHistory)
{
FileSystemStatusCode returnCode = FileSystemStatusCode.InProgress;
Progress<FileSystemStatusCode> errorCode = new Progress<FileSystemStatusCode>();
var returnCode = FileSystemStatusCode.InProgress;
var errorCode = new Progress<FileSystemStatusCode>();
errorCode.ProgressChanged += (s, e) => returnCode = e;

IStorageHistory history = await filesystemOperations.RenameAsync(source, newName, collision, errorCode, cancellationToken);
IStorageHistory history = null;

switch (source.ItemType)
{
case FilesystemItemType.Directory:
history = await filesystemOperations.RenameAsync(source, newName, collision, errorCode, cancellationToken);
break;
case FilesystemItemType.File:

if (Path.HasExtension(source.Path) && !Path.HasExtension(newName))
{
newName += Path.GetExtension(source.Path);
}

/* Only prompt user when extension has changed,
not when file name has changed
*/
if (Path.GetExtension(source.Path) != Path.GetExtension(newName))
{
var renameDialogText = "RenameFileDialog/Text".GetLocalized();

var yesSelected = await DialogDisplayHelper.ShowDialogAsync("Rename", renameDialogText, "Yes", "No");
if (yesSelected)
{
history = await filesystemOperations.RenameAsync(source, newName, collision, errorCode, cancellationToken);
break;
}

break;
}

history = await filesystemOperations.RenameAsync(source, newName, collision, errorCode, cancellationToken);
break;
default:
history = await filesystemOperations.RenameAsync(source, newName, collision, errorCode, cancellationToken);
break;
}

if (registerHistory && !string.IsNullOrWhiteSpace(source.Path))
{
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.ar.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,10 @@
<source>Enable multiselect options (currently only available in the tiles and grid view layout modes)</source>
<target state="new">Enable multiselect options (currently only available in the tiles and grid view layout modes)</target>
</trans-unit>
<trans-unit id="RenameFileDialog.Text" translate="yes" xml:space="preserve">
<source>If you change a file extension, the file might become unusable. Are you sure you want to change it?</source>
<target state="new">If you change a file extension, the file might become unusable. Are you sure you want to change it?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.cs-CZ.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,10 @@
<source>Enable multiselect options (currently only available in the tiles and grid view layout modes)</source>
<target state="new">Enable multiselect options (currently only available in the tiles and grid view layout modes)</target>
</trans-unit>
<trans-unit id="RenameFileDialog.Text" translate="yes" xml:space="preserve">
<source>If you change a file extension, the file might become unusable. Are you sure you want to change it?</source>
<target state="new">If you change a file extension, the file might become unusable. Are you sure you want to change it?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.da-DK.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,10 @@
<source>Enable multiselect options (currently only available in the tiles and grid view layout modes)</source>
<target state="new">Enable multiselect options (currently only available in the tiles and grid view layout modes)</target>
</trans-unit>
<trans-unit id="RenameFileDialog.Text" translate="yes" xml:space="preserve">
<source>If you change a file extension, the file might become unusable. Are you sure you want to change it?</source>
<target state="new">If you change a file extension, the file might become unusable. Are you sure you want to change it?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.da.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,10 @@
<source>Enable multiselect options (currently only available in the tiles and grid view layout modes)</source>
<target state="new">Enable multiselect options (currently only available in the tiles and grid view layout modes)</target>
</trans-unit>
<trans-unit id="RenameFileDialog.Text" translate="yes" xml:space="preserve">
<source>If you change a file extension, the file might become unusable. Are you sure you want to change it?</source>
<target state="new">If you change a file extension, the file might become unusable. Are you sure you want to change it?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.de-DE.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,10 @@
<target state="needs-review-translation">Mehrfachauswahl aktivieren (derzeitig nur für Kachel- und Gridansicht)</target>
<note from="MultilingualUpdate" annotates="source" priority="2">Please verify the translation’s accuracy as the source string was updated after it was translated.</note>
</trans-unit>
<trans-unit id="RenameFileDialog.Text" translate="yes" xml:space="preserve">
<source>If you change a file extension, the file might become unusable. Are you sure you want to change it?</source>
<target state="new">If you change a file extension, the file might become unusable. Are you sure you want to change it?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.es-ES.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,10 @@
<source>Enable multiselect options (currently only available in the tiles and grid view layout modes)</source>
<target state="new">Enable multiselect options (currently only available in the tiles and grid view layout modes)</target>
</trans-unit>
<trans-unit id="RenameFileDialog.Text" translate="yes" xml:space="preserve">
<source>If you change a file extension, the file might become unusable. Are you sure you want to change it?</source>
<target state="new">If you change a file extension, the file might become unusable. Are you sure you want to change it?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.fr-FR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,10 @@
<target state="needs-review-translation">Active l'option de sélection multiple (uniquement disponible sur la vue en tuiles ou en grilles pour le moment)</target>
<note from="MultilingualUpdate" annotates="source" priority="2">Please verify the translation’s accuracy as the source string was updated after it was translated.</note>
</trans-unit>
<trans-unit id="RenameFileDialog.Text" translate="yes" xml:space="preserve">
<source>If you change a file extension, the file might become unusable. Are you sure you want to change it?</source>
<target state="new">If you change a file extension, the file might become unusable. Are you sure you want to change it?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.he-IL.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,10 @@
<source>Enable multiselect options (currently only available in the tiles and grid view layout modes)</source>
<target state="new">Enable multiselect options (currently only available in the tiles and grid view layout modes)</target>
</trans-unit>
<trans-unit id="RenameFileDialog.Text" translate="yes" xml:space="preserve">
<source>If you change a file extension, the file might become unusable. Are you sure you want to change it?</source>
<target state="new">If you change a file extension, the file might become unusable. Are you sure you want to change it?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.hi-IN.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,10 @@
<source>Enable multiselect options (currently only available in the tiles and grid view layout modes)</source>
<target state="new">Enable multiselect options (currently only available in the tiles and grid view layout modes)</target>
</trans-unit>
<trans-unit id="RenameFileDialog.Text" translate="yes" xml:space="preserve">
<source>If you change a file extension, the file might become unusable. Are you sure you want to change it?</source>
<target state="new">If you change a file extension, the file might become unusable. Are you sure you want to change it?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.hu-HU.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2275,6 +2275,10 @@
<target state="needs-review-translation">Többszörös kijelőlés (jelenleg lista és ikon nézetekben elérhető)</target>
<note from="MultilingualUpdate" annotates="source" priority="2">Please verify the translation’s accuracy as the source string was updated after it was translated.</note>
</trans-unit>
<trans-unit id="RenameFileDialog.Text" translate="yes" xml:space="preserve">
<source>If you change a file extension, the file might become unusable. Are you sure you want to change it?</source>
<target state="new">If you change a file extension, the file might become unusable. Are you sure you want to change it?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
4 changes: 4 additions & 0 deletions Files/MultilingualResources/Files.it-IT.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2275,6 +2275,10 @@
<source>Enable multiselect options (currently only available in the tiles and grid view layout modes)</source>
<target state="new">Enable multiselect options (currently only available in the tiles and grid view layout modes)</target>
</trans-unit>
<trans-unit id="RenameFileDialog.Text" translate="yes" xml:space="preserve">
<source>If you change a file extension, the file might become unusable. Are you sure you want to change it?</source>
<target state="new">If you change a file extension, the file might become unusable. Are you sure you want to change it?</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
Loading