From 11eb3eb8653d60a69e6105cb19e578c9bfaa5642 Mon Sep 17 00:00:00 2001 From: Cinka Date: Sun, 20 Apr 2025 15:43:57 +0300 Subject: [PATCH] - add: unpack think --- Nebula.Launcher/Services/DecompilerService.cs | 9 +--- .../ContentView/DecompilerContentView.cs | 12 ------ .../Pages/ContentBrowserViewModel.cs | 43 +++++++++++++------ .../Views/Pages/ContentBrowserView.axaml | 13 ++++-- .../Services/ContentService.Download.cs | 9 ++-- Nebula.Shared/Services/FileService.cs | 7 +++ 6 files changed, 53 insertions(+), 40 deletions(-) diff --git a/Nebula.Launcher/Services/DecompilerService.cs b/Nebula.Launcher/Services/DecompilerService.cs index b0576af..b921eac 100644 --- a/Nebula.Launcher/Services/DecompilerService.cs +++ b/Nebula.Launcher/Services/DecompilerService.cs @@ -44,7 +44,7 @@ public sealed partial class DecompilerService public async void OpenServerDecompiler(RobustUrl url) { - var myTempDir = EnsureTempDir(out var tmpDir); + var myTempDir = FileService.EnsureTempDir(out var tmpDir); ILoadingHandler loadingHandler = ViewHelperService.GetViewModel(); @@ -78,13 +78,6 @@ public sealed partial class DecompilerService OpenDecompiler(string.Join(' ', myTempDir.AllFiles.Select(f=>Path.Join(tmpDir, f))) + " --newinstance"); } - private IReadWriteFileApi EnsureTempDir(out string path) - { - path = Path.Combine(Path.GetTempPath(), "tempDlls"+Path.GetRandomFileName()); - Directory.CreateDirectory(path); - return new FileApi(path); - } - private void Initialise(){} private void InitialiseInDesignMode(){} diff --git a/Nebula.Launcher/ViewModels/ContentView/DecompilerContentView.cs b/Nebula.Launcher/ViewModels/ContentView/DecompilerContentView.cs index 74fbc4f..e5471de 100644 --- a/Nebula.Launcher/ViewModels/ContentView/DecompilerContentView.cs +++ b/Nebula.Launcher/ViewModels/ContentView/DecompilerContentView.cs @@ -16,18 +16,6 @@ public sealed partial class DecompilerContentView: ContentViewBase decompilerService.OpenServerDecompiler(contentEntry.ServerName.ToRobustUrl()); } - private void unpackContent(Stream stream) - { - var myTempFile = Path.Combine(Path.GetTempPath(), "tempie.dll"); - - var sw = new FileStream(myTempFile, FileMode.Create, FileAccess.Write, FileShare.None); - stream.CopyTo(sw); - sw.Dispose(); - stream.Dispose(); - - decompilerService.OpenDecompiler(myTempFile); - } - protected override void Initialise() { } diff --git a/Nebula.Launcher/ViewModels/Pages/ContentBrowserViewModel.cs b/Nebula.Launcher/ViewModels/Pages/ContentBrowserViewModel.cs index 4b2f829..8d201fe 100644 --- a/Nebula.Launcher/ViewModels/Pages/ContentBrowserViewModel.cs +++ b/Nebula.Launcher/ViewModels/Pages/ContentBrowserViewModel.cs @@ -193,6 +193,24 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel Go(new ContentPath(SearchText)); } + public void OnUnpack() + { + if (SelectedEntry == null) return; + var myTempDir = FileService.EnsureTempDir(out var tmpDir); + + var loading = ViewHelperService.GetViewModel(); + loading.LoadingName = "Unpacking entry"; + PopupService.Popup(loading); + + Task.Run(() => ContentService.Unpack(SelectedEntry.FileApi, myTempDir, loading)); + var startInfo = new ProcessStartInfo(){ + FileName = "explorer.exe", + Arguments = tmpDir, + }; + DebugService.Log("Opening " + tmpDir); + Process.Start(startInfo); + } + private async Task CreateEntry(string serverUrl) { var loading = ViewHelperService.GetViewModel(); @@ -204,12 +222,12 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel var hashApi = await ContentService.EnsureItems(info.RobustManifestInfo, loading, CancellationService.Token); - var rootEntry = new ContentEntry(this, "", "", serverUrl, default!); + var rootEntry = new ContentEntry(this, "", "", serverUrl, hashApi); foreach (var item in hashApi.Manifest.Values) { var path = new ContentPath(item.Path); - rootEntry.CreateItem(path, item, hashApi); + rootEntry.CreateItem(path, item); } loading.Dispose(); @@ -241,17 +259,17 @@ public class ContentEntry private readonly Dictionary _childs = new(); private readonly ContentBrowserViewModel _viewModel; - private HashApi _fileApi; + public readonly HashApi FileApi; + public readonly RobustManifestItem? Item; - public RobustManifestItem? Item { get; private set; } - - internal ContentEntry(ContentBrowserViewModel viewModel, string name, string pathName, string serverName, HashApi fileApi) + internal ContentEntry(ContentBrowserViewModel viewModel, string name, string pathName, string serverName, HashApi fileApi, RobustManifestItem? item = null) { Name = name; ServerName = serverName; PathName = pathName; _viewModel = viewModel; - _fileApi = fileApi; + FileApi = fileApi; + Item = item; } public bool IsDirectory => Item == null; @@ -270,7 +288,7 @@ public class ContentEntry public bool TryOpen([NotNullWhen(true)] out Stream? stream,[NotNullWhen(true)] out RobustManifestItem? item){ stream = null; item = null; - if(Item is null || !_fileApi.TryOpen(Item.Value, out stream)) + if(Item is null || !FileApi.TryOpen(Item.Value, out stream)) return false; item = Item; @@ -313,7 +331,7 @@ public class ContentEntry if (!TryGetChild(fName, out var child)) { - child = new ContentEntry(_viewModel, fName, fName, ServerName, _fileApi); + child = new ContentEntry(_viewModel, fName, fName, ServerName, FileApi); TryAddChild(child); } @@ -326,16 +344,13 @@ public class ContentEntry return Parent.GetRoot(); } - public ContentEntry CreateItem(ContentPath path, RobustManifestItem item, HashApi fileApi) + public ContentEntry CreateItem(ContentPath path, RobustManifestItem item) { var dir = path.GetDirectory(); var dirEntry = GetOrCreateDirectory(dir); var name = path.GetName(); - var entry = new ContentEntry(_viewModel, name, name, ServerName, fileApi) - { - Item = item - }; + var entry = new ContentEntry(_viewModel, name, name, ServerName, FileApi, item); dirEntry.TryAddChild(entry); entry.IconPath = "/Assets/svg/file.svg"; diff --git a/Nebula.Launcher/Views/Pages/ContentBrowserView.axaml b/Nebula.Launcher/Views/Pages/ContentBrowserView.axaml index 580866e..5d538ca 100644 --- a/Nebula.Launcher/Views/Pages/ContentBrowserView.axaml +++ b/Nebula.Launcher/Views/Pages/ContentBrowserView.axaml @@ -14,10 +14,10 @@ - + @@ -47,10 +47,17 @@ + diff --git a/Nebula.Shared/Services/ContentService.Download.cs b/Nebula.Shared/Services/ContentService.Download.cs index 1fae235..472dc8e 100644 --- a/Nebula.Shared/Services/ContentService.Download.cs +++ b/Nebula.Shared/Services/ContentService.Download.cs @@ -64,11 +64,9 @@ public partial class ContentService return await EnsureItems(manifestReader, info.DownloadUri, loadingHandler, cancellationToken); } - public async Task Unpack(RobustManifestInfo info, IWriteFileApi otherApi, ILoadingHandler loadingHandler, - CancellationToken cancellationToken) + public void Unpack(HashApi hashApi, IWriteFileApi otherApi, ILoadingHandler loadingHandler) { debugService.Log("Unpack manifest files"); - var hashApi = await EnsureItems(info, loadingHandler, cancellationToken); var items = hashApi.Manifest.Values.ToList(); loadingHandler.AppendJob(items.Count); foreach (var item in items) @@ -86,6 +84,11 @@ public partial class ContentService loadingHandler.AppendResolvedJob(); } + + if (loadingHandler is IDisposable disposable) + { + disposable.Dispose(); + } } public async Task Download(Uri contentCdn, List toDownload, HashApi hashApi, ILoadingHandler loadingHandler, diff --git a/Nebula.Shared/Services/FileService.cs b/Nebula.Shared/Services/FileService.cs index 5a6d85e..26b5fc0 100644 --- a/Nebula.Shared/Services/FileService.cs +++ b/Nebula.Shared/Services/FileService.cs @@ -74,6 +74,13 @@ public class FileService { return new FileApi(Path.Join(RootPath, path)); } + + public IReadWriteFileApi EnsureTempDir(out string path) + { + path = Path.Combine(Path.GetTempPath(), "tempThink"+Path.GetRandomFileName()); + Directory.CreateDirectory(path); + return new FileApi(path); + } public ZipFileApi? OpenZip(string path, IFileApi fileApi) {