Skip to content

Commit

Permalink
Asset browser implementation (WolvenKit#328)
Browse files Browse the repository at this point in the history
* Begin work on asset browser bindings

* Basic file browsing

* Working cyberpunk archivemanager without hashes

* Fix hashservice for asset browser

* ProjectWizard Design fixes

* Added basic design (no content) For :

IntegratedToolsPage
UserPage
BugReportWizard
FeedBackWizard

* Changed to Public HandyControls Nuget! Woohoo!

* Preperations for adding CyberCAT
Wizards design work.

* PreviewView Grid

(Name = PreviewGridAsset)

* Directorytree and path display for AssetBrowser

* Assetbrowser bugfixes

* FIx build

* Assetbrowser class and extension list

* Virtualize comboboxes and home button

* Fix project loading async await bug

* Adding mod files works for witcher3

Co-authored-by: R503B <[email protected]>
  • Loading branch information
Traderain and Offline-R503B authored Feb 1, 2021
1 parent 32ced1f commit 37e792c
Show file tree
Hide file tree
Showing 92 changed files with 1,354 additions and 244 deletions.
56 changes: 21 additions & 35 deletions CP77.CR2W/Archive/ArchiveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
using System.Reflection;
using System.Windows.Navigation;
using Catel.Collections;
using CP77Tools.Model;
using Catel.IoC;
using CP77Tools.Model;
using WolvenKit.Common;
using WolvenKit.Common.Model;
using WolvenKit.Common.Tools;
using WolvenKit.Common.Services;
using WolvenKit.Common.Tools;
using Path = System.IO.Path;

namespace CP77.CR2W.Archive
Expand All @@ -21,6 +23,11 @@ public class ArchiveManager : CyberArchiveManager

public ArchiveManager()
{
Archives = new Dictionary<string, Archive>();
Files = new Dictionary<ulong, List<FileEntry>>();
Items = new Dictionary<string, List<IGameFile>>();
var hashService = ServiceLocator.Default.ResolveType<IHashService>();
hashService.ReloadLocally();
}

public ArchiveManager(DirectoryInfo indir)
Expand All @@ -29,6 +36,9 @@ public ArchiveManager(DirectoryInfo indir)

Archives = new Dictionary<string, Archive>();
Files = new Dictionary<ulong, List<FileEntry>>();
Items = new Dictionary<string, List<IGameFile>>();
var hashService = ServiceLocator.Default.ResolveType<IHashService>();
hashService.ReloadLocally();

// load files
Reload(indir);
Expand Down Expand Up @@ -110,6 +120,7 @@ private void ReloadFiles()
/// </param>
public override void LoadModArchive(string filename)
{
return;
if (Archives.ContainsKey(filename))
return;

Expand Down Expand Up @@ -139,9 +150,9 @@ public override void LoadArchive(string filename, bool ispatch = false)
foreach (KeyValuePair<ulong, FileEntry> item in bundle.Files)
{
// add new key if the file isn't already in another bundle
if (!Items.ContainsKey(item.Key.ToString()))
Items.Add(item.Key.ToString(), new List<IGameFile>());
Items[item.Key.ToString()].Add(item.Value);
if (!Items.ContainsKey(item.Value.Name))
Items.Add(item.Value.Name, new List<IGameFile>());
Items[item.Value.Name].Add(item.Value);
}
Archives.Add(filename, bundle);
}
Expand All @@ -152,42 +163,16 @@ public override void LoadArchive(string filename, bool ispatch = false)
/// <param name="exedir">Path to executable directory</param>
public override void LoadAll(string exedir)
{
exedir = "D:\\SteamLibrary\\steamapps\\common\\Cyberpunk 2077\\bin\\x64\\";
var di = new DirectoryInfo(exedir);
if (!di.Exists)
return;
var dlc = Path.Combine(di.Parent.Parent.FullName, "DLC");
var content = Path.Combine(di.Parent.Parent.FullName, "content");
var archivedir = Path.Combine(di.Parent.Parent.FullName, "archive", "pc", "content");

var contentdirs = new List<string>(Directory.GetDirectories(content, "content*"));
contentdirs.Sort(new AlphanumComparator<string>());
foreach (var file in contentdirs.SelectMany(dir => Directory.GetFiles(dir, "*.archive", SearchOption.AllDirectories)))
foreach (var file in Directory.GetFiles(archivedir, "*.archive"))
{
LoadArchive(file);
}

var patchdirs = new List<string>(Directory.GetDirectories(content, "patch*"));
patchdirs.Sort(new AlphanumComparator<string>());
foreach (var file in patchdirs.SelectMany(dir =>
Directory.GetFiles(dir, "*.archive", SearchOption.AllDirectories)))
{
LoadArchive(file, true);
}

if (Directory.Exists(dlc))
{
var dlcdirs = new List<string>(Directory.GetDirectories(dlc));
dlcdirs.Sort(new AlphanumComparator<string>());

foreach (var file in dlcdirs
.Where(_ => VanillaDlClist.Contains(new DirectoryInfo(_).Name))
.SelectMany(dir => Directory.GetFiles(dir ?? "", "*.archive", SearchOption.AllDirectories)
.OrderBy(k => k)))
{
LoadArchive(file);
}
}


RebuildRootNode();
}

Expand All @@ -198,6 +183,7 @@ public override void LoadAll(string exedir)
/// <param name="dlc"></param>
public override void LoadModsArchives(string mods, string dlc)
{
return;
if (!Directory.Exists(mods))
Directory.CreateDirectory(mods);
var modsdirs = new List<string>(Directory.GetDirectories(mods));
Expand Down Expand Up @@ -225,4 +211,4 @@ public override void LoadModsArchives(string mods, string dlc)
#endregion

}
}
}
18 changes: 13 additions & 5 deletions CP77.CR2W/Archive/FileEntry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using Catel.IoC;
using CP77.CR2W.Types;
Expand Down Expand Up @@ -29,12 +30,12 @@ public class FileEntry : IGameFile
public string Extension => Path.GetExtension(FileName);

public IGameArchive Archive { get; set; }
public string Name { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public uint Size { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public uint ZSize { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public long PageOffset { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string Name { get; set; }
public uint Size { get; set; }
public uint ZSize { get; set; }
public long PageOffset { get; set; }

public string CompressionType => throw new NotImplementedException();
public string CompressionType { get; set; }

public FileEntry(BinaryReader br, IGameArchive parent)
{
Expand Down Expand Up @@ -62,7 +63,9 @@ private void Read(BinaryReader br, IHashService mainController)
NameHash64 = br.ReadUInt64();

if (mainController != null && mainController.Hashdict.ContainsKey(NameHash64))
{
_nameStr = mainController.Hashdict[NameHash64];
}

// x-platform support
if (System.Runtime.InteropServices.RuntimeInformation
Expand All @@ -82,6 +85,11 @@ private void Read(BinaryReader br, IHashService mainController)
ResourceDependenciesEnd = br.ReadUInt32();

SHA1Hash = br.ReadBytes(20);

if (!string.IsNullOrEmpty(_nameStr))
Name = _nameStr;
else
Name = NameHash64.ToString();
}

public void Write(BinaryWriter bw)
Expand Down
2 changes: 1 addition & 1 deletion WolvenKit.Bundles/BundleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override void LoadArchive(string filename, bool ispatch = false)
{
// add new key if the file isn't already in another bundle
if (!Items.ContainsKey(item.Key))
Items.Add(item.Key, new List<IGameFile>());
Items.TryAdd(item.Key, new List<IGameFile>());

// if file is already in another bundle
if (ispatch && Items[item.Key].Count > 0)
Expand Down
23 changes: 23 additions & 0 deletions WolvenKit.Common/Model/AssetBrowserData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Windows.Documents;

namespace WolvenKit.Common.Model
{
public class AssetBrowserData
{
public string Name { get; set; }
public string Size { get; set; }
public GameFileTreeNode Parent { get; set; }
public GameFileTreeNode This { get; set; }
public GameFileTreeNode Children { get; set; }
public EntryType Type { get; set; }
public List<IGameFile> AmbigiousFiles { get; set; }
}

public enum EntryType
{
Directory,
File,
MoveUP
}
}
1 change: 1 addition & 0 deletions WolvenKit.Common/Model/CyberArchiveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private void RebuildExtensions()
/// </summary>
private void RebuildAutoCompleteSource()
{
AutocompleteSource = new List<string>();
AutocompleteSource.AddRange(FileList.Select(x => GetFileName(x.Name)).Distinct().ToArray());
}

Expand Down
38 changes: 38 additions & 0 deletions WolvenKit.Common/Model/GameFileTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using WolvenKit.Common.Model;

namespace WolvenKit.Common
Expand Down Expand Up @@ -41,6 +42,9 @@ public EArchiveType Type
bundlename = bundlenodenames.First();
}

if (String.IsNullOrEmpty(bundlename) || bundlename.ToUpper() == "ROOT" || bundlename.ToUpper() == "DEPOT")
bundlename = EArchiveType.ANY.ToString();

return (EArchiveType)Enum.Parse(typeof(EArchiveType), bundlename);
}
}
Expand All @@ -63,9 +67,43 @@ public string FullPath
}
}

public List<GameFileTreeNode> SubDirectories => Directories.Values.ToList();

public string Name { get; set; }
public GameFileTreeNode Parent { get; set; }
public Dictionary<string, GameFileTreeNode> Directories { get; set; }
public Dictionary<string, List<IGameFile>> Files { get; set; }

public List<AssetBrowserData> ToAssetBrowserData()
{
var ret = new List<AssetBrowserData>();
ret.Add(new AssetBrowserData()
{
Name = "..",
Type = EntryType.MoveUP,
This = this,
Parent = this.Parent
});
ret.AddRange(Directories.Select(d => new AssetBrowserData()
{
Name = d.Key,
Size = d.Value.Directories.Count + " directories, " + d.Value.Files.Count + " files",
Parent = this.Parent,
Children = d.Value,
This = this,
Type = EntryType.Directory
}));

ret.AddRange(Files.Select(f => new AssetBrowserData()
{
Name = f.Key,
Size = f.Value[0].Size + " bytes",
This = this,
Type = EntryType.File,
Parent = this.Parent
}));

return ret;
}
}
}
3 changes: 0 additions & 3 deletions WolvenKit.Common/Model/IGameFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,4 @@ public interface IGameFile

void Extract(Stream output);
}



}
38 changes: 27 additions & 11 deletions WolvenKit/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ protected override async void OnStartup(StartupEventArgs e)
viewModelLocator.Register(typeof(Views.HomePage.Pages.WelcomePageView), typeof(ViewModels.HomePage.Pages.WelcomePageViewModel));
viewModelLocator.Register(typeof(Views.HomePage.Pages.WebsitePageView), typeof(ViewModels.HomePage.Pages.WebsitePageViewModel));
viewModelLocator.Register(typeof(Views.HomePage.Pages.SettingsPageView), typeof(ViewModels.HomePage.Pages.SettingsPageViewModel));
viewModelLocator.Register(typeof(Views.HomePage.Pages.UserPageView), typeof(ViewModels.HomePage.Pages.UserPageViewModel));


//-- Category : Integrated Tools
viewModelLocator.Register(typeof(Views.HomePage.Pages.IntegratedToolsPageView), typeof(ViewModels.HomePage.Pages.IntegratedToolsPageViewModel));
viewModelLocator.Register(typeof(Views.IntegratedToolsPages.CyberCAT.CyberCATPageView), typeof(ViewModels.IntegratedToolsPages.CyberCAT.CyberCATPageViewModel));



//-- Category : Settings Pages
viewModelLocator.Register(typeof(Views.SettingsPages.GeneralSettingsView), typeof(ViewModels.SettingsPages.GeneralSettingsViewModel));
Expand All @@ -117,29 +125,22 @@ protected override async void OnStartup(StartupEventArgs e)
viewModelLocator.Register(typeof(Views.SettingsPages.SubPages.General.UpdatesSubSettingsView), typeof(ViewModels.SettingsPages.SubPages.General.UpdatesSubSettingsViewModel));
viewModelLocator.Register(typeof(Views.SettingsPages.SubPages.General.ThemeSubSettingsView), typeof(ViewModels.SettingsPages.SubPages.General.ThemeSubSettingsViewModel));
viewModelLocator.Register(typeof(Views.SettingsPages.SubPages.General.LoggingSubSettingsView), typeof(ViewModels.SettingsPages.SubPages.General.LoggingSubSettingsViewModel));


// - Tools
viewModelLocator.Register(typeof(Views.SettingsPages.ToolSettingsView), typeof(ViewModels.SettingsPages.ToolSettingsViewModel));
viewModelLocator.Register(typeof(Views.SettingsPages.SubPages.Tool.AssetBrowserSubSettingsView), typeof(ViewModels.SettingsPages.SubPages.Tool.AssetBrowserSubSettingsViewModel));
viewModelLocator.Register(typeof(Views.SettingsPages.SubPages.Tool.CodeEditorSubSettingsView), typeof(ViewModels.SettingsPages.SubPages.Tool.CodeEditorSubSettingsViewModel));
viewModelLocator.Register(typeof(Views.SettingsPages.SubPages.Tool.PluginManagerSubSettingsView), typeof(ViewModels.SettingsPages.SubPages.Tool.PluginManagerSubSettingsViewModel));
viewModelLocator.Register(typeof(Views.SettingsPages.SubPages.Tool.VisualEditorSubSettingsView), typeof(ViewModels.SettingsPages.SubPages.Tool.VisualEditorSubSettingsViewModel));


// - Editor
viewModelLocator.Register(typeof(Views.SettingsPages.EditorSettingsView), typeof(ViewModels.SettingsPages.EditorSettingsViewModel));
viewModelLocator.Register(typeof(Views.SettingsPages.SubPages.Editor.GeneralSubSettingsView), typeof(ViewModels.SettingsPages.SubPages.Editor.GeneralSubSettingsViewModel));
viewModelLocator.Register(typeof(Views.SettingsPages.SubPages.Editor.CompatibilitySubSettingsView), typeof(ViewModels.SettingsPages.SubPages.Editor.CompatibilitySubSettingsViewModel));


// - Packaging
viewModelLocator.Register(typeof(Views.SettingsPages.PackagingSettingsView), typeof(ViewModels.SettingsPages.PackagingSettingsViewModel));


// - Integrations
viewModelLocator.Register(typeof(Views.SettingsPages.IntegrationsSettingsView), typeof(ViewModels.SettingsPages.IntegrationsSettingsViewModel));





// ---- HeadCategory : Wizards
//-- Category : UserWizard
viewModelLocator.Register(typeof(Views.Wizards.UserWizardView), typeof(ViewModels.Wizards.UserWizardViewModel));
Expand Down Expand Up @@ -169,6 +170,21 @@ protected override async void OnStartup(StartupEventArgs e)
viewModelLocator.Register(typeof(Views.Wizards.WizardPages.FirstSetupWizard.LocateGameDateView), typeof(ViewModels.Wizards.WizardPages.FirstSetupWizard.LocateGameDataViewModel));
viewModelLocator.Register(typeof(Views.Wizards.WizardPages.FirstSetupWizard.FinalizeSetupView), typeof(ViewModels.Wizards.WizardPages.FirstSetupWizard.FinalizeSetupViewModel));

//-- Category : FeedBackWizard
viewModelLocator.Register(typeof(Views.Wizards.FeedbackWizardView), typeof(ViewModels.Wizards.FeedbackWizardViewModel));
viewModelLocator.Register(typeof(Views.Wizards.WizardPages.FeedbackWizard.RateView), typeof(ViewModels.Wizards.WizardPages.FeedbackWizard.RateViewModel));
viewModelLocator.Register(typeof(Views.Wizards.WizardPages.FeedbackWizard.SendView), typeof(ViewModels.Wizards.WizardPages.FeedbackWizard.SendViewModel));
viewModelLocator.Register(typeof(Views.Wizards.WizardPages.FeedbackWizard.ReviewView), typeof(ViewModels.Wizards.WizardPages.FeedbackWizard.ReviewViewModel));


//-- Category : InstallerWizard
viewModelLocator.Register(typeof(Views.Wizards.InstallerWizardView), typeof(ViewModels.Wizards.InstallerWizardViewModel));

//-- Category : BugReportWizard
viewModelLocator.Register(typeof(Views.Wizards.BugReportWizard), typeof(ViewModels.Wizards.BugReportWizardViewModel));
viewModelLocator.Register(typeof(Views.Wizards.WizardPages.BugReportWizard.AttachBugView), typeof(ViewModels.Wizards.WizardPages.BugReportWizard.AttachBugViewModel));
viewModelLocator.Register(typeof(Views.Wizards.WizardPages.BugReportWizard.DescribeBugView), typeof(ViewModels.Wizards.WizardPages.BugReportWizard.DescribeBugViewModel));
viewModelLocator.Register(typeof(Views.Wizards.WizardPages.BugReportWizard.SendBugView), typeof(ViewModels.Wizards.WizardPages.BugReportWizard.SendBugViewModel));


var viewLocator = ServiceLocator.Default.ResolveType<IViewLocator>();
Expand Down
13 changes: 9 additions & 4 deletions WolvenKit/Commands/ProjectCommandContainerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------


using System;
using Catel.IoC;
using Catel.Services;
using Orc.Notifications;
Expand Down Expand Up @@ -54,21 +55,25 @@ protected ProjectCommandContainerBase(string commandName,
#endregion

#region Methods
private async Task OnProjectActivatedAsync(object sender, ProjectUpdatedEventArgs e)
private Task OnProjectActivatedAsync(object sender, ProjectUpdatedEventArgs e)
{
//await Task.Run(() => ProjectActivated((Project) e.OldProject, (Project) e.NewProject));
await ProjectActivatedAsync((EditorProject)e.OldProject, (EditorProject)e.NewProject);
//Task.Run(() => ProjectActivated((EditorProject) e.OldProject, (EditorProject) e.NewProject));
var asd = ProjectActivated((EditorProject)e.OldProject, (EditorProject)e.NewProject);

//TODO: why is that here?
_commandManager.InvalidateCommands();

return TaskHelper.Completed;
}

protected virtual async Task ProjectActivatedAsync(EditorProject oldEditorProject, EditorProject newEditorProject)
protected virtual async Task ProjectActivated(EditorProject oldEditorProject, EditorProject newEditorProject)
{
if (newEditorProject == null)
return;

await Task.Run(() => newEditorProject.Initialize());


}

protected override bool CanExecute(object parameter)
Expand Down
Loading

0 comments on commit 37e792c

Please sign in to comment.