diff --git a/.gitignore b/.gitignore index 85842c9..41b2ef9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /target ./PATH + +.idea +.vs \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 4ea86c0..e6fdf97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,14 +9,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] -name = "atty" -version = "0.2.14" +name = "aes" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" dependencies = [ - "hermit-abi", - "libc", - "winapi", + "cfg-if", + "cipher", + "cpufeatures", + "opaque-debug", ] [[package]] @@ -31,12 +32,27 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "base64ct" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b645a089122eccb6111b4f81cbc1a49f5900ac4666bb93ac027feaecf15607bf" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "block-buffer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +dependencies = [ + "generic-array", +] + [[package]] name = "bumpalo" version = "3.9.1" @@ -81,6 +97,9 @@ name = "cc" version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" +dependencies = [ + "jobserver", +] [[package]] name = "cfg-if" @@ -88,28 +107,35 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cipher" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" +dependencies = [ + "generic-array", +] + [[package]] name = "clap" -version = "3.0.10" +version = "4.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375" +checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" dependencies = [ - "atty", "bitflags", "clap_derive", - "indexmap", - "lazy_static", - "os_str_bytes", + "clap_lex", + "is-terminal", + "once_cell", "strsim", "termcolor", - "textwrap", ] [[package]] name = "clap_derive" -version = "3.0.6" +version = "4.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "517358c28fcef6607bf6f76108e02afad7e82297d132a6b846dcc1fc3efcd153" +checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" dependencies = [ "heck", "proc-macro-error", @@ -118,6 +144,15 @@ dependencies = [ "syn", ] +[[package]] +name = "clap_lex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "console" version = "0.15.0" @@ -133,6 +168,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + [[package]] name = "core-foundation" version = "0.9.2" @@ -149,6 +190,15 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +[[package]] +name = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.3.2" @@ -158,6 +208,36 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-utils" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + [[package]] name = "dotenv" version = "0.15.0" @@ -166,11 +246,11 @@ checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" [[package]] name = "download_rs_reborned" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa23e9049cd76fb013d0b06a8e2614e5d3e0b01e0588f1497967051a7f5ad03f" +checksum = "e6c98caf241b56bcb90027afda4d6de851ada32be5cfedb62646971c3a11c884" dependencies = [ - "indicatif", + "indicatif 0.16.2", "reqwest", "tokio", ] @@ -190,6 +270,27 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "fastrand" version = "1.7.0" @@ -201,13 +302,11 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.22" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" +checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" dependencies = [ - "cfg-if", "crc32fast", - "libc", "miniz_oxide", ] @@ -290,6 +389,16 @@ dependencies = [ "slab", ] +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "h2" version = "0.3.11" @@ -330,6 +439,24 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "http" version = "0.2.6" @@ -434,6 +561,18 @@ dependencies = [ "regex", ] +[[package]] +name = "indicatif" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4295cbb7573c16d310e99e713cf9e75101eb190ab31fccd35f2d2691b4352b19" +dependencies = [ + "console", + "number_prefix", + "portable-atomic", + "unicode-width", +] + [[package]] name = "instant" version = "0.1.12" @@ -443,12 +582,34 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "io-lifetimes" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "ipnet" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" +[[package]] +name = "is-terminal" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" +dependencies = [ + "hermit-abi 0.2.6", + "io-lifetimes", + "rustix", + "windows-sys", +] + [[package]] name = "itoa" version = "0.4.8" @@ -461,6 +622,15 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" +[[package]] +name = "jobserver" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.56" @@ -477,7 +647,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" [[package]] -name = "jvman" +name = "jvmain" version = "0.2.0" dependencies = [ "clap", @@ -485,13 +655,13 @@ dependencies = [ "dotenv", "download_rs_reborned", "http", - "indicatif", + "indicatif 0.17.2", "json", "reqwest", "serde", + "serde_json", "tokio", "toml", - "winapi", "zip", ] @@ -503,9 +673,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.113" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eef78b64d87775463c549fbd80e19249ef436ea3bf1de2a1eb7e717ec7fab1e9" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "lock_api" @@ -545,12 +721,11 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "miniz_oxide" -version = "0.4.4" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" dependencies = [ "adler", - "autocfg", ] [[package]] @@ -608,7 +783,7 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", ] @@ -620,9 +795,15 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "once_cell" -version = "1.9.0" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" + +[[package]] +name = "opaque-debug" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" @@ -662,9 +843,6 @@ name = "os_str_bytes" version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" -dependencies = [ - "memchr", -] [[package]] name = "parking_lot" @@ -691,6 +869,29 @@ dependencies = [ "winapi", ] +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest", + "hmac", + "password-hash", + "sha2", +] + [[package]] name = "percent-encoding" version = "2.1.0" @@ -715,6 +916,12 @@ version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" +[[package]] +name = "portable-atomic" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26f6a7b87c2e435a3241addceeeff740ff8b7e76b74c13bf9acb17fa454ea00b" + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -741,11 +948,11 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.36" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -757,6 +964,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + [[package]] name = "redox_syscall" version = "0.2.10" @@ -826,6 +1039,20 @@ dependencies = [ "winreg", ] +[[package]] +name = "rustix" +version = "0.36.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.9" @@ -893,9 +1120,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.78" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d23c1ba4cf0efd44be32017709280b32d1cea5c3f1275c3b6d9e8bc54f758085" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" dependencies = [ "itoa 1.0.1", "ryu", @@ -914,6 +1141,28 @@ dependencies = [ "serde", ] +[[package]] +name = "sha1" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -951,6 +1200,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + [[package]] name = "syn" version = "1.0.86" @@ -996,40 +1251,30 @@ dependencies = [ ] [[package]] -name = "textwrap" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" - -[[package]] -name = "thiserror" -version = "1.0.30" +name = "time" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" dependencies = [ - "thiserror-impl", + "itoa 1.0.1", + "serde", + "time-core", + "time-macros", ] [[package]] -name = "thiserror-impl" -version = "1.0.30" +name = "time-core" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" [[package]] -name = "time" -version = "0.1.44" +name = "time-macros" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" dependencies = [ - "libc", - "wasi", - "winapi", + "time-core", ] [[package]] @@ -1142,12 +1387,24 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + [[package]] name = "unicode-bidi" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + [[package]] name = "unicode-normalization" version = "0.1.19" @@ -1203,12 +1460,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasm-bindgen" version = "0.2.79" @@ -1316,6 +1567,63 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "winreg" version = "0.7.0" @@ -1327,14 +1635,49 @@ dependencies = [ [[package]] name = "zip" -version = "0.5.13" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ab48844d61251bb3835145c521d88aa4031d7139e8485990f60ca911fa0815" +checksum = "537ce7411d25e54e8ae21a7ce0b15840e7bfcff15b51d697ec3266cc76bdf080" dependencies = [ + "aes", "byteorder", "bzip2", + "constant_time_eq", "crc32fast", + "crossbeam-utils", "flate2", - "thiserror", + "hmac", + "pbkdf2", + "sha1", "time", + "zstd", +] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.4+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0" +dependencies = [ + "cc", + "libc", ] diff --git a/Cargo.toml b/Cargo.toml index 62a9b10..fd28f20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,24 +1,28 @@ [package] edition = "2021" -name = "jvman" +name = "jvmain" version = "0.2.0" - +[[bin]] +name="jvmain" +[lib] +name="libjvs" +crate-type=["cdylib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = {version = "3.0.10", features = ["derive"]} -download_rs_reborned = {version = "0.2.0", features = ["sync_download"]} +clap = {version = "4.0.32", features = ["derive"]} +download_rs_reborned = {version = "0.2.2", features = ["async_download"]} http = "0.2.6" json = "0.12.4" reqwest = {version = "0.11", features = ["json"]} serde = {version = "1.0", features = ["derive"]} tokio = {version = "1", features = ["full"]} toml = "0.5" -zip = "0.5.13" +zip = "0.6.3" dotenv = "0.15.0" console = "0.15.0" -indicatif = "0.16.2" -winapi = {version="0.3.9", features = ["winuser"]} +indicatif = "0.17.2" +serde_json="1.0.91" # windows-sys = {version = "0.32.0", features = ["Win32_Foundation","Win32_Security", "Win32_System_Threading", "Win32_System_SystemServices"]} diff --git a/README.md b/README.md index 276fa91..71fbf05 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ + # JavaVersionManager JavaVersionMANager(JVMAN),一个基于 [Elipse Adoptium API](https://api.adoptium.net/) 使用 Rust 开发的轻量级 JDK 版本管理应用,支持 Windows 平台。 @@ -11,12 +18,14 @@ JavaVersionMANager(JVMAN),一个基于 [Elipse Adoptium API](https://api.adopt ```cmd jvman list remote // 获取可用的主版本号 -jvman get remote 11 // 下载 JDK 11 的最新构建版 +jvman install remote 11 // 下载 JDK 11 的最新构建版 ``` +**注意,由于tuna镜像站的 Elipse Adoptium JDK(Adopt OpenJDK)版本过于残缺,软件添加了nju镜像站和官方镜像作为备份,下载顺序为 tuna->nju->官方github源** + ### 加载本地jdk环境 -`get local {Path}` 可以从路径中获取已安装的JDK的版本信息`注:目前能够完美支持的只有Adopt OpenJDK系列`. 例如: +`install local {Path}` 可以从路径中获取已安装的JDK的版本信息`注:目前经过验证过的能够完美支持的只有Adopt OpenJDK系列`. 例如: ```cmd "C:/Program Files/Eclipse Foundation/jdk-16.0.2.7-hotspot" @@ -26,21 +35,22 @@ jvman get remote 11 // 下载 JDK 11 的最新构建版 ### 本地已安装的 JDK 版本的查看和使用 -`list local` 命令可以查看当前已安装版本的版本列表, 使用`enable -i {implementor} -v {version}` 命令可以全局启用特定版本的JDK。例如: +`list local` 命令可以查看当前已安装版本的版本列表, 使用 `enable -i {implementor} -v {version}` 命令可以启用在当前会话中生效的JDK,使用 `--global` 选项可以全局启用特定版本的JDK。例如: ```cmd jvman list local // 列出本机的所有已下载的JDK /* 将会呈现的输出类似于如下形式: All available JDKs: - "Eclipse Adoptium" jdk-11.0.14.1+1 - "Eclipse Foundation" 16.0.2+7 - "Eclipse Adoptium" jdk8u322-b06 + Eclipse Adoptium jdk-11.0.14.1+1 + Eclipse Foundation 16.0.2+7 + Eclipse Adoptium jdk8u322-b06 */ jvman enable -i "Eclipse Adoptium" -v jdk-11.0.14.1+1 // 启用版本为 jdk-11.0.14.1+1 的 JDK +jvman enable -g -i "Eclipse Adoptium" -v jdk-11.0.14.1+1 // 全局启用版本为 jdk-11.0.14.1+1 的 JDK ``` -**请注意**,由于当前版本尚未实现 UAC 提权~~(很可能以后也不会实现)~~,所以 `jvman enable` 命令会出现 `Enable FAILED, 客户端没有所需的特权。 (os error 1314)` 的错误报告,推荐搭配 [gsudo](https://github.com/gerardog/gsudo) 使用,安装后使用方法为 `sudo jvman enable {version}`. +**请注意**,由于当前版本尚未实现 UAC 提权(很可能以后也不会实现),所以 `jvman enable -g` 命令会出现 `Enable FAILED, 客户端没有所需的特权。 (os error 1314)` 的错误报告,推荐搭配 [gsudo](https://github.com/gerardog/gsudo) 使用,安装后使用方法为 `sudo jvman enable -i -v `. ## 自行构建 @@ -48,4 +58,4 @@ jvman enable -i "Eclipse Adoptium" -v jdk-11.0.14.1+1 // 启用版本为 jdk-11. cargo build --release ``` -将编译好的 `jvman.exe` 文件拖拽到单独的文件夹,新建 `versions.toml` 文件, `temp` 和 `java` 文件夹, 向 Path 中添加 jvman.exe 的文件路径和`{jvman.exe所在文件夹路径}/OpenJDK/bin` 两个项目,即可正常使用。 \ No newline at end of file +将编译好的 `jvmain.exe` 文件拖拽到单独的文件夹,将项目中的`jvman.ps1`和`jvman.cmd`文件复制到根目录下,新建 `versions.toml` 文件, `temp` 和 `java` 文件夹, 向 Path 中添加 jvman.exe 的文件路径和`{jvman.exe所在文件夹路径}/OpenJDK/bin` 两个项目,即可正常使用。 \ No newline at end of file diff --git a/jvman.cmd b/jvman.cmd new file mode 100644 index 0000000..36c13ef --- /dev/null +++ b/jvman.cmd @@ -0,0 +1,24 @@ +@ECHO OFF + +IF "%JVS_HOME%"=="" SET JVS_HOME=%~dp0 + +IF "%JVS_LEVEL%"=="DEBUG" ( + SET ExecutePath="%JVS_HOME%target\debug\jvmain.exe" + ) ELSE ( + SET ExecutePath="%JVS_HOME%jvmain.exe" + ) + +SET /A JVS_POSTSCRIPT=%RANDOM% * 32568 + %RANDOM% +SET JVS_POSTSCRIPT=%JVS_HOME%nvs_tmp_%JVS_POSTSCRIPT%.cmd +SET JVS_EXEC_SHELL=CMD + + %ExecutePath% %* + +IF NOT EXIST "%JVS_POSTSCRIPT%" GOTO :CLEANUP +CALL "%JVS_POSTSCRIPT%" +DEL "%JVS_POSTSCRIPT%" + +:CLEANUP +SET JVS_POSTSCRIPT= + +EXIT /B \ No newline at end of file diff --git a/jvman.ps1 b/jvman.ps1 new file mode 100644 index 0000000..c68da9b --- /dev/null +++ b/jvman.ps1 @@ -0,0 +1,41 @@ + +if ($env:JVS_LEVEL -eq "DEBUG") +{ + $executePath = $PSScriptRoot + "/target/debug/jvmain.exe" +} else { + $executePath = $PSScriptRoot + "/jvmain.exe" +} + + +$formatted_args = New-Object System.Collections.ArrayList + +for($i=0; $i -le $args.Count; $i++){ + if ($args[$i]){ + $__ = $formatted_args.Add("`"" + $args[$i] +"`"" ); + } +} + + +$env:JVS_EXEC_SHELL="pwsh" + + +$env:JVS_POSTSCRIPT = Join-Path $PSScriptRoot ("jvs_tmp_" + (Get-Random -SetSeed $PID) + ".ps1") + +$startInfo = New-Object System.Diagnostics.ProcessStartInfo "`"$executePath`"" +$startInfo.Arguments = ($formatted_args) +$startInfo.UseShellExecute = $false +$startInfo.RedirectStandardOutput = $true +$proc = [System.Diagnostics.Process]::Start($startInfo) +while (($b = $proc.StandardOutput.Read()) -ne -1) { + Write-Host -NoNewline ([char]$b) +} +$proc.WaitForExit +$exitCode = $proc.ExitCode + +if ($env:JVS_POSTSCRIPT -and (Test-Path $env:JVS_POSTSCRIPT)) { + . $env:JVS_POSTSCRIPT + Remove-Item -Force $env:JVS_POSTSCRIPT +} + +$env:JVS_POSTSCRIPT = $null +exit $exitCode \ No newline at end of file diff --git a/src/java_remote.rs b/src/java_remote.rs index 22ac3d9..370e7c9 100644 --- a/src/java_remote.rs +++ b/src/java_remote.rs @@ -1,99 +1,206 @@ /* * @Author: ZuoXichen * @Date: 2022-01-30 11:56:36 - * @LastEditTime: 2022-05-12 23:49:20 + * @LastEditTime: 2023-01-01 15:09:17 * @LastEditors: ZuoXichen - * @Description: + * @Description: */ use crate::java_ver; use download_rs::async_download::Download; -use json; use reqwest; use console::Style; +use serde::{ Deserialize, Serialize }; use crate::utils::ziputil; -pub async fn list_remote() -> json::JsonValue { - let url = String::from("https://api.adoptium.net/v3/info/available_releases?image_type=jdk&os=windows&page=0&release_type=ga&sort_order=ASC"); - println!("{}", url); +#[derive(Serialize, Deserialize)] +struct JsonPackage { + checksum: String, + checksum_link: Option, + download_count: i32, + link: String, + metadata_link: Option, + name: String, + signature_link: Option, + size: i32, +} + +#[derive(Serialize, Deserialize)] +struct JsonVersion { + build: i32, + major: i32, + minor: i32, + openjdk_version: String, + security: i32, + semver: String, +} + +#[derive(Serialize, Deserialize)] +struct JsonBinary { + architecture: String, + download_count: i32, + heap_size: String, + image_type: String, + jvm_impl: String, + os: String, + installer: Option, + package: JsonPackage, + project: String, + scm_ref: String, + updated_at: String, +} + +#[derive(Serialize, Deserialize)] +struct JsonInfo { + binary: JsonBinary, + release_link: String, + release_name: String, + vendor: String, + version: JsonVersion, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct JsonRelease { + pub available_lts_releases: Vec, + pub available_releases: Vec, + pub most_recent_feature_release: i32, + pub most_recent_feature_version: i32, + pub most_recent_lts: i32, + pub tip_version: i32, +} + +pub async fn list_remote() -> JsonRelease { + let url = String::from( + "https://api.adoptium.net/v3/info/available_releases?image_type=jdk&os=windows&page=0&release_type=ga&sort_order=ASC" + ); + // println!("{}", url); let request = reqwest::get(url).await.unwrap().text().await.unwrap(); - let result = json::parse(&request).unwrap(); + let result: JsonRelease = serde_json::from_str(&request).unwrap(); return result; } -pub async fn get_remote(version: &str) { - let url = format!( - "https://api.adoptium.net/v3/assets/latest/{}/hotspot?vendor=eclipse", - version - ); - let green = Style::new().green(); +pub async fn get_remote(version: i32) { + let url = + format!("https://api.adoptium.net/v3/assets/latest/{}/hotspot?vendor=eclipse", version); let red = Style::new().red(); //println!("{}", url); let request = reqwest::get(url).await.unwrap().text().await.unwrap(); - let result = json::parse(&request).unwrap(); - let mut i = 0; - let mut file_name: &str; - let mut arch = ""; - if std::env::consts::ARCH == "x86_64" { - arch = "x64"; - } else if std::env::consts::ARCH == "x86" { - arch = "x32"; + let result: Vec = serde_json::from_str(&request).unwrap(); + // let mut arch = ""; + // if std::env::consts::ARCH == "x86_64" { + // arch = "x64"; + // } else if std::env::consts::ARCH == "x86" { + // arch = "x32"; + // } + let arch = match std::env::consts::ARCH { + "x86_64" => "x64", + "x86" => "x32", + &_ => "unknown", + }; + if result.len() == 0 { + eprintln!("{} JDK not found!", red.apply_to("Error")); + return; } - while i < result.len() { + + for assets in result { // println!("{}",result[i]["binary"].pretty(4)); - if result[i]["binary"]["image_type"] == "jdk" - && result[i]["binary"].has_key("package") - && result[i]["binary"]["os"] == "windows" - && arch == result[i]["binary"]["architecture"] + if + assets.binary.image_type == "jdk" && + assets.binary.os == "windows" && + arch == assets.binary.architecture { - let file_name = result[i]["binary"]["package"]["name"].to_string(); - let version_name = result[i]["release_name"].to_string(); + let file_name = assets.binary.package.name; + let version_name = assets.release_name; let mut version_store = java_ver::read_version(); if !version_store.contains(&version_name, "Eclipse Adoptium") { // println!("{}", file_name); - let download_url = format!( + let download_url_tuna = format!( "https://mirrors.tuna.tsinghua.edu.cn/Adoptium/{}/jdk/{}/windows/{}", - version, arch, file_name + version, + arch, + file_name ); - // println!("{}", download_url); + let download_url_nju = format!( + "https://mirrors.tuna.tsinghua.edu.cn/Adoptium/{}/jdk/{}/windows/{}", + version, + arch, + file_name + ); let mut current_location = std::env::current_exe().unwrap(); current_location.pop(); current_location.push("temp/"); let save_location = current_location.to_str().unwrap(); // println!("{}", save_location); - let download = Download::new(&download_url, Some(save_location), None); - match download.download_async().await { - Ok(_) => { - println!("{}", green.apply_to("下载完成")); - let mut java_location = std::env::current_exe().unwrap(); - java_location.pop(); - java_location.push("java/"); - java_location.push(&version_name); - let java: java_ver::JavaNew = java_ver::JavaNew::new( - "Eclipse Adoptium", - &version_name, - "Hotspot", - "jdk", - java_location.to_str().unwrap(), - ); - let mut current_location = std::env::current_exe().unwrap(); - current_location.pop(); - current_location.push("java/"); - let file = String::from(save_location) + &file_name; - ziputil::extract(std::path::Path::new(&file), ¤t_location); - java_ver::version_record(java); - match std::fs::remove_file(std::path::Path::new(&file)) { - Ok(_) => println!("{}", green.apply_to("jdk install finish!")), - Err(e) => println!("{} temp file delete failed, {}", red.apply_to("Error"), e.to_string()) + let download_url_vec = vec![ + download_url_tuna, + download_url_nju, + assets.binary.package.link.to_owned() + ]; + + for download_url in download_url_vec { + match download_resources(&download_url, save_location).await { + Ok(_) => { + // println!("OK, {}",download_url); + record_java_data_to_file(&version_name); + unzip_and_transfer_java_files(&file_name); + break; + } + Err(e) => { + if download_url == assets.binary.package.link { + eprintln!( + "{} Download JDK Failed, {}", + red.apply_to("Error"), + e.to_string() + ); + } } } - Err(e) => println!("{} Download Failed, {}", red.apply_to("Error"), e.to_string()), - }; + } } else { - println!("{}JDK already exist!", red.apply_to("Error")); + eprintln!("{}JDK already exist!", red.apply_to("Error")); } } - i += 1; } } + +fn record_java_data_to_file(version_name: &str) { + let mut java_location = std::env::current_exe().unwrap(); + java_location.pop(); + java_location.push("java/"); + java_location.push(&version_name); + let java_location_str = java_location.to_str().unwrap(); + let java_location_str = java_location_str.replace("\\", "/"); + let java: java_ver::JavaNew = java_ver::JavaNew::new( + "Eclipse Adoptium", + &version_name, + "Hotspot", + "jdk", + &java_location_str + ); + java_ver::version_record(java); +} + +fn unzip_and_transfer_java_files(file_name: &str) { + let green = Style::new().green(); + let red = Style::new().red(); + let mut current_location = std::env::current_exe().unwrap(); + current_location.pop(); + current_location.push("temp/"); + let save_location = current_location.to_str().unwrap().to_owned(); + current_location.pop(); + current_location.push("java/"); + let ziped_file = save_location + &file_name; + ziputil::extract(std::path::Path::new(&ziped_file), ¤t_location); + match std::fs::remove_file(std::path::Path::new(&ziped_file)) { + Ok(_) => println!("{}", green.apply_to("JDK install finish!")), + Err(e) => println!("{} temp file delete failed, {}", red.apply_to("Error"), e.to_string()), + } +} +async fn download_resources( + url: &str, + save_location: &str +) -> Result<(), Box> { + let download = Download::new(url, Some(save_location), None); + return download.download_async().await; +} \ No newline at end of file diff --git a/src/java_ver.rs b/src/java_ver.rs index 64ea14a..2b8efae 100644 --- a/src/java_ver.rs +++ b/src/java_ver.rs @@ -1,16 +1,10 @@ -use std::error::Error; -use std::fs::File; -use crate::utils::{uac_utils, ziputil}; use console::Style; use serde::Deserialize; use serde::Serialize; -use std::io::Write; -use std::{fs, path, result}; -use std::path::Path; +use std::fs; use std::path::PathBuf; use toml; use crate::utils::release_utils::ReleaseParser; -use std::process::Command; #[derive(Serialize, Deserialize)] pub struct Java { @@ -30,12 +24,13 @@ pub struct JavaNew { } impl JavaNew { - pub fn new(implementor: &str, - full_version: &str, - jvm_variant: &str, - image_type: &str, - path: &str) -> JavaNew - { + pub fn new( + implementor: &str, + full_version: &str, + jvm_variant: &str, + image_type: &str, + path: &str + ) -> JavaNew { let implementor = implementor.to_string(); let full_version = full_version.to_string(); let jvm_variant = jvm_variant.to_string(); @@ -58,7 +53,7 @@ impl Java { full_version: String, jvm_variant: String, image_type: String, - path: String, + path: String ) -> Java { Java { full_version, @@ -81,20 +76,20 @@ pub struct StoreNew { impl StoreNew { pub fn new() -> StoreNew { - let mut vec: Vec = Vec::new(); + let vec: Vec = Vec::new(); return StoreNew { java_version: Some(vec) }; } pub fn add(&mut self, obj: JavaNew) { - let mut list = self.java_version.as_mut().unwrap(); + let list = self.java_version.as_mut().unwrap(); list.push(obj); } pub fn get_java_versions(&mut self) -> &mut Vec { - let mut list = self.java_version.as_mut().unwrap(); + let list = self.java_version.as_mut().unwrap(); return list; } pub fn get_full_version_list(&mut self) -> Vec { - let mut list = self.java_version.as_mut().unwrap(); + let list = self.java_version.as_mut().unwrap(); let mut version_list: Vec = Vec::new(); for element in list { version_list.push(element.full_version.to_string()); @@ -102,16 +97,25 @@ impl StoreNew { version_list } - pub fn contains(&mut self, version: &str, implementor: &str) -> bool { - let list = self.java_version.as_ref().unwrap(); + match self.java_version { + Some(_) => { + let list = self.java_version.as_ref().unwrap(); - for element in list { - if element.full_version == String::from(version) && element.implementor == String::from(implementor) { - return true; + for element in list { + if + element.full_version == String::from(version) && + element.implementor == String::from(implementor) + { + return true; + } + } + return false; + } + None => { + return false; } } - return false; } } @@ -119,7 +123,13 @@ pub fn old_to_new(store: Store) -> StoreNew { let mut new = StoreNew::new(); if let Some(list) = store.Java_Version { for element in list { - let java_new = JavaNew::new("Eclipse Adoptium", &element.full_version, &element.jvm_variant, &element.image_type, &element.path); + let java_new = JavaNew::new( + "Eclipse Adoptium", + &element.full_version, + &element.jvm_variant, + &element.image_type, + &element.path + ); new.add(java_new); } } else { @@ -128,15 +138,20 @@ pub fn old_to_new(store: Store) -> StoreNew { return new; } - pub fn read_version() -> StoreNew { let mut current_location = std::env::current_exe().unwrap(); current_location.pop(); current_location.push("versions.toml"); - let contents = std::fs::read_to_string(¤t_location).expect("Unable to load Version Files"); - let mut result: Store = toml::from_str(&contents).unwrap(); - if let Some(store) = result.Java_Version { - let javaverisions = old_to_new( toml::from_str(&contents).unwrap()); + let contents = std::fs + ::read_to_string(¤t_location) + .expect("Unable to load Version Files"); + if contents == "" { + let mut _store = StoreNew::new(); + return _store; + } + let result: Store = toml::from_str(&contents).unwrap(); + if let Some(_) = result.Java_Version { + let javaverisions = old_to_new(toml::from_str(&contents).unwrap()); let content_string = toml::to_string(&javaverisions).unwrap(); fs::write(¤t_location, content_string).unwrap(); return javaverisions; @@ -146,7 +161,6 @@ pub fn read_version() -> StoreNew { } } - pub fn version_record(java_config: JavaNew) { let mut version_file = std::env::current_exe().unwrap(); version_file.pop(); @@ -157,7 +171,7 @@ pub fn version_record(java_config: JavaNew) { fs::write(&version_file, config.as_bytes()).expect("Err"); } -pub fn enable_version(implementor: &str, version: &str) { +pub fn enable_jdk_global(implementor: &str, version: &str) { println!("enable global"); let store: StoreNew = read_version(); if let Some(lists) = store.java_version { @@ -178,11 +192,11 @@ pub fn enable_version(implementor: &str, version: &str) { match result { Ok(_) => { let green = Style::new().green(); - println!("{}, JDK VERSION:{}", green.apply_to("Enable SUCCESS"), version) + println!("{}, JDK VERSION:{}", green.apply_to("Enable SUCCESS"), version); } Err(e) => { let red = Style::new().red(); - println!("{}, {}", red.apply_to("Enable FAILED"), e.to_string()); + eprintln!("{}, {}", red.apply_to("Enable FAILED"), e.to_string()); } } } @@ -190,10 +204,10 @@ pub fn enable_version(implementor: &str, version: &str) { } } - -pub fn read_local(path: &str) { +pub fn install_local_jdk(path: &str) { let mut record = read_version(); - let mut release_parser = ReleaseParser::new(path); + let java_location_str = path.replace("\\", "/"); + let release_parser = ReleaseParser::new(&java_location_str); let java = release_parser.parse(); if !record.contains(&java.full_version, &java.implementor) { @@ -202,28 +216,49 @@ pub fn read_local(path: &str) { println!("{}", green.apply_to("jdk install finish!")) } else { let red = Style::new().red(); - println!("{}JDK already exist!", red.apply_to("Error")); + eprintln!("{} JDK already exist!", red.apply_to("Error")); } } -pub fn enable_temp(implementor: &str, version: &str) { +pub fn enable_local(implementor: &str, version: &str) { let store: StoreNew = read_version(); if let Some(lists) = store.java_version { for element in lists { if version == element.full_version && implementor == element.implementor { let mut path = PathBuf::new(); path.push(&element.path); - let str_path:String = path.to_str().unwrap().to_owned(); - str_path.replace("\\", "/"); - let result = std::process::Command::new("cmd").arg(format!("/K set path={str_path};%path%")).output(); - match result { - Ok(_) => { - let green = Style::new().green(); - println!("{}, JDK VERSION:{}", green.apply_to("Enable SUCCESS"), version) + + match std::env::var("JVS_EXEC_SHELL") { + Ok(shell) => { + match std::env::var("JVS_POSTSCRIPT") { + Ok(postscript_path) => { + if shell == "pwsh" { + let str_java_path: String = path.to_str().unwrap().to_owned().replace("\\", "/"); + let path_string = + format!("$env:PATH=\"{}/bin/;\"+$env:Path", str_java_path); + fs::write(&postscript_path, path_string.as_bytes()).unwrap(); + } else if shell == "CMD" { + let str_java_path: String = path.to_str().unwrap().to_owned().replace("/", "\\"); + let path_string = + format!("SET PATH={}\\bin;%PATH%", str_java_path); + fs::write(&postscript_path, path_string.as_bytes()).unwrap(); + } + } + Err(_) => { + let red = Style::new().red(); + eprintln!( + "{}, JVS_POSTSCRIPT environment variable not set.", + red.apply_to("Enable FAILED") + ); + } + } } - Err(e) => { + Err(_) => { let red = Style::new().red(); - println!("{}, {}", red.apply_to("Enable FAILED"), e.to_string()); + eprintln!( + "{}, You need execute jvs from shell", + red.apply_to("Enable FAILED") + ); } } } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..6e96452 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,15 @@ +/* + * @Author: ZuoXichen + * @Date: 2022-12-28 15:01:41 + * @LastEditTime: 2023-01-01 14:13:33 + * @LastEditors: ZuoXichen + * @Description: + */ +pub mod java_remote; +pub mod java_ver; +pub mod utils; + +#[no_mangle] +pub async extern "C" fn get_remote_java_version()->java_remote::JsonRelease{ + return java_remote::list_remote().await ; +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 9fdded3..24d6592 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,112 +1,212 @@ -use clap; +use clap::{ self, Parser, command, Subcommand, arg }; +use java_ver::install_local_jdk; use tokio; -use console::Style; use dotenv::dotenv; -use crate::java_ver::read_local; +use std::io::Write; pub mod java_remote; pub mod java_ver; pub mod utils; +#[derive(Parser)] +#[command( + name="jvman", + author = "BicPotato", + version = "0.3.0", + about = "Install and manage JDKs", + long_about = None +)] +struct Cli { + #[command(subcommand)] + command: Commands, +} + +#[derive(Subcommand)] +enum Commands { + List { + #[command(subcommand)] + list_jdk: ListJDK, + }, + Install { + #[command(subcommand)] + install: Install, + }, + Enable { + #[arg(short, long)] + implementor: String, + #[arg(short='v', long)] + jdk_version: String, + #[arg(short, long, default_value_t = false)] + global: bool, + }, +} + +#[derive(Subcommand)] +enum Install { + Remote { + #[arg(short = 'v', long)] + jdk_version: i32, + }, + Local { + #[arg(short, long)] + jdk_path: String, + }, +} + +#[derive(Subcommand)] +enum ListJDK { + Local, + Remote, +} + #[tokio::main] async fn main() { dotenv().ok(); - let matches = clap::App::new("java-version") - .about("Manage Java Developer Kit Versions") - .author("ZuoXichen") - .version("0.2.0") - .subcommand( - clap::App::new("list") - .about("List local available JDKs") - .short_flag('l') - .subcommand( - clap::App::new("remote").about("List available JDKs from remote server"), - ) - .subcommand(clap::App::new("local").about("List local jdk versions")), - ) - .subcommand( - clap::App::new("enable") - .about("enable one jdk version globally") - .args(&[clap::Arg::new("implementor").takes_value(true).short('i'), - clap::Arg::new("version").takes_value(true).short('v'), - // clap::Arg::new("global").short('g').long("global").takes_value(false).help("enable jdk globally").default_missing_value("true") - ]) - - .override_usage("jdkman.exe enable -i [IMPLEMENTOR] -v [JDK_VERSION]"), - ) - .subcommand( - clap::App::new("disable") - .about("disable jdk version globally") - .arg(clap::Arg::new("version").takes_value(true)), - ) - .subcommand( - clap::App::new("get").subcommand( - clap::App::new("remote").arg( - clap::Arg::new("version") - .takes_value(true) - .value_name("Version"), - )).subcommand( - clap::App::new("local").arg( - clap::Arg::new("path") - .takes_value(true) - .value_name("Path"), - ), - )) - .get_matches(); - - if let Some(f) = matches.subcommand_matches("list") { - if let Some(_) = f.subcommand_matches("remote") { - let result = java_remote::list_remote().await; - println!("{}", result.pretty(4)); - } else if let Some(_) = f.subcommand_matches("local") { - let mut version_list = java_ver::read_version(); - println!("All available JDKs:"); - let mut element = version_list.get_java_versions(); - for mut elem in element { - println!("\t\"{}\" {}", elem.get_implementor(), elem.get_full_version()) - } - } - } else if let Some(g) = matches.subcommand_matches("get") { - if let Some(r) = g.subcommand_matches("remote") { - if let Some(v) = r.value_of("version") { - let version = String::from(v); - let _: i32 = version.trim().parse().expect("Please enter a number"); - java_remote::get_remote(v).await; - } - } else if let Some(local) = g.subcommand_matches("local") { - if let Some(pos) = local.value_of("path") { - let postion = String::from(pos); - let postions = postion.replace("\"", ""); - read_local(&postions); + let cli = Cli::parse(); + match cli.command { + Commands::List { list_jdk } => { + match list_jdk { + ListJDK::Local => { + let mut version_list = java_ver::read_version(); + println!("All available JDKs:"); + let jdk_versions = version_list.get_java_versions(); + for jdk_version in jdk_versions { + println!( + "\t{} {}", + jdk_version.get_implementor(), + jdk_version.get_full_version() + ); + } + } + ListJDK::Remote => { + let java_release_result = java_remote::list_remote().await; + print!("available_lts_releases: "); + for version in java_release_result.available_lts_releases { + print!("{} ", version); + } + print!("\n"); + print!("available_releases: "); + for version in java_release_result.available_releases { + print!("{} ", version); + } + print!("\n"); + std::io::stdout().flush().unwrap(); + } } } - } else if let Some(e) = matches.subcommand_matches("enable") { - if let Some(implementor) = e.value_of("implementor") { - if let Some(version) = e.value_of("version") { - let implementors = String::from(implementor); - let imple = implementors.replace("\"", ""); - java_ver::enable_version(&imple, version); - // if let Some(_) = e.value_of("global"){ - // java_ver::enable_version(&imple, version); - // } else { - // java_ver::enable_temp(&imple, version); - // } + Commands::Install { install } => { + match install { + Install::Local { jdk_path } => { + let postions = jdk_path.replace("\"", ""); + install_local_jdk(&postions); + } + Install::Remote { jdk_version } => { + java_remote::get_remote(jdk_version).await; + } } } - } else if let Some(_) = matches.subcommand_matches("disable") { - let mut current_location = std::env::current_exe().unwrap(); - current_location.pop(); - current_location.push("OpenJDK/"); - let result = std::fs::remove_dir_all(¤t_location); - match result { - Ok(_) => { - let green = Style::new().green(); - println!("{}", green.apply_to("Disable JDK SUCCESS")) - } - Err(e) => { - let red = Style::new().red(); - println!("{} {}", red.apply_to("Disable JDK FAILED"), e.to_string()); + Commands::Enable { implementor, jdk_version, global } => { + if global { + java_ver::enable_jdk_global(&implementor, &jdk_version); + } else { + java_ver::enable_local(&implementor, &jdk_version); } } } -} + // let matches = Command::new("java-version") + // .about("Manage Java Developer Kit Versions") + // .author("ZuoXichen") + // .version("0.2.0") + // .subcommand( + // Command::new("list") + // .about("List local available JDKs") + // .short_flag('l') + // .subcommand( + // Command::new("remote").about("List available JDKs from remote server"), + // ) + // .subcommand(Command::new("local").about("List local jdk versions")), + // ) + // .subcommand( + // Command::new("enable") + // .about("enable one jdk version globally") + // .args(&[Arg::new("implementor").short('i'), + // Arg::new("version").short('v'), + // Arg::new("global").short('g').long("global").help("enable jdk globally").default_missing_value("true") + // ]) + + // .override_usage("jdkman.exe enable -i [IMPLEMENTOR] -v [JDK_VERSION]"), + // ) + // .subcommand( + // Command::new("disable") + // .about("disable jdk version globally") + // .arg(clap::Arg::new("version")), + // ) + // .subcommand( + // Command::new("get").subcommand( + // Command::new("remote").arg( + // clap::Arg::new("version") + // .value_name("Version"), + // )).subcommand( + // Command::new("local").arg( + // clap::Arg::new("path") + // .value_name("Path"), + // ), + // )) + // .get_matches(); + + // if let Some(f) = matches.subcommand_matches("list") { + // if let Some(_) = f.subcommand_matches("remote") { + // let result = java_remote::list_remote().await; + // println!("{:?}", result); + // } else if let Some(_) = f.subcommand_matches("local") { + // let mut version_list = java_ver::read_version(); + // println!("All available JDKs:"); + // let mut element = version_list.get_java_versions(); + // for mut elem in element { + // println!("\t\"{}\" {}", elem.get_implementor(), elem.get_full_version()) + // } + // } + // } else if let Some(g) = matches.subcommand_matches("get") { + // if let Some(r) = g.subcommand_matches("remote") { + // if let Some(v) = r.value_of("version") { + // let version = String::from(v); + // let _: i32 = version.trim().parse().expect("Please enter a number"); + // java_remote::get_remote(v).await; + // } + // } else if let Some(local) = g.subcommand_matches("local") { + // if let Some(pos) = local.value_of("path") { + // let postion = String::from(pos); + // let postions = postion.replace("\"", ""); + // read_local(&postions); + // } + // } + // } else if let Some(e) = matches.subcommand_matches("enable") { + // if let Some(implementor) = e.value_of("implementor") { + // if let Some(version) = e.value_of("version") { + // let implementors = String::from(implementor); + // let imple = implementors.replace("\"", ""); + // java_ver::enable_version(&imple, version); + // // if let Some(_) = e.value_of("global"){ + // // java_ver::enable_version(&imple, version); + // // } else { + // // java_ver::enable_temp(&imple, version); + // // } + // } + // } + // } else if let Some(_) = matches.subcommand_matches("disable") { + // let mut current_location = std::env::current_exe().unwrap(); + // current_location.pop(); + // current_location.push("OpenJDK/"); + // let result = std::fs::remove_dir_all(¤t_location); + // match result { + // Ok(_) => { + // let green = Style::new().green(); + // println!("{}", green.apply_to("Disable JDK SUCCESS")) + // } + // Err(e) => { + // let red = Style::new().red(); + // println!("{} {}", red.apply_to("Disable JDK FAILED"), e.to_string()); + // } + // } + // } +} \ No newline at end of file diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 19839e4..1958a9c 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,3 +1,9 @@ +/* + * @Author: ZuoXichen + * @Date: 2022-10-26 19:41:43 + * @LastEditTime: 2022-12-31 21:41:16 + * @LastEditors: ZuoXichen + * @Description: + */ pub mod ziputil; pub mod release_utils; -pub mod uac_utils; \ No newline at end of file diff --git a/src/utils/release_utils.rs b/src/utils/release_utils.rs index 61008fd..e187422 100644 --- a/src/utils/release_utils.rs +++ b/src/utils/release_utils.rs @@ -1,8 +1,14 @@ +/* + * @Author: ZuoXichen + * @Date: 2022-10-26 19:41:43 + * @LastEditTime: 2023-01-01 15:08:39 + * @LastEditors: ZuoXichen + * @Description: + */ use std::collections::HashMap; -use std::fs; use std::fs::File; use std::io::Read; -use std::path::{Path, PathBuf}; +use std::path:: PathBuf; use console::Style; use crate::java_ver::JavaNew; @@ -32,7 +38,7 @@ impl ReleaseParser { println!("{:?}", vec); if vec.len() > 1 { let a = vec[0]; - let mut b = vec[1]; + let b = vec[1]; let b1 = b.replace("\"", ""); let mut b2 = String::from(""); if b1.contains("\r") { diff --git a/src/utils/uac_utils.rs b/src/utils/uac_utils.rs deleted file mode 100644 index 98cf7b0..0000000 --- a/src/utils/uac_utils.rs +++ /dev/null @@ -1,77 +0,0 @@ -use std::ffi::CString; -use std::mem::size_of_val; -use std::ptr; -use std::ptr::null; -use winapi::shared::minwindef::{DWORD, PDWORD}; -use winapi::shared::ntdef::NULL; -use winapi::um::errhandlingapi::GetLastError; -use winapi::um::securitybaseapi::AdjustTokenPrivileges; -use winapi::um::winnt::{HANDLE, LPCSTR, LUID, LUID_AND_ATTRIBUTES, SE_CREATE_SYMBOLIC_LINK_NAME, SE_PRIVILEGE_ENABLED, TOKEN_ADJUST_PRIVILEGES, TOKEN_PRIVILEGES}; -use winapi::um::processthreadsapi::OpenProcessToken; -use winapi::um::processthreadsapi::GetCurrentProcess; -use winapi::um::winbase::LookupPrivilegeValueA; - - -#[cfg(windows)] -pub unsafe fn get_privilage() -> bool { - let mut hToken: HANDLE = NULL; - let mut token = &mut hToken; - let mut process_handle = OpenProcessToken( - GetCurrentProcess(), - TOKEN_ADJUST_PRIVILEGES, - token, - ); - println!("{}", process_handle); - let mut luid: LUID = Default::default(); - let mut luid_pointer = &mut luid; - let privilage = CString::new("SeCreateSymbolicLinkPrivilege").unwrap(); - let name_ptr: *const i8 = privilage.as_ptr() as *const i8; - let lookup = LookupPrivilegeValueA( - 0 as LPCSTR, - name_ptr, - luid_pointer, - ); - println!("{}", lookup); - println!("0x{:08X}", GetLastError()); - let mut structs = LUID_AND_ATTRIBUTES { - Luid: luid, - Attributes: SE_PRIVILEGE_ENABLED, - }; - - let mut tokenstate = TOKEN_PRIVILEGES { - PrivilegeCount: 1, - Privileges: [structs], - }; - let mut token_pre = TOKEN_PRIVILEGES { - PrivilegeCount: 1, - Privileges: [structs], - }; - let return_len = size_of_val(&token); - let mut return_length = DWORD::try_from(return_len).unwrap(); - let secure = AdjustTokenPrivileges( - hToken, - 0, - &mut tokenstate, - DWORD::try_from(size_of_val(&token_pre)).unwrap(), - &mut token_pre, - &mut return_length - ); - if secure != 0 { - return true - } else { - println!("0x{:08X}", GetLastError()); - return false} -} - -#[cfg(test)] -mod uac_test{ - use crate::utils::uac_utils; - #[test] - fn uac_tests () { - unsafe { - let boolean = uac_utils::get_privilage(); - - println!("{}", boolean); - } - } -} \ No newline at end of file diff --git a/src/utils/ziputil.rs b/src/utils/ziputil.rs index a62ffb5..1777d59 100644 --- a/src/utils/ziputil.rs +++ b/src/utils/ziputil.rs @@ -1,7 +1,7 @@ /* * @Author: ZuoXichen * @Date: 2022-02-11 18:02:31 - * @LastEditTime: 2022-05-12 23:43:47 + * @LastEditTime: 2023-01-01 15:10:50 * @LastEditors: ZuoXichen * @Description: */ @@ -11,7 +11,6 @@ use std::path::PathBuf; use indicatif::ProgressStyle; use zip; use indicatif::ProgressBar; -use console::Term; pub fn extract(files: &Path, current_location: &PathBuf) { println!("{}", files.to_str().unwrap()); @@ -22,7 +21,7 @@ pub fn extract(files: &Path, current_location: &PathBuf) { let prograss = ProgressBar::new(archive.len().try_into().unwrap()); prograss.set_style(ProgressStyle::default_bar() - .template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({eta})") + .template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{human_len} ({eta})").unwrap() .progress_chars("#>-")); for i in 0..archive.len() { let mut file = archive.by_index(i).unwrap(); diff --git a/test/parser_test.rs b/test/parser_test.rs deleted file mode 100644 index 1b7afc0..0000000 --- a/test/parser_test.rs +++ /dev/null @@ -1,11 +0,0 @@ -mod parser_test { - use jvman::utils::release_utils::ReleasePraser; - #[test] - fn parser_test(){ - let paths = "./"; - let parser = ReleasePraser::new(paths); - let dic = praser::prase(); - println!("{}", dic); - } - -} \ No newline at end of file diff --git a/tests/parser_test.rs b/tests/parser_test.rs new file mode 100644 index 0000000..f96e918 --- /dev/null +++ b/tests/parser_test.rs @@ -0,0 +1,25 @@ +/* + * @Author: ZuoXichen + * @Date: 2022-10-26 19:41:43 + * @LastEditTime: 2022-12-28 19:33:24 + * @LastEditors: ZuoXichen + * @Description: + */ +mod parser_test { + use utils::release_utils::ReleasePraser; + use java_remote; + #[test] + fn parser_test(){ + let paths = "./"; + let parser = ReleasePraser::new(paths); + let dic = praser::prase(); + println!("{}", dic); + } + #[test] + fn json_parser(){ + let json = std::fs::File::open("./releases.json"); + let result:Vec = serde_json::from_str(json).unwrap(); + } + + +} \ No newline at end of file diff --git a/test/release b/tests/release similarity index 100% rename from test/release rename to tests/release diff --git a/tests/releases.json b/tests/releases.json new file mode 100644 index 0000000..04b33e0 --- /dev/null +++ b/tests/releases.json @@ -0,0 +1,407 @@ + +[ + { + "binary": { + "architecture": "x64", + "download_count": 349007, + "heap_size": "normal", + "image_type": "jdk", + "jvm_impl": "hotspot", + "os": "linux", + "package": { + "checksum": "1633bd7590cb1cd72f5a1378ae8294451028b274d798e2a4ac672059a2f00fee", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u352b08.tar.gz.sha256.txt", + "download_count": 349007, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u352b08.tar.gz", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u352b08.tar.gz.json", + "name": "OpenJDK8U-jdk_x64_linux_hotspot_8u352b08.tar.gz", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u352b08.tar.gz.sig", + "size": 102942531 + }, + "project": "jdk", + "scm_ref": "jdk8u352-b08_adopt", + "updated_at": "2022-10-25T11:41:30Z" + }, + "release_link": "https://github.com/adoptium/temurin8-binaries/releases/tag/jdk8u352-b08", + "release_name": "jdk8u352-b08", + "vendor": "eclipse", + "version": { + "build": 8, + "major": 8, + "minor": 0, + "openjdk_version": "1.8.0_352-b08", + "security": 352, + "semver": "8.0.352+8" + } + }, + { + "binary": { + "architecture": "x64", + "download_count": 42334, + "heap_size": "normal", + "image_type": "jdk", + "installer": { + "checksum": "13fbfa68fb04ca9264ff8f24e5ed5521f39a2bee41398cafce9a76e39358d16e", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_mac_hotspot_8u352b08.pkg.sha256.txt", + "download_count": 29547, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_mac_hotspot_8u352b08.pkg", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_mac_hotspot_8u352b08.pkg.json", + "name": "OpenJDK8U-jdk_x64_mac_hotspot_8u352b08.pkg", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_mac_hotspot_8u352b08.pkg.sig", + "size": 108136084 + }, + "jvm_impl": "hotspot", + "os": "mac", + "package": { + "checksum": "f74d949aaaabd6116eaeccc34cc5ff707d3317b2cdbd3a8147920e1851d20cf2", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_mac_hotspot_8u352b08.tar.gz.sha256.txt", + "download_count": 12787, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_mac_hotspot_8u352b08.tar.gz", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_mac_hotspot_8u352b08.tar.gz.json", + "name": "OpenJDK8U-jdk_x64_mac_hotspot_8u352b08.tar.gz", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_mac_hotspot_8u352b08.tar.gz.sig", + "size": 107947323 + }, + "project": "jdk", + "scm_ref": "jdk8u352-b08_adopt", + "updated_at": "2022-11-03T10:52:01Z" + }, + "release_link": "https://github.com/adoptium/temurin8-binaries/releases/tag/jdk8u352-b08", + "release_name": "jdk8u352-b08", + "vendor": "eclipse", + "version": { + "build": 8, + "major": 8, + "minor": 0, + "openjdk_version": "1.8.0_352-b08", + "security": 352, + "semver": "8.0.352+8" + } + }, + { + "binary": { + "architecture": "x64", + "download_count": 292577, + "heap_size": "normal", + "image_type": "jdk", + "installer": { + "checksum": "c3f2ee62970bae81aa163e155faab8498638962a0a480aa01620d3122ad902ee", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_windows_hotspot_8u352b08.msi.sha256.txt", + "download_count": 215843, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_windows_hotspot_8u352b08.msi", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_windows_hotspot_8u352b08.msi.json", + "name": "OpenJDK8U-jdk_x64_windows_hotspot_8u352b08.msi", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_windows_hotspot_8u352b08.msi.sig", + "size": 89772032 + }, + "jvm_impl": "hotspot", + "os": "windows", + "package": { + "checksum": "debea8cf24b93b6c34ec06bd4d85f4bc3b710d596419acbce25928e88e2805d0", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_windows_hotspot_8u352b08.zip.sha256.txt", + "download_count": 76734, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_windows_hotspot_8u352b08.zip", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_windows_hotspot_8u352b08.zip.json", + "name": "OpenJDK8U-jdk_x64_windows_hotspot_8u352b08.zip", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_windows_hotspot_8u352b08.zip.sig", + "size": 104704978 + }, + "project": "jdk", + "scm_ref": "jdk8u352-b08_adopt", + "updated_at": "2022-11-04T12:37:21Z" + }, + "release_link": "https://github.com/adoptium/temurin8-binaries/releases/tag/jdk8u352-b08", + "release_name": "jdk8u352-b08", + "vendor": "eclipse", + "version": { + "build": 8, + "major": 8, + "minor": 0, + "openjdk_version": "1.8.0_352-b08", + "security": 352, + "semver": "8.0.352+8" + } + }, + { + "binary": { + "architecture": "aarch64", + "download_count": 3780, + "heap_size": "normal", + "image_type": "jdk", + "jvm_impl": "hotspot", + "os": "linux", + "package": { + "checksum": "a70768968bbcccccf977f036e87e545c3b080ed6c44072a01e9dadb94051c454", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_aarch64_linux_hotspot_8u352b08.tar.gz.sha256.txt", + "download_count": 3780, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_aarch64_linux_hotspot_8u352b08.tar.gz", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_aarch64_linux_hotspot_8u352b08.tar.gz.json", + "name": "OpenJDK8U-jdk_aarch64_linux_hotspot_8u352b08.tar.gz", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_aarch64_linux_hotspot_8u352b08.tar.gz.sig", + "size": 102045265 + }, + "project": "jdk", + "scm_ref": "jdk8u352-b08_adopt", + "updated_at": "2022-10-28T10:20:04Z" + }, + "release_link": "https://github.com/adoptium/temurin8-binaries/releases/tag/jdk8u352-b08", + "release_name": "jdk8u352-b08", + "vendor": "eclipse", + "version": { + "build": 8, + "major": 8, + "minor": 0, + "openjdk_version": "1.8.0_352-b08", + "security": 352, + "semver": "8.0.352+8" + } + }, + { + "binary": { + "architecture": "ppc64le", + "download_count": 548, + "heap_size": "normal", + "image_type": "jdk", + "jvm_impl": "hotspot", + "os": "linux", + "package": { + "checksum": "863791dd8e0536a678f5e439c9c67199a0f3f18c76138a8e242775dfe1784009", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_ppc64le_linux_hotspot_8u352b08.tar.gz.sha256.txt", + "download_count": 548, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_ppc64le_linux_hotspot_8u352b08.tar.gz", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_ppc64le_linux_hotspot_8u352b08.tar.gz.json", + "name": "OpenJDK8U-jdk_ppc64le_linux_hotspot_8u352b08.tar.gz", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_ppc64le_linux_hotspot_8u352b08.tar.gz.sig", + "size": 100508249 + }, + "project": "jdk", + "scm_ref": "jdk8u352-b08_adopt", + "updated_at": "2022-10-27T13:15:17Z" + }, + "release_link": "https://github.com/adoptium/temurin8-binaries/releases/tag/jdk8u352-b08", + "release_name": "jdk8u352-b08", + "vendor": "eclipse", + "version": { + "build": 8, + "major": 8, + "minor": 0, + "openjdk_version": "1.8.0_352-b08", + "security": 352, + "semver": "8.0.352+8" + } + }, + { + "binary": { + "architecture": "ppc64", + "download_count": 357, + "heap_size": "normal", + "image_type": "jdk", + "jvm_impl": "hotspot", + "os": "aix", + "package": { + "checksum": "f7a1b75ab4b3a7ae5dc17a08d648e80cc54be75f29704a947e37b30189cff956", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_ppc64_aix_hotspot_8u352b08.tar.gz.sha256.txt", + "download_count": 357, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_ppc64_aix_hotspot_8u352b08.tar.gz", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_ppc64_aix_hotspot_8u352b08.tar.gz.json", + "name": "OpenJDK8U-jdk_ppc64_aix_hotspot_8u352b08.tar.gz", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_ppc64_aix_hotspot_8u352b08.tar.gz.sig", + "size": 104769037 + }, + "project": "jdk", + "scm_ref": "jdk8u352-b08_adopt", + "updated_at": "2022-11-10T14:02:22Z" + }, + "release_link": "https://github.com/adoptium/temurin8-binaries/releases/tag/jdk8u352-b08", + "release_name": "jdk8u352-b08", + "vendor": "eclipse", + "version": { + "build": 8, + "major": 8, + "minor": 0, + "openjdk_version": "1.8.0_352-b08", + "security": 352, + "semver": "8.0.352+8" + } + }, + { + "binary": { + "architecture": "x32", + "download_count": 68340, + "heap_size": "normal", + "image_type": "jdk", + "installer": { + "checksum": "c4e7e38444bbf57572b15c7ff16ecf58ae4939e804d9a1902974ede615227b06", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x86-32_windows_hotspot_8u352b08.msi.sha256.txt", + "download_count": 44598, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x86-32_windows_hotspot_8u352b08.msi", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x86-32_windows_hotspot_8u352b08.msi.json", + "name": "OpenJDK8U-jdk_x86-32_windows_hotspot_8u352b08.msi", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x86-32_windows_hotspot_8u352b08.msi.sig", + "size": 90513408 + }, + "jvm_impl": "hotspot", + "os": "windows", + "package": { + "checksum": "abc535f91f763871e7ddee25acce31a871e47f25c722ca559d1f4e01e67c0fd0", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x86-32_windows_hotspot_8u352b08.zip.sha256.txt", + "download_count": 23742, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x86-32_windows_hotspot_8u352b08.zip", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x86-32_windows_hotspot_8u352b08.zip.json", + "name": "OpenJDK8U-jdk_x86-32_windows_hotspot_8u352b08.zip", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x86-32_windows_hotspot_8u352b08.zip.sig", + "size": 105516404 + }, + "project": "jdk", + "scm_ref": "jdk8u352-b08_adopt", + "updated_at": "2022-11-04T12:38:21Z" + }, + "release_link": "https://github.com/adoptium/temurin8-binaries/releases/tag/jdk8u352-b08", + "release_name": "jdk8u352-b08", + "vendor": "eclipse", + "version": { + "build": 8, + "major": 8, + "minor": 0, + "openjdk_version": "1.8.0_352-b08", + "security": 352, + "semver": "8.0.352+8" + } + }, + { + "binary": { + "architecture": "arm", + "download_count": 770, + "heap_size": "normal", + "image_type": "jdk", + "jvm_impl": "hotspot", + "os": "linux", + "package": { + "checksum": "c9126fe87ebec147af2f237424d9b77f7ea5a9844999e8c90d046fdb741bf463", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_arm_linux_hotspot_8u352b08.tar.gz.sha256.txt", + "download_count": 770, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_arm_linux_hotspot_8u352b08.tar.gz", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_arm_linux_hotspot_8u352b08.tar.gz.json", + "name": "OpenJDK8U-jdk_arm_linux_hotspot_8u352b08.tar.gz", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_arm_linux_hotspot_8u352b08.tar.gz.sig", + "size": 98283632 + }, + "project": "jdk", + "scm_ref": "jdk8u352-b08-aarch32-20221020_adopt", + "updated_at": "2022-11-03T16:41:10Z" + }, + "release_link": "https://github.com/adoptium/temurin8-binaries/releases/tag/jdk8u352-b08", + "release_name": "jdk8u352-b08", + "vendor": "eclipse", + "version": { + "build": 8, + "major": 8, + "minor": 0, + "openjdk_version": "1.8.0_352-b08", + "security": 352, + "semver": "8.0.352+8" + } + }, + { + "binary": { + "architecture": "sparcv9", + "download_count": 283, + "heap_size": "normal", + "image_type": "jdk", + "jvm_impl": "hotspot", + "os": "solaris", + "package": { + "checksum": "b9b25f5bed419c5ab36c7a68693192e5022ec366acc0147df1fd45b18248a94a", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_sparcv9_solaris_hotspot_8u352b08.tar.gz.sha256.txt", + "download_count": 283, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_sparcv9_solaris_hotspot_8u352b08.tar.gz", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_sparcv9_solaris_hotspot_8u352b08.tar.gz.json", + "name": "OpenJDK8U-jdk_sparcv9_solaris_hotspot_8u352b08.tar.gz", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_sparcv9_solaris_hotspot_8u352b08.tar.gz.sig", + "size": 115235031 + }, + "project": "jdk", + "scm_ref": "jdk8u352-b08_adopt", + "updated_at": "2022-11-15T12:22:21Z" + }, + "release_link": "https://github.com/adoptium/temurin8-binaries/releases/tag/jdk8u352-b08", + "release_name": "jdk8u352-b08", + "vendor": "eclipse", + "version": { + "build": 8, + "major": 8, + "minor": 0, + "openjdk_version": "1.8.0_352-b08", + "security": 352, + "semver": "8.0.352+8" + } + }, + { + "binary": { + "architecture": "x64", + "download_count": 344, + "heap_size": "normal", + "image_type": "jdk", + "jvm_impl": "hotspot", + "os": "solaris", + "package": { + "checksum": "d053c2d5b3c7d4fd0a20af96232c3e657682e3d9bce3e7aba9d06a7bfb540b38", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_solaris_hotspot_8u352b08.tar.gz.sha256.txt", + "download_count": 344, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_solaris_hotspot_8u352b08.tar.gz", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_solaris_hotspot_8u352b08.tar.gz.json", + "name": "OpenJDK8U-jdk_x64_solaris_hotspot_8u352b08.tar.gz", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_solaris_hotspot_8u352b08.tar.gz.sig", + "size": 112128126 + }, + "project": "jdk", + "scm_ref": "jdk8u352-b08_adopt", + "updated_at": "2022-11-04T10:31:31Z" + }, + "release_link": "https://github.com/adoptium/temurin8-binaries/releases/tag/jdk8u352-b08", + "release_name": "jdk8u352-b08", + "vendor": "eclipse", + "version": { + "build": 8, + "major": 8, + "minor": 0, + "openjdk_version": "1.8.0_352-b08", + "security": 352, + "semver": "8.0.352+8" + } + }, + { + "binary": { + "architecture": "x64", + "download_count": 35149, + "heap_size": "normal", + "image_type": "jdk", + "jvm_impl": "hotspot", + "os": "alpine-linux", + "package": { + "checksum": "aa782e3c561b041a5730cbe728c210e234db71fa7222bd8b661f9f4df7799375", + "checksum_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_alpine-linux_hotspot_8u352b08.tar.gz.sha256.txt", + "download_count": 35149, + "link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_alpine-linux_hotspot_8u352b08.tar.gz", + "metadata_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_alpine-linux_hotspot_8u352b08.tar.gz.json", + "name": "OpenJDK8U-jdk_x64_alpine-linux_hotspot_8u352b08.tar.gz", + "signature_link": "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u352-b08/OpenJDK8U-jdk_x64_alpine-linux_hotspot_8u352b08.tar.gz.sig", + "size": 100852175 + }, + "project": "jdk", + "scm_ref": "jdk8u352-b08_adopt", + "updated_at": "2022-11-02T10:27:02Z" + }, + "release_link": "https://github.com/adoptium/temurin8-binaries/releases/tag/jdk8u352-b08", + "release_name": "jdk8u352-b08", + "vendor": "eclipse", + "version": { + "build": 8, + "major": 8, + "minor": 0, + "openjdk_version": "1.8.0_352-b08", + "security": 352, + "semver": "8.0.352+8" + } + } +] \ No newline at end of file diff --git a/versions.toml b/versions.toml new file mode 100644 index 0000000..e69de29 diff --git a/x64.iss b/x64.iss new file mode 100644 index 0000000..6208e24 --- /dev/null +++ b/x64.iss @@ -0,0 +1,131 @@ +; Script generated by the Inno Setup Script Wizard. +; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! + +#define MyAppName "Java Version Manager" +#define MyAppVersion "0.3.0" +#define MyAppPublisher "Bic Potato" +#define MyAppURL "https://github.com/bic-potato/JavaVersionManager" +#define MyAppExeName "jvmain.exe" + +[Setup] +; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications. +; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) +AppId={{8D86B7FB-6F06-4B04-8C70-3F8F74F8FD14} +AppName={#MyAppName} +AppVersion={#MyAppVersion} +;AppVerName={#MyAppName} {#MyAppVersion} +AppPublisher={#MyAppPublisher} +AppPublisherURL={#MyAppURL} +AppSupportURL={#MyAppURL} +AppUpdatesURL={#MyAppURL} +DefaultDirName={localappdata}\{#MyAppName} +;DefaultGroupName={#MyAppName} +LicenseFile=C:\Users\m1333\Documents\Programming\JavaVersionManager\LICENSE +; Uncomment the following line to run in non administrative install mode (install for current user only.) +;PrivilegesRequired=lowest +OutputDir=C:\Users\m1333\Documents\Programming\JavaVersionManager\target\release +OutputBaseFilename=JavaVersionManager_v0.3.0_x64 +Compression=lzma +SolidCompression=yes +WizardStyle=modern +ChangesEnvironment=yes + +[Languages] +Name: "english"; MessagesFile: "compiler:Default.isl" +Name: "SimplifiedChinese"; MessagesFile: "compiler:\Languages\ChineseSimplified.isl" + +[Tasks] +Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked + +[Files] +Source: "C:\Users\m1333\Documents\Programming\JavaVersionManager\target\release\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion +Source: "C:\Users\m1333\Documents\Programming\JavaVersionManager\jvman.cmd"; DestDir: "{app}"; Flags: ignoreversion +Source: "C:\Users\m1333\Documents\Programming\JavaVersionManager\jvman.ps1"; DestDir: "{app}"; Flags: ignoreversion +Source: "C:\Users\m1333\Documents\Programming\JavaVersionManager\versions.toml"; DestDir: "{app}"; Flags: onlyifdoesntexist +; NOTE: Don't use "Flags: ignoreversion" on any shared system files + +[Icons] +Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" +Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon + +;[Run] +;Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent + + +[dirs] +Name:"{app}\java" +Name:"{app}\temp" + +[UninstallDelete] +Type: filesandordirs; Name: "{app}\java" +Type: filesandordirs; Name: "{app}\temp" + +[Registry] +Root: HKLM; Subkey:"SYSTEM\CurrentControlSet\Control\Session Manager\Environment";ValueType: expandsz; ValueName:"Path"; ValueData:"{app}/OpenJDK/bin;{app};{olddata}";Check: NeedsAddPath('{app}') + + +[Code] + +const + EnvironmentKey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'; +function NeedsAddPath(Param: string): boolean; +var + OrigPath: string; +begin + if not RegQueryStringValue(HKEY_LOCAL_MACHINE, + EnvironmentKey, + 'Path', OrigPath) + then begin + Result := True; + exit; + end; + { look for the path with leading and trailing semicolon } + { Pos() returns 0 if not found } + Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0; +end; +procedure RemovePath(Path: string); +var + Paths: string; + P: Integer; +begin + if not RegQueryStringValue(HKLM, EnvironmentKey, 'Path', Paths) then + begin + Log('PATH not found'); + end + else + begin + Log(Format('PATH is [%s]', [Paths])); + + P := Pos(';' + Uppercase(Path) + ';', ';' + Uppercase(Paths) + ';'); + if P = 0 then + begin + Log(Format('Path [%s] not found in PATH', [Path])); + end + else + begin + if P > 1 then P := P - 1; + Delete(Paths, P, Length(Path) + 1); + Log(Format('Path [%s] removed from PATH => [%s]', [Path, Paths])); + + if RegWriteStringValue(HKLM, EnvironmentKey, 'Path', Paths) then + begin + Log('PATH written'); + end + else + begin + Log('Error writing PATH'); + end; + end; + end; +end; + +procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); +begin + if CurUninstallStep = usUninstall then + begin + RemovePath(ExpandConstant('{app}')); + RemovePath(ExpandConstant('{app}/OpenJDK/bin')); + end; +end; + +