initial push with clean and rebuild commands
This commit is contained in:
50
engine/compile.go
Normal file
50
engine/compile.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"golang.org/x/sys/windows/registry"
|
||||
)
|
||||
|
||||
func findUnrealVersionPath(version string) (string, error) {
|
||||
//Attempting to build project files programattically
|
||||
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\EpicGames\Unreal Engine\`+version, registry.QUERY_VALUE)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer k.Close()
|
||||
s, _, err := k.GetStringValue("InstalledDirectory") //Pulling the (Default) value which has the path
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func buildProject(version string, projectABSPath string) error {
|
||||
unrealVersionPath, err := findUnrealVersionPath(version)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to find the path to Unreal Engine version %s, please build project files manually: %s ", version, err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
unrealVersionPath = unrealVersionPath + string(filepath.Separator) + "Engine" + string(filepath.Separator) + "Build" + string(filepath.Separator) + "BatchFiles" + string(filepath.Separator) + "Build.bat"
|
||||
checkPath(unrealVersionPath) // Verifying path, will exit if fail
|
||||
fmt.Println("Using Unreal Engine Path: ", unrealVersionPath)
|
||||
// Manually building up the commmand
|
||||
buildArgs := []string{"Development", "Win64", "-Project=" + projectABSPath, "-TargetType=Editor", "-Progress", "-NoEngineChanges", "-NoHotReloadFromIDE"}
|
||||
buildFilesCMD := exec.Command(unrealVersionPath, buildArgs...)
|
||||
// Making sure we write the output of the command to the command prompt
|
||||
out := io.Writer(os.Stdout)
|
||||
buildFilesCMD.Stdout = out
|
||||
// finally running the command
|
||||
err = buildFilesCMD.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
98
engine/engine.go
Normal file
98
engine/engine.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var version = "4.25" //Need to manually set the UEVersion, don't know how to guess this
|
||||
|
||||
// RebuildProject is the main function to clean up the project, generate files and build
|
||||
func RebuildProject(riderEnabled bool, doBuild bool) {
|
||||
_, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Println("Unable to get working dir, returned error: ", err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
projectFile, err := os.Stat("ForlornOutcast.uproject")
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
fmt.Println("unable to locate project file, are you in the right directory?")
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
} else {
|
||||
fmt.Println("Unknown error when trying to open ForlornOutcast.uproject... exiting")
|
||||
}
|
||||
}
|
||||
fmt.Println("Found project file... continuing ")
|
||||
projectABSPath, err := filepath.Abs("ForlornOutcast.uproject")
|
||||
if err != nil {
|
||||
fmt.Println("Unable to generate absolute file path to project file: ", err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
checkPath(projectABSPath) // Verifying path, will exit if fail
|
||||
fmt.Println("Using Project Absolute Path: ", projectABSPath)
|
||||
// Setting the folders to remove //remove.go
|
||||
folderRemove := []string{".vs", "Binaries", "Intermediate", "Saved"}
|
||||
fmt.Println("Removing Folders...")
|
||||
err = removeFolders(folderRemove)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
// Setting the files to remove //remove.go
|
||||
fileRemove := []string{"ForlornOutcast.sln"}
|
||||
fmt.Println("Removing Files...")
|
||||
err = removeFiles(fileRemove)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
// Editing the .uproject file //jsonEdit.go
|
||||
err = editProjectFile(projectFile, riderEnabled)
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading/modifying project file: %s", err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("Project file has been modified as requested")
|
||||
// Generating the vs files //generateFiles.go
|
||||
err = generateFiles(projectABSPath)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to generate project files, please generate project files manually: ", err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("Project Files should have been generated...")
|
||||
if !doBuild {
|
||||
fmt.Println("Finished, press <enter> to exit!")
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
// Building the project //compile.go
|
||||
err = buildProject(version, projectABSPath)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to build project, please build the project manually: ", err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("Finished, press <enter> to exit!")
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// checkPath is a generic function to just verify file exists
|
||||
func checkPath(path string) {
|
||||
_, err := os.Stat(path)
|
||||
if err != nil {
|
||||
fmt.Printf("Path for file %s does not appear to be correct, error: %s exiting...", path, err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
50
engine/generateFiles.go
Normal file
50
engine/generateFiles.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/windows/registry"
|
||||
)
|
||||
|
||||
func findUnrealPath() (string, error) {
|
||||
//Attempting to generate project files programattically
|
||||
k, err := registry.OpenKey(registry.CLASSES_ROOT, `Unreal.ProjectFile\DefaultIcon`, registry.QUERY_VALUE)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer k.Close()
|
||||
s, _, err := k.GetStringValue("") //Pulling the (Default) value which has the path
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
s = strings.Trim(s, "\"") //Trim the quotes from around the string
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func generateFiles(projectFileABSPath string) error {
|
||||
// find the path to versionswitcher which is not in a specific unreal version directory since it needs to switch between versions
|
||||
unrealExPath, err := findUnrealPath()
|
||||
if err != nil {
|
||||
fmt.Println("Unable to find the path to Unreal engine, please generate project files manually: ", err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
checkPath(unrealExPath) // Verifying path, will exit if fail
|
||||
fmt.Println("Using Unreal Engine Path: ", unrealExPath)
|
||||
generateArgs := []string{"/projectfiles", projectFileABSPath}
|
||||
generateFilesCMD := exec.Command(unrealExPath, generateArgs...)
|
||||
// var stdBuffer bytes.Buffer
|
||||
// mw := io.MultiWriter(os.Stdout, &stdBuffer)
|
||||
out := io.Writer(os.Stdout)
|
||||
generateFilesCMD.Stdout = out
|
||||
err = generateFilesCMD.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
64
engine/jsonEdit.go
Normal file
64
engine/jsonEdit.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
// This is the entire JSON File Struct so we can modify it as needed
|
||||
type unrealProjectJSON struct {
|
||||
FileVersion int `json:"FileVersion"`
|
||||
EngineAssociation string `json:"EngineAssociation"`
|
||||
Category string `json:"Category"`
|
||||
Description string `json:"Description"`
|
||||
Modules []struct {
|
||||
Name string `json:"Name"`
|
||||
Type string `json:"Type"`
|
||||
LoadingPhase string `json:"LoadingPhase"`
|
||||
AdditionalDependencies []string `json:"AdditionalDependencies,omitempty"`
|
||||
} `json:"Modules"`
|
||||
Plugins []struct {
|
||||
Name string `json:"Name"`
|
||||
Enabled bool `json:"Enabled"`
|
||||
MarketplaceURL string `json:"MarketplaceURL,omitempty"`
|
||||
SupportedTargetPlatforms []string `json:"SupportedTargetPlatforms,omitempty"`
|
||||
} `json:"Plugins"`
|
||||
}
|
||||
|
||||
func editProjectFile(projectFile os.FileInfo, enableRider bool) error {
|
||||
byteValue, err := ioutil.ReadFile(projectFile.Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var projectStruct unrealProjectJSON
|
||||
json.Unmarshal([]byte(byteValue), &projectStruct)
|
||||
|
||||
for i, plugin := range projectStruct.Plugins {
|
||||
if plugin.Name == "OculusVR" {
|
||||
projectStruct.Plugins[i].Enabled = false
|
||||
|
||||
}
|
||||
if plugin.Name == "SteamVR" {
|
||||
projectStruct.Plugins[i].Enabled = false
|
||||
|
||||
}
|
||||
if plugin.Name == "RiderLink" {
|
||||
if enableRider {
|
||||
projectStruct.Plugins[i].Enabled = true
|
||||
} else {
|
||||
projectStruct.Plugins[i].Enabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
file, err := json.MarshalIndent(projectStruct, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(projectFile.Name(), file, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
39
engine/remove.go
Normal file
39
engine/remove.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func removeFolders(folders []string) error {
|
||||
for _, folder := range folders {
|
||||
if err := os.RemoveAll(folder); err != nil {
|
||||
if os.IsNotExist(err) { //If it doesn't exist that is fine, we would delete it anyway
|
||||
continue
|
||||
} else {
|
||||
fmt.Printf("Error removing %s folder, error: %s exiting...", folder, err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
fmt.Println("Removed Folder: ", folder)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeFiles(files []string) error {
|
||||
for _, file := range files {
|
||||
if err := os.Remove(file); err != nil {
|
||||
if os.IsNotExist(err) { //If it doesn't exist that is fine, we would delete it anyway
|
||||
continue
|
||||
} else {
|
||||
fmt.Printf("Error removing %s file, error: %s exiting...", file, err)
|
||||
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
fmt.Println("Removed file: ", file)
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user