Merge pull request #181 from SunboX/code-formatting-and-renaming
some code formatting, re-naming & cleanup
This commit is contained in:
Коммит
06a8d08728
|
@ -227,7 +227,7 @@ namespace NextcloudApp
|
|||
await base.OnActivateApplicationAsync(args);
|
||||
|
||||
// Remove unnecessary notifications whenever the app is used.
|
||||
ToastNotificationManager.History.RemoveGroup(ToastNotificationService.SYNCACTION);
|
||||
ToastNotificationManager.History.RemoveGroup(ToastNotificationService.SyncAction);
|
||||
|
||||
// Handle toast activation
|
||||
var eventArgs = args as ToastNotificationActivatedEventArgs;
|
||||
|
@ -240,12 +240,12 @@ namespace NextcloudApp
|
|||
switch (query["action"])
|
||||
{
|
||||
// Nothing to do here
|
||||
case ToastNotificationService.SYNCACTION:
|
||||
case ToastNotificationService.SyncAction:
|
||||
NavigationService.Navigate(PageToken.DirectoryList.ToString(), null);
|
||||
break;
|
||||
// Open Conflict Page
|
||||
case ToastNotificationService.SYNCONFLICTACTION:
|
||||
ToastNotificationManager.History.RemoveGroup(ToastNotificationService.SYNCONFLICTACTION);
|
||||
case ToastNotificationService.SyncConflictAction:
|
||||
ToastNotificationManager.History.RemoveGroup(ToastNotificationService.SyncConflictAction);
|
||||
NavigationService.Navigate(PageToken.SyncConflict.ToString(), null);
|
||||
break;
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ namespace NextcloudApp
|
|||
// Ensure the current window is active
|
||||
Window.Current.Activate();
|
||||
// Remove unnecessary notifications whenever the app is used.
|
||||
ToastNotificationManager.History.RemoveGroup(ToastNotificationService.SYNCACTION);
|
||||
ToastNotificationManager.History.RemoveGroup(ToastNotificationService.SyncAction);
|
||||
PinStartPageParameters pageParameters = null;
|
||||
if (!string.IsNullOrEmpty(args?.Arguments))
|
||||
{
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace NextcloudApp.Converter
|
|||
{
|
||||
var conflictType = (ConflictType)value;
|
||||
|
||||
if (conflictType != ConflictType.NONE)
|
||||
if (conflictType != ConflictType.None)
|
||||
return new SolidColorBrush(Colors.Red);
|
||||
else
|
||||
return null;
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
{
|
||||
public enum ConflictSolution
|
||||
{
|
||||
NONE, PREFER_LOCAL, PREFER_REMOTE
|
||||
None,
|
||||
PreferLocal,
|
||||
PreferRemote
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using NextcloudApp.Annotations;
|
||||
using NextcloudClient.Types;
|
||||
|
@ -44,7 +42,7 @@ namespace NextcloudApp.Models
|
|||
|
||||
public BitmapImage Thumbnail
|
||||
{
|
||||
get { return _thumbnail; }
|
||||
get => _thumbnail;
|
||||
set
|
||||
{
|
||||
if (_thumbnail == value)
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
using NextcloudClient.Types;
|
||||
using SQLite.Net.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SQLite.Net.Attributes;
|
||||
|
||||
namespace NextcloudApp.Models
|
||||
{
|
||||
|
@ -14,12 +8,6 @@ namespace NextcloudApp.Models
|
|||
public int Id { get; set; }
|
||||
public string Path { get; set; }
|
||||
public bool Active { get; set; }
|
||||
public string AccessListKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.Replace('/', '_');
|
||||
}
|
||||
}
|
||||
public string AccessListKey => Path.Replace('/', '_');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,40 +21,22 @@ namespace NextcloudApp.Models
|
|||
[DefaultSettingValue(Value = DefaultValueEmptyString)]
|
||||
public string ServerAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<string>();
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(value);
|
||||
}
|
||||
get => Get<string>();
|
||||
set => Set(value);
|
||||
}
|
||||
|
||||
[DefaultSettingValue(Value = DefaultValueEmptyString)]
|
||||
public string Username
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<string>();
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(value);
|
||||
}
|
||||
get => Get<string>();
|
||||
set => Set(value);
|
||||
}
|
||||
|
||||
[DefaultSettingValue(Value = true)]
|
||||
public bool ShowFileAndFolderGroupingHeader
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<bool>();
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(value);
|
||||
}
|
||||
get => Get<bool>();
|
||||
set => Set(value);
|
||||
}
|
||||
|
||||
// As only serializable objects can be stored in the LocalSettings, we use a string internally.
|
||||
|
@ -65,10 +47,7 @@ namespace NextcloudApp.Models
|
|||
{
|
||||
var strVal = Get<string>();
|
||||
|
||||
if (string.IsNullOrEmpty(strVal))
|
||||
return PreviewImageDownloadMode.Always;
|
||||
else
|
||||
return JsonConvert.DeserializeObject<PreviewImageDownloadMode>(strVal);
|
||||
return string.IsNullOrEmpty(strVal) ? PreviewImageDownloadMode.Always : JsonConvert.DeserializeObject<PreviewImageDownloadMode>(strVal);
|
||||
}
|
||||
set
|
||||
{
|
||||
|
@ -80,92 +59,50 @@ namespace NextcloudApp.Models
|
|||
[DefaultSettingValue(Value = 0)]
|
||||
public int AppTotalRuns
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<int>();
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(value);
|
||||
}
|
||||
get => Get<int>();
|
||||
set => Set(value);
|
||||
}
|
||||
|
||||
[DefaultSettingValue(Value = DefaultValueEmptyString)]
|
||||
public string AppRunsAfterLastUpdateVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<string>();
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(value);
|
||||
}
|
||||
get => Get<string>();
|
||||
set => Set(value);
|
||||
}
|
||||
|
||||
[DefaultSettingValue(Value = 0)]
|
||||
public int AppRunsAfterLastUpdate
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<int>();
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(value);
|
||||
}
|
||||
get => Get<int>();
|
||||
set => Set(value);
|
||||
}
|
||||
|
||||
[DefaultSettingValue(Value = false)]
|
||||
public bool UseWindowsHello
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<bool>();
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(value);
|
||||
}
|
||||
get => Get<bool>();
|
||||
set => Set(value);
|
||||
}
|
||||
|
||||
[DefaultSettingValue(Value = false)]
|
||||
public bool ShowUpdateMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<bool>();
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(value);
|
||||
}
|
||||
get => Get<bool>();
|
||||
set => Set(value);
|
||||
}
|
||||
|
||||
[DefaultSettingValue(Value = false)]
|
||||
public bool IgnoreServerCertificateErrors
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<bool>();
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(value);
|
||||
}
|
||||
get => Get<bool>();
|
||||
set => Set(value);
|
||||
}
|
||||
|
||||
[DefaultSettingValue(Value = false)]
|
||||
public bool ExpertMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get<bool>();
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(value);
|
||||
}
|
||||
get => Get<bool>();
|
||||
set => Set(value);
|
||||
}
|
||||
|
||||
// As only serializable objects can be stored in the LocalSettings, we use a string internally.
|
||||
|
@ -176,10 +113,7 @@ namespace NextcloudApp.Models
|
|||
{
|
||||
var strVal = Get<string>();
|
||||
|
||||
if (string.IsNullOrEmpty(strVal))
|
||||
return GroupMode.GroupByNameAscending;
|
||||
else
|
||||
return JsonConvert.DeserializeObject<GroupMode>(strVal);
|
||||
return string.IsNullOrEmpty(strVal) ? GroupMode.GroupByNameAscending : JsonConvert.DeserializeObject<GroupMode>(strVal);
|
||||
}
|
||||
set
|
||||
{
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NextcloudClient.Types;
|
||||
|
||||
namespace NextcloudApp.Models
|
||||
namespace NextcloudApp.Models
|
||||
{
|
||||
public class PinStartPageParameters : FileInfoPageParameters
|
||||
{
|
||||
|
|
|
@ -4,9 +4,19 @@ namespace NextcloudApp.Models
|
|||
{
|
||||
public class PreviewImageDownloadModeItem
|
||||
{
|
||||
public PreviewImageDownloadModeItem()
|
||||
{
|
||||
}
|
||||
|
||||
public PreviewImageDownloadModeItem(string name, PreviewImageDownloadMode value)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public PreviewImageDownloadMode Value { get; set; }
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.ApplicationModel.DataTransfer.ShareTarget;
|
||||
|
||||
namespace NextcloudApp.Models
|
||||
{
|
||||
|
|
|
@ -6,36 +6,40 @@ namespace NextcloudApp.Models
|
|||
|
||||
public enum ConflictType
|
||||
{
|
||||
NONE, BOTHNEW, BOTH_CHANGED, LOCALDEL_REMOTECHANGE, REMOTEDEL_LOCALCHANGE
|
||||
None,
|
||||
BothNew,
|
||||
BothChanged,
|
||||
LocalDelRemoteChange,
|
||||
RemoteDelLocalChange
|
||||
}
|
||||
|
||||
public class SyncConflict
|
||||
{
|
||||
public static String GetConflictMessage(ConflictType type)
|
||||
public static string GetConflictMessage(ConflictType type)
|
||||
{
|
||||
var _resourceLoader = new ResourceLoader();
|
||||
var resourceLoader = new ResourceLoader();
|
||||
string conflictMessage;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ConflictType.NONE: return "";
|
||||
case ConflictType.BOTHNEW:
|
||||
conflictMessage = _resourceLoader.GetString("SyncConflictBothNew");
|
||||
case ConflictType.None: return "";
|
||||
case ConflictType.BothNew:
|
||||
conflictMessage = resourceLoader.GetString("SyncConflictBothNew");
|
||||
break;
|
||||
case ConflictType.BOTH_CHANGED:
|
||||
conflictMessage = _resourceLoader.GetString("SyncConflictBothChanged");
|
||||
case ConflictType.BothChanged:
|
||||
conflictMessage = resourceLoader.GetString("SyncConflictBothChanged");
|
||||
break;
|
||||
case ConflictType.LOCALDEL_REMOTECHANGE:
|
||||
conflictMessage = _resourceLoader.GetString("SyncConflictLocalDel");
|
||||
case ConflictType.LocalDelRemoteChange:
|
||||
conflictMessage = resourceLoader.GetString("SyncConflictLocalDel");
|
||||
break;
|
||||
case ConflictType.REMOTEDEL_LOCALCHANGE:
|
||||
conflictMessage = _resourceLoader.GetString("SyncConflictRemoteDel");
|
||||
case ConflictType.RemoteDelLocalChange:
|
||||
conflictMessage = resourceLoader.GetString("SyncConflictRemoteDel");
|
||||
break;
|
||||
default:
|
||||
conflictMessage = "Unknown";
|
||||
break;
|
||||
}
|
||||
return $"{_resourceLoader.GetString("SyncConflictPrefix")} {conflictMessage}";
|
||||
return $"{resourceLoader.GetString("SyncConflictPrefix")} {conflictMessage}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,6 @@ namespace NextcloudApp.Models
|
|||
public DateTime SyncDate { get; set; }
|
||||
public ConflictType ConflictType { get; set; }
|
||||
|
||||
public SyncHistory()
|
||||
{
|
||||
}
|
||||
|
||||
public bool Equals(SyncHistory other)
|
||||
{
|
||||
return Id != 0 && other.Id == Id;
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace NextcloudApp.Models
|
|||
public int Id { get; set; }
|
||||
public string ETag { get; set; }
|
||||
public DateTimeOffset? DateModified { get; set; }
|
||||
public int FsiID { get; set; }
|
||||
public int FsiId { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
public string Error { get; internal set; }
|
||||
|
@ -22,7 +22,7 @@ namespace NextcloudApp.Models
|
|||
|
||||
public SyncInfoDetail(FolderSyncInfo fsi)
|
||||
{
|
||||
this.FsiID = fsi.Id;
|
||||
FsiId = fsi.Id;
|
||||
}
|
||||
|
||||
public bool Equals(SyncInfoDetail other)
|
||||
|
@ -38,7 +38,7 @@ namespace NextcloudApp.Models
|
|||
/// </returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string datemodified = DateModified.HasValue ? DateModified.Value.ToString("u") : "";
|
||||
var datemodified = DateModified.HasValue ? DateModified.Value.ToString("u") : "";
|
||||
return "Path: " + Path + " - " +
|
||||
"FilePath: " + FilePath + " - " +
|
||||
"ETag: " + ETag + " - " +
|
||||
|
|
|
@ -4,6 +4,16 @@ namespace NextcloudApp.Models
|
|||
{
|
||||
public class ThemeItem
|
||||
{
|
||||
public ThemeItem()
|
||||
{
|
||||
}
|
||||
|
||||
public ThemeItem(string name, Theme value)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public Theme Value { get; set; }
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ using NextcloudApp.Models;
|
|||
using NextcloudApp.Utils;
|
||||
using NextcloudClient.Exceptions;
|
||||
using NextcloudClient.Types;
|
||||
using Windows.UI.Core;
|
||||
|
||||
namespace NextcloudApp.Services
|
||||
{
|
||||
|
@ -22,7 +21,7 @@ namespace NextcloudApp.Services
|
|||
{
|
||||
private static DirectoryService _instance;
|
||||
private readonly ObservableGroupingCollection<string, FileOrFolder> _groupedFilesAndFolders;
|
||||
private ObservableGroupingCollection<string, FileOrFolder> _groupedFolders;
|
||||
private readonly ObservableGroupingCollection<string, FileOrFolder> _groupedFolders;
|
||||
private bool _isSorting;
|
||||
private bool _continueListing;
|
||||
private bool _isSelecting;
|
||||
|
@ -89,8 +88,6 @@ namespace NextcloudApp.Services
|
|||
case GroupMode.GroupByTypeDescending:
|
||||
GroupByTypeDescending();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,7 +179,7 @@ namespace NextcloudApp.Services
|
|||
|
||||
public void ToggleSelectionMode()
|
||||
{
|
||||
IsSelecting = IsSelecting ? false : true;
|
||||
IsSelecting = !IsSelecting;
|
||||
}
|
||||
|
||||
private static string GetSizeHeader(ResourceInfo fileOrFolder)
|
||||
|
@ -194,12 +191,16 @@ namespace NextcloudApp.Services
|
|||
|
||||
var index = 0;
|
||||
|
||||
for (int i = 0; i < sizesValuesMb.Length; i++)
|
||||
foreach (var t in sizesValuesMb)
|
||||
{
|
||||
if (sizeMb > sizesValuesMb[i])
|
||||
if (sizeMb > t)
|
||||
{
|
||||
index++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return sizesDisplay[index];
|
||||
|
@ -212,7 +213,7 @@ namespace NextcloudApp.Services
|
|||
|
||||
public async Task StartDirectoryListing()
|
||||
{
|
||||
await StartDirectoryListing(null, null);
|
||||
await StartDirectoryListing(null);
|
||||
}
|
||||
|
||||
public async Task StartDirectoryListing(ResourceInfo resourceInfoToExclude, String viewName = null)
|
||||
|
@ -272,29 +273,28 @@ namespace NextcloudApp.Services
|
|||
foreach (var item in list)
|
||||
{
|
||||
if (resourceInfoToExclude != null && item == resourceInfoToExclude)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
FilesAndFolders.Add(new FileOrFolder(item));
|
||||
|
||||
if (item.IsDirectory)
|
||||
if (!item.IsDirectory)
|
||||
{
|
||||
if (RemoveResourceInfos != null)
|
||||
{
|
||||
int index = RemoveResourceInfos.FindIndex(
|
||||
delegate (ResourceInfo res)
|
||||
{
|
||||
return res.Path.Equals(item.Path, StringComparison.Ordinal);
|
||||
});
|
||||
if (index == -1)
|
||||
{
|
||||
Folders.Add(new FileOrFolder(item));
|
||||
}
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
if (RemoveResourceInfos != null)
|
||||
{
|
||||
var index = RemoveResourceInfos.FindIndex(res => res.Path.Equals(item.Path, StringComparison.Ordinal));
|
||||
if (index == -1)
|
||||
{
|
||||
Folders.Add(new FileOrFolder(item));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Folders.Add(new FileOrFolder(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -372,7 +372,7 @@ namespace NextcloudApp.Services
|
|||
|
||||
public bool IsSorting
|
||||
{
|
||||
get { return _isSorting; }
|
||||
get => _isSorting;
|
||||
set
|
||||
{
|
||||
if (_isSorting == value)
|
||||
|
@ -387,7 +387,7 @@ namespace NextcloudApp.Services
|
|||
|
||||
public string SelectionMode
|
||||
{
|
||||
get { return _selectionMode; }
|
||||
get => _selectionMode;
|
||||
set
|
||||
{
|
||||
if (_selectionMode == value)
|
||||
|
@ -401,7 +401,7 @@ namespace NextcloudApp.Services
|
|||
|
||||
public bool IsSelecting
|
||||
{
|
||||
get { return _isSelecting; }
|
||||
get => _isSelecting;
|
||||
set
|
||||
{
|
||||
if (_isSelecting == value)
|
||||
|
@ -511,7 +511,7 @@ namespace NextcloudApp.Services
|
|||
var success = await client.Delete(path);
|
||||
if (!success)
|
||||
{
|
||||
return success;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,16 +16,17 @@ namespace NextcloudApp.Services
|
|||
public void StartMigration()
|
||||
{
|
||||
var localSettings = ApplicationData.Current.LocalSettings;
|
||||
if (localSettings.Values.ContainsKey("Password"))
|
||||
if (!localSettings.Values.ContainsKey("Password"))
|
||||
{
|
||||
var vault = new PasswordVault();
|
||||
vault.Add(new PasswordCredential(
|
||||
SettingsService.Instance.LocalSettings.ServerAddress,
|
||||
SettingsService.Instance.LocalSettings.Username,
|
||||
(string)localSettings.Values["Password"]
|
||||
));
|
||||
localSettings.Values.Remove("Password");
|
||||
return;
|
||||
}
|
||||
var vault = new PasswordVault();
|
||||
vault.Add(new PasswordCredential(
|
||||
SettingsService.Instance.LocalSettings.ServerAddress,
|
||||
SettingsService.Instance.LocalSettings.Username,
|
||||
(string)localSettings.Values["Password"]
|
||||
));
|
||||
localSettings.Values.Remove("Password");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System.Net;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Microsoft.Practices.Unity;
|
||||
using NextcloudClient.Exceptions;
|
||||
|
|
|
@ -14,45 +14,47 @@ namespace NextcloudApp.Services
|
|||
|
||||
private StatusBarService()
|
||||
{
|
||||
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
|
||||
if (!ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
|
||||
{
|
||||
var statusBar = StatusBar.GetForCurrentView();
|
||||
statusBar.BackgroundOpacity = 1;
|
||||
var theme = SettingsService.Instance.RoamingSettings.Theme;
|
||||
switch (theme)
|
||||
{
|
||||
case Theme.Dark:
|
||||
statusBar.BackgroundColor = Colors.Black;
|
||||
statusBar.ForegroundColor = Colors.White;
|
||||
break;
|
||||
case Theme.Light:
|
||||
statusBar.BackgroundColor = Colors.White;
|
||||
statusBar.ForegroundColor = Colors.Black;
|
||||
break;
|
||||
}
|
||||
|
||||
SettingsService.Instance.RoamingSettings.PropertyChanged += RoamingSettingsOnPropertyChanged;
|
||||
return;
|
||||
}
|
||||
var statusBar = StatusBar.GetForCurrentView();
|
||||
statusBar.BackgroundOpacity = 1;
|
||||
var theme = SettingsService.Instance.RoamingSettings.Theme;
|
||||
switch (theme)
|
||||
{
|
||||
case Theme.Dark:
|
||||
statusBar.BackgroundColor = Colors.Black;
|
||||
statusBar.ForegroundColor = Colors.White;
|
||||
break;
|
||||
case Theme.Light:
|
||||
statusBar.BackgroundColor = Colors.White;
|
||||
statusBar.ForegroundColor = Colors.Black;
|
||||
break;
|
||||
}
|
||||
|
||||
SettingsService.Instance.RoamingSettings.PropertyChanged += RoamingSettingsOnPropertyChanged;
|
||||
}
|
||||
|
||||
private void RoamingSettingsOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName.Equals("Theme"))
|
||||
if (!e.PropertyName.Equals("Theme"))
|
||||
{
|
||||
var statusBar = StatusBar.GetForCurrentView();
|
||||
statusBar.BackgroundOpacity = 1;
|
||||
var theme = SettingsService.Instance.RoamingSettings.Theme;
|
||||
switch (theme)
|
||||
{
|
||||
case Theme.Dark:
|
||||
statusBar.BackgroundColor = Colors.Black;
|
||||
statusBar.ForegroundColor = Colors.White;
|
||||
break;
|
||||
case Theme.Light:
|
||||
statusBar.BackgroundColor = Colors.White;
|
||||
statusBar.ForegroundColor = Colors.Black;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
var statusBar = StatusBar.GetForCurrentView();
|
||||
statusBar.BackgroundOpacity = 1;
|
||||
var theme = SettingsService.Instance.RoamingSettings.Theme;
|
||||
switch (theme)
|
||||
{
|
||||
case Theme.Dark:
|
||||
statusBar.BackgroundColor = Colors.Black;
|
||||
statusBar.ForegroundColor = Colors.White;
|
||||
break;
|
||||
case Theme.Light:
|
||||
statusBar.BackgroundColor = Colors.White;
|
||||
statusBar.ForegroundColor = Colors.Black;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ using System.Threading.Tasks;
|
|||
using NextcloudClient.Types;
|
||||
using NextcloudClient.Exceptions;
|
||||
using NextcloudApp.Models;
|
||||
using Windows.Storage.FileProperties;
|
||||
using NextcloudApp.Utils;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
|
@ -19,103 +18,107 @@ namespace NextcloudApp.Services
|
|||
{
|
||||
public class SyncService
|
||||
{
|
||||
private FolderSyncInfo folderSyncInfo;
|
||||
private StorageFolder baseFolder;
|
||||
private ResourceInfo resourceInfo;
|
||||
private NextcloudClient.NextcloudClient client;
|
||||
private List<SyncInfoDetail> sidList;
|
||||
private readonly IResourceLoader resourceLoader;
|
||||
private readonly FolderSyncInfo _folderSyncInfo;
|
||||
private readonly StorageFolder _baseFolder;
|
||||
private readonly ResourceInfo _resourceInfo;
|
||||
private NextcloudClient.NextcloudClient _client;
|
||||
private readonly List<SyncInfoDetail> _sidList;
|
||||
private readonly IResourceLoader _resourceLoader;
|
||||
|
||||
public SyncService(StorageFolder startFolder, ResourceInfo resourceInfo, FolderSyncInfo syncInfo, IResourceLoader resourceLoader)
|
||||
{
|
||||
this.baseFolder = startFolder;
|
||||
this.folderSyncInfo = syncInfo;
|
||||
this.resourceInfo = resourceInfo;
|
||||
this.resourceLoader = resourceLoader;
|
||||
sidList = new List<SyncInfoDetail>();
|
||||
_baseFolder = startFolder;
|
||||
_folderSyncInfo = syncInfo;
|
||||
_resourceInfo = resourceInfo;
|
||||
_resourceLoader = resourceLoader;
|
||||
_sidList = new List<SyncInfoDetail>();
|
||||
}
|
||||
|
||||
public async Task<bool> StartSync()
|
||||
{
|
||||
if (!SyncDbUtils.LockFolderSyncInfo(folderSyncInfo))
|
||||
if (!SyncDbUtils.LockFolderSyncInfo(_folderSyncInfo))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
client = await ClientService.GetClient();
|
||||
_client = await ClientService.GetClient();
|
||||
|
||||
if (client == null)
|
||||
if (_client == null)
|
||||
{
|
||||
// ERROR
|
||||
throw new NullReferenceException(this.resourceLoader.GetString(ResourceConstants.SyncService_Error_CannotCreateClient));
|
||||
throw new NullReferenceException(_resourceLoader.GetString(ResourceConstants.SyncService_Error_CannotCreateClient));
|
||||
}
|
||||
|
||||
int changedCount = 0;
|
||||
List<SyncInfoDetail> oldList = SyncDbUtils.GetAllSyncInfoDetails(folderSyncInfo);
|
||||
var changedCount = 0;
|
||||
var oldList = SyncDbUtils.GetAllSyncInfoDetails(_folderSyncInfo);
|
||||
Debug.WriteLine("Sid List before Sync: ");
|
||||
|
||||
foreach (SyncInfoDetail detail in oldList)
|
||||
foreach (var detail in oldList)
|
||||
{
|
||||
Debug.WriteLine("Detail: " + detail.ToString());
|
||||
Debug.WriteLine("Detail: " + detail);
|
||||
}
|
||||
|
||||
var sid = SyncDbUtils.GetSyncInfoDetail(resourceInfo, folderSyncInfo);
|
||||
var sid = SyncDbUtils.GetSyncInfoDetail(_resourceInfo, _folderSyncInfo);
|
||||
var errorCount = 0;
|
||||
|
||||
try
|
||||
{
|
||||
if (sid == null)
|
||||
{
|
||||
sid = new SyncInfoDetail(folderSyncInfo)
|
||||
sid = new SyncInfoDetail(_folderSyncInfo)
|
||||
{
|
||||
Path = resourceInfo.Path,
|
||||
FilePath = baseFolder.Path,
|
||||
Path = _resourceInfo.Path,
|
||||
FilePath = _baseFolder.Path,
|
||||
};
|
||||
|
||||
SyncDbUtils.SaveSyncInfoDetail(sid);
|
||||
}
|
||||
else
|
||||
{
|
||||
sidList.Remove(sid);
|
||||
_sidList.Remove(sid);
|
||||
sid.Error = null;
|
||||
}
|
||||
|
||||
changedCount = await SyncFolder(resourceInfo, baseFolder);
|
||||
changedCount = await SyncFolder(_resourceInfo, _baseFolder);
|
||||
|
||||
foreach (SyncInfoDetail detail in oldList)
|
||||
foreach (var detail in oldList)
|
||||
{
|
||||
if (!sidList.Contains(detail) && detail.FilePath.StartsWith(baseFolder.Path))
|
||||
if (_sidList.Contains(detail) || !detail.FilePath.StartsWith(_baseFolder.Path))
|
||||
{
|
||||
// The items left here must have been deleted both remotely and locally so the sid is obsolete.
|
||||
SyncDbUtils.DeleteSyncInfoDetail(detail, false);
|
||||
changedCount++;
|
||||
continue;
|
||||
}
|
||||
// The items left here must have been deleted both remotely and locally so the sid is obsolete.
|
||||
SyncDbUtils.DeleteSyncInfoDetail(detail, false);
|
||||
changedCount++;
|
||||
}
|
||||
errorCount = SyncDbUtils.GetErrorConflictCount(folderSyncInfo);
|
||||
errorCount = SyncDbUtils.GetErrorConflictCount(_folderSyncInfo);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
sid.Error = e.Message;
|
||||
if (sid != null)
|
||||
{
|
||||
sid.Error = e.Message;
|
||||
}
|
||||
errorCount++;
|
||||
}
|
||||
|
||||
SyncDbUtils.SaveSyncInfoDetail(sid);
|
||||
List<SyncInfoDetail> newSidList = SyncDbUtils.GetAllSyncInfoDetails(folderSyncInfo);
|
||||
var newSidList = SyncDbUtils.GetAllSyncInfoDetails(_folderSyncInfo);
|
||||
Debug.WriteLine("Sid List after Sync: ");
|
||||
|
||||
foreach (SyncInfoDetail detail in newSidList)
|
||||
foreach (var detail in newSidList)
|
||||
{
|
||||
Debug.WriteLine("Detail: " + detail.ToString());
|
||||
Debug.WriteLine("Detail: " + detail);
|
||||
}
|
||||
|
||||
ToastNotificationService.ShowSyncFinishedNotification(folderSyncInfo.Path, changedCount, errorCount);
|
||||
ToastNotificationService.ShowSyncFinishedNotification(_folderSyncInfo.Path, changedCount, errorCount);
|
||||
return errorCount == 0;
|
||||
}
|
||||
finally
|
||||
{
|
||||
SyncDbUtils.UnlockFolderSyncInfo(folderSyncInfo);
|
||||
SyncDbUtils.UnlockFolderSyncInfo(_folderSyncInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,51 +127,51 @@ namespace NextcloudApp.Services
|
|||
/// </summary>
|
||||
/// <param name="resourceInfo">webdav Resource to sync</param>
|
||||
/// <param name="folder">Target folder</param>
|
||||
private async Task<int> SyncFolder(ResourceInfo info, StorageFolder folder)
|
||||
private async Task<int> SyncFolder(ResourceInfo resourceInfo, StorageFolder folder)
|
||||
{
|
||||
SyncInfoDetail sid = SyncDbUtils.GetSyncInfoDetail(info, folderSyncInfo);
|
||||
var sid = SyncDbUtils.GetSyncInfoDetail(resourceInfo, _folderSyncInfo);
|
||||
sid.Error = null;
|
||||
int changesCount = 0;
|
||||
var changesCount = 0;
|
||||
try
|
||||
{
|
||||
Debug.WriteLine("Sync folder " + info.Path + ":" + folder.Path);
|
||||
IReadOnlyList<StorageFile> localFiles = await folder.GetFilesAsync();
|
||||
IReadOnlyList<StorageFolder> localFolders = await folder.GetFoldersAsync();
|
||||
Debug.WriteLine("Sync folder " + resourceInfo.Path + ":" + folder.Path);
|
||||
var localFiles = await folder.GetFilesAsync();
|
||||
var localFolders = await folder.GetFoldersAsync();
|
||||
|
||||
List<ResourceInfo> list = null;
|
||||
try
|
||||
{
|
||||
list = await client.List(info.Path);
|
||||
list = await _client.List(resourceInfo.Path);
|
||||
}
|
||||
catch (ResponseError e)
|
||||
{
|
||||
ResponseErrorHandlerService.HandleException(e);
|
||||
}
|
||||
|
||||
List<IStorageItem> synced = new List<IStorageItem>();
|
||||
var synced = new List<IStorageItem>();
|
||||
|
||||
if (list != null && list.Count > 0)
|
||||
{
|
||||
foreach (ResourceInfo subInfo in list)
|
||||
foreach (var subInfo in list)
|
||||
{
|
||||
if (subInfo.IsDirectory)
|
||||
{
|
||||
IEnumerable<StorageFolder> localFoldersWithName = localFolders.Where(f => f.Name.Equals(subInfo.Name));
|
||||
StorageFolder subFolder = localFoldersWithName.FirstOrDefault();
|
||||
var localFoldersWithName = localFolders.Where(f => f.Name.Equals(subInfo.Name));
|
||||
var subFolder = localFoldersWithName.FirstOrDefault();
|
||||
// Can localFoldersWithName be null?
|
||||
if (subFolder == null)
|
||||
{
|
||||
var subSid = SyncDbUtils.GetSyncInfoDetail(subInfo, folderSyncInfo);
|
||||
var subSid = SyncDbUtils.GetSyncInfoDetail(subInfo, _folderSyncInfo);
|
||||
if (subSid != null)
|
||||
{
|
||||
Debug.WriteLine("Sync folder (delete remotely) " + subInfo.Path);
|
||||
if (await client.Delete(subInfo.Path))
|
||||
if (await _client.Delete(subInfo.Path))
|
||||
{
|
||||
SyncDbUtils.DeleteSyncInfoDetail(subSid, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
sid.Error = String.Format(this.resourceLoader.GetString(ResourceConstants.SyncService_Error_DeleteFolderRemotely), subInfo.Path);
|
||||
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_DeleteFolderRemotely), subInfo.Path);
|
||||
// Error could be overridden by other errors
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +181,7 @@ namespace NextcloudApp.Services
|
|||
Debug.WriteLine("Sync folder (create locally) " + subInfo.Path);
|
||||
subFolder = await folder.CreateFolderAsync(subInfo.Name);
|
||||
|
||||
SyncInfoDetail syncInfoDetail = new SyncInfoDetail(folderSyncInfo)
|
||||
var syncInfoDetail = new SyncInfoDetail(_folderSyncInfo)
|
||||
{
|
||||
Path = subInfo.Path,
|
||||
FilePath = subFolder.Path
|
||||
|
@ -191,13 +194,13 @@ namespace NextcloudApp.Services
|
|||
}
|
||||
else
|
||||
{
|
||||
var subSid = SyncDbUtils.GetSyncInfoDetail(subInfo, folderSyncInfo);
|
||||
var subSid = SyncDbUtils.GetSyncInfoDetail(subInfo, _folderSyncInfo);
|
||||
if (subSid == null)
|
||||
{
|
||||
// Both new
|
||||
Debug.WriteLine("Sync folder (create both) " + subInfo.Path);
|
||||
|
||||
SyncInfoDetail syncInfoDetail = new SyncInfoDetail(folderSyncInfo)
|
||||
var syncInfoDetail = new SyncInfoDetail(_folderSyncInfo)
|
||||
{
|
||||
Path = subInfo.Path,
|
||||
FilePath = subFolder.Path
|
||||
|
@ -212,62 +215,63 @@ namespace NextcloudApp.Services
|
|||
}
|
||||
else
|
||||
{
|
||||
IEnumerable<StorageFile> localFilessWithName = localFiles.Where(f => f.Name.Equals(subInfo.Name));
|
||||
var localFilessWithName = localFiles.Where(f => f.Name.Equals(subInfo.Name));
|
||||
// Can localFilessWithName be null?
|
||||
StorageFile subFile = localFilessWithName.FirstOrDefault();
|
||||
var subFile = localFilessWithName.FirstOrDefault();
|
||||
if (subFile != null)
|
||||
{
|
||||
synced.Add(subFile);
|
||||
}
|
||||
changesCount = changesCount + await SyncFile(subInfo, subFile, info, folder);
|
||||
changesCount = changesCount + await SyncFile(subInfo, subFile, resourceInfo, folder);
|
||||
//syncTasks.Add(SyncFile(subInfo, subFile, info, folder));
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (StorageFile file in localFiles)
|
||||
foreach (var file in localFiles)
|
||||
{
|
||||
if (!synced.Contains(file))
|
||||
{
|
||||
changesCount = changesCount + await SyncFile(null, file, info, folder);
|
||||
changesCount = changesCount + await SyncFile(null, file, resourceInfo, folder);
|
||||
//syncTasks.Add(SyncFile(null, file, info, folder));
|
||||
}
|
||||
}
|
||||
foreach (StorageFolder localFolder in localFolders)
|
||||
foreach (var localFolder in localFolders)
|
||||
{
|
||||
if (!synced.Contains(localFolder))
|
||||
if (synced.Contains(localFolder))
|
||||
{
|
||||
var subSid = SyncDbUtils.GetSyncInfoDetail(localFolder, folderSyncInfo);
|
||||
if (subSid != null)
|
||||
continue;
|
||||
}
|
||||
var subSid = SyncDbUtils.GetSyncInfoDetail(localFolder, _folderSyncInfo);
|
||||
if (subSid != null)
|
||||
{
|
||||
// Delete all sids and local folder
|
||||
Debug.WriteLine("Sync folder (delete locally) " + localFolder.Path);
|
||||
await localFolder.DeleteAsync();
|
||||
SyncDbUtils.DeleteSyncInfoDetail(subSid, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create sid and remotefolder
|
||||
var newPath = resourceInfo.Path + localFolder.Name;
|
||||
Debug.WriteLine("Sync folder (create remotely) " + newPath);
|
||||
|
||||
if (await _client.CreateDirectory(newPath))
|
||||
{
|
||||
// Delete all sids and local folder
|
||||
Debug.WriteLine("Sync folder (delete locally) " + localFolder.Path);
|
||||
await localFolder.DeleteAsync();
|
||||
SyncDbUtils.DeleteSyncInfoDetail(subSid, true);
|
||||
var subInfo = await _client.GetResourceInfo(resourceInfo.Path, localFolder.Name);
|
||||
|
||||
var syncInfoDetail = new SyncInfoDetail(_folderSyncInfo)
|
||||
{
|
||||
Path = subInfo.Path,
|
||||
FilePath = localFolder.Path
|
||||
};
|
||||
|
||||
SyncDbUtils.SaveSyncInfoDetail(syncInfoDetail);
|
||||
changesCount = changesCount + await SyncFolder(subInfo, localFolder);
|
||||
//syncTasks.Add(SyncFolder(subInfo, localFolder));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create sid and remotefolder
|
||||
string newPath = info.Path + localFolder.Name;
|
||||
Debug.WriteLine("Sync folder (create remotely) " + newPath);
|
||||
|
||||
if (await client.CreateDirectory(newPath))
|
||||
{
|
||||
ResourceInfo subInfo = await client.GetResourceInfo(info.Path, localFolder.Name);
|
||||
|
||||
SyncInfoDetail syncInfoDetail = new SyncInfoDetail(folderSyncInfo)
|
||||
{
|
||||
Path = subInfo.Path,
|
||||
FilePath = localFolder.Path
|
||||
};
|
||||
|
||||
SyncDbUtils.SaveSyncInfoDetail(syncInfoDetail);
|
||||
changesCount = changesCount + await SyncFolder(subInfo, localFolder);
|
||||
//syncTasks.Add(SyncFolder(subInfo, localFolder));
|
||||
}
|
||||
else
|
||||
{
|
||||
sid.Error = String.Format(this.resourceLoader.GetString(ResourceConstants.SyncService_Error_CreateFolderRemotely), newPath);
|
||||
}
|
||||
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_CreateFolderRemotely), newPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -277,7 +281,7 @@ namespace NextcloudApp.Services
|
|||
{
|
||||
sid.Error = e.Message;
|
||||
}
|
||||
sidList.Add(sid);
|
||||
_sidList.Add(sid);
|
||||
SyncDbUtils.SaveSyncInfoDetail(sid);
|
||||
SyncDbUtils.SaveSyncHistory(sid);
|
||||
return changesCount;
|
||||
|
@ -286,29 +290,29 @@ namespace NextcloudApp.Services
|
|||
private async Task<int> SyncFile(ResourceInfo info, StorageFile file, ResourceInfo parent, StorageFolder parentFolder)
|
||||
{
|
||||
SyncInfoDetail sid = null;
|
||||
bool changed = false;
|
||||
bool deleted = false;
|
||||
var changed = false;
|
||||
var deleted = false;
|
||||
if (info != null)
|
||||
{
|
||||
sid = SyncDbUtils.GetSyncInfoDetail(info, folderSyncInfo);
|
||||
sid = SyncDbUtils.GetSyncInfoDetail(info, _folderSyncInfo);
|
||||
}
|
||||
else if (file != null)
|
||||
{
|
||||
sid = SyncDbUtils.GetSyncInfoDetail(file, folderSyncInfo);
|
||||
sid = SyncDbUtils.GetSyncInfoDetail(file, _folderSyncInfo);
|
||||
}
|
||||
if (sid == null)
|
||||
{
|
||||
sid = new SyncInfoDetail(folderSyncInfo);
|
||||
sid = new SyncInfoDetail(_folderSyncInfo);
|
||||
}
|
||||
sid.Error = null;
|
||||
sid.ConflictType = ConflictType.NONE;
|
||||
sid.ConflictType = ConflictType.None;
|
||||
|
||||
try
|
||||
{
|
||||
DateTimeOffset currentModified;
|
||||
if (file != null)
|
||||
{
|
||||
BasicProperties basicProperties = await file.GetBasicPropertiesAsync();
|
||||
var basicProperties = await file.GetBasicPropertiesAsync();
|
||||
currentModified = basicProperties.DateModified;
|
||||
}
|
||||
|
||||
|
@ -318,36 +322,36 @@ namespace NextcloudApp.Services
|
|||
{
|
||||
sid.Path = info.Path + "/" + info.Name;
|
||||
sid.FilePath = file.Path;
|
||||
sid.ConflictType = ConflictType.BOTHNEW;
|
||||
sid.ConflictType = ConflictType.BothNew;
|
||||
Debug.WriteLine("Sync file: Conflict (both new) " + info.Path + "/" + info.Name);
|
||||
}
|
||||
else if (file != null)
|
||||
{
|
||||
// Create sid and upload file
|
||||
string newPath = parent.Path + file.Name;
|
||||
var newPath = parent.Path + file.Name;
|
||||
Debug.WriteLine("Sync file (Upload)" + newPath);
|
||||
sid.DateModified = currentModified;
|
||||
sid.FilePath = file.Path;
|
||||
if (await UploadFile(file, newPath))
|
||||
{
|
||||
ResourceInfo newInfo = await client.GetResourceInfo(parent.Path, file.Name);
|
||||
var newInfo = await _client.GetResourceInfo(parent.Path, file.Name);
|
||||
sid.Path = newInfo.Path + "/" + newInfo.Name;
|
||||
sid.ETag = newInfo.ETag;
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sid.Error = String.Format(this.resourceLoader.GetString(ResourceConstants.SyncService_Error_UploadFile), file.Name);
|
||||
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_UploadFile), file.Name);
|
||||
}
|
||||
}
|
||||
else if (info != null)
|
||||
{
|
||||
// Create sid and download file
|
||||
StorageFile localFile = await parentFolder.CreateFileAsync(info.Name);
|
||||
var localFile = await parentFolder.CreateFileAsync(info.Name);
|
||||
Debug.WriteLine("Sync file (Download)" + localFile.Path);
|
||||
if (await this.DownloadFile(localFile, info.Path + "/" + info.Name))
|
||||
if (await DownloadFile(localFile, info.Path + "/" + info.Name))
|
||||
{
|
||||
BasicProperties basicProperties = await localFile.GetBasicPropertiesAsync();
|
||||
var basicProperties = await localFile.GetBasicPropertiesAsync();
|
||||
currentModified = basicProperties.DateModified;
|
||||
sid.Path = info.Path + "/" + info.Name;
|
||||
sid.ETag = info.ETag;
|
||||
|
@ -357,7 +361,7 @@ namespace NextcloudApp.Services
|
|||
}
|
||||
else
|
||||
{
|
||||
sid.Error = String.Format(this.resourceLoader.GetString(ResourceConstants.SyncService_Error_DownloadFile), info.Name);
|
||||
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_DownloadFile), info.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -365,11 +369,14 @@ namespace NextcloudApp.Services
|
|||
{
|
||||
if (info == null)
|
||||
{
|
||||
if (sid.DateModified.Value.Equals(currentModified))
|
||||
if (sid.DateModified != null && sid.DateModified.Value.Equals(currentModified))
|
||||
{
|
||||
Debug.WriteLine("Sync file (Delete locally) " + sid.Path);
|
||||
// Remove sid and local file
|
||||
await file.DeleteAsync();
|
||||
if (file != null)
|
||||
{
|
||||
await file.DeleteAsync();
|
||||
}
|
||||
SyncDbUtils.DeleteSyncInfoDetail(sid, false);
|
||||
changed = true;
|
||||
deleted = true;
|
||||
|
@ -378,35 +385,43 @@ namespace NextcloudApp.Services
|
|||
{
|
||||
switch (sid.ConflictSolution)
|
||||
{
|
||||
case ConflictSolution.PREFER_LOCAL:
|
||||
string newPath = parent.Path + file.Name;
|
||||
Debug.WriteLine("Sync file (Upload)" + newPath);
|
||||
sid.DateModified = currentModified;
|
||||
sid.FilePath = file.Path;
|
||||
if (await UploadFile(file, newPath))
|
||||
case ConflictSolution.PreferLocal:
|
||||
if (file != null)
|
||||
{
|
||||
ResourceInfo newInfo = await client.GetResourceInfo(parent.Path, file.Name);
|
||||
sid.Path = newInfo.Path + "/" + newInfo.Name;
|
||||
sid.ETag = newInfo.ETag;
|
||||
sid.ConflictSolution = ConflictSolution.NONE;
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sid.Error = String.Format(this.resourceLoader.GetString(ResourceConstants.SyncService_Error_UploadFile), file.Name);
|
||||
var newPath = parent.Path + file.Name;
|
||||
Debug.WriteLine("Sync file (Upload)" + newPath);
|
||||
sid.DateModified = currentModified;
|
||||
sid.FilePath = file.Path;
|
||||
if (await UploadFile(file, newPath))
|
||||
{
|
||||
var newInfo = await _client.GetResourceInfo(parent.Path, file.Name);
|
||||
sid.Path = newInfo.Path + "/" + newInfo.Name;
|
||||
sid.ETag = newInfo.ETag;
|
||||
sid.ConflictSolution = ConflictSolution.None;
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_UploadFile), file.Name);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ConflictSolution.PREFER_REMOTE:
|
||||
case ConflictSolution.PreferRemote:
|
||||
Debug.WriteLine("Sync file (Delete locally) " + sid.Path);
|
||||
// Remove sid and local file
|
||||
await file.DeleteAsync();
|
||||
if (file != null)
|
||||
{
|
||||
await file.DeleteAsync();
|
||||
}
|
||||
SyncDbUtils.DeleteSyncInfoDetail(sid, false);
|
||||
deleted = true;
|
||||
changed = true;
|
||||
break;
|
||||
case ConflictSolution.None:
|
||||
break;
|
||||
default:
|
||||
Debug.WriteLine("Sync file: Conflict (Deleted remotely, but changed locally) " + sid.Path);
|
||||
sid.ConflictType = ConflictType.REMOTEDEL_LOCALCHANGE;
|
||||
sid.ConflictType = ConflictType.RemoteDelLocalChange;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -417,7 +432,7 @@ namespace NextcloudApp.Services
|
|||
{
|
||||
Debug.WriteLine("Sync file (Delete remotely) " + sid.Path);
|
||||
// Remove sid and remote file
|
||||
await client.Delete(info.Path + "/" + info.Name);
|
||||
await _client.Delete(info.Path + "/" + info.Name);
|
||||
SyncDbUtils.DeleteSyncInfoDetail(sid, false);
|
||||
deleted = true;
|
||||
changed = true;
|
||||
|
@ -426,36 +441,38 @@ namespace NextcloudApp.Services
|
|||
{
|
||||
switch (sid.ConflictSolution)
|
||||
{
|
||||
case ConflictSolution.PREFER_LOCAL:
|
||||
case ConflictSolution.PreferLocal:
|
||||
Debug.WriteLine("Sync file (Delete remotely) " + sid.Path);
|
||||
// Remove sid and remote file
|
||||
await client.Delete(info.Path + "/" + info.Name);
|
||||
await _client.Delete(info.Path + "/" + info.Name);
|
||||
SyncDbUtils.DeleteSyncInfoDetail(sid, false);
|
||||
deleted = true;
|
||||
changed = true;
|
||||
break;
|
||||
case ConflictSolution.PREFER_REMOTE:
|
||||
case ConflictSolution.PreferRemote:
|
||||
// Update local file
|
||||
StorageFile localFile = await parentFolder.CreateFileAsync(info.Name);
|
||||
var localFile = await parentFolder.CreateFileAsync(info.Name);
|
||||
Debug.WriteLine("Sync file (Download)" + localFile.Path);
|
||||
if (await this.DownloadFile(localFile, info.Path + "/" + info.Name))
|
||||
if (await DownloadFile(localFile, info.Path + "/" + info.Name))
|
||||
{
|
||||
BasicProperties basicProperties = await localFile.GetBasicPropertiesAsync();
|
||||
var basicProperties = await localFile.GetBasicPropertiesAsync();
|
||||
currentModified = basicProperties.DateModified;
|
||||
sid.ETag = info.ETag;
|
||||
sid.DateModified = currentModified;
|
||||
sid.ConflictSolution = ConflictSolution.NONE;
|
||||
sid.ConflictSolution = ConflictSolution.None;
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sid.Error = String.Format(this.resourceLoader.GetString(ResourceConstants.SyncService_Error_DownloadFile), info.Name);
|
||||
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_DownloadFile), info.Name);
|
||||
}
|
||||
break;
|
||||
case ConflictSolution.None:
|
||||
break;
|
||||
default:
|
||||
// Conflict
|
||||
Debug.WriteLine("Sync file: Conflict (Deleted locally, but changed remotely) " + sid.Path);
|
||||
sid.ConflictType = ConflictType.LOCALDEL_REMOTECHANGE;
|
||||
sid.ConflictType = ConflictType.LocalDelRemoteChange;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -468,7 +485,7 @@ namespace NextcloudApp.Services
|
|||
{
|
||||
// Update local file
|
||||
Debug.WriteLine("Sync file (update locally) " + info.Path + "/" + info.Name);
|
||||
if (await this.DownloadFile(file, info.Path + "/" + info.Name))
|
||||
if (await DownloadFile(file, info.Path + "/" + info.Name))
|
||||
{
|
||||
sid.ETag = info.ETag;
|
||||
sid.DateModified = currentModified;
|
||||
|
@ -476,7 +493,7 @@ namespace NextcloudApp.Services
|
|||
}
|
||||
else
|
||||
{
|
||||
sid.Error = String.Format(this.resourceLoader.GetString(ResourceConstants.SyncService_Error_DownloadFile), info.Name);
|
||||
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_DownloadFile), info.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -487,63 +504,65 @@ namespace NextcloudApp.Services
|
|||
|
||||
if (await UploadFile(file, info.Path + "/" + info.Name))
|
||||
{
|
||||
ResourceInfo newInfo = await client.GetResourceInfo(info.Path, info.Name);
|
||||
var newInfo = await _client.GetResourceInfo(info.Path, info.Name);
|
||||
sid.ETag = newInfo.ETag;
|
||||
sid.DateModified = currentModified;
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sid.Error = String.Format(this.resourceLoader.GetString(ResourceConstants.SyncService_Error_UploadFile), info.Name);
|
||||
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_UploadFile), info.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (sid.ConflictSolution)
|
||||
{
|
||||
case ConflictSolution.PREFER_LOCAL:
|
||||
case ConflictSolution.PreferLocal:
|
||||
// update file on nextcloud
|
||||
Debug.WriteLine("Sync file (update remotely) " + info.Path + "/" + info.Name);
|
||||
|
||||
if (await UploadFile(file, info.Path + "/" + info.Name))
|
||||
{
|
||||
ResourceInfo newInfo = await client.GetResourceInfo(info.Path, info.Name);
|
||||
var newInfo = await _client.GetResourceInfo(info.Path, info.Name);
|
||||
sid.ETag = newInfo.ETag;
|
||||
sid.DateModified = currentModified;
|
||||
sid.ConflictSolution = ConflictSolution.NONE;
|
||||
sid.ConflictSolution = ConflictSolution.None;
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sid.Error = String.Format(this.resourceLoader.GetString(ResourceConstants.SyncService_Error_UploadFile), info.Name);
|
||||
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_UploadFile), info.Name);
|
||||
}
|
||||
break;
|
||||
case ConflictSolution.PREFER_REMOTE:
|
||||
case ConflictSolution.PreferRemote:
|
||||
// Update local file
|
||||
Debug.WriteLine("Sync file (update locally) " + info.Path + "/" + info.Name);
|
||||
if (await this.DownloadFile(file, info.Path + "/" + info.Name))
|
||||
if (await DownloadFile(file, info.Path + "/" + info.Name))
|
||||
{
|
||||
sid.ETag = info.ETag;
|
||||
sid.DateModified = currentModified;
|
||||
sid.ConflictSolution = ConflictSolution.NONE;
|
||||
sid.ConflictSolution = ConflictSolution.None;
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sid.Error = String.Format(this.resourceLoader.GetString(ResourceConstants.SyncService_Error_DownloadFile), info.Name);
|
||||
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_DownloadFile), info.Name);
|
||||
}
|
||||
break;
|
||||
case ConflictSolution.None:
|
||||
break;
|
||||
default:
|
||||
// Conflict
|
||||
if (sid.ETag == null && !sid.DateModified.HasValue)
|
||||
{
|
||||
sid.ConflictType = ConflictType.BOTHNEW;
|
||||
sid.ConflictType = ConflictType.BothNew;
|
||||
Debug.WriteLine("Sync file: Conflict (both new) " + info.Path + "/" + info.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("Sync file: Conflict (Changed remotely and locally) " + sid.Path);
|
||||
sid.ConflictType = ConflictType.BOTH_CHANGED;
|
||||
sid.ConflictType = ConflictType.BothChanged;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -556,8 +575,8 @@ namespace NextcloudApp.Services
|
|||
// TODO: do not write only the raw exception message in the sid.Error.
|
||||
sid.Error = e.Message;
|
||||
}
|
||||
Debug.WriteLine("Synced file " + sid.ToString());
|
||||
sidList.Add(sid);
|
||||
Debug.WriteLine("Synced file " + sid);
|
||||
_sidList.Add(sid);
|
||||
SyncDbUtils.SaveSyncHistory(sid);
|
||||
if (!deleted)
|
||||
{
|
||||
|
@ -566,27 +585,24 @@ namespace NextcloudApp.Services
|
|||
return changed ? 1 : 0;
|
||||
}
|
||||
|
||||
private void ProgressHandler(WebDavProgress progressInfo)
|
||||
private static void ProgressHandler(WebDavProgress progressInfo)
|
||||
{
|
||||
// progress
|
||||
}
|
||||
|
||||
private async Task<bool> UploadFile(StorageFile localFile, string path)
|
||||
private async Task<bool> UploadFile(IStorageFile localFile, string path)
|
||||
{
|
||||
bool result = false;
|
||||
var _cts = new CancellationTokenSource();
|
||||
var result = false;
|
||||
var cts = new CancellationTokenSource();
|
||||
CachedFileManager.DeferUpdates(localFile);
|
||||
try
|
||||
{
|
||||
var properties = await localFile.GetBasicPropertiesAsync();
|
||||
long BytesTotal = (long)properties.Size;
|
||||
|
||||
using (var stream = await localFile.OpenAsync(FileAccessMode.Read))
|
||||
{
|
||||
var targetStream = stream.AsStreamForRead();
|
||||
|
||||
IProgress<WebDavProgress> progress = new Progress<WebDavProgress>(ProgressHandler);
|
||||
result = await client.Upload(path, targetStream, localFile.ContentType, progress, _cts.Token);
|
||||
result = await _client.Upload(path, targetStream, localFile.ContentType, progress, cts.Token);
|
||||
}
|
||||
}
|
||||
catch (ResponseError e2)
|
||||
|
@ -601,18 +617,18 @@ namespace NextcloudApp.Services
|
|||
return result;
|
||||
}
|
||||
|
||||
private async Task<bool> DownloadFile(StorageFile localFile, string path)
|
||||
private async Task<bool> DownloadFile(IStorageFile localFile, string path)
|
||||
{
|
||||
bool result = false;
|
||||
bool result;
|
||||
CachedFileManager.DeferUpdates(localFile);
|
||||
var _cts = new CancellationTokenSource();
|
||||
var cts = new CancellationTokenSource();
|
||||
IProgress<WebDavProgress> progress = new Progress<WebDavProgress>(ProgressHandler);
|
||||
|
||||
using (var randomAccessStream = await localFile.OpenAsync(FileAccessMode.ReadWrite))
|
||||
{
|
||||
Stream targetStream = randomAccessStream.AsStreamForWrite();
|
||||
var targetStream = randomAccessStream.AsStreamForWrite();
|
||||
|
||||
result = await client.Download(path, targetStream, progress, _cts.Token);
|
||||
result = await _client.Download(path, targetStream, progress, cts.Token);
|
||||
}
|
||||
|
||||
// Let Windows know that we're finished changing the file so
|
||||
|
|
|
@ -22,14 +22,6 @@ namespace NextcloudApp.Services
|
|||
/// </value>
|
||||
public static TileService Instance => _instance ?? (_instance = new TileService());
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TileService"/> class.
|
||||
/// </summary>
|
||||
public TileService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether [is tile pinned] [the specified identifier].
|
||||
/// </summary>
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
using Microsoft.QueryStringDotNET;
|
||||
using Microsoft.Toolkit.Uwp.Notifications;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Windows.ApplicationModel.Resources;
|
||||
using Windows.UI.Notifications;
|
||||
using Microsoft.QueryStringDotNET;
|
||||
using Microsoft.Toolkit.Uwp.Notifications;
|
||||
using NextcloudApp.Models;
|
||||
|
||||
namespace NextcloudApp.Services
|
||||
{
|
||||
class ToastNotificationService
|
||||
internal class ToastNotificationService
|
||||
{
|
||||
public const string SYNCACTION = "syncAction";
|
||||
public const string SYNCONFLICTACTION = "syncConflict";
|
||||
public const string SyncAction = "syncAction";
|
||||
public const string SyncConflictAction = "syncConflict";
|
||||
|
||||
public static void ShowSyncFinishedNotification(string folder, int changes, int errors)
|
||||
{
|
||||
|
@ -23,50 +19,55 @@ namespace NextcloudApp.Services
|
|||
// Don't spam the people when nothing happened.
|
||||
return;
|
||||
}
|
||||
ResourceLoader loader = new ResourceLoader();
|
||||
string title = loader.GetString("SyncFinishedTitle");
|
||||
var loader = new ResourceLoader();
|
||||
var title = loader.GetString("SyncFinishedTitle");
|
||||
string content;
|
||||
string action;
|
||||
if (errors == 0)
|
||||
{
|
||||
action = SYNCACTION;
|
||||
content = String.Format(loader.GetString("SyncFinishedSuccessful"), folder, changes);
|
||||
} else {
|
||||
action = SYNCONFLICTACTION;
|
||||
content = String.Format(loader.GetString("SyncFinishedConflicts"), folder, changes, errors);
|
||||
action = SyncAction;
|
||||
content = string.Format(loader.GetString("SyncFinishedSuccessful"), folder, changes);
|
||||
}
|
||||
else
|
||||
{
|
||||
action = SyncConflictAction;
|
||||
content = string.Format(loader.GetString("SyncFinishedConflicts"), folder, changes, errors);
|
||||
}
|
||||
// Construct the visuals of the toast
|
||||
ToastVisual visual = new ToastVisual()
|
||||
var visual = new ToastVisual
|
||||
{
|
||||
BindingGeneric = new ToastBindingGeneric()
|
||||
BindingGeneric = new ToastBindingGeneric
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new AdaptiveText()
|
||||
new AdaptiveText
|
||||
{
|
||||
Text = title
|
||||
},
|
||||
new AdaptiveText()
|
||||
new AdaptiveText
|
||||
{
|
||||
Text = content
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
ToastContent toastContent = new ToastContent()
|
||||
var toastContent = new ToastContent
|
||||
{
|
||||
Visual = visual,
|
||||
|
||||
// Arguments when the user taps body of toast
|
||||
Launch = new QueryString()
|
||||
Launch = new QueryString
|
||||
{
|
||||
{ "action", action }
|
||||
}.ToString()
|
||||
};
|
||||
var toast = new ToastNotification(toastContent.GetXml());
|
||||
toast.ExpirationTime = DateTime.Now.AddMinutes(30); // TODO Replace with syncinterval from settings.
|
||||
var toast = new ToastNotification(toastContent.GetXml())
|
||||
{
|
||||
ExpirationTime = DateTime.Now.AddMinutes(30),
|
||||
Group = action
|
||||
};
|
||||
// TODO Replace with syncinterval from settings.
|
||||
// TODO groups/tags?
|
||||
toast.Group = action;
|
||||
ToastNotificationManager.CreateToastNotifier().Show(toast);
|
||||
}
|
||||
|
||||
|
@ -76,43 +77,46 @@ namespace NextcloudApp.Services
|
|||
{
|
||||
return;
|
||||
}
|
||||
ResourceLoader loader = new ResourceLoader();
|
||||
string title = loader.GetString("SyncSuspendedTitle");
|
||||
string content = String.Format(loader.GetString("SyncSuspendedDescription"), fsi.Path);
|
||||
string action = SYNCACTION;
|
||||
var loader = new ResourceLoader();
|
||||
var title = loader.GetString("SyncSuspendedTitle");
|
||||
var content = string.Format(loader.GetString("SyncSuspendedDescription"), fsi.Path);
|
||||
const string action = SyncAction;
|
||||
|
||||
// Construct the visuals of the toast
|
||||
ToastVisual visual = new ToastVisual()
|
||||
var visual = new ToastVisual
|
||||
{
|
||||
BindingGeneric = new ToastBindingGeneric()
|
||||
BindingGeneric = new ToastBindingGeneric
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new AdaptiveText()
|
||||
new AdaptiveText
|
||||
{
|
||||
Text = title
|
||||
},
|
||||
new AdaptiveText()
|
||||
new AdaptiveText
|
||||
{
|
||||
Text = content
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
ToastContent toastContent = new ToastContent()
|
||||
var toastContent = new ToastContent
|
||||
{
|
||||
Visual = visual,
|
||||
|
||||
// Arguments when the user taps body of toast
|
||||
Launch = new QueryString()
|
||||
Launch = new QueryString
|
||||
{
|
||||
{ "action", action }
|
||||
}.ToString()
|
||||
};
|
||||
var toast = new ToastNotification(toastContent.GetXml());
|
||||
toast.ExpirationTime = DateTime.Now.AddMinutes(30); // TODO Replace with syncinterval from settings.
|
||||
var toast = new ToastNotification(toastContent.GetXml())
|
||||
{
|
||||
ExpirationTime = DateTime.Now.AddMinutes(30),
|
||||
Group = action
|
||||
};
|
||||
// TODO Replace with syncinterval from settings.
|
||||
// TODO groups/tags?
|
||||
toast.Group = action;
|
||||
ToastNotificationManager.CreateToastNotifier().Show(toast);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
using System.Threading.Tasks;
|
||||
using Windows.Security.Credentials.UI;
|
||||
using Windows.UI.Xaml;
|
||||
using Microsoft.Practices.Unity;
|
||||
using Microsoft.Practices.Unity;
|
||||
using Prism.Windows.AppModel;
|
||||
using NextcloudApp.Constants;
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace NextcloudApp.Services
|
|||
public static async Task<bool> CheckAvailabilityAsync()
|
||||
{
|
||||
var available = await UserConsentVerifier.CheckAvailabilityAsync();
|
||||
return available == Windows.Security.Credentials.UI.UserConsentVerifierAvailability.Available;
|
||||
return available == UserConsentVerifierAvailability.Available;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -50,8 +50,10 @@ namespace NextcloudApp.Services
|
|||
|
||||
var resourceLoader = app.Container.Resolve<IResourceLoader>();
|
||||
|
||||
if (String.IsNullOrEmpty(prompt))
|
||||
if (string.IsNullOrEmpty(prompt))
|
||||
{
|
||||
prompt = resourceLoader.GetString(ResourceConstants.VerificationService_Prompt);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -100,8 +100,8 @@
|
|||
using (var db = DbConnection)
|
||||
{
|
||||
return (from sid in db.Table<SyncInfoDetail>()
|
||||
where sid.FsiID == folderSyncInfo.Id
|
||||
&& (sid.ConflictType != ConflictType.NONE
|
||||
where sid.FsiId == folderSyncInfo.Id
|
||||
&& (sid.ConflictType != ConflictType.None
|
||||
|| sid.Error != null)
|
||||
select sid).Count();
|
||||
}
|
||||
|
@ -212,7 +212,7 @@
|
|||
using (var db = DbConnection)
|
||||
{
|
||||
SyncInfoDetail sid = (from detail in db.Table<SyncInfoDetail>()
|
||||
where detail.Path == fullPath && detail.FsiID == fsi.Id
|
||||
where detail.Path == fullPath && detail.FsiId == fsi.Id
|
||||
select detail).FirstOrDefault();
|
||||
return sid;
|
||||
}
|
||||
|
@ -243,7 +243,7 @@
|
|||
using (var db = DbConnection)
|
||||
{
|
||||
SyncInfoDetail sid = (from detail in db.Table<SyncInfoDetail>()
|
||||
where detail.FilePath == file.Path && detail.FsiID == fsi.Id
|
||||
where detail.FilePath == file.Path && detail.FsiId == fsi.Id
|
||||
select detail).FirstOrDefault();
|
||||
return sid;
|
||||
}
|
||||
|
@ -254,7 +254,7 @@
|
|||
using (var db = DbConnection)
|
||||
{
|
||||
IEnumerable<SyncInfoDetail> sidList = (from detail in db.Table<SyncInfoDetail>()
|
||||
where detail.FsiID == fsi.Id
|
||||
where detail.FsiId == fsi.Id
|
||||
select detail);
|
||||
return sidList.ToList();
|
||||
}
|
||||
|
@ -265,7 +265,7 @@
|
|||
using (var db = DbConnection)
|
||||
{
|
||||
IEnumerable<SyncInfoDetail> sidList = (from detail in db.Table<SyncInfoDetail>()
|
||||
where detail.ConflictType != ConflictType.NONE
|
||||
where detail.ConflictType != ConflictType.None
|
||||
select detail);
|
||||
return sidList.ToList();
|
||||
}
|
||||
|
@ -278,7 +278,7 @@
|
|||
if (isFolder)
|
||||
{
|
||||
// Including subpaths
|
||||
db.Execute("DELETE FROM SyncInfoDetail WHERE Path LIKE '?%' AND FsiID = ?", sid.Path, sid.FsiID);
|
||||
db.Execute("DELETE FROM SyncInfoDetail WHERE Path LIKE '?%' AND FsiID = ?", sid.Path, sid.FsiId);
|
||||
} else
|
||||
{
|
||||
db.Delete(sid);
|
||||
|
|
|
@ -19,7 +19,7 @@ using System.Linq;
|
|||
|
||||
namespace NextcloudApp.ViewModels
|
||||
{
|
||||
public class DirectoryListPageViewModel : ViewModel
|
||||
public sealed class DirectoryListPageViewModel : ViewModel
|
||||
{
|
||||
private LocalSettings _settings;
|
||||
private DirectoryService _directoryService;
|
||||
|
@ -31,32 +31,32 @@ namespace NextcloudApp.ViewModels
|
|||
private readonly DialogService _dialogService;
|
||||
private bool _isNavigatingBack;
|
||||
|
||||
public ICommand GroupByNameAscendingCommand { get; private set; }
|
||||
public ICommand GroupByNameDescendingCommand { get; private set; }
|
||||
public ICommand GroupByDateAscendingCommand { get; private set; }
|
||||
public ICommand GroupByDateDescendingCommand { get; private set; }
|
||||
public ICommand GroupBySizeAscendingCommand { get; private set; }
|
||||
public ICommand GroupBySizeDescendingCommand { get; private set; }
|
||||
public ICommand GroupByTypeAscendingCommand { get; private set; }
|
||||
public ICommand GroupByTypeDescendingCommand { get; private set; }
|
||||
public ICommand RefreshCommand { get; private set; }
|
||||
public ICommand CreateDirectoryCommand { get; private set; }
|
||||
public ICommand UploadFilesCommand { get; private set; }
|
||||
public ICommand UploadPhotosCommand { get; private set; }
|
||||
public ICommand DownloadResourceCommand { get; private set; }
|
||||
public ICommand DownloadSelectedCommand { get; private set; }
|
||||
public ICommand DeleteResourceCommand { get; private set; }
|
||||
public ICommand DeleteSelectedCommand { get; private set; }
|
||||
public ICommand RenameResourceCommand { get; private set; }
|
||||
public ICommand MoveResourceCommand { get; private set; }
|
||||
public ICommand SynchronizeFolderCommand { get; private set; }
|
||||
public ICommand SynchronizeThisFolderCommand { get; private set; }
|
||||
public ICommand StopSynchronizeFolderCommand { get; private set; }
|
||||
public ICommand StopSynchronizeThisFolderCommand { get; private set; }
|
||||
public ICommand MoveSelectedCommand { get; private set; }
|
||||
public ICommand PinToStartCommand { get; private set; }
|
||||
public ICommand SelectToggleCommand { get; private set; }
|
||||
public ICommand ToggleFavoriteCommand { get; private set; }
|
||||
public ICommand GroupByNameAscendingCommand { get; }
|
||||
public ICommand GroupByNameDescendingCommand { get; }
|
||||
public ICommand GroupByDateAscendingCommand { get; }
|
||||
public ICommand GroupByDateDescendingCommand { get; }
|
||||
public ICommand GroupBySizeAscendingCommand { get; }
|
||||
public ICommand GroupBySizeDescendingCommand { get; }
|
||||
public ICommand GroupByTypeAscendingCommand { get; }
|
||||
public ICommand GroupByTypeDescendingCommand { get; }
|
||||
public ICommand RefreshCommand { get; }
|
||||
public ICommand CreateDirectoryCommand { get; }
|
||||
public ICommand UploadFilesCommand { get; }
|
||||
public ICommand UploadPhotosCommand { get; }
|
||||
public ICommand DownloadResourceCommand { get; }
|
||||
public ICommand DownloadSelectedCommand { get; }
|
||||
public ICommand DeleteResourceCommand { get; }
|
||||
public ICommand DeleteSelectedCommand { get; }
|
||||
public ICommand RenameResourceCommand { get; }
|
||||
public ICommand MoveResourceCommand { get; }
|
||||
public ICommand SynchronizeFolderCommand { get; }
|
||||
public ICommand SynchronizeThisFolderCommand { get; }
|
||||
public ICommand StopSynchronizeFolderCommand { get; }
|
||||
public ICommand StopSynchronizeThisFolderCommand { get; }
|
||||
public ICommand MoveSelectedCommand { get; }
|
||||
public ICommand PinToStartCommand { get; }
|
||||
public ICommand SelectToggleCommand { get; }
|
||||
public ICommand ToggleFavoriteCommand { get; }
|
||||
|
||||
public DirectoryListPageViewModel(INavigationService navigationService, IResourceLoader resourceLoader, DialogService dialogService)
|
||||
{
|
||||
|
@ -125,7 +125,7 @@ namespace NextcloudApp.ViewModels
|
|||
ShowProgressIndicator();
|
||||
await Directory.Refresh();
|
||||
HideProgressIndicator();
|
||||
this.SelectedFileOrFolder = null;
|
||||
SelectedFileOrFolder = null;
|
||||
});
|
||||
|
||||
SelectToggleCommand = new DelegateCommand(() =>
|
||||
|
@ -167,7 +167,7 @@ namespace NextcloudApp.ViewModels
|
|||
if (!suspending)
|
||||
{
|
||||
_isNavigatingBack = true;
|
||||
if (Directory != null) Directory.StopDirectoryListing();
|
||||
Directory?.StopDirectoryListing();
|
||||
Directory = null;
|
||||
_selectedFileOrFolder = null;
|
||||
}
|
||||
|
@ -277,11 +277,11 @@ namespace NextcloudApp.ViewModels
|
|||
}
|
||||
|
||||
var syncInfo = SyncDbUtils.GetFolderSyncInfoByPath(resourceInfo.Path);
|
||||
StorageFolder folder;
|
||||
|
||||
try
|
||||
{
|
||||
Task<ContentDialogResult> firstRunDialog = null;
|
||||
StorageFolder folder;
|
||||
if (syncInfo == null)
|
||||
{
|
||||
// try to Get parent or initialize
|
||||
|
@ -301,7 +301,7 @@ namespace NextcloudApp.ViewModels
|
|||
};
|
||||
|
||||
folderPicker.FileTypeFilter.Add(".txt");
|
||||
StorageFolder newFolder = await folderPicker.PickSingleFolderAsync();
|
||||
var newFolder = await folderPicker.PickSingleFolderAsync();
|
||||
|
||||
if (newFolder == null)
|
||||
{
|
||||
|
@ -309,8 +309,8 @@ namespace NextcloudApp.ViewModels
|
|||
}
|
||||
|
||||
StorageApplicationPermissions.FutureAccessList.AddOrReplace(syncInfo.AccessListKey, newFolder);
|
||||
IReadOnlyList<IStorageItem> subElements = await newFolder.GetItemsAsync();
|
||||
NextcloudClient.NextcloudClient client = await ClientService.GetClient();
|
||||
var subElements = await newFolder.GetItemsAsync();
|
||||
var client = await ClientService.GetClient();
|
||||
var remoteElements = await client.List(resourceInfo.Path);
|
||||
|
||||
if (subElements.Count > 0 && remoteElements.Count > 0)
|
||||
|
@ -343,7 +343,7 @@ namespace NextcloudApp.ViewModels
|
|||
var dialog = new ContentDialog
|
||||
{
|
||||
Title = _resourceLoader.GetString("SyncStarted"),
|
||||
Content = new TextBlock()
|
||||
Content = new TextBlock
|
||||
{
|
||||
Text = _resourceLoader.GetString("SyncStartedDetail"),
|
||||
TextWrapping = TextWrapping.WrapWholeWords,
|
||||
|
@ -355,9 +355,9 @@ namespace NextcloudApp.ViewModels
|
|||
}
|
||||
else
|
||||
{
|
||||
string subPath = resourceInfo.Path.Substring(syncInfo.Path.Length);
|
||||
StorageFolder tempFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(syncInfo.AccessListKey);
|
||||
foreach (string foldername in subPath.Split('/'))
|
||||
var subPath = resourceInfo.Path.Substring(syncInfo.Path.Length);
|
||||
var tempFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(syncInfo.AccessListKey);
|
||||
foreach (var foldername in subPath.Split('/'))
|
||||
{
|
||||
if (foldername.Length > 0)
|
||||
tempFolder = await tempFolder.GetFolderAsync(foldername);
|
||||
|
@ -371,7 +371,7 @@ namespace NextcloudApp.ViewModels
|
|||
// TODO catch exceptions
|
||||
}
|
||||
|
||||
SyncService service = new SyncService(folder, resourceInfo, syncInfo, _resourceLoader);
|
||||
var service = new SyncService(folder, resourceInfo, syncInfo, _resourceLoader);
|
||||
await service.StartSync();
|
||||
|
||||
if (firstRunDialog != null)
|
||||
|
@ -419,59 +419,61 @@ namespace NextcloudApp.ViewModels
|
|||
|
||||
var syncInfo = SyncDbUtils.GetFolderSyncInfoByPath(resourceInfo.Path);
|
||||
|
||||
if (syncInfo != null)
|
||||
if (syncInfo == null)
|
||||
{
|
||||
// If there exists an entry for this path - stop sync command has been triggered.
|
||||
SyncDbUtils.DeleteFolderSyncInfo(syncInfo);
|
||||
StartDirectoryListing(); // This is just to update the menu flyout - maybe there is a better way
|
||||
return;
|
||||
}
|
||||
// If there exists an entry for this path - stop sync command has been triggered.
|
||||
SyncDbUtils.DeleteFolderSyncInfo(syncInfo);
|
||||
StartDirectoryListing(); // This is just to update the menu flyout - maybe there is a better way
|
||||
}
|
||||
|
||||
private void MoveSelected(object parameter)
|
||||
{
|
||||
if (parameter is ListView listView)
|
||||
if (!(parameter is ListView listView))
|
||||
{
|
||||
var selectedItems = new List<ResourceInfo>();
|
||||
|
||||
foreach (var selectedItem in listView.SelectedItems)
|
||||
{
|
||||
if (selectedItem is ResourceInfo resourceInfo)
|
||||
{
|
||||
selectedItems.Add(resourceInfo);
|
||||
}
|
||||
}
|
||||
|
||||
var parameters = new MoveFileOrFolderPageParameters
|
||||
{
|
||||
ResourceInfos = selectedItems
|
||||
};
|
||||
|
||||
if (selectedItems.Count == 1)
|
||||
{
|
||||
parameters = new MoveFileOrFolderPageParameters
|
||||
{
|
||||
ResourceInfo = selectedItems[0]
|
||||
};
|
||||
}
|
||||
|
||||
Directory.ToggleSelectionMode();
|
||||
_navigationService.Navigate(PageToken.MoveFileOrFolder.ToString(), parameters.Serialize());
|
||||
return;
|
||||
}
|
||||
var selectedItems = new List<ResourceInfo>();
|
||||
|
||||
foreach (var selectedItem in listView.SelectedItems)
|
||||
{
|
||||
if (selectedItem is ResourceInfo resourceInfo)
|
||||
{
|
||||
selectedItems.Add(resourceInfo);
|
||||
}
|
||||
}
|
||||
|
||||
var parameters = new MoveFileOrFolderPageParameters
|
||||
{
|
||||
ResourceInfos = selectedItems
|
||||
};
|
||||
|
||||
if (selectedItems.Count == 1)
|
||||
{
|
||||
parameters = new MoveFileOrFolderPageParameters
|
||||
{
|
||||
ResourceInfo = selectedItems[0]
|
||||
};
|
||||
}
|
||||
|
||||
Directory.ToggleSelectionMode();
|
||||
_navigationService.Navigate(PageToken.MoveFileOrFolder.ToString(), parameters.Serialize());
|
||||
}
|
||||
|
||||
private async void DeleteResource(object parameter)
|
||||
{
|
||||
if (parameter as ResourceInfo == null)
|
||||
if (!(parameter is ResourceInfo))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dialog = new ContentDialog
|
||||
{
|
||||
Title = _resourceLoader.GetString((parameter as ResourceInfo).ContentType.Equals("dav/directory") ? "DeleteFolder" : "DeleteFile"),
|
||||
Content = new TextBlock()
|
||||
Title = _resourceLoader.GetString(((ResourceInfo) parameter).ContentType.Equals("dav/directory") ? "DeleteFolder" : "DeleteFile"),
|
||||
Content = new TextBlock
|
||||
{
|
||||
Text = string.Format(_resourceLoader.GetString((parameter as ResourceInfo).ContentType.Equals("dav/directory") ? "DeleteFolder_Description" : "DeleteFile_Description"), (parameter as ResourceInfo).Name),
|
||||
Text = string.Format(_resourceLoader.GetString(((ResourceInfo) parameter).ContentType.Equals("dav/directory") ? "DeleteFolder_Description" : "DeleteFile_Description"), ((ResourceInfo) parameter).Name),
|
||||
TextWrapping = TextWrapping.WrapWholeWords,
|
||||
Margin = new Thickness(0, 20, 0, 0)
|
||||
},
|
||||
|
@ -487,7 +489,7 @@ namespace NextcloudApp.ViewModels
|
|||
}
|
||||
|
||||
ShowProgressIndicator();
|
||||
await Directory.DeleteResource(parameter as ResourceInfo);
|
||||
await Directory.DeleteResource((ResourceInfo) parameter);
|
||||
HideProgressIndicator();
|
||||
SelectedFileOrFolder = null;
|
||||
RaisePropertyChanged(nameof(StatusBarText));
|
||||
|
@ -495,43 +497,44 @@ namespace NextcloudApp.ViewModels
|
|||
|
||||
private async void DeleteSelected(object parameter)
|
||||
{
|
||||
if (parameter is ListView listView)
|
||||
if (!(parameter is ListView listView))
|
||||
{
|
||||
var selectedItems = new List<ResourceInfo>();
|
||||
foreach (var selectedItem in listView.SelectedItems)
|
||||
{
|
||||
if (selectedItem is ResourceInfo resourceInfo)
|
||||
{
|
||||
selectedItems.Add(resourceInfo);
|
||||
}
|
||||
}
|
||||
var dialog = new ContentDialog
|
||||
{
|
||||
Title = _resourceLoader.GetString("DeleteFiles"),
|
||||
Content = new TextBlock()
|
||||
{
|
||||
Text = string.Format(_resourceLoader.GetString("DeleteFiles_Description"), selectedItems.Count),
|
||||
TextWrapping = TextWrapping.WrapWholeWords,
|
||||
Margin = new Thickness(0, 20, 0, 0)
|
||||
},
|
||||
PrimaryButtonText = _resourceLoader.GetString("Yes"),
|
||||
SecondaryButtonText = _resourceLoader.GetString("No")
|
||||
};
|
||||
|
||||
var dialogResult = await _dialogService.ShowAsync(dialog);
|
||||
|
||||
if (dialogResult != ContentDialogResult.Primary)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Directory.ToggleSelectionMode();
|
||||
ShowProgressIndicator();
|
||||
await Directory.DeleteSelected(selectedItems);
|
||||
HideProgressIndicator();
|
||||
SelectedFileOrFolder = null;
|
||||
RaisePropertyChanged(nameof(StatusBarText));
|
||||
return;
|
||||
}
|
||||
var selectedItems = new List<ResourceInfo>();
|
||||
foreach (var selectedItem in listView.SelectedItems)
|
||||
{
|
||||
if (selectedItem is ResourceInfo resourceInfo)
|
||||
{
|
||||
selectedItems.Add(resourceInfo);
|
||||
}
|
||||
}
|
||||
var dialog = new ContentDialog
|
||||
{
|
||||
Title = _resourceLoader.GetString("DeleteFiles"),
|
||||
Content = new TextBlock()
|
||||
{
|
||||
Text = string.Format(_resourceLoader.GetString("DeleteFiles_Description"), selectedItems.Count),
|
||||
TextWrapping = TextWrapping.WrapWholeWords,
|
||||
Margin = new Thickness(0, 20, 0, 0)
|
||||
},
|
||||
PrimaryButtonText = _resourceLoader.GetString("Yes"),
|
||||
SecondaryButtonText = _resourceLoader.GetString("No")
|
||||
};
|
||||
|
||||
var dialogResult = await _dialogService.ShowAsync(dialog);
|
||||
|
||||
if (dialogResult != ContentDialogResult.Primary)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Directory.ToggleSelectionMode();
|
||||
ShowProgressIndicator();
|
||||
await Directory.DeleteSelected(selectedItems);
|
||||
HideProgressIndicator();
|
||||
SelectedFileOrFolder = null;
|
||||
RaisePropertyChanged(nameof(StatusBarText));
|
||||
}
|
||||
|
||||
private void PinToStart(object parameter)
|
||||
|
@ -539,20 +542,19 @@ namespace NextcloudApp.ViewModels
|
|||
if (!(parameter is ResourceInfo))
|
||||
return;
|
||||
|
||||
var resourceInfo = parameter as ResourceInfo;
|
||||
var resourceInfo = (ResourceInfo) parameter;
|
||||
_tileService.CreatePinnedObject(resourceInfo);
|
||||
SelectedFileOrFolder = null;
|
||||
}
|
||||
|
||||
private bool CanPinToStart(object parameter)
|
||||
{
|
||||
if (parameter is ResourceInfo)
|
||||
if (!(parameter is ResourceInfo))
|
||||
{
|
||||
var resourceInfo = parameter as ResourceInfo;
|
||||
return _tileService.IsTilePinned(resourceInfo);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
var resourceInfo = (ResourceInfo) parameter;
|
||||
return _tileService.IsTilePinned(resourceInfo);
|
||||
}
|
||||
|
||||
private void UploadFiles()
|
||||
|
@ -585,7 +587,9 @@ namespace NextcloudApp.ViewModels
|
|||
var res = parameter as ResourceInfo;
|
||||
|
||||
if (res == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ShowProgressIndicator();
|
||||
await Directory.ToggleFavorite(res);
|
||||
|
@ -601,7 +605,7 @@ namespace NextcloudApp.ViewModels
|
|||
var dialog = new ContentDialog
|
||||
{
|
||||
Title = _resourceLoader.GetString("CreateNewFolder"),
|
||||
Content = new TextBox()
|
||||
Content = new TextBox
|
||||
{
|
||||
Header = _resourceLoader.GetString("FolderName"),
|
||||
PlaceholderText = _resourceLoader.GetString("NewFolder"),
|
||||
|
@ -658,12 +662,13 @@ namespace NextcloudApp.ViewModels
|
|||
|
||||
dialogResult = await _dialogService.ShowAsync(dialog);
|
||||
|
||||
if (dialogResult != ContentDialogResult.Primary)
|
||||
if (dialogResult == ContentDialogResult.Primary)
|
||||
{
|
||||
SelectedFileOrFolder = null;
|
||||
RaisePropertyChanged(nameof(StatusBarText));
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
SelectedFileOrFolder = null;
|
||||
RaisePropertyChanged(nameof(StatusBarText));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -679,7 +684,7 @@ namespace NextcloudApp.ViewModels
|
|||
var dialog = new ContentDialog
|
||||
{
|
||||
Title = _resourceLoader.GetString("Rename"),
|
||||
Content = new TextBox()
|
||||
Content = new TextBox
|
||||
{
|
||||
Header = _resourceLoader.GetString("ChooseANewName"),
|
||||
Text = resourceInfo.Name,
|
||||
|
@ -708,28 +713,28 @@ namespace NextcloudApp.ViewModels
|
|||
var success = await Directory.Rename(resourceInfo.Name, newName);
|
||||
HideProgressIndicator();
|
||||
|
||||
if (success)
|
||||
if (!success)
|
||||
{
|
||||
SelectedFileOrFolder = null;
|
||||
return;
|
||||
}
|
||||
SelectedFileOrFolder = null;
|
||||
}
|
||||
|
||||
public DirectoryService Directory
|
||||
{
|
||||
get { return _directoryService; }
|
||||
set { SetProperty(ref _directoryService, value); }
|
||||
get => _directoryService;
|
||||
set => SetProperty(ref _directoryService, value);
|
||||
}
|
||||
|
||||
public LocalSettings Settings
|
||||
{
|
||||
get { return _settings; }
|
||||
private set { SetProperty(ref _settings, value); }
|
||||
get => _settings;
|
||||
private set => SetProperty(ref _settings, value);
|
||||
}
|
||||
|
||||
public virtual ResourceInfo SelectedFileOrFolder
|
||||
public ResourceInfo SelectedFileOrFolder
|
||||
{
|
||||
get { return _selectedFileOrFolder; }
|
||||
get => _selectedFileOrFolder;
|
||||
set
|
||||
{
|
||||
if (Directory != null && Directory.IsSelecting)
|
||||
|
@ -790,7 +795,7 @@ namespace NextcloudApp.ViewModels
|
|||
|
||||
public int SelectedPathIndex
|
||||
{
|
||||
get { return _selectedPathIndex; }
|
||||
get => _selectedPathIndex;
|
||||
set
|
||||
{
|
||||
try
|
||||
|
@ -846,9 +851,9 @@ namespace NextcloudApp.ViewModels
|
|||
{
|
||||
get
|
||||
{
|
||||
var folderCount = Directory.FilesAndFolders.Where(x => x.IsDirectory).Count();
|
||||
var fileCount = Directory.FilesAndFolders.Where(x => !x.IsDirectory).Count();
|
||||
return String.Format(_resourceLoader.GetString("DirectoryListStatusBarText"), fileCount + folderCount, folderCount, fileCount);
|
||||
var folderCount = Directory.FilesAndFolders.Count(x => x.IsDirectory);
|
||||
var fileCount = Directory.FilesAndFolders.Count(x => !x.IsDirectory);
|
||||
return string.Format(_resourceLoader.GetString("DirectoryListStatusBarText"), fileCount + folderCount, folderCount, fileCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ namespace NextcloudApp.ViewModels
|
|||
|
||||
public SyncStatusPageViewModel(INavigationService navigationService, IResourceLoader resourceLoader, DialogService dialogService)
|
||||
{
|
||||
ToastNotificationManager.History.RemoveGroup(ToastNotificationService.SYNCACTION);
|
||||
ToastNotificationManager.History.RemoveGroup(ToastNotificationService.SYNCONFLICTACTION);
|
||||
ToastNotificationManager.History.RemoveGroup(ToastNotificationService.SyncAction);
|
||||
ToastNotificationManager.History.RemoveGroup(ToastNotificationService.SyncConflictAction);
|
||||
_navigationService = navigationService;
|
||||
_resourceLoader = resourceLoader;
|
||||
_dialogService = dialogService;
|
||||
|
@ -69,7 +69,7 @@ namespace NextcloudApp.ViewModels
|
|||
|
||||
foreach (SyncInfoDetail detail in listView.SelectedItems)
|
||||
{
|
||||
detail.ConflictSolution = ConflictSolution.PREFER_LOCAL;
|
||||
detail.ConflictSolution = ConflictSolution.PreferLocal;
|
||||
SyncDbUtils.SaveSyncInfoDetail(detail);
|
||||
selectedList.Add(detail);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ namespace NextcloudApp.ViewModels
|
|||
|
||||
foreach (SyncInfoDetail detail in listView.SelectedItems)
|
||||
{
|
||||
detail.ConflictSolution = ConflictSolution.PREFER_REMOTE;
|
||||
detail.ConflictSolution = ConflictSolution.PreferRemote;
|
||||
SyncDbUtils.SaveSyncInfoDetail(detail);
|
||||
selectedList.Add(detail);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче