71 const std::filesystem::path& root,
72 const std::filesystem::path& solution,
73 const std::filesystem::path& source)
75 const auto name = executable.filename().wstring();
76 const auto file = std::filesystem::absolute(source).wstring();
77 if (_wcsicmp(name.c_str(), L
"devenv.exe") == 0)
79 if (_wcsicmp(name.c_str(), L
"Code.exe") == 0 ||
80 _wcsicmp(name.c_str(), L
"Code - Insiders.exe") == 0)
81 return L
"--reuse-window \"" +
82 (root / (solution.stem().
string() +
".code-workspace")).wstring() + L
"\" --goto \"" +
84 return L
"\"" + root.wstring() + L
"\" \"" + file + L
"\"";
138 const auto now = std::chrono::steady_clock::now();
145 Status =
"Opened file in project solution";
150 Status =
"Solution opened; Visual Studio did not become ready to open the selected file";
159 if (result.ExitCode == 0)
168 Detection.wait_for(std::chrono::seconds(0)) != std::future_status::ready)
172 std::istringstream lines(result.Output);
174 while (std::getline(lines, line))
176 if (!line.empty() && line.back() ==
'\r')
178 const auto executable = std::filesystem::path(line) /
"Common7/IDE/devenv.exe";
179 if (std::filesystem::is_regular_file(executable))
182 for (
const auto* variable : {
"LOCALAPPDATA",
"ProgramFiles",
"ProgramFiles(x86)"})
183 if (
const auto* base = std::getenv(variable))
184 for (
const auto& relative :
185 {
"Programs/Microsoft VS Code/Code.exe",
"Microsoft VS Code/Code.exe",
186 "Programs/Microsoft VS Code Insiders/Code - Insiders.exe",
187 "Microsoft VS Code Insiders/Code - Insiders.exe"})
189 const auto executable = std::filesystem::path(base) / relative;
190 if (std::filesystem::is_regular_file(executable) &&
201 :
"No editors detected; select an executable manually";
204 bool OpenScript(
const std::filesystem::path& source,
bool allowGeneration =
true)
206 if (!std::filesystem::is_regular_file(source))
210 Status =
"Select a script editor under Project Settings > External Tools";
213 const std::filesystem::path executable(
Executable);
215 bool included =
false;
216 std::ifstream manifest(
ProjectRoot /
".Finality/NativeScripts/IDEFiles.txt");
217 const auto sourceKey = std::filesystem::absolute(source).lexically_normal().generic_string();
219 while (std::getline(manifest, line))
221 if (!line.empty() && line.back() ==
'\r')
223 std::error_code error;
224 if (_stricmp(line.c_str(), sourceKey.c_str()) == 0 ||
225 std::filesystem::equivalent(std::filesystem::path(line), source, error))
231 if (!std::filesystem::is_regular_file(solution) &&
234 if (!included || !std::filesystem::is_regular_file(solution) ||
236 ".Finality/NativeScripts/GameScripts.vcxproj") ||
239 if (!allowGeneration)
241 Status =
"The selected file could not be added to the project solution";
248 while (!engine.empty() &&
249 !std::filesystem::is_regular_file(engine /
"Scripts/Templates/ProjectScripts.lua"))
251 const auto parent = engine.parent_path();
252 if (parent == engine)
261 Status =
"Native script tools were not found";
270 std::async(std::launch::async, [engine, root, bin, scripts, projectName] {
272 const std::wstring configuration = L
"Release";
274 const std::wstring configuration = L
"Debug";
276 return Process::Run({(bin /
"FIBuild.exe").wstring(), L
"native",
280 std::filesystem::path(projectName).wstring(),
286 std::filesystem::path(scripts).wstring(),
292 Status =
"Generating engine-linked solution";
295 if (_wcsicmp(executable.filename().c_str(), L
"devenv.exe") == 0 &&
298 Status =
"Opened script in project solution";
301 if (_wcsicmp(executable.filename().c_str(), L
"devenv.exe") == 0 &&
308 const auto result =
reinterpret_cast<INT_PTR
>(ShellExecuteW(
309 nullptr, L
"open", executable.c_str(), arguments.c_str(),
ProjectRoot.c_str(), SW_SHOWNORMAL));
310 Status = result > 32 ?
"Opened script in external editor"
311 :
"Could not launch the selected external editor";
314 else if (_wcsicmp(executable.filename().c_str(), L
"devenv.exe") == 0)
319 VisualStudioRetry = std::chrono::steady_clock::now() + std::chrono::milliseconds(500);
320 Status =
"Opening project solution in Visual Studio";