mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Modified template and improved template creation
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunManager" selected=".NET Launch Settings Profile.ScriptCoreGenerator: Debug Code Generator">
|
||||
<configuration name="Attach to Glitchy Engine" type="ConnectRemote" factoryName="Mono Remote" show_console_on_std_err="false" show_console_on_std_out="false" port="2550" address="localhost">
|
||||
<option name="allowRunningInParallel" value="false" />
|
||||
<option name="listenPortForConnections" value="false" />
|
||||
<option name="projectPathOnTarget" />
|
||||
<option name="selectedOptions">
|
||||
<list />
|
||||
</option>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<list>
|
||||
<item itemvalue="Mono Remote.Attach to Glitchy Engine" />
|
||||
</list>
|
||||
</component>
|
||||
</project>
|
||||
@@ -629,18 +629,73 @@ namespace GlitchyEditor
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
const String ProjectNamePlaceholder = "[ProjectName]";
|
||||
const String CoreLibPathPlaceholder = "[CoreLibPath]";
|
||||
|
||||
/// Initializes the given project with the template.
|
||||
private static Result<void> InitProject(Project project)
|
||||
{
|
||||
Try!(CopyTemplate(project));
|
||||
|
||||
// Rename files within project
|
||||
Try!(MoveFile(project, "TemplateProject.sln", scope $"{project.Name}.sln"));
|
||||
Try!(MoveFile(project, "TemplateProject.csproj", scope $"{project.Name}.csproj"));
|
||||
Try!(RenameAndFixupFiles(project.WorkspacePath, project));
|
||||
|
||||
Try!(FixupTemplateFile(project, scope $"{project.Name}.sln"));
|
||||
Try!(FixupTemplateFile(project, scope $"{project.Name}.csproj"));
|
||||
Try!(FixupTemplateFile(project, scope $"Properties/AssemblyInfo.cs"));
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
/// Moves files so that [ProjectName] in their paths will be replaced by the actual project name
|
||||
private static Result<void> RenameAndFixupFiles(StringView directoryPath, Project project)
|
||||
{
|
||||
String fullPath = scope .(256);
|
||||
String modifiedFileName = scope String(256);
|
||||
|
||||
for (FileFindEntry entry in Directory.Enumerate(scope $"{directoryPath}/*", .Files | .Directories))
|
||||
{
|
||||
entry.GetFilePath(fullPath..Clear());
|
||||
|
||||
if (fullPath.Contains(ProjectNamePlaceholder))
|
||||
{
|
||||
modifiedFileName.Set(fullPath);
|
||||
modifiedFileName.Replace(ProjectNamePlaceholder, project.Name);
|
||||
|
||||
if (entry.IsDirectory)
|
||||
Try!(Directory.Move(fullPath, modifiedFileName));
|
||||
else
|
||||
Try!(File.Move(fullPath, modifiedFileName));
|
||||
|
||||
Swap!(fullPath, modifiedFileName);
|
||||
}
|
||||
|
||||
if (entry.IsDirectory)
|
||||
{
|
||||
Try!(RenameAndFixupFiles(fullPath, project));
|
||||
}
|
||||
else
|
||||
{
|
||||
String fileContent = scope String();
|
||||
if (File.ReadAllText(fullPath, fileContent, true) case .Err)
|
||||
{
|
||||
Log.EngineLogger.Error($"FixupFile: Failed to read file {fullPath}.");
|
||||
return .Err;
|
||||
}
|
||||
|
||||
if (!fileContent.Contains(ProjectNamePlaceholder) && !fileContent.Contains(CoreLibPathPlaceholder))
|
||||
continue;
|
||||
|
||||
fileContent.Replace(ProjectNamePlaceholder, project.Name);
|
||||
|
||||
// TODO: This is pretty bad, we don't really want to hard code the script core path like that!
|
||||
String scriptCorePath = scope .();
|
||||
Directory.GetCurrentDirectory(scriptCorePath);
|
||||
scriptCorePath.Append("/Resources/Scripts/ScriptCore.dll");
|
||||
fileContent.Replace(CoreLibPathPlaceholder, scriptCorePath);
|
||||
|
||||
if (File.WriteAllText(fullPath, fileContent, false) case .Err)
|
||||
{
|
||||
Log.EngineLogger.Error($"FixupFile: Failed to write file {fullPath}.");
|
||||
return .Err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return .Ok;
|
||||
}
|
||||
@@ -661,53 +716,6 @@ namespace GlitchyEditor
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
/// Renames a file within the project.
|
||||
private static Result<void> MoveFile(Project project, StringView fromName, StringView toName)
|
||||
{
|
||||
String fromPath = scope String();
|
||||
project.PathInProject(fromPath, fromName);
|
||||
|
||||
String toPath = scope String();
|
||||
project.PathInProject(toPath, toName);
|
||||
|
||||
if (File.Move(fromPath, toPath) case .Err(let error))
|
||||
{
|
||||
Log.EngineLogger.Error($"Failed to move file from {fromPath} to {toPath}. ({error})");
|
||||
return .Err;
|
||||
}
|
||||
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
/// Fixups a template file by replacing placeholders with actual values.
|
||||
private static Result<void> FixupTemplateFile(Project project, StringView fileName)
|
||||
{
|
||||
String fileTargetPath = scope String();
|
||||
project.PathInProject(fileTargetPath, fileName);
|
||||
|
||||
String fileContent = scope String();
|
||||
if (File.ReadAllText(fileTargetPath, fileContent, true) case .Err)
|
||||
{
|
||||
Log.EngineLogger.Error($"FixupFile: Failed to read file {fileTargetPath}.");
|
||||
return .Err;
|
||||
}
|
||||
|
||||
fileContent.Replace("[ProjectName]", project.Name);
|
||||
|
||||
String scriptCorePath = scope .();
|
||||
Directory.GetCurrentDirectory(scriptCorePath);
|
||||
scriptCorePath.Append("/Resources/Scripts/ScriptCore.dll");
|
||||
fileContent.Replace("[CoreLibPath]", scriptCorePath);
|
||||
|
||||
if (File.WriteAllText(fileTargetPath, fileContent, false) case .Err)
|
||||
{
|
||||
Log.EngineLogger.Error($"FixupFile: Failed to write file {fileTargetPath}.");
|
||||
return .Err;
|
||||
}
|
||||
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
/// If set to true, the popup for creating a new project will be shown.
|
||||
private bool _openCreateProjectModal;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user