Check if wine is used.
This commit is contained in:
@@ -126,7 +126,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
|||||||
Logger.LogWarning("Lightless file path is not set, cannot start the FSW for Lightless.");
|
Logger.LogWarning("Lightless file path is not set, cannot start the FSW for Lightless.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var fsType = FileSystemHelper.GetFilesystemType(_configService.Current.CacheFolder);
|
var fsType = FileSystemHelper.GetFilesystemType(_configService.Current.CacheFolder, _dalamudUtil.IsWine);
|
||||||
|
|
||||||
if (fsType == FileSystemHelper.FilesystemType.NTFS)
|
if (fsType == FileSystemHelper.FilesystemType.NTFS)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using LightlessSync.Utils;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
using static LightlessSync.Utils.FileSystemHelper;
|
using static LightlessSync.Utils.FileSystemHelper;
|
||||||
@@ -88,7 +89,7 @@ public sealed class FileCompactor : IDisposable
|
|||||||
|
|
||||||
public long GetFileSizeOnDisk(FileInfo fileInfo)
|
public long GetFileSizeOnDisk(FileInfo fileInfo)
|
||||||
{
|
{
|
||||||
var fsType = GetFilesystemType(fileInfo.FullName);
|
var fsType = GetFilesystemType(fileInfo.FullName, _dalamudUtilService.IsWine);
|
||||||
|
|
||||||
if (fsType != FilesystemType.Btrfs && fsType != FilesystemType.NTFS)
|
if (fsType != FilesystemType.Btrfs && fsType != FilesystemType.NTFS)
|
||||||
{
|
{
|
||||||
@@ -216,7 +217,7 @@ public sealed class FileCompactor : IDisposable
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fsType = GetFilesystemType(filePath);
|
var fsType = GetFilesystemType(filePath, _dalamudUtilService.IsWine);
|
||||||
var oldSize = fi.Length;
|
var oldSize = fi.Length;
|
||||||
|
|
||||||
int clusterSize = GetClusterSize(fi);
|
int clusterSize = GetClusterSize(fi);
|
||||||
@@ -252,7 +253,7 @@ public sealed class FileCompactor : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BTRFS Compression
|
// BTRFS Compression
|
||||||
if (fsType == FileSystemHelper.FilesystemType.Btrfs)
|
if (fsType == FilesystemType.Btrfs)
|
||||||
{
|
{
|
||||||
if (!IsBtrfsCompressedFile(filePath))
|
if (!IsBtrfsCompressedFile(filePath))
|
||||||
{
|
{
|
||||||
@@ -317,20 +318,18 @@ public sealed class FileCompactor : IDisposable
|
|||||||
private void DecompressFile(string path)
|
private void DecompressFile(string path)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Removing compression from {file}", path);
|
_logger.LogDebug("Removing compression from {file}", path);
|
||||||
var fsType = GetFilesystemType(path);
|
var fsType = GetFilesystemType(path, _dalamudUtilService.IsWine);
|
||||||
|
|
||||||
//NTFS Decompression
|
//NTFS Decompression
|
||||||
if (fsType == FilesystemType.NTFS && !_dalamudUtilService.IsWine)
|
if (fsType == FilesystemType.NTFS && !_dalamudUtilService.IsWine)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var fs = new FileStream(path, FileMode.Open))
|
using var fs = new FileStream(path, FileMode.Open);
|
||||||
{
|
|
||||||
#pragma warning disable S3869 // "SafeHandle.DangerousGetHandle" should not be called
|
#pragma warning disable S3869 // "SafeHandle.DangerousGetHandle" should not be called
|
||||||
var hDevice = fs.SafeFileHandle.DangerousGetHandle();
|
var hDevice = fs.SafeFileHandle.DangerousGetHandle();
|
||||||
#pragma warning restore S3869 // "SafeHandle.DangerousGetHandle" should not be called
|
#pragma warning restore S3869 // "SafeHandle.DangerousGetHandle" should not be called
|
||||||
_ = DeviceIoControl(hDevice, FSCTL_DELETE_EXTERNAL_BACKING, nint.Zero, 0, nint.Zero, 0, out _, out _);
|
_ = DeviceIoControl(hDevice, FSCTL_DELETE_EXTERNAL_BACKING, nint.Zero, 0, nint.Zero, 0, out _, out _);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -380,7 +379,6 @@ public sealed class FileCompactor : IDisposable
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Log output only in debug mode to avoid clutter
|
|
||||||
if (!string.IsNullOrWhiteSpace(stdout))
|
if (!string.IsNullOrWhiteSpace(stdout))
|
||||||
_logger.LogDebug("btrfs defragment output for {file}: {out}", path, stdout.Trim());
|
_logger.LogDebug("btrfs defragment output for {file}: {out}", path, stdout.Trim());
|
||||||
|
|
||||||
@@ -414,7 +412,7 @@ public sealed class FileCompactor : IDisposable
|
|||||||
|
|
||||||
int clusterSize;
|
int clusterSize;
|
||||||
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !_dalamudUtilService.IsWine)
|
||||||
{
|
{
|
||||||
int result = GetDiskFreeSpaceW(
|
int result = GetDiskFreeSpaceW(
|
||||||
root,
|
root,
|
||||||
@@ -602,7 +600,7 @@ public sealed class FileCompactor : IDisposable
|
|||||||
{
|
{
|
||||||
var parts = line.Split(' ');
|
var parts = line.Split(' ');
|
||||||
if (parts.Length < 4) continue;
|
if (parts.Length < 4) continue;
|
||||||
var mountPoint = parts[1].Replace("\\040", " ", StringComparison.Ordinal); // unescape spaces
|
var mountPoint = parts[1].Replace("\\040", " ", StringComparison.Ordinal);
|
||||||
string normalized;
|
string normalized;
|
||||||
try { normalized = Path.GetFullPath(mountPoint); }
|
try { normalized = Path.GetFullPath(mountPoint); }
|
||||||
catch { normalized = mountPoint; }
|
catch { normalized = mountPoint; }
|
||||||
@@ -635,7 +633,7 @@ public sealed class FileCompactor : IDisposable
|
|||||||
if (!_pendingCompactions.TryAdd(filePath, 0))
|
if (!_pendingCompactions.TryAdd(filePath, 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var fsType = GetFilesystemType(filePath);
|
var fsType = GetFilesystemType(filePath, _dalamudUtilService.IsWine);
|
||||||
|
|
||||||
if (fsType != FilesystemType.NTFS && fsType != FilesystemType.Btrfs)
|
if (fsType != FilesystemType.NTFS && fsType != FilesystemType.Btrfs)
|
||||||
{
|
{
|
||||||
@@ -700,7 +698,7 @@ public sealed class FileCompactor : IDisposable
|
|||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
// expected during shutdown
|
_logger.LogDebug("Queue has been cancelled by token");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ namespace LightlessSync.Utils
|
|||||||
|
|
||||||
private static readonly ConcurrentDictionary<string, FilesystemType> _filesystemTypeCache = new(StringComparer.OrdinalIgnoreCase);
|
private static readonly ConcurrentDictionary<string, FilesystemType> _filesystemTypeCache = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
public static FilesystemType GetFilesystemType(string filePath)
|
public static FilesystemType GetFilesystemType(string filePath, bool isWine = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string rootPath;
|
string rootPath;
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (!IsProbablyWine() || !isWine))
|
||||||
{
|
{
|
||||||
var info = new FileInfo(filePath);
|
var info = new FileInfo(filePath);
|
||||||
var dir = info.Directory ?? new DirectoryInfo(filePath);
|
var dir = info.Directory ?? new DirectoryInfo(filePath);
|
||||||
@@ -44,7 +44,7 @@ namespace LightlessSync.Utils
|
|||||||
|
|
||||||
FilesystemType detected;
|
FilesystemType detected;
|
||||||
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && (!IsProbablyWine() || !isWine))
|
||||||
{
|
{
|
||||||
var root = new DriveInfo(rootPath);
|
var root = new DriveInfo(rootPath);
|
||||||
var format = root.DriveFormat?.ToUpperInvariant() ?? string.Empty;
|
var format = root.DriveFormat?.ToUpperInvariant() ?? string.Empty;
|
||||||
@@ -139,5 +139,7 @@ namespace LightlessSync.Utils
|
|||||||
return FilesystemType.Unknown;
|
return FilesystemType.Unknown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsProbablyWine() => Environment.GetEnvironmentVariable("WINELOADERNOEXEC") != null || Environment.GetEnvironmentVariable("WINEDLLPATH") != null || Directory.Exists("/proc/self") && File.Exists("/proc/mounts");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user