- add: unpack think
This commit is contained in:
@@ -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<LoadingContextViewModel>();
|
||||
|
||||
@@ -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(){}
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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<LoadingContextViewModel>();
|
||||
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<ContentEntry> CreateEntry(string serverUrl)
|
||||
{
|
||||
var loading = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||
@@ -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<string, ContentEntry> _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";
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
</Design.DataContext>
|
||||
|
||||
<Grid
|
||||
ColumnDefinitions="*,2*,40,40"
|
||||
ColumnDefinitions="*,2*,40,40,40"
|
||||
Margin="8"
|
||||
RowDefinitions="40,*">
|
||||
<Border CornerRadius="10,10,0,0" Grid.ColumnSpan="4" Background="{StaticResource DefaultGrad}" BorderThickness="0,0,0,2">
|
||||
<Border CornerRadius="10,10,0,0" Grid.ColumnSpan="5" Background="{StaticResource DefaultGrad}" BorderThickness="0,0,0,2">
|
||||
<Border.BorderBrush>
|
||||
<LinearGradientBrush EndPoint="100%,50%" StartPoint="0%,50%">
|
||||
<GradientStop Color="#222222" Offset="0.0" />
|
||||
@@ -47,10 +47,17 @@
|
||||
<Svg Path="/Assets/svg/undo.svg" />
|
||||
</Button>
|
||||
<Button
|
||||
Command="{Binding OnGoEnter}"
|
||||
Command="{Binding OnUnpack}"
|
||||
Grid.Column="3"
|
||||
Grid.Row="0"
|
||||
Padding="10">
|
||||
<Svg Path="/Assets/svg/folder.svg" />
|
||||
</Button>
|
||||
<Button
|
||||
Command="{Binding OnGoEnter}"
|
||||
Grid.Column="4"
|
||||
Grid.Row="0"
|
||||
Padding="10">
|
||||
<Svg Path="/Assets/svg/next.svg" />
|
||||
</Button>
|
||||
|
||||
|
||||
@@ -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<RobustManifestItem> toDownload, HashApi hashApi, ILoadingHandler loadingHandler,
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user