mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[processstarter] Handle Elastic and AdvantageScope (#8068)
Since they are in different directories, they need to be special cased This is needed to support wpilibsuite/WPILibInstaller-Avalonia#492, since those are currently handled by special scripts.
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include "Windows.h"
|
||||
#include "main.h"
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
LPTSTR pCmdLine, int nCmdShow) {
|
||||
@@ -29,6 +27,24 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ExePath.stem() == (L"AdvantageScope")) {
|
||||
std::filesystem::path AdvantageScopePath{
|
||||
ExePath.parent_path().parent_path() / L"advantagescope" /
|
||||
L"AdvantageScope (WPILib).exe"};
|
||||
return StartExeTool(AdvantageScopePath);
|
||||
} else if (ExePath.stem() == (L"Elastic")) {
|
||||
std::filesystem::path ElasticPath{ExePath.parent_path().parent_path() /
|
||||
L"elastic" / L"elastic_dashboard.exe"};
|
||||
return StartExeTool(ElasticPath);
|
||||
} else {
|
||||
return StartJavaTool(ExePath);
|
||||
}
|
||||
}
|
||||
|
||||
int StartJavaTool(std::filesystem::path& ExePath) {
|
||||
WCHAR ExePathRaw[1024];
|
||||
DWORD Status;
|
||||
|
||||
std::filesystem::path JarPath{ExePath};
|
||||
JarPath.replace_extension(L"jar");
|
||||
std::filesystem::path ParentPath{ExePath.parent_path()};
|
||||
@@ -83,3 +99,25 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
|
||||
return Status == WAIT_TIMEOUT ? 0 : 1;
|
||||
}
|
||||
|
||||
int StartExeTool(std::filesystem::path& ExePath) {
|
||||
STARTUPINFOW StartupInfo;
|
||||
PROCESS_INFORMATION ProcessInfo;
|
||||
DWORD Status;
|
||||
|
||||
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
|
||||
StartupInfo.cb = sizeof(StartupInfo);
|
||||
ZeroMemory(&ProcessInfo, sizeof(ProcessInfo));
|
||||
|
||||
if (!CreateProcessW(ExePath.c_str(), NULL, NULL, NULL, FALSE, 0, NULL, NULL,
|
||||
&StartupInfo, &ProcessInfo)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Status =
|
||||
WaitForSingleObject(ProcessInfo.hProcess, 5000); // Wait for 5 seconds
|
||||
CloseHandle(ProcessInfo.hProcess);
|
||||
CloseHandle(ProcessInfo.hThread);
|
||||
|
||||
return Status == WAIT_TIMEOUT ? 0 : 1;
|
||||
}
|
||||
|
||||
15
processstarter/src/main/native/windows/main.h
Normal file
15
processstarter/src/main/native/windows/main.h
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
int StartExeTool(std::filesystem::path& ExePath);
|
||||
int StartJavaTool(std::filesystem::path& ExePath);
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
LPTSTR pCmdLine, int nCmdShow);
|
||||
Reference in New Issue
Block a user