浏览代码

added game folder files info in treeview and forge warning message

Veloe 2 年之前
父节点
当前提交
625a00f905

+ 2 - 2
VeloeMinecraftLauncher/VeloeMinecraftLauncher.csproj

@@ -10,8 +10,8 @@
     <DebugType>embedded</DebugType>
     <StartupObject>VeloeMinecraftLauncher.Program</StartupObject>
     <PlatformTarget>x64</PlatformTarget>
-    <AssemblyVersion>1.3.1.6</AssemblyVersion>
-    <FileVersion>1.3.1.6</FileVersion>
+    <AssemblyVersion>1.3.2.27</AssemblyVersion>
+    <FileVersion>1.3.2.27</FileVersion>
     <Configurations>Debug;Release</Configurations>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

+ 90 - 47
VeloeMinecraftLauncher/ViewModels/VersionsDownloaderViewModel.cs

@@ -15,6 +15,7 @@ using VeloeMinecraftLauncher.Utils;
 using VeloeMinecraftLauncher.Models.Entity;
 using VeloeMinecraftLauncher.Entity.Version;
 using System.Diagnostics;
+using System.Linq.Expressions;
 
 namespace VeloeMinecraftLauncher.ViewModels;
 
@@ -253,48 +254,43 @@ public class VersionsDownloaderViewModel : ViewModelBase
 
                     //calc Size
 
-                    long allSize = 0;
-                    string[] size_label = { "bytes", "KB", "MB", "GB" };
+                    var allSize = 0L;
+                    var dirSize = 0L;
                     var dirInfo = new DirectoryInfo(versionDir);
+                    var sizeTreeNode = new TreeNode();
+                    var dirTreeNode = new TreeNode();
 
-                    foreach (var file in dirInfo.EnumerateFiles("*", SearchOption.AllDirectories))
-                    { allSize += file.Length; }
+                    dirTreeNode.SubNode.AddRange(DirectoryToTreeNode(dirInfo,out dirSize));
+                    dirTreeNode.Title = "versions/" + dirInfo.Name + " (" + BytesToString(dirSize) + ")";
+                    sizeTreeNode.SubNode.Add(dirTreeNode);
+                    allSize += dirSize;
 
                     if (version.InheritsFrom is null)
                     {
-                        //TODO add subnodes with size
                         dirInfo = new DirectoryInfo(Settings.minecraftForlderPath);
-                        foreach (var dir in dirInfo.GetDirectories())
-                        {
-                            if (dir.Name != ".mixin.out" &&
-                                dir.Name != "assets" &&
-                                dir.Name != "javaruntime" &&
-                                dir.Name != "libraries" &&
-                                dir.Name != "logs" &&
-                                dir.Name != "versions")
-                                foreach (var file in dir.EnumerateFiles("*", SearchOption.AllDirectories))
-                                { allSize += file.Length; }
-                        }
-
-                        foreach (var file in dirInfo.GetFiles("*"))
-                        {
-                            if (!(file.Name.Contains("Veloe") &&
-                                file.Name.Contains("log") &&
-                                file.Name.Contains("exe")) &&
-                                file.Name == "launcher_profiles.json")
-                                allSize += file.Length;
-                        }
+                        sizeTreeNode.SubNode.AddRange(
+                            DirectoryToTreeNode(
+                                dirInfo,
+                                out dirSize,
+                                (dir) => dir.Name == ".mixin.out" ||
+                                    dir.Name == "assets" ||
+                                    dir.Name == "javaruntime" ||
+                                    dir.Name == "libraries" ||
+                                    dir.Name == "logs" ||
+                                    dir.Name == "versions",
+                                (file) => file.Name.Contains("Veloe") ||
+                                    file.Name.Contains("log") ||
+                                    file.Name.Contains("exe") ||
+                                    file.Name == "launcher_profiles.json" ||
+                                    file.Name == "libHarfBuzzSharp.dll" ||
+                                    file.Name == "libSkiaSharp.dll" ||
+                                    file.Name == "settings.json")
+                            );
+                        allSize += dirSize;
                     }
 
-                    var j = 0;
-                    var result = (double)allSize;
-                    while (j < size_label.Length && result > 1024)
-                    {
-                        result = result / 1024;
-                        j++;
-                    }
-
-                    DownloadedVersionTree.Add(new TreeNode() { Title = "Size: " + string.Format("{0:N2}", result) + " " + size_label[j] });
+                    sizeTreeNode.Title = "Size: " + BytesToString(allSize); 
+                    DownloadedVersionTree.Add(sizeTreeNode);
 
                     //calc Worlds
 
@@ -323,7 +319,10 @@ public class VersionsDownloaderViewModel : ViewModelBase
                     if (version.InheritsFrom is null)
                         modsTreeNode.Title = "Modloader: No";
                     else if (version.Libraries.Any(l => l.Downloads?.Artifact?.Url?.Contains("forge") ?? false))
+                    {
                         modsTreeNode.Title = "Modloader: Forge";
+                        OpenErrorWindow("This version contains forge modloader, it installs some libraries that can't be displayed and deleted in current launcher versions manager.");
+                    }
                     else if (version.Libraries.Any(l => l.Name.Contains("fabric")))
                         modsTreeNode.Title = "Modloader: Fabric";
 
@@ -381,14 +380,6 @@ public class VersionsDownloaderViewModel : ViewModelBase
                         foreach (var file in dirInfo.EnumerateFiles("*", SearchOption.AllDirectories))
                         { allSize += file.Length; }
 
-                        j = 0;
-                        result = (double)allSize;
-                        while (j < size_label.Length && result > 1024)
-                        {
-                            result = result / 1024;
-                            j++;
-                        }
-
                         var assetsTreeNode = new TreeNode();
                         var usedByVersionCount = 0;
 
@@ -405,7 +396,7 @@ public class VersionsDownloaderViewModel : ViewModelBase
                             }
                         }
 
-                        assetsTreeNode.Title = "Assets: " + version.Assets + " (" + string.Format("{0:N2}", result) + " " + size_label[j] + ") (" + usedByVersionCount + ")";
+                        assetsTreeNode.Title = "Assets: " + version.Assets + " (" + BytesToString(allSize) + ") (" + usedByVersionCount + ")";
                         DownloadedVersionTree.Add(assetsTreeNode);
                     }
 
@@ -734,7 +725,7 @@ public class VersionsDownloaderViewModel : ViewModelBase
 
     public async Task OnDeleteButtonClick()
     {
-        await Task.Run(async () => {
+        await Task.Run(() => {
             try
             {
                 IsControlsEnabled = false;
@@ -851,6 +842,58 @@ public class VersionsDownloaderViewModel : ViewModelBase
         });
     }
 
+    static string[] _size_label = { "bytes", "KB", "MB", "GB" };
+
+    private string BytesToString(long size)
+    {
+        var j = 0;
+        var result = (double)size;
+        while (j < _size_label.Length && result > 1024)
+        {
+            result = result / 1024;
+            j++;
+        }
+        return string.Format("{0:N2}", result) + " " + _size_label[j];
+    }
+
+    private List<TreeNode> DirectoryToTreeNode(DirectoryInfo? dirInfo, out long size, Expression<Func<DirectoryInfo?, bool>>? dirExpression = null, Expression<Func<FileInfo?,bool>>? fileExpression = null)
+    {
+        size = 0L;
+        var nodes = new List<TreeNode>();
+
+        if (!(dirInfo is not null && dirInfo.Exists)) return nodes;
+
+        if (dirExpression is null)
+            dirExpression = (x) => false;
+
+        if (fileExpression is null)
+            fileExpression = (x) => false;
+
+        var dirDelegate = dirExpression.Compile();
+        var fileDelegate = fileExpression.Compile();
+
+        foreach (var dir in dirInfo.EnumerateDirectories("*", SearchOption.TopDirectoryOnly))
+        {
+            if (dirDelegate(dir)) continue;
+
+            var subDirSize = 0L;
+            var subDirTreeNode = new TreeNode();
+            subDirTreeNode.SubNode.AddRange(DirectoryToTreeNode(dir,out subDirSize));
+            subDirTreeNode.Title = dir.Name + " (" + BytesToString(subDirSize) + ")";
+            nodes.Add(subDirTreeNode);
+            size += subDirSize;
+        }
+
+        foreach (var file in dirInfo.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
+        {
+            if (fileDelegate(file)) continue;
+            nodes.Add(new TreeNode() { Title = file.Name + " (" + BytesToString(file.Length) + ")" });
+            size += file.Length;
+        }
+
+        return nodes;
+    }
+
     private void DeleteLibrariesFromTreeNode(TreeNode library)
     {
         foreach (var node in library.SubNode)
@@ -881,7 +924,7 @@ public class VersionsDownloaderViewModel : ViewModelBase
         }
     }
 
-    public void UpdateList()
+    private void UpdateList()
     {
         try
         {
@@ -899,7 +942,7 @@ public class VersionsDownloaderViewModel : ViewModelBase
         }
     }
 
-    public void SearchGameFolderForVersions()
+    private void SearchGameFolderForVersions()
     {
         if (DownloadedVersions is null)
             DownloadedVersions = new();
@@ -948,7 +991,7 @@ public class VersionsDownloaderViewModel : ViewModelBase
         _filteredVersionTokenSource.Dispose();
     }
 
-    public IEnumerable<KeyValuePair<string,Library>> GetLibrariesFromVersions(Dictionary<string, Entity.Version.Version?> versions)
+    private IEnumerable<KeyValuePair<string,Library>> GetLibrariesFromVersions(Dictionary<string, Entity.Version.Version?> versions)
     {
         foreach (var version in versions)
         {

+ 0 - 2
VeloeMinecraftLauncher/ViewModels/ViewModelBase.cs

@@ -3,13 +3,11 @@ using Avalonia.Controls;
 using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Media;
 using Avalonia.Threading;
-using Avalonia.VisualTree;
 using ReactiveUI;
 using ReactiveUI.Validation.Helpers;
 using System;
 using System.ComponentModel;
 using System.IO;
-using System.Linq;
 using System.Net;
 using VeloeMinecraftLauncher.Utils;
 using VeloeMinecraftLauncher.Views;