Browse Source

reverse unintended changes

pull/4180/head
Jumar Macato 6 years ago
parent
commit
af05518a44
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 5
      .ncrunch/NativeEmbedSample.v3.ncrunchproject
  2. 85
      src/Windows/Avalonia.Win32/WindowsMountedVolumeInfoListener.cs

5
.ncrunch/NativeEmbedSample.v3.ncrunchproject

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
</Settings>
</ProjectConfiguration>

85
src/Windows/Avalonia.Win32/WindowsMountedVolumeInfoListener.cs

@ -0,0 +1,85 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia.Controls.Platform;
using Avalonia.Logging;
namespace Avalonia.Win32
{
internal class WindowsMountedVolumeInfoListener : IDisposable
{
private readonly CompositeDisposable _disposables;
private bool _beenDisposed = false;
private ObservableCollection<MountedVolumeInfo> mountedDrives;
public WindowsMountedVolumeInfoListener(ObservableCollection<MountedVolumeInfo> mountedDrives)
{
this.mountedDrives = mountedDrives;
_disposables = new CompositeDisposable();
var pollTimer = Observable.Interval(TimeSpan.FromSeconds(1))
.Subscribe(Poll);
_disposables.Add(pollTimer);
Poll(0);
}
private void Poll(long _)
{
var allDrives = DriveInfo.GetDrives();
var mountVolInfos = allDrives
.Where(p =>
{
try
{
var ret = p.IsReady;
return ret;
}
catch (Exception e)
{
Logger.TryGet(LogEventLevel.Warning, LogArea.Control)?.Log(this, $"Error in Windows drive enumeration: {e.Message}");
}
return false;
})
.Select(p => new MountedVolumeInfo()
{
VolumeLabel = string.IsNullOrEmpty(p.VolumeLabel.Trim()) ? p.RootDirectory.FullName
: $"{p.VolumeLabel} ({p.Name})",
VolumePath = p.RootDirectory.FullName,
VolumeSizeBytes = (ulong)p.TotalSize
})
.ToArray();
if (mountedDrives.SequenceEqual(mountVolInfos))
return;
else
{
mountedDrives.Clear();
foreach (var i in mountVolInfos)
mountedDrives.Add(i);
}
}
protected virtual void Dispose(bool disposing)
{
if (!_beenDisposed)
{
if (disposing)
{
}
_beenDisposed = true;
}
}
public void Dispose()
{
Dispose(true);
}
}
}
Loading…
Cancel
Save