-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathRunConfiguration.kt
More file actions
168 lines (139 loc) · 7.24 KB
/
RunConfiguration.kt
File metadata and controls
168 lines (139 loc) · 7.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package RimworldDev.Rider.run
import com.intellij.execution.Executor
import com.intellij.execution.configuration.EnvironmentVariablesData
import com.intellij.execution.configurations.*
import com.intellij.execution.configurations.ConfigurationFactory
import com.intellij.execution.configurations.RunConfiguration
import com.intellij.execution.process.*
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import com.intellij.util.system.OS
import com.jetbrains.rider.debugger.IRiderDebuggable
import com.jetbrains.rider.plugins.unity.run.configurations.UnityAttachToPlayerFactory
import com.jetbrains.rider.plugins.unity.run.configurations.UnityPlayerDebugConfigurationOptions
import com.jetbrains.rider.run.configurations.AsyncRunConfiguration
import org.jetbrains.concurrency.Promise
import com.jetbrains.rider.plugins.unity.UnityBundle
import com.jetbrains.rider.plugins.unity.run.configurations.unityExe.UnityExeConfiguration
import com.jetbrains.rider.run.RiderRunBundle
import icons.UnityIcons
internal class UnityPlayerDebugConfigurationTypeInternal : ConfigurationTypeBase(
ID,
UnityBundle.message("configuration.type.name.attach.to.unity.player"),
UnityBundle.message("configuration.type.description.attach.to.unity.player.and.debug"),
UnityIcons.RunConfigurations.AttachToPlayer
), VirtualConfigurationType {
val attachToPlayerFactory = UnityAttachToPlayerFactory(this)
init {
addFactory(attachToPlayerFactory)
}
companion object {
const val ID = "UnityPlayer"
}
}
class RunConfiguration(project: Project, factory: ConfigurationFactory, name: String) :
RunConfigurationBase<ConfigurationOptions>(project, factory, name),
LocatableConfiguration,
RunProfileWithCompileBeforeLaunchOption,
RunConfigurationWithSuppressedDefaultDebugAction,
AsyncRunConfiguration,
IRiderDebuggable {
override fun isGeneratedName(): Boolean = false
override fun suggestedName(): String = "RimWorld"
override fun getOptions(): ConfigurationOptions {
return super.getOptions() as ConfigurationOptions
}
fun getScriptName(): String = options.getScriptName()
fun setScriptName(scriptName: String?) = options.setScriptName(scriptName ?: "")
fun getModListPath(): String = options.getModListPath()
fun setModListPath(modListPath: String?) = options.setModListPath(modListPath ?: "")
fun getSaveFilePath(): String = options.getSaveFilePath()
fun setSaveFilePath(saveFilePath: String?) = options.setSaveFilePath(saveFilePath ?: "")
fun getCommandLineOptions(): String = options.getCommandLineOptions()
fun setCommandLineOptions(scriptName: String?) = options.setCommandLineOptions(scriptName ?: "")
fun getEnvData(): Map<String, String> = options.getEnvironmentVariables()
fun setEnvData(data: MutableMap<String, String>) = options.setEnvironmentVariables(data)
override fun getState(executor: Executor, environment: ExecutionEnvironment): RunProfileState {
return getRimworldState(environment)
}
@Suppress("UsagesOfObsoleteApi")
@Deprecated("Please, override 'getRunProfileStateAsync' instead")
override fun getStateAsync(
executor: Executor,
environment: ExecutionEnvironment
): Promise<RunProfileState> {
@Suppress("DEPRECATION")
throw UnsupportedOperationException(
RiderRunBundle.message(
"obsolete.synchronous.api.is.used.message",
UnityExeConfiguration::getStateAsync.name
)
)
}
override suspend fun getRunProfileStateAsync(
executor: Executor,
environment: ExecutionEnvironment
): RunProfileState {
val attachToDebugFactory = UnityAttachToPlayerFactory(UnityPlayerDebugConfigurationTypeInternal())
val attachToDebug = attachToDebugFactory.createTemplateConfiguration(project)
attachToDebug.name = "Custom Player"
val attachToDebugOptions = UnityPlayerDebugConfigurationOptions()
attachToDebugOptions.playerId = "CustomPlayer(localhost:56000)"
attachToDebugOptions.projectName = "Custom"
attachToDebug.loadState(attachToDebugOptions)
return RunState(
getScriptName(),
getSaveFilePath(),
getModListPath(),
getRimworldState(environment),
UnityDebugRemoteConfiguration(),
environment,
"CustomPlayer"
);
}
override fun getConfigurationEditor(): SettingsEditor<out RunConfiguration> {
return RimworldDev.Rider.run.SettingsEditor(project)
}
// Previously this function accepted a `debugWithScript: Boolean` parameter that, when true,
// constructed a "/bin/sh run.sh <gamePath>" command and was used for the Linux/macOS debug path.
// That parameter was removed because RunState.execute() bypasses rimworldState.execute() entirely
// on macOS/Linux (it uses ProcessBuilder directly to avoid silent failures in the Rider sandbox's
// coroutine context). The CommandLineState returned here is now only ever executed on Windows.
// The old approach also had a space-in-path bug: it joined all arguments into one string and then
// split on ' ', which broke paths containing spaces (e.g. "Application Support" in the Steam path).
private fun getRimworldState(environment: ExecutionEnvironment): CommandLineState {
return object : CommandLineState(environment) {
override fun startProcess(): ProcessHandler {
val scriptName = getScriptName()
// Split extra CLI options by space — these are game flags, not paths, so this is safe
val extraArgs = getCommandLineOptions().split(' ').filter { it.isNotEmpty() }
val commandLine = when {
OS.CURRENT == OS.macOS -> {
// .app bundles are directories and cannot be exec'd directly; use 'open' to launch them.
val params = if (extraArgs.isEmpty()) listOf(scriptName)
else listOf(scriptName, "--args") + extraArgs
GeneralCommandLine("open").withParameters(params)
}
else -> GeneralCommandLine(scriptName).withParameters(extraArgs)
}
EnvironmentVariablesData.create(getEnvData(), true).configureCommandLine(commandLine, true)
QuickStartUtils.setup(getModListPath(), getSaveFilePath());
val processHandler = ProcessHandlerFactory.getInstance()
.createColoredProcessHandler(commandLine)
processHandler.addProcessListener(createProcessListener(processHandler))
ProcessTerminatedListener.attach(processHandler)
return processHandler
}
}
}
private fun createProcessListener(siblingProcessHandler: ProcessHandler?): ProcessListener {
return object : ProcessAdapter() {
override fun processTerminated(event: ProcessEvent) {
val processHandler = event.processHandler
processHandler.removeProcessListener(this)
QuickStartUtils.tearDown(getSaveFilePath());
}
}
}
}