- add: unpack think
This commit is contained in:
@@ -44,7 +44,7 @@ public sealed partial class DecompilerService
|
|||||||
|
|
||||||
public async void OpenServerDecompiler(RobustUrl url)
|
public async void OpenServerDecompiler(RobustUrl url)
|
||||||
{
|
{
|
||||||
var myTempDir = EnsureTempDir(out var tmpDir);
|
var myTempDir = FileService.EnsureTempDir(out var tmpDir);
|
||||||
|
|
||||||
ILoadingHandler loadingHandler = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
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");
|
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 Initialise(){}
|
||||||
private void InitialiseInDesignMode(){}
|
private void InitialiseInDesignMode(){}
|
||||||
|
|
||||||
|
|||||||
@@ -16,18 +16,6 @@ public sealed partial class DecompilerContentView: ContentViewBase
|
|||||||
decompilerService.OpenServerDecompiler(contentEntry.ServerName.ToRobustUrl());
|
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()
|
protected override void Initialise()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,6 +193,24 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
|||||||
Go(new ContentPath(SearchText));
|
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)
|
private async Task<ContentEntry> CreateEntry(string serverUrl)
|
||||||
{
|
{
|
||||||
var loading = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
var loading = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||||
@@ -204,12 +222,12 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
|||||||
var hashApi = await ContentService.EnsureItems(info.RobustManifestInfo, loading,
|
var hashApi = await ContentService.EnsureItems(info.RobustManifestInfo, loading,
|
||||||
CancellationService.Token);
|
CancellationService.Token);
|
||||||
|
|
||||||
var rootEntry = new ContentEntry(this, "", "", serverUrl, default!);
|
var rootEntry = new ContentEntry(this, "", "", serverUrl, hashApi);
|
||||||
|
|
||||||
foreach (var item in hashApi.Manifest.Values)
|
foreach (var item in hashApi.Manifest.Values)
|
||||||
{
|
{
|
||||||
var path = new ContentPath(item.Path);
|
var path = new ContentPath(item.Path);
|
||||||
rootEntry.CreateItem(path, item, hashApi);
|
rootEntry.CreateItem(path, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
loading.Dispose();
|
loading.Dispose();
|
||||||
@@ -241,17 +259,17 @@ public class ContentEntry
|
|||||||
private readonly Dictionary<string, ContentEntry> _childs = new();
|
private readonly Dictionary<string, ContentEntry> _childs = new();
|
||||||
|
|
||||||
private readonly ContentBrowserViewModel _viewModel;
|
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, RobustManifestItem? item = null)
|
||||||
|
|
||||||
internal ContentEntry(ContentBrowserViewModel viewModel, string name, string pathName, string serverName, HashApi fileApi)
|
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
ServerName = serverName;
|
ServerName = serverName;
|
||||||
PathName = pathName;
|
PathName = pathName;
|
||||||
_viewModel = viewModel;
|
_viewModel = viewModel;
|
||||||
_fileApi = fileApi;
|
FileApi = fileApi;
|
||||||
|
Item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsDirectory => Item == null;
|
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){
|
public bool TryOpen([NotNullWhen(true)] out Stream? stream,[NotNullWhen(true)] out RobustManifestItem? item){
|
||||||
stream = null;
|
stream = null;
|
||||||
item = 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;
|
return false;
|
||||||
|
|
||||||
item = Item;
|
item = Item;
|
||||||
@@ -313,7 +331,7 @@ public class ContentEntry
|
|||||||
|
|
||||||
if (!TryGetChild(fName, out var child))
|
if (!TryGetChild(fName, out var child))
|
||||||
{
|
{
|
||||||
child = new ContentEntry(_viewModel, fName, fName, ServerName, _fileApi);
|
child = new ContentEntry(_viewModel, fName, fName, ServerName, FileApi);
|
||||||
TryAddChild(child);
|
TryAddChild(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,16 +344,13 @@ public class ContentEntry
|
|||||||
return Parent.GetRoot();
|
return Parent.GetRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentEntry CreateItem(ContentPath path, RobustManifestItem item, HashApi fileApi)
|
public ContentEntry CreateItem(ContentPath path, RobustManifestItem item)
|
||||||
{
|
{
|
||||||
var dir = path.GetDirectory();
|
var dir = path.GetDirectory();
|
||||||
var dirEntry = GetOrCreateDirectory(dir);
|
var dirEntry = GetOrCreateDirectory(dir);
|
||||||
|
|
||||||
var name = path.GetName();
|
var name = path.GetName();
|
||||||
var entry = new ContentEntry(_viewModel, name, name, ServerName, fileApi)
|
var entry = new ContentEntry(_viewModel, name, name, ServerName, FileApi, item);
|
||||||
{
|
|
||||||
Item = item
|
|
||||||
};
|
|
||||||
|
|
||||||
dirEntry.TryAddChild(entry);
|
dirEntry.TryAddChild(entry);
|
||||||
entry.IconPath = "/Assets/svg/file.svg";
|
entry.IconPath = "/Assets/svg/file.svg";
|
||||||
|
|||||||
@@ -14,10 +14,10 @@
|
|||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
|
|
||||||
<Grid
|
<Grid
|
||||||
ColumnDefinitions="*,2*,40,40"
|
ColumnDefinitions="*,2*,40,40,40"
|
||||||
Margin="8"
|
Margin="8"
|
||||||
RowDefinitions="40,*">
|
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>
|
<Border.BorderBrush>
|
||||||
<LinearGradientBrush EndPoint="100%,50%" StartPoint="0%,50%">
|
<LinearGradientBrush EndPoint="100%,50%" StartPoint="0%,50%">
|
||||||
<GradientStop Color="#222222" Offset="0.0" />
|
<GradientStop Color="#222222" Offset="0.0" />
|
||||||
@@ -47,10 +47,17 @@
|
|||||||
<Svg Path="/Assets/svg/undo.svg" />
|
<Svg Path="/Assets/svg/undo.svg" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
Command="{Binding OnGoEnter}"
|
Command="{Binding OnUnpack}"
|
||||||
Grid.Column="3"
|
Grid.Column="3"
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Padding="10">
|
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" />
|
<Svg Path="/Assets/svg/next.svg" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
|||||||
@@ -64,11 +64,9 @@ public partial class ContentService
|
|||||||
return await EnsureItems(manifestReader, info.DownloadUri, loadingHandler, cancellationToken);
|
return await EnsureItems(manifestReader, info.DownloadUri, loadingHandler, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Unpack(RobustManifestInfo info, IWriteFileApi otherApi, ILoadingHandler loadingHandler,
|
public void Unpack(HashApi hashApi, IWriteFileApi otherApi, ILoadingHandler loadingHandler)
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
{
|
||||||
debugService.Log("Unpack manifest files");
|
debugService.Log("Unpack manifest files");
|
||||||
var hashApi = await EnsureItems(info, loadingHandler, cancellationToken);
|
|
||||||
var items = hashApi.Manifest.Values.ToList();
|
var items = hashApi.Manifest.Values.ToList();
|
||||||
loadingHandler.AppendJob(items.Count);
|
loadingHandler.AppendJob(items.Count);
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
@@ -86,6 +84,11 @@ public partial class ContentService
|
|||||||
|
|
||||||
loadingHandler.AppendResolvedJob();
|
loadingHandler.AppendResolvedJob();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (loadingHandler is IDisposable disposable)
|
||||||
|
{
|
||||||
|
disposable.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Download(Uri contentCdn, List<RobustManifestItem> toDownload, HashApi hashApi, ILoadingHandler loadingHandler,
|
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));
|
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)
|
public ZipFileApi? OpenZip(string path, IFileApi fileApi)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user