Added new commands
This commit is contained in:
145
main.go
145
main.go
@@ -7,7 +7,9 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
@@ -29,6 +31,26 @@ const projectsFilePath = "projects.json"
|
|||||||
var projectList *fyne.Container
|
var projectList *fyne.Container
|
||||||
var logText *widget.Entry
|
var logText *widget.Entry
|
||||||
var scrollContainer *container.Scroll
|
var scrollContainer *container.Scroll
|
||||||
|
var logBuffer []string
|
||||||
|
var logMaxLines = 7
|
||||||
|
|
||||||
|
type hoverableButton struct {
|
||||||
|
widget.Button
|
||||||
|
onMouseIn func()
|
||||||
|
onMouseOut func()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *hoverableButton) MouseIn() {
|
||||||
|
if h.onMouseIn != nil {
|
||||||
|
h.onMouseIn()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *hoverableButton) MouseOut() {
|
||||||
|
if h.onMouseOut != nil {
|
||||||
|
h.onMouseOut()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func loadProjects() ([]Project, error) {
|
func loadProjects() ([]Project, error) {
|
||||||
file, err := os.ReadFile(projectsFilePath)
|
file, err := os.ReadFile(projectsFilePath)
|
||||||
@@ -45,6 +67,46 @@ func loadProjects() ([]Project, error) {
|
|||||||
return projects, nil
|
return projects, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeDir(path string) {
|
||||||
|
err := os.RemoveAll(path)
|
||||||
|
if err != nil {
|
||||||
|
log("Can't remove content at " + path)
|
||||||
|
} else {
|
||||||
|
log("Removed " + path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanUnrealProject(project Project) {
|
||||||
|
dirs := []string {
|
||||||
|
"Binaries",
|
||||||
|
"DerivedDataCache",
|
||||||
|
"Intermediate",
|
||||||
|
"Saved",
|
||||||
|
"Script",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, dir := range dirs {
|
||||||
|
fullPath := filepath.Join(project.ProjectPath, dir)
|
||||||
|
removeDir(fullPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginsPath := filepath.Join(project.ProjectPath, "Plugins")
|
||||||
|
entries, err := os.ReadDir(pluginsPath)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
if !entry.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginDir := filepath.Join(pluginsPath, entry.Name())
|
||||||
|
removeDir(filepath.Join(pluginDir, "Binaries"))
|
||||||
|
removeDir(filepath.Join(pluginDir, "Intermediate"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func generateUnrealSolution(project Project) {
|
func generateUnrealSolution(project Project) {
|
||||||
var buildCmd string
|
var buildCmd string
|
||||||
|
|
||||||
@@ -64,6 +126,17 @@ func generateUnrealSolution(project Project) {
|
|||||||
logToOutput(cmd)
|
logToOutput(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildUnrealSolution(project Project) {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
cmd := exec.Command("make", "-C", project.ProjectPath, project.ProjectName)
|
||||||
|
logToOutput(cmd)
|
||||||
|
default:
|
||||||
|
fmt.Println("Build Project is not yet supported on Windows")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func runUnrealProject(project Project) {
|
func runUnrealProject(project Project) {
|
||||||
var buildCmd string
|
var buildCmd string
|
||||||
|
|
||||||
@@ -100,8 +173,8 @@ func logToOutput(cmd *exec.Cmd) {
|
|||||||
readPipe := func(reader io.ReadCloser) {
|
readPipe := func(reader io.ReadCloser) {
|
||||||
scanner := bufio.NewScanner(reader)
|
scanner := bufio.NewScanner(reader)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
logText.SetText(logText.Text + scanner.Text() + "\n")
|
line := scanner.Text()
|
||||||
scrollContainer.ScrollToTop()
|
log(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,25 +186,18 @@ func logToOutput(cmd *exec.Cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func log(line string) {
|
||||||
myApp := app.New()
|
logBuffer = append(logBuffer, line)
|
||||||
myWindow := myApp.NewWindow("Unreal Project Launcher")
|
if len(logBuffer) > logMaxLines {
|
||||||
myWindow.Resize(fyne.NewSize(640, 400))
|
logBuffer = logBuffer[1:]
|
||||||
|
|
||||||
projects, err := loadProjects()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error while loading projects")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logText = widget.NewMultiLineEntry()
|
logText.SetText(strings.Join(logBuffer, "\n"))
|
||||||
logText.SetMinRowsVisible(5)
|
}
|
||||||
|
|
||||||
reloadUI := func() {
|
func newProjectRow(project Project) fyne.CanvasObject {
|
||||||
projectList.RemoveAll()
|
|
||||||
|
|
||||||
for _, project := range projects {
|
|
||||||
projectName := project.ProjectName
|
projectName := project.ProjectName
|
||||||
iconPath := project.ProjectPath + "/" + projectName + ".png"
|
iconPath := filepath.Join(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 {
|
||||||
@@ -140,7 +206,6 @@ func main() {
|
|||||||
projectIcon = icon
|
projectIcon = icon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if projectIcon == nil {
|
if projectIcon == nil {
|
||||||
projectIcon = theme.FileIcon()
|
projectIcon = theme.FileIcon()
|
||||||
}
|
}
|
||||||
@@ -151,31 +216,51 @@ func main() {
|
|||||||
nameLabel := widget.NewLabel(projectName + " / Unreal Engine " + project.Version)
|
nameLabel := widget.NewLabel(projectName + " / Unreal Engine " + project.Version)
|
||||||
nameLabel.Alignment = fyne.TextAlignLeading
|
nameLabel.Alignment = fyne.TextAlignLeading
|
||||||
|
|
||||||
// Buttons
|
// Crée les boutons masqués par défaut
|
||||||
|
clearButton := widget.NewButton("Clean", func() {
|
||||||
|
cleanUnrealProject(project)
|
||||||
|
})
|
||||||
generateBtn := widget.NewButton("Generate", func() {
|
generateBtn := widget.NewButton("Generate", func() {
|
||||||
generateUnrealSolution(project)
|
generateUnrealSolution(project)
|
||||||
})
|
})
|
||||||
generateBtn.Resize(fyne.NewSize(150, 40))
|
buildBtn := widget.NewButton("Build", func() {
|
||||||
generateBtn.Size().Min(fyne.NewSize(150, 40))
|
buildUnrealSolution(project)
|
||||||
|
})
|
||||||
launchBtn := widget.NewButton("Start", func() {
|
launchBtn := widget.NewButton("Run", func() {
|
||||||
runUnrealProject(project)
|
runUnrealProject(project)
|
||||||
})
|
})
|
||||||
launchBtn.Size().Min(fyne.NewSize(150, 40))
|
|
||||||
|
|
||||||
deleteBtn := widget.NewButton("X", func() {
|
buttons := container.NewHBox(clearButton, generateBtn, buildBtn, launchBtn)
|
||||||
})
|
|
||||||
|
|
||||||
// Row
|
// Conteneur principal
|
||||||
row := container.NewHBox(
|
row := container.NewHBox(
|
||||||
icon,
|
icon,
|
||||||
nameLabel,
|
nameLabel,
|
||||||
layout.NewSpacer(),
|
layout.NewSpacer(),
|
||||||
generateBtn,
|
buttons,
|
||||||
launchBtn,
|
|
||||||
deleteBtn,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return row
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
myApp := app.New()
|
||||||
|
myWindow := myApp.NewWindow("Unreal Project Launcher")
|
||||||
|
myWindow.Resize(fyne.NewSize(730, 460))
|
||||||
|
|
||||||
|
projects, err := loadProjects()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error while loading projects")
|
||||||
|
}
|
||||||
|
|
||||||
|
logText = widget.NewMultiLineEntry()
|
||||||
|
logText.SetMinRowsVisible(logMaxLines);
|
||||||
|
|
||||||
|
reloadUI := func() {
|
||||||
|
projectList.RemoveAll()
|
||||||
|
|
||||||
|
for _, project := range projects {
|
||||||
|
row := newProjectRow(project)
|
||||||
projectList.Add(row)
|
projectList.Add(row)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user