Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AssetEditor/AssetEditor.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<LangVersion>preview</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions AssetEditor/Services/EditorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ public IEditorInterface CreateFromFile(PackFile file, EditorEnums? preferedEdito
{
if (existingFileEditor.CurrentFile == file)
{
_logger.Here().Information($"Attempting to open file '{file.Name}', but is is already open");
_logger.Here().Information($"Attempting to open file '{fullFileName}', but is is already open");
SelectedEditorIndex = i;
return CurrentEditorsList[i];
}
}
}

// Open the file
_logger.Here().Information($"Opening {file.Name} with {editorViewModel?.GetType().Name}");
_logger.Here().Information($"Opening {fullFileName} with {editorViewModel?.GetType().Name}");
fileEditor.LoadFile(file);
}

Expand Down
2 changes: 1 addition & 1 deletion AssetEditor/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public MainViewModel(

[RelayCommand] private void Closing(IEditorInterface editor)
{
var hasUnsavedPackFiles = FileTree.Files.Any(node => node.UnsavedChanged);
var hasUnsavedPackFiles = FileTree.Files.Any(node => node.UnsavedChanges.HasChanges);
if (EditorManager.ShouldBlockCloseCommand(editor, hasUnsavedPackFiles))
{
IsClosingWithoutPrompt = true;
Expand Down
12 changes: 9 additions & 3 deletions Editors/Audio/ContextMenu/ExportCAVp8AsIvfCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using System.IO;
using Editors.Audio.Shared.Utilities;
using Shared.Core.Misc;
using Shared.Core.PackFiles.Models;
using Shared.Core.Services;
using Shared.Ui.BaseDialogs.PackFileTree;
using Shared.Ui.BaseDialogs.PackFileTree.ContextMenu.Commands;
using Shared.Ui.BaseDialogs.PackFileTree.Utility;

namespace Editors.Audio.ContextMenu
{
Expand All @@ -14,12 +16,16 @@ public class ExportCAVp8AsIvfCommand(IStandardDialogs standardDialogs, IFileSyst
private readonly IFileSystemAccess _fileSystemAccess = fileSystemAccess;

public string GetDisplayName(TreeNode node) => "Export as IVF";
public bool ShouldAdd(TreeNode node) => node.NodeType == NodeType.File && node.Item != null;
public bool IsEnabled(TreeNode node) => node.Item != null && node.Item.Name.EndsWith(".ca_vp8", StringComparison.OrdinalIgnoreCase);
public bool ShouldAdd(TreeNode node) => node.NodeType == NodeType.File && TreeNodeHelper.GetPackFile(node) != null;
public bool IsEnabled(TreeNode node)
{
var packFile = TreeNodeHelper.GetPackFile(node);
return packFile != null && packFile.Name.EndsWith(".ca_vp8", StringComparison.OrdinalIgnoreCase);
}

public void Execute(TreeNode selectedNode)
{
var packFile = selectedNode.Item;
var packFile = TreeNodeHelper.GetPackFile(selectedNode);
if (packFile == null)
return;

Expand Down
20 changes: 13 additions & 7 deletions Editors/Audio/ContextMenu/ExportCAVp8AsWebMCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
using Editors.Audio.Shared.Utilities;
using Shared.Core.Misc;
using Shared.Core.PackFiles;
using Shared.Core.PackFiles.Models;
using Shared.Core.Services;
using Shared.Ui.BaseDialogs.PackFileTree;
using Shared.Ui.BaseDialogs.PackFileTree.ContextMenu.Commands;
using Shared.Ui.BaseDialogs.PackFileTree.Utility;

namespace Editors.Audio.ContextMenu
{
Expand All @@ -25,13 +27,17 @@ public class ExportCAVp8AsWebMCommand(
private readonly IMovieAudioResolver _movieAudioResolver = movieAudioResolver;

public string GetDisplayName(TreeNode node) => "Export as WebM";
public bool ShouldAdd(TreeNode node) => node.NodeType == NodeType.File && node.Item != null;
public bool IsEnabled(TreeNode node) => node.Item != null && node.Item.Name.EndsWith(".ca_vp8", StringComparison.OrdinalIgnoreCase);
public bool ShouldAdd(TreeNode node) => node.NodeType == NodeType.File && TreeNodeHelper.GetPackFile(node) != null;
public bool IsEnabled(TreeNode node)
{
var packFile = TreeNodeHelper.GetPackFile(node);
return packFile != null && packFile.Name.EndsWith(".ca_vp8", StringComparison.OrdinalIgnoreCase);
}

public void Execute(TreeNode selectedNode)
{
var caVp8PackFile = selectedNode.Item;
if (caVp8PackFile == null)
var packFile = TreeNodeHelper.GetPackFile(selectedNode);
if (packFile == null)
return;

var dialogResult = _standardDialogs.ShowSystemFolderBrowserDialog();
Expand All @@ -42,10 +48,10 @@ public void Execute(TreeNode selectedNode)

_audioRepository.Load(Wh3LanguageInformation.GetAllLanguages());

var caVp8PackFilePath = _packFileService.GetFullPath(caVp8PackFile);
var caVp8PackFilePath = _packFileService.GetFullPath(packFile);
var wemPackFile = _movieAudioResolver.ResolveMovieWem(caVp8PackFilePath);
var webMPath = Path.Combine(dialogResult.FolderPath, Path.ChangeExtension(caVp8PackFile.Name, ".webm"));
var webMBytes = CAVp8Exporter.ExportToWebM(caVp8PackFile, wemPackFile);
var webMPath = Path.Combine(dialogResult.FolderPath, Path.ChangeExtension(packFile.Name, ".webm"));
var webMBytes = CAVp8Exporter.ExportToWebM(packFile, wemPackFile);
_fileSystemAccess.FileWriteAllBytes(webMPath, webMBytes);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace Editors.ImportExport.ContextMenu
public interface IImportFileContextMenuHelper
{
bool CanImportFile(PackFile file);
void ShowDialog(TreeNode node);
void ShowDialog(IPackFileContainer container, TreeNode node);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
using Shared.Ui.BaseDialogs.PackFileTree.ContextMenu.Commands;
using Shared.Ui.BaseDialogs.PackFileTree.ContextMenu.Commands;
using Shared.Ui.BaseDialogs.PackFileTree;
using Editors.ImportExport.ContextMenu;
using Shared.Core.PackFiles.Models;
using Shared.Ui.BaseDialogs.PackFileTree.Utility;

namespace Editors.ImportExport.Exporting
{
public class AdvancedExportCommand(IExportFileContextMenuHelper exportFileContextMenuHelper) : IContextMenuCommand
{
public string GetDisplayName(TreeNode node) => "Advanced Export";
public bool ShouldAdd(TreeNode node) => node.NodeType == NodeType.File && node.Item != null;
public bool IsEnabled(TreeNode node) => exportFileContextMenuHelper.CanExportFile(node.Item);
public bool ShouldAdd(TreeNode node) => node.NodeType == NodeType.File && TreeNodeHelper.GetPackFile(node) != null;
public bool IsEnabled(TreeNode node)
{
var packFile = TreeNodeHelper.GetPackFile(node);
return packFile != null && exportFileContextMenuHelper.CanExportFile(packFile);
}

public void Execute(TreeNode selectedNode) => exportFileContextMenuHelper.ShowDialog(selectedNode.Item);
public void Execute(TreeNode selectedNode)
{
var packFile = TreeNodeHelper.GetPackFile(selectedNode);
if (packFile == null)
return;

exportFileContextMenuHelper.ShowDialog(packFile);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
using Editors.ImportExport.ContextMenu;
using Editors.ImportExport.ContextMenu;
using Shared.Core.PackFiles;
using Shared.Core.PackFiles.Models;
using Shared.Ui.BaseDialogs.PackFileTree;
using Shared.Ui.BaseDialogs.PackFileTree.ContextMenu.Commands;
using Shared.Ui.BaseDialogs.PackFileTree.Utility;

namespace Editors.ImportExport.Importing
{
public class AdvancedImportCommand(IImportFileContextMenuHelper importFileContextMenuHelper) : IContextMenuCommand
public class AdvancedImportCommand(IPackFileService packFileService, IImportFileContextMenuHelper importFileContextMenuHelper) : IContextMenuCommand
{
public string GetDisplayName(TreeNode node) => "Advanced Import";
public bool ShouldAdd(TreeNode node) => node.NodeType == NodeType.Directory && !node.FileOwner.IsCaPackFile;
public bool ShouldAdd(TreeNode node)
{
var container = TreeNodeHelper.GetPackFileContainer(node);
return node.NodeType == NodeType.Directory && container is { IsCaPackFile: false };
}

public bool IsEnabled(TreeNode node) => true;

public void Execute(TreeNode selectedNode) => importFileContextMenuHelper.ShowDialog(selectedNode);
public void Execute(TreeNode selectedNode)
{
var container = TreeNodeHelper.GetPackFileContainer(selectedNode);
if (container == null)
return;

importFileContextMenuHelper.ShowDialog(container, selectedNode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public bool CanImportFile(PackFile filePath)
return false;
}

public void ShowDialog(TreeNode clickedNode) =>
_uiCommandFactory.Create<DisplayImportFileToolCommand>().Execute(clickedNode.FileOwner, clickedNode.GetFullPath());
public void ShowDialog(IPackFileContainer container, TreeNode clickedNode) =>
_uiCommandFactory.Create<DisplayImportFileToolCommand>().Execute(container, clickedNode.GetFullPath());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO;
using Editors.KitbasherEditor.UiCommands;
using Shared.Core.Events;
using Shared.Core.PackFiles.Models;
using Shared.Ui.BaseDialogs.PackFileTree;

namespace Editors.KitbasherEditor.ViewModels
Expand All @@ -14,20 +15,23 @@ public KitbashViewDropHandler(IUiCommandFactory uiCommandFactory)
_uiCommandFactory = uiCommandFactory;
}

public bool AllowDrop(TreeNode node, TreeNode targeNode = null)
public bool AllowDrop(PackFile file, PackFile targeNode = null)
{
if (node != null && node.NodeType == NodeType.File)
if (file != null)
{
var extension = Path.GetExtension(node.Name).ToLower();
var extension = Path.GetExtension(file.Name).ToLower();
if (extension == ".rigid_model_v2" || extension == ".wsmodel" || extension == ".variantmeshdefinition")
return true;
}
return false;
}

public bool Drop(TreeNode node)
public bool Drop(PackFile file)
{
_uiCommandFactory.Create<ImportReferenceMeshCommand>().Execute(node.Item);
if (file == null)
return false;

_uiCommandFactory.Create<ImportReferenceMeshCommand>().Execute(file);
return true;
}
}
Expand Down
5 changes: 3 additions & 2 deletions Editors/Kitbashing/KitbasherEditor/Core/KitbasherView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Windows;
using System.Windows.Controls;
using Shared.Core.PackFiles.Models;
using Shared.Ui.BaseDialogs.PackFileTree;
using Shared.Ui.Common;
using Shared.Ui.Common.MenuSystem;
Expand All @@ -18,12 +19,12 @@ public KitbasherView()

private void treeView_Drop(object sender, DragEventArgs e)
{
var dropTarget = DataContext as IDropTarget<TreeNode>;
var dropTarget = DataContext as IDropTarget<PackFile>;
if (dropTarget != null)
{
var formats = e.Data.GetFormats();
object droppedObject = e.Data.GetData(formats[0]);
var node = droppedObject as TreeNode;
var node = droppedObject as PackFile;

if (dropTarget.AllowDrop(node))
{
Expand Down
7 changes: 3 additions & 4 deletions Editors/Kitbashing/KitbasherEditor/Core/KitbasherViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Shared.Core.PackFiles.Models;
using Shared.Core.Services;
using Shared.Core.ToolCreation;
using Shared.Ui.BaseDialogs.PackFileTree;
using Shared.Ui.Common;

namespace Editors.KitbasherEditor.ViewModels
Expand All @@ -24,7 +23,7 @@ public partial class KitbasherViewModel : ObservableObject,
IEditorInterface,
IFileEditor,
ISaveableEditor,
IDropTarget<TreeNode>
IDropTarget<PackFile>
{
private readonly ILogger _logger = Logging.Create<KitbasherViewModel>();

Expand Down Expand Up @@ -110,8 +109,8 @@ public bool HasUnsavedChanges
}
}

public bool AllowDrop(TreeNode node, TreeNode targeNode = null) => _dropHandler.AllowDrop(node, targeNode);
public bool Drop(TreeNode node, TreeNode targeNode = null) => _dropHandler.Drop(node);
public bool AllowDrop(PackFile node, PackFile targeNode = null) => _dropHandler.AllowDrop(node, targeNode);
public bool Drop(PackFile node, PackFile targeNode = null) => _dropHandler.Drop(node);

void OnFileSaved(ScopedFileSavedEvent notification)
{
Expand Down
13 changes: 11 additions & 2 deletions Editors/Reports/Geometry/RmvToTextReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Shared.GameFormats.RigidModel.MaterialHeaders;
using Shared.Ui.BaseDialogs.PackFileTree;
using Shared.Ui.BaseDialogs.PackFileTree.ContextMenu.Commands;
using Shared.Ui.BaseDialogs.PackFileTree.Utility;

namespace Editors.Reports.Geometry
{
Expand All @@ -17,11 +18,19 @@ public class RmvToTextCommand(RmvToTextReport report) : IContextMenuCommand

public bool ShouldAdd(TreeNode node) => IsEnabled(node);

public bool IsEnabled(TreeNode node) => node.NodeType == NodeType.File && node.Item != null && node.Name.EndsWith(".rigid_model_v2", StringComparison.OrdinalIgnoreCase);
public bool IsEnabled(TreeNode node)
{
var packFile = TreeNodeHelper.GetPackFile(node);
return node.NodeType == NodeType.File && packFile != null && node.Name.EndsWith(".rigid_model_v2", StringComparison.OrdinalIgnoreCase);
}

public void Execute(TreeNode node)
{
report.Generate(node.Item!);
var packFile = TreeNodeHelper.GetPackFile(node);
if (packFile == null)
return;

report.Generate(packFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore;
using System.Diagnostics;
using System.Windows.Forms;
using Microsoft.EntityFrameworkCore;
using Shared.Core.ErrorHandling;
using Shared.Core.PackFiles.Models.FileSources;
using Shared.Core.PackFiles.Serialization.CacheDatabase;
using Shared.Core.PackFiles.Utility;
Expand All @@ -8,6 +11,8 @@ namespace Shared.Core.PackFiles.Models.Containers
{
internal class CachedPackFileContainer : IPackFileContainerInternal
{
private readonly ILogger _logger = Logging.Create<CachedPackFileContainer>();

private readonly CacheDbContext _db;
private readonly object _dbLock = new();

Expand Down Expand Up @@ -129,11 +134,24 @@ public bool ContainsFile(string path)

public Dictionary<string, PackFile> GetAllFiles()
{
var time = Stopwatch.StartNew();
List<CachedFileEntity> entries;
lock (_dbLock)
{
//var x = _db.Files
// .GroupBy(x=>x.FolderPath)
// .Select(g => new
// {
// Folder = g.Key,
// FileList = g.Select(x => x.FileName).ToList()
// })
// .ToList();
//
//

entries = _db.Files.ToList();
}
_logger.Here().Information("Getting all files from cached container took {ElapsedMilliseconds} ms", time.ElapsedMilliseconds);

var parentCache = new Dictionary<string, PackedFileSourceParent>(StringComparer.OrdinalIgnoreCase);
var result = new Dictionary<string, PackFile>(entries.Count);
Expand All @@ -154,6 +172,8 @@ public Dictionary<string, PackFile> GetAllFiles()
result[entry.RelativePath] = new PackFile(entry.FileName, source);
}

_logger.Here().Information("Getting all files and processing from cached container took {ElapsedMilliseconds} ms", time.ElapsedMilliseconds);

return result;
}

Expand Down
3 changes: 3 additions & 0 deletions Shared/SharedUI/Shared.Ui/Assembly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Shared.UiTest")]
Loading
Loading