Added commands
This commit is contained in:
115
main.go
115
main.go
@@ -1,10 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
@@ -16,14 +19,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Project struct {
|
type Project struct {
|
||||||
Path string `json:"path"`
|
EnginePath string `json:"enginePath"`
|
||||||
Version float64 `json:"version"`
|
ProjectPath string `json:"projectPath"`
|
||||||
|
ProjectName string `json:"projectName"`
|
||||||
|
Version string `json:"engineVersion"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const jsonFilePath = "projects.json"
|
const projectsFilePath = "projects.json"
|
||||||
|
var projectList *fyne.Container
|
||||||
|
var logText *widget.Entry
|
||||||
|
var scrollContainer *container.Scroll
|
||||||
|
|
||||||
func loadProjects() ([]Project, error) {
|
func loadProjects() ([]Project, error) {
|
||||||
file, err := os.ReadFile(jsonFilePath)
|
file, err := os.ReadFile(projectsFilePath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -37,32 +45,93 @@ func loadProjects() ([]Project, error) {
|
|||||||
return projects, nil
|
return projects, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateUnrealSolution(project Project) {
|
||||||
|
var buildCmd string
|
||||||
|
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
buildCmd = project.EnginePath + "/Engine/Build/BatchFiles/Linux/GenerateProjectFiles.sh";
|
||||||
|
case "darwin":
|
||||||
|
buildCmd = project.EnginePath + "/Engine/Build/BatchFiles/Mac/GenerateProjectFiles.sh"
|
||||||
|
default:
|
||||||
|
fmt.Println("Generate Project is not yet supported on Windows")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
projectCmd := project.ProjectPath + "/" + project.ProjectName + ".uproject"
|
||||||
|
cmd := exec.Command(buildCmd, projectCmd, "-game")
|
||||||
|
|
||||||
|
logToOutput(cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runUnrealProject(project Project) {
|
||||||
|
var buildCmd string
|
||||||
|
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
buildCmd = project.EnginePath + "/Engine/Binaries/Linux/UnrealEditor"
|
||||||
|
case "darwin":
|
||||||
|
buildCmd = project.EnginePath + "/Engine/Binaries/Mac/UnrealEditor.app/Contents/MacOS/UnrealEditor"
|
||||||
|
default:
|
||||||
|
buildCmd = project.EnginePath + "/Engine/Binaries/Win64/UnrealEditor.exe"
|
||||||
|
}
|
||||||
|
|
||||||
|
projectCmd := project.ProjectPath + "/" + project.ProjectName + ".uproject"
|
||||||
|
cmd := exec.Command(buildCmd, projectCmd)
|
||||||
|
|
||||||
|
logToOutput(cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func logToOutput(cmd *exec.Cmd) {
|
||||||
|
stdout, err := cmd.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error during pipe stdout creation")
|
||||||
|
}
|
||||||
|
|
||||||
|
stderr, err := cmd.StderrPipe()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error during pipe stderr creation")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
fmt.Println("Error while loading command")
|
||||||
|
}
|
||||||
|
|
||||||
|
readPipe := func(reader io.ReadCloser) {
|
||||||
|
scanner := bufio.NewScanner(reader)
|
||||||
|
for scanner.Scan() {
|
||||||
|
logText.SetText(logText.Text + scanner.Text() + "\n")
|
||||||
|
scrollContainer.ScrollToTop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
go readPipe(stdout)
|
||||||
|
go readPipe(stderr)
|
||||||
|
|
||||||
|
if err := cmd.Wait(); err != nil {
|
||||||
|
fmt.Println("Error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
myApp := app.New()
|
myApp := app.New()
|
||||||
myWindow := myApp.NewWindow("Unreal Project Launcher")
|
myWindow := myApp.NewWindow("Unreal Project Launcher")
|
||||||
myWindow.Resize(fyne.NewSize(800, 600))
|
myWindow.Resize(fyne.NewSize(640, 400))
|
||||||
|
|
||||||
projects, err := loadProjects()
|
projects, err := loadProjects()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error while loading projects")
|
fmt.Println("Error while loading projects")
|
||||||
}
|
}
|
||||||
|
|
||||||
logText := widget.NewMultiLineEntry()
|
logText = widget.NewMultiLineEntry()
|
||||||
logText.SetMinRowsVisible(5)
|
logText.SetMinRowsVisible(5)
|
||||||
logText.Disable()
|
|
||||||
|
|
||||||
logMessage := func(msg string) {
|
|
||||||
logText.SetText(logText.Text + msg + "\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
var projectList *fyne.Container
|
|
||||||
|
|
||||||
reloadUI := func() {
|
reloadUI := func() {
|
||||||
projectList.RemoveAll()
|
projectList.RemoveAll()
|
||||||
|
|
||||||
for _, project := range projects {
|
for _, project := range projects {
|
||||||
projectName := filepath.Base(project.Path)
|
projectName := project.ProjectName
|
||||||
iconPath := projectName + ".png"
|
iconPath := project.ProjectPath + "/" + projectName + ".png"
|
||||||
var projectIcon fyne.Resource
|
var projectIcon fyne.Resource
|
||||||
|
|
||||||
if _, err := os.Stat(iconPath); err == nil {
|
if _, err := os.Stat(iconPath); err == nil {
|
||||||
@@ -77,26 +146,27 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
icon := canvas.NewImageFromResource(projectIcon)
|
icon := canvas.NewImageFromResource(projectIcon)
|
||||||
icon.SetMinSize(fyne.NewSize(32, 32))
|
icon.SetMinSize(fyne.NewSize(48, 48))
|
||||||
|
|
||||||
nameLabel := widget.NewLabel(projectName)
|
nameLabel := widget.NewLabel(projectName + " / Unreal Engine " + project.Version)
|
||||||
nameLabel.Alignment = fyne.TextAlignLeading
|
nameLabel.Alignment = fyne.TextAlignLeading
|
||||||
|
|
||||||
|
// Buttons
|
||||||
generateBtn := widget.NewButton("Generate", func() {
|
generateBtn := widget.NewButton("Generate", func() {
|
||||||
logMessage("Generate Project: " + projectName)
|
generateUnrealSolution(project)
|
||||||
})
|
})
|
||||||
generateBtn.Resize(fyne.NewSize(150, 40))
|
generateBtn.Resize(fyne.NewSize(150, 40))
|
||||||
generateBtn.Size().Min(fyne.NewSize(150, 40))
|
generateBtn.Size().Min(fyne.NewSize(150, 40))
|
||||||
|
|
||||||
launchBtn := widget.NewButton("Start", func() {
|
launchBtn := widget.NewButton("Start", func() {
|
||||||
logMessage("Start Project " + projectName)
|
runUnrealProject(project)
|
||||||
})
|
})
|
||||||
launchBtn.Size().Min(fyne.NewSize(150, 40))
|
launchBtn.Size().Min(fyne.NewSize(150, 40))
|
||||||
|
|
||||||
deleteBtn := widget.NewButton("X", func() {
|
deleteBtn := widget.NewButton("X", func() {
|
||||||
logMessage("Delete Project " + projectName)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Row
|
||||||
row := container.NewHBox(
|
row := container.NewHBox(
|
||||||
icon,
|
icon,
|
||||||
nameLabel,
|
nameLabel,
|
||||||
@@ -107,14 +177,13 @@ func main() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
projectList.Add(row)
|
projectList.Add(row)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
projectList = container.NewVBox()
|
projectList = container.NewVBox()
|
||||||
reloadUI()
|
reloadUI()
|
||||||
|
|
||||||
scrollContainer := container.NewVScroll(projectList)
|
scrollContainer = container.NewVScroll(projectList)
|
||||||
mainContainer := container.NewBorder(nil, logText, nil, nil, scrollContainer)
|
mainContainer := container.NewBorder(nil, logText, nil, nil, scrollContainer)
|
||||||
|
|
||||||
myWindow.SetContent(mainContainer)
|
myWindow.SetContent(mainContainer)
|
||||||
|
|||||||
@@ -1,82 +1,38 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"path": "/usr/local/bin/app1",
|
"enginePath": "/home/yann/Apps/UE_5.5/",
|
||||||
"version": 1.0
|
"projectPath": "/home/yann/Projects/unreal/NpcChatbot/",
|
||||||
|
"projectName": "NpcChatbot",
|
||||||
|
"engineVersion": "5.5"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "/opt/software/tool2",
|
"enginePath": "/home/yann/Apps/UE_5.5/",
|
||||||
"version": 2.5
|
"projectPath": "/home/yann/Projects/unreal/jsbsim/UnrealEngine/",
|
||||||
|
"projectName": "UEReferenceApp",
|
||||||
|
"engineVersion": "5.5"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "/home/user/games/game1",
|
"enginePath": "/home/yann/Apps/UE_5.5/",
|
||||||
"version": 3.2
|
"projectPath": "/run/media/yann/Devel/Unreal/AeroSyncUFS",
|
||||||
|
"projectName": "MiniFS",
|
||||||
|
"engineVersion": "5.5"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "/var/lib/serviceX",
|
"enginePath": "/home/yann/Apps/UE_5.5/",
|
||||||
"version": 4.8
|
"projectPath": "/run/media/yann/Devel/Unreal/CyberneticRequiem",
|
||||||
|
"projectName": "CyberneticRequiem",
|
||||||
|
"engineVersion": "5.5"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "/usr/bin/editor",
|
"enginePath": "/home/yann/Apps/UE_5.5/",
|
||||||
"version": 5.6
|
"projectPath": "/run/media/yann/Devel/Unreal/DVRSimulator",
|
||||||
|
"projectName": "DVRSimulator",
|
||||||
|
"engineVersion": "5.5"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "/usr/sbin/daemonY",
|
"enginePath": "/home/yann/Apps/UE_5.5/",
|
||||||
"version": 6.3
|
"projectPath": "/run/media/yann/Devel/Unreal/GunSpinningVR",
|
||||||
},
|
"projectName": "GSPVR",
|
||||||
{
|
"engineVersion": "5.5"
|
||||||
"path": "/home/user/tools/cli",
|
|
||||||
"version": 7.1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/etc/configurator",
|
|
||||||
"version": 8.9
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/home/admin/scripts/utility",
|
|
||||||
"version": 9.4
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/usr/local/share/app2",
|
|
||||||
"version": 10.2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/usr/local/bin/app1",
|
|
||||||
"version": 1.0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/opt/software/tool2",
|
|
||||||
"version": 2.5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/home/user/games/game1",
|
|
||||||
"version": 3.2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/var/lib/serviceX",
|
|
||||||
"version": 4.8
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/usr/bin/editor",
|
|
||||||
"version": 5.6
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/usr/sbin/daemonY",
|
|
||||||
"version": 6.3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/home/user/tools/cli",
|
|
||||||
"version": 7.1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/etc/configurator",
|
|
||||||
"version": 8.9
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/home/admin/scripts/utility",
|
|
||||||
"version": 9.4
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/usr/local/share/app2",
|
|
||||||
"version": 10.2
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user