-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathLibrary.cs
113 lines (92 loc) · 4.58 KB
/
Library.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace Steam_Library_Manager.Definitions
{
public abstract class Library : INotifyPropertyChanged
{
public readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
public Enums.LibraryType Type { get; set; }
public bool IsMain { get; set; }
public bool IsUpdatingAppList { get; set; }
public DirectoryInfo DirectoryInfo { get; set; }
private string _fullPath;
public string FullPath
{
get => _fullPath;
set
{
_fullPath = value;
Functions.FileSystem.GetDiskFreeSpaceEx(_fullPath, out var freeSpace, out var totalSpace, out var totalFreeSpace);
FreeSpace = (long)freeSpace;
TotalSize = (long)totalSpace;
}
}
public System.Collections.ObjectModel.ObservableCollection<dynamic> Apps { get; set; } = new System.Collections.ObjectModel.ObservableCollection<dynamic>();
public Dictionary<string, DirectoryInfo> DirectoryList { get; set; } = new Dictionary<string, DirectoryInfo>();
public long FreeSpace { get; set; }
public long TotalSize { get; set; }
public string PrettyFreeSpace => DirectoryInfo.Exists && !DirectoryInfo.FullName.StartsWith(Path.DirectorySeparatorChar.ToString()) ? $"{Functions.FileSystem.FormatBytes(FreeSpace)} / {Functions.FileSystem.FormatBytes(TotalSize)}" : "";
public int FreeSpacePerc => DirectoryInfo.Exists && !DirectoryInfo.FullName.StartsWith(Path.DirectorySeparatorChar.ToString()) ? 100 - ((int)Math.Round((double)(100 * FreeSpace) / TotalSize)) : 0;
public List<FrameworkElement> ContextMenu => _contextMenuElements ?? (_contextMenuElements = GenerateCMenuItems());
private List<FrameworkElement> _contextMenuElements;
private List<FrameworkElement> GenerateCMenuItems()
{
var cMenu = new List<FrameworkElement>();
try
{
foreach (var cMenuItem in List.LibraryCMenuItems.Where(x => x.IsActive && x.AllowedLibraryTypes.Contains(Type)).ToList())
{
if (!cMenuItem.ShowToNormal && IsMain)
{
continue;
}
if (cMenuItem.IsSeparator)
{
cMenu.Add(new Separator());
}
else
{
var menuItem = new MenuItem()
{
Tag = cMenuItem.Action,
Header = Framework.StringFormat.Format(cMenuItem.Header, new { LibraryFullPath = DirectoryInfo.FullName, FreeDiskSpace = PrettyFreeSpace }),
Icon = Functions.FAwesome.GetAwesomeIcon(cMenuItem.Icon, cMenuItem.IconColor),
HorizontalContentAlignment = HorizontalAlignment.Left,
VerticalContentAlignment = VerticalAlignment.Center
};
menuItem.Click += Main.FormAccessor.LibraryCMenuItem_Click;
cMenu.Add(menuItem);
}
}
return cMenu;
}
catch (FormatException ex)
{
MessageBox.Show(Framework.StringFormat.Format(Functions.SLM.Translate(nameof(Properties.Resources.SteamAppInfo_FormatException)), new { ExceptionMessage = ex.Message }));
return cMenu;
}
}
public abstract void UpdateAppListAsync();
public abstract void ParseMenuItemActionAsync(string action);
public abstract void RemoveLibraryAsync(bool withFiles);
public abstract void UpdateJunks();
public abstract void UpdateDupes();
public void UpdateDiskDetails()
{
Functions.FileSystem.GetDiskFreeSpaceEx(_fullPath, out var freeSpace, out var totalSpace, out var totalFreeSpace);
FreeSpace = (long)freeSpace;
TotalSize = (long)totalSpace;
OnPropertyChanged("DirectoryInfo");
OnPropertyChanged("FreeSpace");
OnPropertyChanged("PrettyFreeSpace");
OnPropertyChanged("FreeSpacePerc");
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string info) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
}
}