Skip to content

Commit 947d465

Browse files
authored
CloudProvider: Code refactor (#2327)
1 parent afb563b commit 947d465

20 files changed

+561
-415
lines changed

Files/Enums/CloudDriveSyncStatus.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Files.Enums
2+
{
3+
public enum CloudDriveSyncStatus
4+
{
5+
Unknown = -1,
6+
FolderOnline = 0,
7+
FolderOfflinePartial = 1,
8+
FolderOfflineFull = 2,
9+
FolderOfflinePinned = 3,
10+
FolderExcluded = 4,
11+
FolderEmpty = 5,
12+
NotSynced = 6,
13+
FileOnline = 8,
14+
FileSync = 9,
15+
FileOffline = 14,
16+
FileOfflinePinned = 15,
17+
}
18+
}

Files/Enums/CloudProviders.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Files.Filesystem
2+
{
3+
public enum CloudProviders
4+
{
5+
OneDrive,
6+
OneDriveCommercial,
7+
Mega,
8+
GoogleDrive,
9+
DropBox,
10+
AppleCloud,
11+
Box
12+
}
13+
}

Files/Files.csproj

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,19 @@
177177
<Compile Include="Dialogs\RestartDialog.xaml.cs">
178178
<DependentUpon>RestartDialog.xaml</DependentUpon>
179179
</Compile>
180-
<Compile Include="Filesystem\CloudDriveSyncStatus.cs" />
181-
<Compile Include="Filesystem\CloudProvider.cs" />
180+
<Compile Include="Filesystem\Cloud\CloudDriveSyncStatusUI.cs" />
181+
<Compile Include="Filesystem\Cloud\CloudProvider.cs" />
182+
<Compile Include="Filesystem\Cloud\Providers\AppleCloudProvider.cs" />
183+
<Compile Include="Filesystem\Cloud\Providers\BoxCloudProvider.cs" />
184+
<Compile Include="Enums\CloudDriveSyncStatus.cs" />
185+
<Compile Include="Filesystem\Cloud\CloudProviderController.cs" />
186+
<Compile Include="Enums\CloudProviders.cs" />
187+
<Compile Include="Filesystem\Cloud\Providers\DropBoxCloudProvider.cs" />
188+
<Compile Include="Filesystem\Cloud\Providers\GoogleDriveCloudProvider.cs" />
189+
<Compile Include="Filesystem\Cloud\ICloudProviderDetector.cs" />
190+
<Compile Include="Filesystem\Cloud\Providers\MegaCloudProvider.cs" />
191+
<Compile Include="Filesystem\Cloud\Providers\OneDriveCloudProvider.cs" />
192+
<Compile Include="Filesystem\Cloud\Providers\OneDriveCommercialCloudProvider.cs" />
182193
<Compile Include="Filesystem\PropertiesData.cs" />
183194
<Compile Include="Filesystem\StorageFileHelpers\FilesystemResult.cs" />
184195
<Compile Include="Filesystem\StorageFileHelpers\StorageFileExtensions.cs" />

Files/Filesystem/CloudDriveSyncStatus.cs renamed to Files/Filesystem/Cloud/CloudDriveSyncStatusUI.cs

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
using Microsoft.Toolkit.Mvvm.ComponentModel;
1+
using Files.Enums;
2+
using Microsoft.Toolkit.Mvvm.ComponentModel;
23
using Windows.UI.Xaml.Media;
34

4-
namespace Files.Filesystem
5+
namespace Files.Filesystem.Cloud
56
{
6-
public enum CloudDriveSyncStatus
7-
{
8-
Unknown = -1,
9-
Folder_Online = 0,
10-
Folder_Offline_Partial = 1,
11-
Folder_Offline_Full = 2,
12-
Folder_Offline_Pinned = 3,
13-
Folder_Excluded = 4,
14-
Folder_Empty = 5,
15-
NotSynced = 6,
16-
File_Online = 8,
17-
File_Sync = 9,
18-
File_Offline = 14,
19-
File_Offline_Pinned = 15,
20-
}
21-
227
public class CloudDriveSyncStatusUI : ObservableObject
238
{
249
private bool loadSyncStatus;
@@ -52,42 +37,42 @@ public static CloudDriveSyncStatusUI FromCloudDriveSyncStatus(CloudDriveSyncStat
5237
switch (syncStatus)
5338
{
5439
// File
55-
case CloudDriveSyncStatus.File_Online:
40+
case CloudDriveSyncStatus.FileOnline:
5641
statusUI.LoadSyncStatus = true;
5742
statusUI.Glyph = "\uE753";
5843
statusUI.Foreground = (SolidColorBrush)App.Current.Resources["CloudDriveSyncStatusOnlineColor"];
5944
break;
6045

61-
case CloudDriveSyncStatus.File_Offline:
62-
case CloudDriveSyncStatus.File_Offline_Pinned:
46+
case CloudDriveSyncStatus.FileOffline:
47+
case CloudDriveSyncStatus.FileOfflinePinned:
6348
statusUI.LoadSyncStatus = true;
6449
statusUI.Glyph = "\uE73E";
6550
statusUI.Foreground = (SolidColorBrush)App.Current.Resources["CloudDriveSyncStatusOfflineColor"];
6651
break;
6752

68-
case CloudDriveSyncStatus.File_Sync:
53+
case CloudDriveSyncStatus.FileSync:
6954
statusUI.LoadSyncStatus = true;
7055
statusUI.Glyph = "\uE895";
7156
statusUI.Foreground = (SolidColorBrush)App.Current.Resources["CloudDriveSyncStatusOnlineColor"];
7257
break;
7358

7459
// Folder
75-
case CloudDriveSyncStatus.Folder_Online:
76-
case CloudDriveSyncStatus.Folder_Offline_Partial:
60+
case CloudDriveSyncStatus.FolderOnline:
61+
case CloudDriveSyncStatus.FolderOfflinePartial:
7762
statusUI.LoadSyncStatus = true;
7863
statusUI.Glyph = "\uE753";
7964
statusUI.Foreground = (SolidColorBrush)App.Current.Resources["CloudDriveSyncStatusOnlineColor"];
8065
break;
8166

82-
case CloudDriveSyncStatus.Folder_Offline_Full:
83-
case CloudDriveSyncStatus.Folder_Offline_Pinned:
84-
case CloudDriveSyncStatus.Folder_Empty:
67+
case CloudDriveSyncStatus.FolderOfflineFull:
68+
case CloudDriveSyncStatus.FolderOfflinePinned:
69+
case CloudDriveSyncStatus.FolderEmpty:
8570
statusUI.LoadSyncStatus = true;
8671
statusUI.Glyph = "\uE73E";
8772
statusUI.Foreground = (SolidColorBrush)App.Current.Resources["CloudDriveSyncStatusOfflineColor"];
8873
break;
8974

90-
case CloudDriveSyncStatus.Folder_Excluded:
75+
case CloudDriveSyncStatus.FolderExcluded:
9176
statusUI.LoadSyncStatus = true;
9277
statusUI.Glyph = "\uF140";
9378
statusUI.Foreground = (SolidColorBrush)App.Current.Resources["CloudDriveSyncStatusExcludedColor"];
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Files.Filesystem.Cloud
2+
{
3+
public class CloudProvider
4+
{
5+
public CloudProviders ID { get; set; }
6+
7+
public string Name { get; set; }
8+
9+
public string SyncFolder { get; set; }
10+
}
11+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Files.Filesystem.Cloud.Providers;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace Files.Filesystem.Cloud
7+
{
8+
public class CloudProviderController
9+
{
10+
private List<CloudProvider> cloudProviders;
11+
12+
public CloudProviderController()
13+
{
14+
CloudProviderDetectors = new List<ICloudProviderDetector>
15+
{
16+
new GoogleDriveCloudProvider(),
17+
new DropBoxCloudProvider(),
18+
new OneDriveCloudProvider(),
19+
new OneDriveCommercialCloudProvider(),
20+
new MegaCloudProvider(),
21+
new BoxCloudProvider(),
22+
new AppleCloudProvider()
23+
};
24+
25+
CloudProviders = new List<CloudProvider>();
26+
}
27+
28+
public List<ICloudProviderDetector> CloudProviderDetectors { get; set; }
29+
30+
public List<CloudProvider> CloudProviders
31+
{
32+
get => cloudProviders.Where(x => !string.IsNullOrEmpty(x.SyncFolder)).ToList();
33+
set => cloudProviders = value;
34+
}
35+
36+
public async Task DetectInstalledCloudProvidersAsync()
37+
{
38+
foreach (var provider in CloudProviderDetectors)
39+
{
40+
await provider.DetectAsync(cloudProviders);
41+
}
42+
}
43+
}
44+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
4+
namespace Files.Filesystem.Cloud
5+
{
6+
public interface ICloudProviderDetector
7+
{
8+
Task DetectAsync(List<CloudProvider> cloudProviders);
9+
}
10+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Threading.Tasks;
5+
using Windows.Storage;
6+
7+
namespace Files.Filesystem.Cloud.Providers
8+
{
9+
public class AppleCloudProvider : ICloudProviderDetector
10+
{
11+
public async Task DetectAsync(List<CloudProvider> cloudProviders)
12+
{
13+
try
14+
{
15+
var userPath = UserDataPaths.GetDefault().Profile;
16+
var iCloudPath = "iCloudDrive";
17+
var driveFolder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(userPath, iCloudPath));
18+
19+
cloudProviders.Add(new CloudProvider()
20+
{
21+
ID = CloudProviders.AppleCloud,
22+
Name = "iCloud",
23+
SyncFolder = driveFolder.Path
24+
});
25+
}
26+
catch
27+
{
28+
// Not detected
29+
}
30+
}
31+
}
32+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Threading.Tasks;
5+
using Windows.Storage;
6+
7+
namespace Files.Filesystem.Cloud.Providers
8+
{
9+
public class BoxCloudProvider : ICloudProviderDetector
10+
{
11+
public async Task DetectAsync(List<CloudProvider> cloudProviders)
12+
{
13+
try
14+
{
15+
var infoPath = @"Box\Box\data\shell\sync_root_folder.txt";
16+
var configPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, infoPath);
17+
var configFile = await StorageFile.GetFileFromPathAsync(configPath);
18+
var syncPath = await FileIO.ReadTextAsync(configFile);
19+
20+
if (!string.IsNullOrEmpty(syncPath))
21+
{
22+
cloudProviders.Add(new CloudProvider()
23+
{
24+
ID = CloudProviders.Box,
25+
Name = "Box",
26+
SyncFolder = syncPath
27+
});
28+
}
29+
}
30+
catch
31+
{
32+
// Not detected
33+
}
34+
}
35+
}
36+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Newtonsoft.Json.Linq;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Threading.Tasks;
6+
using Windows.Storage;
7+
8+
namespace Files.Filesystem.Cloud.Providers
9+
{
10+
public class DropBoxCloudProvider : ICloudProviderDetector
11+
{
12+
public async Task DetectAsync(List<CloudProvider> cloudProviders)
13+
{
14+
try
15+
{
16+
var infoPath = @"Dropbox\info.json";
17+
var jsonPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, infoPath);
18+
var configFile = await StorageFile.GetFileFromPathAsync(jsonPath);
19+
var jsonObj = JObject.Parse(await FileIO.ReadTextAsync(configFile));
20+
var dropboxPath = (string)jsonObj["personal"]["path"];
21+
22+
cloudProviders.Add(new CloudProvider()
23+
{
24+
ID = CloudProviders.DropBox,
25+
Name = "Dropbox",
26+
SyncFolder = dropboxPath
27+
});
28+
}
29+
catch
30+
{
31+
// Not detected
32+
}
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)