-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
39 lines (35 loc) · 796 Bytes
/
main.cpp
File metadata and controls
39 lines (35 loc) · 796 Bytes
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
#include <iostream>
#include "jvs/jvs.hpp"
int main(int size, char* args[])
{
SetConsoleOutputCP(CP_UTF8);
if (size < 2)
{
std::cerr << "Usage: jvs <javaVersion>" << '\n';
return -1;
}
if (std::string(args[1]) == "install")
{
if (size != 3)
{
std::cerr << "Usage: jvs install <javaVersion>" << '\n';
return -1;
}
if (jvs::handleDownload(args[2]))
return 0;
return -1;
}
const std::filesystem::path& path = jvs::getPathForVersion(args[1]);
DWORD pid = jvs::getParentProcessId();
jvs::process proc(pid);
if
(
path.empty()
|| !proc
|| !jvs::addJavaPath(proc, path.string() + (path.has_filename() ? "/bin" : "bin"))
|| !jvs::setJavaHome(proc, path)
)
return -1;
std::cout << "[Success] Java version switched to " << args[1] << '\n';
return 0;
}