Moved Script Solution (.sln) to project root

- Updated vswhere.exe
- Scripts created via Asset browser are now being added to the project
- Fixed Apply not being called for extended Settings
- Correctly wrap New File preview only when line full
- Create Project: Show warning, when target directory already exists
This commit is contained in:
Simon Lübeß
2023-10-27 22:29:10 +02:00
parent 3d8756ec42
commit 909012f518
14 changed files with 657 additions and 417 deletions
@@ -9,6 +9,7 @@ using GlitchyEngine.Math;
using GlitchyEngine.Content;
using GlitchyEngine;
using GlitchyEditor.Assets;
using System.Diagnostics;
namespace GlitchyEditor.EditWindows
{
@@ -191,7 +192,17 @@ namespace GlitchyEditor.EditWindows
if (ImGui.MenuItem("Open C# Project..."))
{
// TODO
String solutionPath = scope .();
Editor.Instance.CurrentProject.PathInProject(solutionPath, scope $"{Editor.Instance.CurrentProject.Name}.sln");
ProcessStartInfo psi = scope .();
psi.SetFileName("devenv");
psi.SetArguments(solutionPath);
scope SpawnedProcess().Start(psi);
/*if (Path.OpenFolder(solutionPath) case .Err)
Log.EngineLogger.Error("Failed to open file.");*/
}
}
@@ -399,7 +410,7 @@ namespace GlitchyEditor.EditWindows
float expectedButtonRight = currentButtonRight + style.ItemSpacing.x + DirectoryItemSize.X;
// If we aren't the last entry and the next button won't fit on the same line we start a new line.
if (entry != files.Back && expectedButtonRight < window_visible_x2)
if ((entry != files.Back || _showNewFile) && expectedButtonRight < window_visible_x2)
ImGui.SameLine();
ImGui.PopID();
@@ -462,7 +473,7 @@ namespace GlitchyEditor.EditWindows
if (ImGui.IsItemHovered() && ImGui.IsMouseDoubleClicked(.Left))
{
EntryDoubleClicked(entry);
OpenEntry(entry);
}
ImGui.TextUnformatted("..");
@@ -562,7 +573,7 @@ namespace GlitchyEditor.EditWindows
if (ImGui.IsItemHovered() && ImGui.IsMouseDoubleClicked(.Left))
{
EntryDoubleClicked(entry);
OpenEntry(entry);
}
if (_assetToRename == entry->Path)
@@ -773,7 +784,7 @@ namespace GlitchyEditor.EditWindows
}
}
private void EntryDoubleClicked(TreeNode<AssetNode> entry)
private void OpenEntry(TreeNode<AssetNode> entry)
{
if (entry->IsDirectory)
{
@@ -782,7 +793,7 @@ namespace GlitchyEditor.EditWindows
else
{
if (Path.OpenFolder(entry->Path) case .Err)
Log.EngineLogger.Error("Failed to open directory in file browser.");
Log.EngineLogger.Error("Failed to open file.");
}
}
}
+9 -1
View File
@@ -15,6 +15,8 @@ namespace GlitchyEditor
private EditorContentManager _contentManager;
private Project _currentProject;
private EntityHierarchyWindow _entityHierarchyWindow ~ delete _;
private ComponentEditWindow _componentEditWindow ~ delete _;
private EditorViewportWindow _sceneViewportWindow ~ delete _;
@@ -38,7 +40,13 @@ namespace GlitchyEditor
}
public EditorContentManager ContentManager => _contentManager;
public Project CurrentProject
{
get => _currentProject;
set => _currentProject = value;
}
public EntityHierarchyWindow EntityHierarchyWindow => _entityHierarchyWindow;
public ComponentEditWindow ComponentEditWindow => _componentEditWindow;
public EditorViewportWindow SceneViewportWindow => _sceneViewportWindow;
+44 -7
View File
@@ -204,6 +204,34 @@ namespace GlitchyEditor
Log.EngineLogger.Error($"Failed to save script file to \"{path}\".");
return;
}
// Add to .csproj
String assetRelativePath = scope .();
Path.GetRelativePath(path, _currentProject.WorkspacePath, assetRelativePath);
String projectPath = scope .();
Editor.Instance.CurrentProject.PathInProject(projectPath, scope $"{Editor.Instance.CurrentProject.Name}.csproj");
String projectFile = scope .();
let loadProjectResult = File.ReadAllText(projectPath, projectFile, true);
if (loadProjectResult case .Err(let err))
{
Log.EngineLogger.Error($"Failed to open project file ({err}). Please add the file to the project manually.");
}
const String scriptFilesMarker = "<!-- Script Files -->";
int index = projectFile.IndexOf(scriptFilesMarker);
int lineEndIndex = projectFile.IndexOf('\n', index);
projectFile.Insert(lineEndIndex + 1, scope $" <Compile Include=\"{assetRelativePath}\" />\n");
let saveProjectResult = File.WriteAllText(projectPath, projectFile);
if (saveProjectResult case .Err(let err))
{
Log.EngineLogger.Error($"Failed to edit project file ({err}). Please add the file to the project manually.");
}
}));
}
@@ -577,13 +605,14 @@ namespace GlitchyEditor
private static Result<void> InitProject(Project project)
{
Try!(CopyTemplate(project));
Try!(MoveFile(project, "Assets/Scripts/TemplateProject.sln", scope $"Assets/Scripts/{project.Name}.sln"));
Try!(MoveFile(project, "Assets/Scripts/TemplateProject.csproj", scope $"Assets/Scripts/{project.Name}.csproj"));
Try!(FixupTemplateFile(project, scope $"Assets/Scripts/{project.Name}.sln"));
Try!(FixupTemplateFile(project, scope $"Assets/Scripts/{project.Name}.csproj"));
Try!(FixupTemplateFile(project, scope $"Assets/Scripts/Properties/AssemblyInfo.cs"));
// Rename files within project
Try!(MoveFile(project, "TemplateProject.sln", scope $"{project.Name}.sln"));
Try!(MoveFile(project, "TemplateProject.csproj", scope $"{project.Name}.csproj"));
Try!(FixupTemplateFile(project, scope $"{project.Name}.sln"));
Try!(FixupTemplateFile(project, scope $"{project.Name}.csproj"));
Try!(FixupTemplateFile(project, scope $"Properties/AssemblyInfo.cs"));
return .Ok;
}
@@ -703,6 +732,11 @@ namespace GlitchyEditor
ImGui.Text($"The Project will be in:\n{target}");
if (Directory.Exists(target))
{
ImGui.TextColored(.(1, 0, 0, 1), "The directory is not empty!");
}
ImGui.NewLine();
ImGui.BeginDisabled(directory.IsWhiteSpace || projectName.IsWhiteSpace);
@@ -775,10 +809,12 @@ namespace GlitchyEditor
_currentProject = project;
_editor.CurrentProject = _currentProject;
String appAssemblyPath = scope String();
_contentManager.SetAssetDirectory(_currentProject.AssetsFolder);
Path.Combine(appAssemblyPath, _currentProject.AssetsFolder, scope $"Scripts/bin/{_currentProject.Name}.dll");
_currentProject.PathInProject(appAssemblyPath, scope $"bin/{_currentProject.Name}.dll");
ScriptEngine.SetAppAssemblyPath(appAssemblyPath);
@@ -1288,6 +1324,7 @@ namespace GlitchyEditor
{
delete workspacePath;
@workspacePath.Remove();
continue;
}
if (ImGui.MenuItem(scope $"{i}: {workspacePath}"))
+145 -2
View File
@@ -3,6 +3,8 @@ using GlitchyEngine;
using Bon;
using GlitchyEditor;
using System.Collections;
using System.IO;
using System.Diagnostics;
namespace GlitchyEngine
{
@@ -10,16 +12,157 @@ namespace GlitchyEngine
{
[SettingContainer, BonInclude]
public readonly EditorSettings EditorSettings = new .() ~ delete _;
public this()
[SettingContainer, BonInclude]
public readonly ScriptSettings ScriptSettings = new .() ~ delete _;
protected override void RegisterEventListeners()
{
OnApplySettings.Add(new (s, e) => EditorSettings.Apply());
OnApplySettings.Add(new (s, e) => ScriptSettings.Apply());
}
}
}
namespace GlitchyEditor;
[Reflect]
class ScriptSettings
{
[Setting("Script", "Visual Studio path", "The path of the Visual Studio devenv.exe"), BonInclude]
public String VisualStudioPath ~ delete _;
public void Apply()
{
if (String.IsNullOrWhiteSpace(VisualStudioPath))
{
// TODO: Do later
//FildVisualStudio();
}
}
void FildVisualStudio()
{
// TODO: Find devenv.exe ourselves
String exeFile = scope .();
Environment.GetExecutableFilePath(exeFile);
String exeDirectory = scope .();
Path.GetDirectoryPath(exeFile, exeDirectory);
String vsWherePath = scope .();
Path.Combine(vsWherePath, exeDirectory, "vswhere.exe");
ProcessStartInfo processInfo = scope .();
processInfo.SetFileName(vsWherePath);
processInfo.UseShellExecute = true;
// Find the installation path of the latest visual studio
processInfo.SetArguments("-latest -property installationPath");
processInfo.RedirectStandardOutput = true;
//processInfo.CreateNoWindow = true;
String vsInstallDirectory = scope .();
{
Windows.FileHandle h = Windows.CreateFileA("vspath.tmp",
Windows.GENERIC_WRITE,
.ReadWrite,
null,
.Create,
128,
.InvalidHandle);
//Windows.FileHandle h = (.)Windows.CreateFileMappingA(.InvalidHandle, null, 0x40, 4096, 4096, null);
Windows.ProcessInformation pi = .();
Windows.StartupInfo si = .();
Windows.IntBool ret = false;
int32 flags = Windows.CREATE_NO_WINDOW;
si.mCb = sizeof(Windows.StartupInfo);
si.mFlags |= Windows.STARTF_USESTDHANDLES;
si.mStdInput = .InvalidHandle;
si.mStdError = .InvalidHandle;
si.mStdOutput = h;
char8* cmd = scope $"{vsWherePath} -latest -property installationPath";
ret = Windows.CreateProcessA(null, cmd, null, null, true, flags, null, null, &si, &pi);
// Wait for the process for one second
Windows.WaitForSingleObject(pi.mProcess, 1000);
/*if ( ret )
{
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}*/
/*let process = scope SpawnedProcess();
process.AttachStandardOutput();
process.Start(processInfo);
while (!process.HasExited)
{
}
BufferedFileStream tmpFile = scope BufferedFileStream();
tmpFile.Open("vspath.tmp", .ReadWrite, .None, 4096, .DeleteOnClose);
//scope SpawnedProcess().Start(processInfo);
//tmpFile.Position = 0;
{
StreamReader reader = scope StreamReader(tmpFile);
reader.ReadToEnd(vsInstallDirectory);
}
tmpFile.Close();*/
}
if (VisualStudioPath == null)
VisualStudioPath = new String();
else
VisualStudioPath.Clear();
Path.Combine(VisualStudioPath, vsInstallDirectory, "Common7/IDE/devenv.exe");
}
#if BF_PLATFORM_WINDOWS
void StartProgramm()
{
/*Windows.FileHandle h = (.)Windows.CreateFileMappingA(.InvalidHandle, null, 0x40, 4096, 4096, null);
Windows.ProcessInformation pi = .();
Windows.StartupInfo si = .();
Windows.IntBool ret = false;
uint32 flags = Windows.CREATE_NO_WINDOW;
si.mCb = sizeof(Windows.StartupInfo);
si.mFlags |= Windows.STARTF_USESTDHANDLES;
si.mStdInput = .InvalidHandle;
si.mStdError = .InvalidHandle;
si.mStdOutput = h;
ret = Windows.CreateProcessA(null, cmd, NULL, NULL, TRUE, flags, NULL, NULL, &si, &pi);
if ( ret )
{
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
return -1;*/
}
#endif
}
[Reflect]
class EditorSettings
{