Skip to content

Feature: Add support for OX Drive integration #17267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion src/Files.App/Utils/Cloud/CloudProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public enum CloudProviders

SyncDrive,

MagentaCloud
MagentaCloud,

OXDrive
}
}
1 change: 1 addition & 0 deletions src/Files.App/Utils/Cloud/Detector/CloudDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private static IEnumerable<ICloudDetector> EnumerateDetectors()
yield return new BoxCloudDetector();
yield return new GenericCloudDetector();
yield return new SynologyDriveCloudDetector();
yield return new OXDriveCloudDetector();
}
}
}
80 changes: 80 additions & 0 deletions src/Files.App/Utils/Cloud/Detector/OXDriveCloudDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.Utils.Cloud;
using Microsoft.Win32;
using System.IO;
using System.Text.Json;
using Windows.Storage;
using static Vanara.PInvoke.Gdi32;

namespace Files.App.Utils.Cloud
{
/// <summary>
/// Provides an utility for OX Drive Cloud detection.
/// </summary>
public sealed class OXDriveCloudDetector : AbstractCloudDetector
{
protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
{
var syncFolder = await GetOXDriveSyncFolder();
if (!string.IsNullOrEmpty(syncFolder))
{
var iconFile = GetOXDriveIconFile();
yield return new CloudProvider(CloudProviders.OXDrive)
{
Name = "OX Drive",
SyncFolder = syncFolder,
IconData = iconFile?.IconData
};
}
}
public static async Task<string?> GetOXDriveSyncFolder()
{
var jsonPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, "Open-Xchange", "OXDrive", "userConfig.json");
if (!File.Exists(jsonPath))
return null;

var configFile = await StorageFile.GetFileFromPathAsync(jsonPath);
using var jsonDoc = JsonDocument.Parse(await FileIO.ReadTextAsync(configFile));
var jsonElem = jsonDoc.RootElement;

string? syncFolderPath = null;

if (jsonElem.TryGetProperty("Accounts", out var accounts) && accounts.GetArrayLength() > 0)
{
var account = accounts[0];

if (account.TryGetProperty("MainFolderPath", out var folderPathElem))
syncFolderPath = folderPathElem.GetString();
}

return syncFolderPath;
}

private static IconFileInfo? GetOXDriveIconFile()
{
var installPath = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Open-Xchange\OXDrive", "InstallDir", null) as string;

// Fallback to default known path if not found in the registry.
if (string.IsNullOrEmpty(installPath))
{
var pfX86 = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
if (string.IsNullOrEmpty(pfX86))
return null;

installPath = Path.Combine(pfX86, "Open-Xchange", "OXDrive");
}

var oxDriveFilePath = Path.Combine(installPath, "OXDrive.exe");
if (!File.Exists(oxDriveFilePath))
{
return null;
}

// Extract the icon from the OXDrive executable (though it is executable, it contains icons)
var icons = Win32Helper.ExtractSelectedIconsFromDLL(oxDriveFilePath, new List<int> { 0 }, 32);
return icons.FirstOrDefault();
}
}
}