Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions Stardrop/Utilities/External/SMAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,57 @@ static class SMAPI

public static ProcessStartInfo GetPrepareProcess(bool hideConsole)
{
var arguments = String.Empty;
var smapiInfo = new FileInfo(Pathing.GetSmapiPath());

var fileName = smapiInfo.FullName;
var arguments = string.Empty;
var parsedModPath = string.Empty;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) is true)
{
fileName = "/usr/bin/env";
arguments = $"bash -c \"SMAPI_MODS_PATH='{Pathing.GetSelectedModsFolderPath()}' '{Pathing.GetSmapiPath().Replace("StardewModdingAPI.dll", "StardewValley")}'\"";
parsedModPath = $"'{Pathing.GetSelectedModsFolderPath()}'";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) is true)
{
arguments = $"bash -c \"'{Pathing.GetSmapiPath().Replace("StardewModdingAPI.dll", "StardewModdingAPI")}' --mods-path '{Pathing.GetSelectedModsFolderPath()}'\"";
fileName = "/usr/bin/open";
arguments = $"-a \"Terminal\" \"{Pathing.GetSmapiPath().Replace("StardewModdingAPI.dll", "StardewModdingAPI")}\" --args --mods-path \"{Pathing.GetSelectedModsFolderPath()}\"";

//Skip setting parsedModPath for macOS due to --mods-path usage
//parsedModPath = $"\"{Pathing.GetSelectedModsFolderPath()}\"";

/* Alternative route (using AppleScript) of activating Terminal + SMAPI
fileName = "/usr/bin/env";
arguments = $@"osascript -e ""tell application \""Terminal\""
set smapi_path to \""{Pathing.GetSmapiPath().Replace("StardewModdingAPI.dll", "StardewModdingAPI")}\""
set mods_path to \""{Pathing.GetSelectedModsFolderPath()}\""
activate
do script \""\"" & quoted form of the POSIX path of smapi_path & \"" --mods-path \"" & quoted form of the POSIX path of mods_path
end tell""";
*/
}
else
{
parsedModPath = Pathing.GetSelectedModsFolderPath();
}

Program.helper.Log($"Starting SMAPI with the following arguments: {arguments}");
var processInfo = new ProcessStartInfo
{
FileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? smapiInfo.FullName : "/usr/bin/env",
FileName = fileName,
Arguments = arguments,
WorkingDirectory = smapiInfo.DirectoryName,
RedirectStandardOutput = false,
RedirectStandardError = false,
CreateNoWindow = hideConsole,
UseShellExecute = false
};
processInfo.EnvironmentVariables["SMAPI_MODS_PATH"] = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) is false ? $"'{Pathing.GetSelectedModsFolderPath()}'" : Pathing.GetSelectedModsFolderPath();

// Set SMAPI_MODS_PATH EnvironmentVariable if required
if (string.IsNullOrEmpty(parsedModPath) is false)
{
processInfo.EnvironmentVariables["SMAPI_MODS_PATH"] = parsedModPath;
}

return processInfo;
}
Expand Down
Loading