Created
April 17, 2020 13:10
-
-
Save Spartan322/085d03a3f275aba605964ae86e7d16c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ModName = XmlPeek("./mod.config", "/Mod/@name"); | |
var target = Argument("target", "Build"); | |
var configuration = Argument("configuration", "Release"); | |
var HacknetDirectoryStr = Argument<string>("hacknet-dir", null); | |
var forceRunPatcherStr = Argument("forcePatch", "false"); | |
var forceRunPatcher = forceRunPatcherStr?.ToLower() == "true"; | |
if(forceRunPatcherStr == "") | |
forceRunPatcher = true; | |
if(HacknetDirectoryStr == null) | |
{ | |
if(IsRunningOnWindows()) { | |
if(HasEnvironmentVariable("ProgramFiles(x86)")) | |
HacknetDirectoryStr = EnvironmentVariable("ProgramFiles(x86)"); | |
else | |
HacknetDirectoryStr = EnvironmentVariable("ProgramFiles"); | |
HacknetDirectoryStr += "\\Steam\\steamapps\\common\\Hacknet"; | |
} else { | |
HacknetDirectoryStr = "/home"; | |
HacknetDirectoryStr += "/"+EnvironmentVariable("USER"); | |
HacknetDirectoryStr += "/.local/share/Steam/steamapps/common/Hacknet/"; | |
} | |
} | |
var HacknetDirectory = new DirectoryPath(HacknetDirectoryStr); | |
if(!DirectoryExists(HacknetDirectory) || !FileExists(HacknetDirectory.GetFilePath("Hacknet.exe"))) | |
{ | |
Error("Could not find valid Hacknet executable in '"+HacknetDirectory+"'"); | |
throw new Exception("Valid Hacknet.exe not found"); | |
} | |
public void CheckContainedOrCopy(DirectoryPath working, FilePath copyFrom) | |
{ | |
Information("Checking for file '"+copyFrom+"' in '"+working+"'"); | |
if(!FileExists(working.GetFilePath(copyFrom.GetFilename()))) | |
CopyFile(copyFrom, working.GetFilePath(copyFrom.GetFilename())); | |
} | |
public void CheckAndDeleteFile(FilePath path) | |
{ | |
Information("Deleting file '"+path+"'"); | |
if(FileExists(path)) | |
DeleteFile(path); | |
} | |
public void CheckAndDeleteDirectory(DirectoryPath path, DeleteDirectorySettings settings) | |
{ | |
Information("Deleting directory '"+path+"'"); | |
if(DirectoryExists(path)) | |
DeleteDirectory(path, settings); | |
} | |
public FilePath GetPathForFileExt(FilePath path, string[] exts) | |
{ | |
foreach(var e in exts) | |
{ | |
FilePath newPath = path.AppendExtension(e); | |
if(FileExists(newPath)) | |
return newPath; | |
} | |
throw new Exception("Could not find valid file extension for "+path); | |
} | |
Task("Clean") | |
.Does(() => { | |
CheckAndDeleteDirectory("./bin", new DeleteDirectorySettings { Recursive = true }); | |
CheckAndDeleteDirectory("./obj", new DeleteDirectorySettings { Recursive = true }); | |
CheckAndDeleteDirectory("./lib/mod", new DeleteDirectorySettings { Recursive = true }); | |
}); | |
Task("Prepare") | |
.Does(() => { | |
CheckContainedOrCopy("./lib", HacknetDirectory.GetFilePath("Pathfinder.dll")); | |
if(forceRunPatcher || !FileExists("./lib/HacknetPathfinder.exe")) { | |
Information("Executing PathfinderPatcher for linkage."); | |
StartProcess(IsRunningOnWindows() ? "call" : "mono", | |
new ProcessSettings{ | |
Arguments = HacknetDirectory.GetFilePath("PathfinderPatcher.exe").ToString() + " -exeDir \"" + HacknetDirectory + "\"", | |
WorkingDirectory = "./lib" | |
}); | |
} | |
CheckContainedOrCopy("./lib", HacknetDirectory.GetFilePath("FNA.dll")); | |
CheckContainedOrCopy("./lib", HacknetDirectory.GetFilePath("AlienFXManagedWrapper3.5.dll")); | |
CheckContainedOrCopy("./lib", HacknetDirectory.GetFilePath("Steamworks.NET.dll")); | |
}); | |
Task("Build") | |
.IsDependentOn("Prepare") | |
.Does(() => { | |
MSBuild("./"+ModName+".csproj", | |
new MSBuildSettings { | |
Configuration = configuration, | |
WorkingDirectory = "./lib" | |
}); | |
if(IsRunningOnUnix()) { | |
Information("Correcting permissions on Unix"); | |
StartProcess("chmod", new ProcessSettings { | |
Arguments = "+x "+ModName+".dll", | |
WorkingDirectory = "./bin/"+configuration | |
}); | |
} | |
}); | |
Task("Package") | |
.IsDependentOn("Build") | |
.Does(() => { | |
Information("Copying README.md and LICENSE to lib"); | |
CopyFile("./README.md", "./lib/README.md"); | |
CopyFile("./LICENSE", "./lib/LICENSE"); | |
CopyFile("./bin/"+configuration+"/"+ModName+".dll", "./lib/"+ModName+".dll"); | |
Information("Zipping releases/"+ModName+".Release.V_.zip"); | |
Zip("./lib", "./releases/"+ModName+".Release.V_.zip", new []{ | |
"./lib/"+ModName+".dll", | |
"./lib/README.md", | |
"./lib/LICENSE" | |
}); | |
Information("Deleting lib/README.md and lib/LICENSE"); | |
DeleteFile("./lib/README.md"); | |
DeleteFile("./lib/LICENSE"); | |
DeleteFile("./lib/"+ModName+".dll"); | |
}); | |
Task("RunHacknet") | |
.IsDependentOn("Build") | |
.Does(() => { | |
FilePath path = null; | |
if(IsRunningOnUnix()) { | |
path = GetPathForFileExt(HacknetDirectory.GetFilePath("HacknetPathfinder.bin"), new[] { "x86", "x86_64", "osx" }); | |
//if(path.GetExtension().Contains("x86")) | |
// StartProcess("declare", new ProcessSettings{ Arguments = "TERM=xterm", WorkingDirectory=HacknetDirectory }); | |
} | |
Information("Starting HacknetPathfinder."); | |
CreateDirectory("./lib/mod"); | |
CopyFile("./bin/"+configuration+"/"+ModName+".dll", "./lib/mod/"+ModName+".dll"); | |
StartProcess(path == null | |
? HacknetDirectory.GetFilePath("HacknetPathfinder.exe") | |
: path, | |
"-modDirectory=\""+MakeAbsolute(Directory("./lib/mod"))+"\""); | |
DeleteDirectory("./lib/mod", new DeleteDirectorySettings { Recursive = true }); | |
}); | |
Task("BuildDocs") | |
.Does(() => { | |
Information("Building documentation."); | |
StartProcess("doxygen"); | |
}); | |
RunTarget(target); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment