Skip to content

Commit 691ecdc

Browse files
authored
Feature: Add support for OX Drive integration (#17267)
1 parent 91e7e7a commit 691ecdc

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

src/Files.App/Utils/Cloud/CloudProviders.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public enum CloudProviders
4949

5050
SyncDrive,
5151

52-
MagentaCloud
52+
MagentaCloud,
53+
54+
OXDrive
5355
}
5456
}

src/Files.App/Utils/Cloud/Detector/CloudDetector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private static IEnumerable<ICloudDetector> EnumerateDetectors()
3333
yield return new BoxCloudDetector();
3434
yield return new GenericCloudDetector();
3535
yield return new SynologyDriveCloudDetector();
36+
yield return new OXDriveCloudDetector();
3637
}
3738
}
3839
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using Files.App.Utils.Cloud;
5+
using Microsoft.Win32;
6+
using System.IO;
7+
using System.Text.Json;
8+
using Windows.Storage;
9+
using static Vanara.PInvoke.Gdi32;
10+
11+
namespace Files.App.Utils.Cloud
12+
{
13+
/// <summary>
14+
/// Provides an utility for OX Drive Cloud detection.
15+
/// </summary>
16+
public sealed class OXDriveCloudDetector : AbstractCloudDetector
17+
{
18+
protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
19+
{
20+
var syncFolder = await GetOXDriveSyncFolder();
21+
if (!string.IsNullOrEmpty(syncFolder))
22+
{
23+
var iconFile = GetOXDriveIconFile();
24+
yield return new CloudProvider(CloudProviders.OXDrive)
25+
{
26+
Name = "OX Drive",
27+
SyncFolder = syncFolder,
28+
IconData = iconFile?.IconData
29+
};
30+
}
31+
}
32+
public static async Task<string?> GetOXDriveSyncFolder()
33+
{
34+
var jsonPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, "Open-Xchange", "OXDrive", "userConfig.json");
35+
if (!File.Exists(jsonPath))
36+
return null;
37+
38+
var configFile = await StorageFile.GetFileFromPathAsync(jsonPath);
39+
using var jsonDoc = JsonDocument.Parse(await FileIO.ReadTextAsync(configFile));
40+
var jsonElem = jsonDoc.RootElement;
41+
42+
string? syncFolderPath = null;
43+
44+
if (jsonElem.TryGetProperty("Accounts", out var accounts) && accounts.GetArrayLength() > 0)
45+
{
46+
var account = accounts[0];
47+
48+
if (account.TryGetProperty("MainFolderPath", out var folderPathElem))
49+
syncFolderPath = folderPathElem.GetString();
50+
}
51+
52+
return syncFolderPath;
53+
}
54+
55+
private static IconFileInfo? GetOXDriveIconFile()
56+
{
57+
var installPath = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Open-Xchange\OXDrive", "InstallDir", null) as string;
58+
59+
// Fallback to default known path if not found in the registry.
60+
if (string.IsNullOrEmpty(installPath))
61+
{
62+
var pfX86 = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
63+
if (string.IsNullOrEmpty(pfX86))
64+
return null;
65+
66+
installPath = Path.Combine(pfX86, "Open-Xchange", "OXDrive");
67+
}
68+
69+
var oxDriveFilePath = Path.Combine(installPath, "OXDrive.exe");
70+
if (!File.Exists(oxDriveFilePath))
71+
{
72+
return null;
73+
}
74+
75+
// Extract the icon from the OXDrive executable (though it is executable, it contains icons)
76+
var icons = Win32Helper.ExtractSelectedIconsFromDLL(oxDriveFilePath, new List<int> { 0 }, 32);
77+
return icons.FirstOrDefault();
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)