Added new commands
This commit is contained in:
145
main.go
145
main.go
@@ -7,7 +7,9 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
@@ -29,6 +31,26 @@ const projectsFilePath = "projects.json"
|
||||
var projectList *fyne.Container
|
||||
var logText *widget.Entry
|
||||
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) {
|
||||
file, err := os.ReadFile(projectsFilePath)
|
||||
@@ -45,6 +67,46 @@ func loadProjects() ([]Project, error) {
|
||||
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) {
|
||||
var buildCmd string
|
||||
|
||||
@@ -64,6 +126,17 @@ func generateUnrealSolution(project Project) {
|
||||
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) {
|
||||
var buildCmd string
|
||||
|
||||
@@ -100,8 +173,8 @@ func logToOutput(cmd *exec.Cmd) {
|
||||
readPipe := func(reader io.ReadCloser) {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
logText.SetText(logText.Text + scanner.Text() + "\n")
|
||||
scrollContainer.ScrollToTop()
|
||||
line := scanner.Text()
|
||||
log(line)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,25 +186,18 @@ func logToOutput(cmd *exec.Cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
myApp := app.New()
|
||||
myWindow := myApp.NewWindow("Unreal Project Launcher")
|
||||
myWindow.Resize(fyne.NewSize(640, 400))
|
||||
|
||||
projects, err := loadProjects()
|
||||
if err != nil {
|
||||
fmt.Println("Error while loading projects")
|
||||
func log(line string) {
|
||||
logBuffer = append(logBuffer, line)
|
||||
if len(logBuffer) > logMaxLines {
|
||||
logBuffer = logBuffer[1:]
|
||||
}
|
||||
|
||||
logText = widget.NewMultiLineEntry()
|
||||
logText.SetMinRowsVisible(5)
|
||||
logText.SetText(strings.Join(logBuffer, "\n"))
|
||||
}
|
||||
|
||||
reloadUI := func() {
|
||||
projectList.RemoveAll()
|
||||
|
||||
for _, project := range projects {
|
||||
func newProjectRow(project Project) fyne.CanvasObject {
|
||||
projectName := project.ProjectName
|
||||
iconPath := project.ProjectPath + "/" + projectName + ".png"
|
||||
iconPath := filepath.Join(project.ProjectPath, projectName+".png")
|
||||
var projectIcon fyne.Resource
|
||||
|
||||
if _, err := os.Stat(iconPath); err == nil {
|
||||
@@ -140,7 +206,6 @@ func main() {
|
||||
projectIcon = icon
|
||||
}
|
||||
}
|
||||
|
||||
if projectIcon == nil {
|
||||
projectIcon = theme.FileIcon()
|
||||
}
|
||||
@@ -151,31 +216,51 @@ func main() {
|
||||
nameLabel := widget.NewLabel(projectName + " / Unreal Engine " + project.Version)
|
||||
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() {
|
||||
generateUnrealSolution(project)
|
||||
})
|
||||
generateBtn.Resize(fyne.NewSize(150, 40))
|
||||
generateBtn.Size().Min(fyne.NewSize(150, 40))
|
||||
|
||||
launchBtn := widget.NewButton("Start", func() {
|
||||
buildBtn := widget.NewButton("Build", func() {
|
||||
buildUnrealSolution(project)
|
||||
})
|
||||
launchBtn := widget.NewButton("Run", func() {
|
||||
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(
|
||||
icon,
|
||||
nameLabel,
|
||||
layout.NewSpacer(),
|
||||
generateBtn,
|
||||
launchBtn,
|
||||
deleteBtn,
|
||||
buttons,
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user