Make CLI update old type names, remove obsidian folder

This commit is contained in:
Cj 2024-07-03 07:03:14 -04:00
parent 8f1fdeadfd
commit c9337cd98a
21 changed files with 109 additions and 480 deletions

View File

@ -1 +0,0 @@
{}

View File

@ -1,3 +0,0 @@
{
"accentColor": ""
}

View File

@ -1,30 +0,0 @@
{
"file-explorer": true,
"global-search": true,
"switcher": true,
"graph": true,
"backlink": true,
"canvas": true,
"outgoing-link": true,
"tag-pane": true,
"properties": false,
"page-preview": true,
"daily-notes": true,
"templates": true,
"note-composer": true,
"command-palette": true,
"slash-command": false,
"editor-status": true,
"bookmarks": true,
"markdown-importer": false,
"zk-prefixer": false,
"random-note": false,
"outline": true,
"word-count": true,
"slides": false,
"audio-recorder": false,
"workspaces": false,
"file-recovery": true,
"publish": false,
"sync": false
}

View File

@ -1,20 +0,0 @@
[
"file-explorer",
"global-search",
"switcher",
"graph",
"backlink",
"canvas",
"outgoing-link",
"tag-pane",
"page-preview",
"daily-notes",
"templates",
"note-composer",
"command-palette",
"editor-status",
"bookmarks",
"outline",
"word-count",
"file-recovery"
]

View File

@ -1,22 +0,0 @@
{
"collapse-filter": true,
"search": "",
"showTags": false,
"showAttachments": false,
"hideUnresolved": false,
"showOrphans": true,
"collapse-color-groups": true,
"colorGroups": [],
"collapse-display": true,
"showArrow": false,
"textFadeMultiplier": 0,
"nodeSizeMultiplier": 1,
"lineSizeMultiplier": 1,
"collapse-forces": true,
"centerStrength": 0.518713248970312,
"repelStrength": 10,
"linkStrength": 1,
"linkDistance": 250,
"scale": 1,
"close": true
}

View File

@ -1,158 +0,0 @@
{
"main": {
"id": "379217465f549fca",
"type": "split",
"children": [
{
"id": "54c1949a2997d742",
"type": "tabs",
"children": [
{
"id": "3ba51241806af7df",
"type": "leaf",
"state": {
"type": "canvas",
"state": {
"file": "Untitled.canvas",
"viewState": {
"x": -1324.3333740234375,
"y": -365.66656494140625,
"zoom": -0.6666666666666666
}
}
}
}
]
}
],
"direction": "vertical"
},
"left": {
"id": "5b6afcf2ac9987d1",
"type": "split",
"children": [
{
"id": "633de3e685c77487",
"type": "tabs",
"children": [
{
"id": "8890b3cf74fd4a96",
"type": "leaf",
"state": {
"type": "file-explorer",
"state": {
"sortOrder": "alphabetical"
}
}
},
{
"id": "7f4412dd886a7682",
"type": "leaf",
"state": {
"type": "search",
"state": {
"query": "",
"matchingCase": false,
"explainSearch": false,
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical"
}
}
},
{
"id": "5bda2ad3b0974edd",
"type": "leaf",
"state": {
"type": "bookmarks",
"state": {}
}
}
]
}
],
"direction": "horizontal",
"width": 300
},
"right": {
"id": "823dd02d5532773c",
"type": "split",
"children": [
{
"id": "52bb8c1a37662004",
"type": "tabs",
"children": [
{
"id": "16f0b64c50ad965f",
"type": "leaf",
"state": {
"type": "backlink",
"state": {
"file": "Untitled.canvas",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
"showSearch": false,
"searchQuery": "",
"backlinkCollapsed": false,
"unlinkedCollapsed": true
}
}
},
{
"id": "4cae092c09f416a0",
"type": "leaf",
"state": {
"type": "outgoing-link",
"state": {
"file": "Untitled.canvas",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
}
},
{
"id": "9ac3d05213c572e2",
"type": "leaf",
"state": {
"type": "tag",
"state": {
"sortOrder": "frequency",
"useHierarchy": true
}
}
},
{
"id": "b92d0982927abb20",
"type": "leaf",
"state": {
"type": "outline",
"state": {
"file": "Untitled.canvas"
}
}
}
]
}
],
"direction": "horizontal",
"width": 300,
"collapsed": true
},
"left-ribbon": {
"hiddenItems": {
"switcher:Open quick switcher": false,
"graph:Open graph view": false,
"canvas:Create new canvas": false,
"daily-notes:Open today's daily note": false,
"templates:Insert template": false,
"command-palette:Open command palette": false
}
},
"active": "3ba51241806af7df",
"lastOpenFiles": [
"Untitled.canvas",
"Untitled.md",
"Welcome.md"
]
}

View File

@ -1,12 +0,0 @@
{
"nodes":[
{"id":"02cecbc06ca4e27e","x":-2460,"y":-840,"width":680,"height":440,"type":"text","text":"Re-Mapper overhaul\n\n- More required parameters for better searches\n - Is Asbstract\n - Is Interface\n - Is Public"},
{"id":"ef843881ce9f25ca","x":-1410,"y":-680,"width":170,"height":60,"type":"text","text":"Is Abstract"},
{"id":"d0995cf4fa4e7306","x":-1194,"y":-840,"width":120,"height":60,"type":"text","text":"IsPublic"},
{"id":"ef16782e8346c662","type":"text","text":"Is Interface","x":-1208,"y":-676,"width":149,"height":56}
],
"edges":[
{"id":"3e2076115efebf6f","fromNode":"d0995cf4fa4e7306","fromSide":"bottom","toNode":"ef843881ce9f25ca","toSide":"top"},
{"id":"a7c1e1576f14002e","fromNode":"d0995cf4fa4e7306","fromSide":"bottom","toNode":"ef16782e8346c662","toSide":"top"}
]
}

View File

@ -3,7 +3,6 @@ using CliFx.Attributes;
using CliFx.Infrastructure;
using ReCodeIt.CrossCompiler;
using ReCodeIt.Utils;
using ReCodeItLib.Utils;
namespace ReCodeIt.Commands;
@ -25,8 +24,6 @@ public class Build : ICommand
if (isRemote) { return; }
await UseLastLoadedProject(console);
// Wait for log termination
Logger.Terminate();
while(Logger.IsRunning()) {}
@ -78,34 +75,6 @@ public class Build : ICommand
return false;
}
private async Task<bool> UseLastLoadedProject(IConsole console)
{
if (RegistryHelper.GetRegistryValue<string>("LastLoadedProject") != null)
{
string currentDirectory = Directory.GetCurrentDirectory();
console.Output.WriteLine($"Project: {RegistryHelper.GetRegistryValue<string>("LastLoadedProject")}");
console.Output.WriteLine($"Working Dir: {currentDirectory}");
CrossCompiler = new();
DataProvider.LoadAppSettings();
DataProvider.IsCli = true;
ProjectManager.LoadProject(RegistryHelper.GetRegistryValue<string>("LastLoadedProject"), true);
if (!Validate(console)) { return false; }
await CrossCompiler.StartCrossCompile();
DataProvider.SaveAppSettings();
return true;
}
return false;
}
private bool Validate(IConsole console)
{
if (ProjectManager.ActiveProject == null)

View File

@ -3,7 +3,6 @@ using CliFx.Attributes;
using CliFx.Infrastructure;
using ReCodeIt.CrossCompiler;
using ReCodeIt.Utils;
using ReCodeItLib.Utils;
namespace ReCodeIt.Commands;
@ -14,16 +13,14 @@ public class BuildRef : ICommand
public ValueTask ExecuteAsync(IConsole console)
{
console.Output.WriteLine(RegistryHelper.GetRegistryValue<string>("LastLoadedProject"));
if (RegistryHelper.GetRegistryValue<string>("LastLoadedProject") != null)
if (DataProvider.Settings.CrossCompiler.LastLoadedProject != null)
{
CrossCompiler = new();
DataProvider.LoadAppSettings();
DataProvider.IsCli = true;
ProjectManager.LoadProject(RegistryHelper.GetRegistryValue<string>("LastLoadedProject"), true);
ProjectManager.LoadProject(DataProvider.Settings.CrossCompiler.LastLoadedProject);
if (!Validate(console)) { return default; }

View File

@ -25,8 +25,8 @@ public class ReMap : ICommand
public ValueTask ExecuteAsync(IConsole console)
{
DataProvider.IsCli = true;
DataProvider.LoadAppSettings();
DataProvider.Settings.Remapper.MappingPath = MappingJsonPath;
var remapperSettings = DataProvider.Settings.Remapper.MappingSettings;

View File

@ -8,6 +8,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(SolutionDir)Templates&quot; &quot;$(TargetDir)Data&quot; /E /I /Y" />
</Target>
<ItemGroup>
<ProjectReference Include="..\RecodeItLib\ReCodeItLib.csproj" />
</ItemGroup>

View File

@ -1093,6 +1093,12 @@ public partial class ReCodeItForm : Form
private void CrossPatchRunButton_Click(object sender, EventArgs e)
{
if (CrossCompiler.ActiveProject == null)
{
MessageBox.Show("No project is loaded");
return;
}
if (CrossCompiler.ActiveProject.RemapModels.Count == 0)
{
MessageBox.Show("You cannot compile without having created remaps first");

View File

@ -1,7 +1,6 @@
using Microsoft.Win32;
using ReCodeIt.GUI;
using ReCodeIt.Utils;
using ReCodeItLib.Utils;
namespace ReCodeIt;
@ -13,21 +12,6 @@ internal static class Program
[STAThread]
private static void Main()
{
RegistryHelper.SetRegistryValue(
"DataPath",
DataProvider.DataPath,
RegistryValueKind.String);
RegistryHelper.SetRegistryValue(
"SettingsPath",
Path.Combine(DataProvider.DataPath, "Settings.jsonc"),
RegistryValueKind.String);
RegistryHelper.SetRegistryValue(
"LogPath",
Path.Combine(DataProvider.DataPath, "Log.log"),
RegistryValueKind.String);
DataProvider.LoadAppSettings();
// To customize application configuration such as set high DPI settings or default font, see https://aka.ms/applicationconfiguration.

View File

@ -3,7 +3,6 @@ using Microsoft.Win32;
using Newtonsoft.Json;
using ReCodeIt.Models;
using ReCodeIt.Utils;
using ReCodeItLib.Utils;
namespace ReCodeIt.CrossCompiler;
@ -68,7 +67,6 @@ public static class ProjectManager
DataProvider.Settings.CrossCompiler.LastLoadedProject = path;
RegistryHelper.SetRegistryValue("LastLoadedProject", path, RegistryValueKind.String);
DataProvider.SaveAppSettings();
Logger.Log($"Cross Compiler project json saved to {path}", ConsoleColor.Green);
@ -107,7 +105,6 @@ public static class ProjectManager
DataProvider.Settings.CrossCompiler.LastLoadedProject = path;
}
RegistryHelper.SetRegistryValue("LastLoadedProject", path, RegistryValueKind.String);
DataProvider.SaveAppSettings();
Logger.Log($"Loaded Cross Compiler Project: {model?.VisualStudioSolutionDirectoryPath}");

View File

@ -69,12 +69,6 @@ public class ReCodeItCrossCompiler
{
newProject = solution.GetProject(projId);
// Skip the ReCodeIt project if it exists
if (newProject!.Name == "ReCodeIt")
{
continue;
}
Logger.Log("Reversing Identifier Changes...", ConsoleColor.Yellow);
foreach (var docId in newProject.DocumentIds)
@ -96,10 +90,35 @@ public class ReCodeItCrossCompiler
newProject = newDoc.Project;
}
newProject = ChangeReferencePath(newProject);
await CompileProject(newProject);
}
}
private Project ChangeReferencePath(Project project)
{
foreach (var reference in project.MetadataReferences)
{
Logger.Log(reference.Display);
if (reference.Display.Contains(ActiveProject.OriginalAssemblyDllName))
{
Logger.Log("Removing old reference...", ConsoleColor.Yellow);
// Remove the reference from the project
project = project.RemoveMetadataReference(reference);
break;
}
}
Logger.Log("Creating new reference...", ConsoleColor.Yellow);
var newRef = MetadataReference.CreateFromFile(ActiveProject.OriginalAssemblyPath);
project = project.AddMetadataReference(newRef);
return project;
}
private async Task CompileProject(Project project)
{
Logger.Log("Compiling Project...", ConsoleColor.Yellow);

View File

@ -1,12 +1,12 @@
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using ReCodeIt.CrossCompiler;
using ReCodeIt.Enums;
using ReCodeIt.Models;
using ReCodeIt.ReMapper.Search;
using ReCodeIt.Utils;
using ReCodeItLib.Remapper.Search;
using System.Diagnostics;
using ReCodeIt.Enums;
namespace ReCodeIt.ReMapper;
@ -141,7 +141,6 @@ public class ReCodeItRemapper
return false;
}
return true;
}
@ -154,6 +153,12 @@ public class ReCodeItRemapper
{
var tokens = DataProvider.Settings.AutoMapper.TokensToMatch;
if (mapping.UseForceRename)
{
HandleDirectRename(mapping, types);
return;
}
if (mapping.SearchParams.IsNested is false or null)
{
types = types.Where(type => tokens.Any(token => type.Name.StartsWith(token)));
@ -196,6 +201,28 @@ public class ReCodeItRemapper
mapping.TypeCandidates.UnionWith(types);
}
private void HandleDirectRename(RemapModel mapping, IEnumerable<TypeDef> types)
{
foreach (var type in types)
{
if (type.Name == mapping.OriginalTypeName)
{
mapping.TypePrimeCandidate = type;
mapping.OriginalTypeName = type.Name.String;
mapping.Succeeded = true;
_alreadyGivenNames.Add(mapping.OriginalTypeName);
if (CrossMapMode)
{// Store the original types for caching
_compiler.ActiveProject.ChangedTypes.Add(mapping.NewTypeName, mapping.OriginalTypeName);
}
return;
}
}
}
/// <summary>
/// Choose the best possible match from all remaps
/// </summary>
@ -213,7 +240,7 @@ public class ReCodeItRemapper
/// <param name="remap"></param>
private void ChooseBestMatch(RemapModel remap)
{
if (remap.TypeCandidates.Count == 0) { return; }
if (remap.TypeCandidates.Count == 0 || remap.Succeeded) { return; }
var winner = remap.TypeCandidates.FirstOrDefault();
remap.TypePrimeCandidate = winner;
@ -230,7 +257,7 @@ public class ReCodeItRemapper
return;
}
_alreadyGivenNames.Add(winner.FullName);
_alreadyGivenNames.Add(remap.OriginalTypeName);
remap.Succeeded = true;
@ -238,7 +265,7 @@ public class ReCodeItRemapper
if (CrossMapMode)
{// Store the original types for caching
//_compiler.ActiveProject.ChangedTypes.Add(highestScore.ProposedNewName, highestScore.Definition.Name);
_compiler.ActiveProject.ChangedTypes.Add(winner.Name.String, remap.OriginalTypeName);
}
}
@ -248,7 +275,10 @@ public class ReCodeItRemapper
private void WriteAssembly()
{
var moduleName = Module.Name;
moduleName = moduleName.Replace(".dll", "-Remapped.dll");
moduleName = CrossMapMode
? moduleName
: moduleName.Replace(".dll", "-Remapped.dll");
OutPath = Path.Combine(OutPath, moduleName);
@ -262,14 +292,17 @@ public class ReCodeItRemapper
throw;
}
Logger.Log("Creating Hollow...", ConsoleColor.Yellow);
Hollow();
if (!CrossMapMode)
{
Logger.Log("Creating Hollow...", ConsoleColor.Yellow);
Hollow();
var hollowedDir = Path.GetDirectoryName(OutPath);
var hollowedPath = Path.Combine(hollowedDir, "Hollowed.dll");
Module.Write(hollowedPath);
var hollowedDir = Path.GetDirectoryName(OutPath);
var hollowedPath = Path.Combine(hollowedDir, "Hollowed.dll");
Module.Write(hollowedPath);
DisplayEndBanner(hollowedPath);
DisplayEndBanner(hollowedPath);
}
if (DataProvider.Settings.Remapper.MappingPath != string.Empty)
{

View File

@ -1,7 +1,6 @@
using dnlib.DotNet;
using Newtonsoft.Json;
using ReCodeIt.Models;
using ReCodeItLib.Utils;
namespace ReCodeIt.Utils;
@ -30,12 +29,6 @@ public static class DataProvider
public static void LoadAppSettings()
{
if (IsCli)
{
Settings = CreateFakeSettings();
return;
}
var settingsPath = Path.Combine(DataPath, "Settings.jsonc");
var jsonText = File.ReadAllText(settingsPath);
@ -47,13 +40,6 @@ public static class DataProvider
Settings = JsonConvert.DeserializeObject<Settings>(jsonText, settings);
if (Settings is null)
{
Logger.Log("Settings were null, creating new settings", ConsoleColor.Red);
Settings = CreateFakeSettings();
SaveAppSettings();
}
Logger.Log($"Settings loaded from '{settingsPath}'");
}
@ -61,7 +47,7 @@ public static class DataProvider
{
if (IsCli) { return; }
var settingsPath = RegistryHelper.GetRegistryValue<string>("SettingsPath");
var settingsPath = Path.Combine(DataPath, "Settings.jsonc");
if (!File.Exists(settingsPath))
{
@ -150,91 +136,4 @@ public static class DataProvider
return module;
}
private static Settings CreateFakeSettings()
{
var settings = new Settings
{
AppSettings = new AppSettings
{
Debug = false,
SilentMode = true
},
Remapper = new RemapperSettings
{
MappingPath = string.Empty,
OutputPath = string.Empty,
UseProjectMappings = false,
MappingSettings = new MappingSettings
{
RenameFields = false,
RenameProperties = false,
Publicize = false,
Unseal = false,
}
},
AutoMapper = new AutoMapperSettings
{
AssemblyPath = string.Empty,
OutputPath = string.Empty,
RequiredMatches = 5,
MinLengthToMatch = 7,
SearchMethods = true,
MappingSettings = new MappingSettings
{
RenameFields = false,
RenameProperties = false,
Publicize = false,
Unseal = false,
},
TypesToIgnore = [
"Boolean",
"List",
"Dictionary",
"Byte",
"Int16",
"Int32",
"Func",
"Action",
"Object",
"String",
"Vector2",
"Vector3",
"Vector4",
"Stream",
"HashSet",
"Double",
"IEnumerator"
],
TokensToMatch = [
"Class",
"GClass",
"GStruct",
"Interface",
"GInterface"
],
PropertyFieldBlackList = [
"Columns",
"mColumns",
"Template",
"Condition",
"Conditions",
"Counter",
"Instance",
"Command",
"_template"
],
MethodParamaterBlackList = [
],
},
CrossCompiler = new CrossCompilerSettings
{
LastLoadedProject = string.Empty,
AutoLoadLastActiveProject = true
}
};
return settings;
}
}

View File

@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using ReCodeItLib.Utils;
namespace ReCodeIt.Utils;
@ -85,8 +84,7 @@ public static class Logger
}
private const string _defaultFileName = "ReCodeIt.log";
private static string _logPath => RegistryHelper.GetRegistryValue<string>("LogPath") ?? $"{AppDomain.CurrentDomain.BaseDirectory}{_defaultFileName}";
private static string _logPath => Path.Combine(AppContext.BaseDirectory, "Data", "Settings.jsonc");
public static void ClearLog()
{
if (File.Exists(_logPath))
@ -110,7 +108,7 @@ public static class Logger
Console.ResetColor();
}
WriteToDisk(message.Message);
//WriteToDisk(message.Message);
}
private static void WriteToDisk(object message)

View File

@ -1,31 +0,0 @@
using Microsoft.Win32;
namespace ReCodeItLib.Utils;
public static class RegistryHelper
{
/// <summary>
/// Sets a key in the registry, given its key, value, and kind
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="kind"></param>
public static void SetRegistryValue(string key, string value, RegistryValueKind kind)
{
var regKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\ReCodeIt");
regKey.SetValue(key, value, kind);
}
/// <summary>
/// Gets a key from the registry, given its key and type
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public static T? GetRegistryValue<T>(string key)
{
var regKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\ReCodeIt");
return (T)regKey?.GetValue(key);
}
}

View File

@ -4,9 +4,9 @@
"SilentMode": true
},
"Remapper": {
"AssemblyPath": "G:\\development\\ReCodeIt\\RecodeItGUI\\bin\\Debug\\net8.0-windows\\Data\\Managed\\Assembly-CSharp-cleaned.dll",
"OutputPath": "G:\\development\\ReCodeIt\\RecodeItGUI\\bin\\Debug\\net8.0-windows\\Data",
"MappingPath": "G:\\development\\ReCodeIt\\RecodeItGUI\\bin\\Debug\\net8.0-windows\\Data\\Mappings.jsonc",
"AssemblyPath": "",
"OutputPath": "",
"MappingPath": "",
"UseProjectMappings": false,
"MappingSettings": {
"RenameFields": true,