diff --git a/.gitignore b/.gitignore index ed73d50..7d2ba7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /target -/core -/plugins/ -minecraft_addon_controller.exe -config.lock \ No newline at end of file +Cargo.lock +lock.toml +/.vscode \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 883cfbc..52c457d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,33 +17,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.8.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b79b82693f705137f8fb9b37871d99e4f9a7df12b917eed79c3d3954830a60b" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "allocator-api2" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" - [[package]] name = "async-trait" version = "0.1.80" @@ -55,20 +28,6 @@ dependencies = [ "syn", ] -[[package]] -name = "async-watcher" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cb0d902fdf0ed6b7b4c199a4cd1fedfb095004a47aeb0fc7580372b373e1fb" -dependencies = [ - "async-trait", - "notify 5.2.0", - "serde", - "thiserror", - "tokio", - "tracing", -] - [[package]] name = "autocfg" version = "1.2.0" @@ -92,9 +51,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.7" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" [[package]] name = "bitflags" @@ -119,9 +78,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.15.4" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytes" @@ -131,9 +90,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.90" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" [[package]] name = "cfg-if" @@ -166,21 +125,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" - [[package]] name = "crypto-common" version = "0.1.6" @@ -203,26 +147,13 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.33" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" dependencies = [ "cfg-if", ] -[[package]] -name = "env_logger" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -241,21 +172,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" - -[[package]] -name = "filetime" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "windows-sys 0.52.0", -] +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "fnv" @@ -287,15 +206,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fsevent-sys" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" -dependencies = [ - "libc", -] - [[package]] name = "futures-channel" version = "0.3.30" @@ -311,23 +221,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "futures-sink" version = "0.3.30" @@ -347,11 +240,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", - "futures-macro", "futures-task", "pin-project-lite", "pin-utils", - "slab", ] [[package]] @@ -372,9 +263,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "h2" -version = "0.3.26" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +checksum = "816ec7294445779408f36fe57bc5b7fc1cf59664059096c65f905c1c61f58069" dependencies = [ "bytes", "fnv", @@ -394,10 +285,6 @@ name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -dependencies = [ - "ahash", - "allocator-api2", -] [[package]] name = "hermit-abi" @@ -407,9 +294,9 @@ checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "http" -version = "0.2.12" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ "bytes", "fnv", @@ -418,12 +305,24 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.6" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" dependencies = [ "bytes", + "futures-core", "http", + "http-body", "pin-project-lite", ] @@ -433,53 +332,60 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" -[[package]] -name = "httpdate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" - -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" -version = "0.14.28" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" dependencies = [ "bytes", "futures-channel", - "futures-core", "futures-util", "h2", "http", "http-body", "httparse", - "httpdate", "itoa", "pin-project-lite", - "socket2", + "smallvec", "tokio", - "tower-service", - "tracing", "want", ] [[package]] name = "hyper-tls" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", + "http-body-util", "hyper", + "hyper-util", "native-tls", "tokio", "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] @@ -502,43 +408,12 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "inotify" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" -dependencies = [ - "bitflags 1.3.2", - "inotify-sys", - "libc", -] - -[[package]] -name = "inotify-sys" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" -dependencies = [ - "libc", -] - [[package]] name = "ipnet" version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" -[[package]] -name = "is-terminal" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "itoa" version = "1.0.11" @@ -554,26 +429,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kqueue" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" -dependencies = [ - "kqueue-sys", - "libc", -] - -[[package]] -name = "kqueue-sys" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" -dependencies = [ - "bitflags 1.3.2", - "libc", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -594,9 +449,9 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -607,9 +462,6 @@ name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" -dependencies = [ - "serde", -] [[package]] name = "md-5" @@ -633,27 +485,6 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "minecraft_addon_controller" -version = "0.0.1" -dependencies = [ - "async-watcher", - "log", - "md-5", - "notify 6.1.1", - "pretty_env_logger", - "reqwest", - "serde", - "serde_json", - "sha1", - "sha2", - "tempfile", - "thiserror", - "tokio", - "tokio-util", - "toml", -] - [[package]] name = "miniz_oxide" version = "0.7.2" @@ -670,7 +501,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", - "log", "wasi", "windows-sys 0.48.0", ] @@ -693,44 +523,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "notify" -version = "5.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729f63e1ca555a43fe3efa4f3efdf4801c479da85b432242a7b726f353c88486" -dependencies = [ - "bitflags 1.3.2", - "crossbeam-channel", - "filetime", - "fsevent-sys", - "inotify", - "kqueue", - "libc", - "mio", - "walkdir", - "windows-sys 0.45.0", -] - -[[package]] -name = "notify" -version = "6.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" -dependencies = [ - "bitflags 2.5.0", - "crossbeam-channel", - "filetime", - "fsevent-sys", - "inotify", - "kqueue", - "libc", - "log", - "mio", - "serde", - "walkdir", - "windows-sys 0.48.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -802,9 +594,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" dependencies = [ "lock_api", "parking_lot_core", @@ -812,15 +604,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -829,6 +621,26 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -847,77 +659,38 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" -[[package]] -name = "pretty_env_logger" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "865724d4dbe39d9f3dd3b52b88d859d66bcb2d6a0acfd5ea68a65fb66d4bdc1c" -dependencies = [ - "env_logger", - "log", -] - [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "regex" -version = "1.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.6" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", + "bitflags 2.5.0", ] -[[package]] -name = "regex-syntax" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" - [[package]] name = "reqwest" -version = "0.11.27" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" +checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" dependencies = [ "base64", "bytes", @@ -927,8 +700,10 @@ dependencies = [ "h2", "http", "http-body", + "http-body-util", "hyper", "hyper-tls", + "hyper-util", "ipnet", "js-sys", "log", @@ -961,9 +736,9 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", "errno", @@ -974,27 +749,25 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.4" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" dependencies = [ "base64", + "rustls-pki-types", ] [[package]] -name = "ryu" -version = "1.0.17" +name = "rustls-pki-types" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "beb461507cee2c2ff151784c52762cf4d9ff6a61f3e80968600ed24fa837fa54" [[package]] -name = "same-file" -version = "1.0.6" +name = "ryu" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "schannel" @@ -1036,18 +809,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.197" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" dependencies = [ "proc-macro2", "quote", @@ -1056,9 +829,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "itoa", "ryu", @@ -1110,9 +883,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -1144,9 +917,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -1192,29 +965,20 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", @@ -1284,12 +1048,8 @@ checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", - "futures-io", "futures-sink", - "futures-util", - "hashbrown", "pin-project-lite", - "slab", "tokio", "tracing", ] @@ -1317,9 +1077,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.9" +version = "0.22.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" dependencies = [ "indexmap", "serde", @@ -1328,6 +1088,28 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" @@ -1340,22 +1122,11 @@ version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ + "log", "pin-project-lite", - "tracing-attributes", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tracing-core" version = "0.1.32" @@ -1365,6 +1136,23 @@ dependencies = [ "once_cell", ] +[[package]] +name = "traits" +version = "0.1.0" +dependencies = [ + "async-trait", + "bytes", + "md-5", + "reqwest", + "serde", + "serde_json", + "sha1", + "sha2", + "thiserror", + "tokio", + "toml", +] + [[package]] name = "try-lock" version = "0.2.5" @@ -1421,16 +1209,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "walkdir" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" -dependencies = [ - "same-file", - "winapi-util", -] - [[package]] name = "want" version = "0.3.1" @@ -1522,46 +1300,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -1577,22 +1315,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", -] - -[[package]] -name = "windows-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows-targets 0.52.5", ] [[package]] @@ -1612,25 +1335,20 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -1639,15 +1357,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -1657,15 +1369,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -1675,15 +1381,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" [[package]] -name = "windows_i686_msvc" -version = "0.42.2" +name = "windows_i686_gnullvm" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -1693,15 +1399,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -1711,15 +1411,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -1729,15 +1423,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -1747,45 +1435,25 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.5" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" dependencies = [ "memchr", ] [[package]] name = "winreg" -version = "0.50.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" dependencies = [ "cfg-if", "windows-sys 0.48.0", ] - -[[package]] -name = "zerocopy" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] diff --git a/Cargo.toml b/Cargo.toml index 0bf9e7a..096f68b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,24 +1,19 @@ [package] -name = "minecraft_addon_controller" -version = "0.0.1" -authors = ["TOwInOK"] +name = "traits" +version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -async-watcher = "0.2.1" -log = { version = "0.4.21", features = ["serde"] } +async-trait = "0.1.80" +bytes = "1.6.0" md-5 = "0.10.6" -notify = { version = "6.1.1", features = ["serde"] } -pretty_env_logger = "0.5.0" -reqwest = { version = "0.11.22", features = ["json"] } -serde = { version = "1.0.193", features = ["derive"] } -serde_json = "1.0.114" +reqwest = { version = "0.12.4", features = ["json"] } +serde = { version = "1.0.199", features = ["derive"] } +serde_json = "1.0.116" sha1 = "0.10.6" sha2 = "0.10.8" -tempfile = "3.10.1" -thiserror = "1.0.57" -tokio = { version = "1.34.0", features = ["full"] } -tokio-util = { version = "0.7.10", features = ["full"] } -toml = "0.8.8" +thiserror = "1.0.59" +tokio = { version = "1.37.0", features = ["full"] } +toml = "0.8.12" diff --git a/README.md b/README.md deleted file mode 100644 index 6100e43..0000000 --- a/README.md +++ /dev/null @@ -1,65 +0,0 @@ -# Minecraft Dependency Controller (MDC) - -# RU - -# Что надо - 1. Загрузка из одного файла - 2. Декларативно - 3. Не нужно запускать сервер чтобы обновить/загрузить плагины и моды! - 4. Есть возможность загружать ядра и обновлять их. - 5. Загружать конфигурационных файлов с git - -# Что реализуется - - [x] Обновление, загрузка плагинов. - - [x] Обновление, загрузка ядра. - - [x] Чтение конфигурационных файлов - - [ ] Обновление, загрузка модов. - - [ ] Запуск minecraft - - [ ] Бекапы - - [ ] Загрузка конфигурационных файлов по ссылке - -# Будут ли добавлены датапаки? - Реализовать можно, но по мери надобности. - Так как датапаки - это специфичный инструмент, который лучше устанавливать в ручную. - -# EN - -# What is needed - 1. Loading from a single file - 2. Declaratively - 3. No need to run the server to update/load plugins and mods! - 4. The ability to load cores and update them. - 5. Loading configuration files from git - -# What is being implemented - - [x] Updating, loading plugins. - - [x] Updating, loading cores. - - [x] Reading configuration files - - [ ] Updating, loading mods. - - [ ] Running Minecraft - - [ ] Backups - - [ ] Loading configuration files via link - -# Will datapacks be added? - It can be implemented, but as needed. - Since data packs are a specific tool, it's better to install them manually. - -# Source: - ## Plugins: - - Modrinth - - Hangar (not implemented) - ## Mods - - Modrinth - - CurseForge (not implemented) - ## Cores - - Vanilla - - PaperMC - - Folia - - PurpurMC - - Fabric (not implemented) - - Forge (not implemented, no api) - - NeoForge (not implemented, no api) - - Velocity - - Waterflow - - diff --git a/Sample of config.toml b/Sample of config.toml deleted file mode 100644 index 6797c43..0000000 --- a/Sample of config.toml +++ /dev/null @@ -1,78 +0,0 @@ -# Пример конфигурации -# Sample of config - -# freez - добавлять ли на проверку/скачивание если object присутствует. -# freez - whether to add for checking/downloading if object is present. - -# Секция ядра / Core section -[core] - # Выбери один из вариантов: vanilla, spigot, bucket, paper, purpur, forge, neoForge, fabric, folia, waterfall, velocity - # Choose one of the options: vanilla, spigot, bucket, paper, purpur, forge, neoForge, fabric, folia, waterfall, velocity - provider = "paper" - # Версия сервера (например, "1.14.4" или специальный код) - # Server version (e.g., "1.14.4" or a special code) - version = "1.14.4" - build = "" - #version = "latest" <- by default - - # Замораживать ли объекты при наличии в системе - # Whether to freeze objects if present in the system - freeze = false - force_update = false - -# Update - не требуется при загрузке, он нужен только когда freez = true, чтобы обновить на туже версию, либо принудительно обновить на самую последнюю, даже когда обновления нет. -# Update - not required on load, only needed when freez = true, to update to the same version, or forcibly update to the latest, even when there are no updates. -# Секция плагинов / Plugins section -[plugins] - # Пример 1 - строчка - # Example 1 - single line - vc1 = {version = "ail5iPUK", channel = "stable", freeze = true, update = false} - - # Пример 2 - строчка - # Example 2 - single line - cooler1 = {source = "Spigot", version = "ail5iPUK", channel = "Beta", freeze = false, update = false} - - # Пример 3 - строчка - # Example 3 - single line - best_plugin_without_any_param1 = {} - - # Пример 1 - секция - # Example 1 - section - [plugins.simple_voice_chat2] - version = "ail5iPUK" - channel = "Stable" - freeze = false - update = false - - # Пример 2 - секция - # Example 2 - section - [plugins.cooler2] - source = "Spigot" - version = "ail5iPUK" - channel = "Beta" - freeze = false - update = true - - # Пример 3 - секция - # Example 3 - section - [plugins.best_plugin_without_any_param2] - #Дефолт: / Default: - #source = Modrith - #version = "Latest" - #channel = "Stable" - #freez = false - #update = false - -# Секция дополнений -# Additions section -[additions] - # Git link для конфига - # Git link for the config - configPluguinsFrom = "git@github.com:TOwInOK/test.git" - # Ключ если в привате - # Key if in private - key = "SUPEREKLy" - # path_to_core = "" - # path_to_mods = "" - # path_to_plugins = "" - # path_to_configs = "" \ No newline at end of file diff --git a/config.toml b/config.toml deleted file mode 100644 index df37379..0000000 --- a/config.toml +++ /dev/null @@ -1,18 +0,0 @@ -[core] -provider = "purpur" -version = "1.20.1" -# build = "2160" -# freeze = false -# force_update = false - -[plugins] -[plugins.simple-voice-chat] -[plugins.chunky] - -[additions] -# configPluguinsFrom = "git@github.com:TOwInOK/test.git" -# key = "SUPEREKLy" -path_to_core = "core" -# path_to_mods = "" -path_to_plugins = "plugins" -path_to_lock = "config.lock" diff --git a/settings.toml b/settings.toml new file mode 100644 index 0000000..f00203a --- /dev/null +++ b/settings.toml @@ -0,0 +1,17 @@ +[core] +Provider = "vanilla" +Version = "Latest" +Freeze = false +ForceUpdate = false + +[plugins.chunky] +source = "modrinth" +channel = "release" +freeze = false +force_update = false + +[plugins.simple-voice-chat] +source = "modrinth" +channel = "release" +freeze = false +force_update = false diff --git a/src/.DS_Store b/src/.DS_Store deleted file mode 100644 index 860c19c..0000000 Binary files a/src/.DS_Store and /dev/null differ diff --git a/src/config/additions.rs b/src/config/additions.rs deleted file mode 100644 index 3d65d06..0000000 --- a/src/config/additions.rs +++ /dev/null @@ -1,45 +0,0 @@ -use log::warn; -use serde::{Deserialize, Serialize}; -#[derive(Deserialize, Serialize, Debug, Default)] -#[serde(rename_all = "snake_case")] -pub struct Additions { - // git link - #[serde(default)] - config_plugins_from: Option, - // git key - #[serde(default)] - key: Option, - // Paths - #[serde(default = "core")] - pub path_to_core: String, - #[serde(default = "mods")] - pub path_to_mods: String, - #[serde(default = "plugins")] - pub path_to_plugins: String, - #[serde(default = "lock")] - pub path_to_lock: String, - #[serde(default = "configs")] - pub path_to_configs: String, -} - -fn core() -> String { - warn!("We use default core path!"); - "core".to_string() -} -fn mods() -> String { - warn!("We use default mods path!"); - "mods".to_string() -} -fn plugins() -> String { - warn!("We use default plugins path!"); - "plugins".to_string() -} -//folder for config files -fn configs() -> String { - warn!("We use default config path!"); - "./configs".to_string() -} -fn lock() -> String { - warn!("We use default lock path!"); - "config.lock".to_string() -} diff --git a/src/config/core.rs b/src/config/core.rs deleted file mode 100644 index 9aed2c7..0000000 --- a/src/config/core.rs +++ /dev/null @@ -1,92 +0,0 @@ -use crate::{ - config::models::{ - cores::{ - folia::Folia, paper::Paper, purpur::Purpur, vanilla::Vanilla, velocity::Velocity, - waterfall::Waterfall, - }, - model::ModelCore, - }, - errors::error::Result, -}; -use log::info; -use serde::{Deserialize, Serialize}; - -use crate::downloader::hash::ChooseHash; -#[derive(Deserialize, Serialize, Debug, Default, PartialEq, Clone)] -pub struct Core { - // Ядро - #[serde(default)] - pub provider: Provider, - // Версия ядра - #[serde(default)] - pub version: Option, - // Версия билда ядра - #[serde(default)] - pub build: Option, - // Приостановить обновление - #[serde(default)] - pub freeze: bool, - // Нужно обновить - #[serde(default)] - pub force_update: bool, -} - -#[derive(Deserialize, Serialize, Debug, Default, PartialEq, Clone)] -#[serde(rename_all = "lowercase")] -pub enum Provider { - #[default] - Vanilla, // done - Paper, // done - Folia, // done - Purpur, // in work, good api - Fabric, // in work, api with out hash - //https://meta.fabricmc.net/v2/versions/game <- version check /v2/versions/intermediary give only stable - // or https://meta.fabricmc.net/v1/versions/game/1.14.4. Если нет версии, ответ пуст. - Forge, //no api - NeoForge, //worst api - Waterfall, // done - Velocity, // done -} - -impl Provider { - pub async fn get_name(&self) -> &'static str { - match self { - Provider::Vanilla => "vanilla", - Provider::Paper => "paper", - Provider::Folia => "folia", - Provider::Purpur => "purpur", - Provider::Fabric => "fabric", - Provider::Forge => "forge", - Provider::NeoForge => "neoforge", - Provider::Waterfall => "waterfall", - Provider::Velocity => "velocity", - } - } -} - -impl Core { - pub async fn freeze(&self) -> bool { - info!("Check freeze and force_update"); - if self.freeze && !self.force_update { - info!("Core has iced"); - return true; - }; - false - } - - ///Check core and add it into list for download. - pub async fn get_link(&self) -> Result<(String, ChooseHash, String)> { - info!("Start to match provider of core"); - match self.provider { - Provider::Vanilla => Vanilla::get_link(self).await, - Provider::Paper => Paper::get_link(self).await, - Provider::Folia => Folia::get_link(self).await, - Provider::Purpur => Purpur::get_link(self).await, - Provider::Fabric => todo!(), - Provider::Forge => todo!(), - Provider::NeoForge => todo!(), - Provider::Waterfall => Waterfall::get_link(self).await, - Provider::Velocity => Velocity::get_link(self).await, - } - } -} diff --git a/src/config/mod.rs b/src/config/mod.rs deleted file mode 100644 index 73550ba..0000000 --- a/src/config/mod.rs +++ /dev/null @@ -1,42 +0,0 @@ -pub mod additions; -pub mod core; -mod models; -pub mod plugins; - -use crate::errors::error::Result; -use additions::Additions; -use core::Core; -use log::info; -use plugins::Plugin; -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use tokio::fs; -/// Структура для инициализации конфигурации -/// -#[derive(Deserialize, Serialize, Debug, Default)] -pub struct Config { - /// Minecraft core - #[serde(default)] - pub core: Core, - /// Plugin list - /// [name]:[Plugin] - #[serde(default)] - pub plugins: HashMap, - /// Additions for git or keys - #[serde(default)] - pub additions: Additions, -} - -impl Config { - pub async fn load_config(path: &str) -> Result { - info!("Загрузка конфигурационного файла..."); - let toml = fs::read_to_string(&path).await?; - info!("Файл успешно загружен."); - - info!("Инициализация конфигурационного файла..."); - let config: Config = toml::from_str(&toml)?; - info!("Конфигурация успешно инициализирована."); - - Ok(config) - } -} diff --git a/src/config/plugins.rs b/src/config/plugins.rs deleted file mode 100644 index b6a9947..0000000 --- a/src/config/plugins.rs +++ /dev/null @@ -1,80 +0,0 @@ -use log::info; -use serde::{Deserialize, Serialize}; - -use crate::{ - config::models::{extensions::modrinth::ModrinthData, model::ModelExtensions}, - downloader::hash::ChooseHash, - errors::error::Result, -}; - -#[derive(Deserialize, Serialize, Debug, PartialEq)] -pub struct Plugin { - // Откуда качаем - #[serde(default)] - pub source: Sources, - // Версия - #[serde(default)] - pub version: Option, - // Стабильная, Альфа, Бета - #[serde(default)] - pub channel: Channels, - // Приостановить обновление - #[serde(default)] - pub freeze: bool, - // Нужно обновить - #[serde(default)] - pub force_update: bool, -} - -#[derive(Deserialize, Serialize, Debug, Default, PartialEq)] -#[serde(rename_all = "lowercase")] -pub enum Sources { - Spigot, // bad api - Hangar, // ? - #[default] - Modrinth, // Favorite - CurseForge, // ? -} - -#[derive(Deserialize, Serialize, Debug, Default, PartialEq)] -#[serde(rename_all = "lowercase")] -pub enum Channels { - #[default] - Release, - Beta, - Alpha, -} - -impl Channels { - pub async fn get_str(&self) -> &'static str { - match self { - Channels::Release => "release", - Channels::Beta => "beta", - Channels::Alpha => "alpha", - } - } -} - -impl Plugin { - pub async fn freeze(&self) -> bool { - info!("Check freeze and force_update"); - if self.freeze && !self.force_update { - return true; - }; - false - } - - pub async fn get_link( - &self, - name: &str, - game_version: Option<&str>, - ) -> Result<(String, ChooseHash, String)> { - info!("Start to match provider of core"); - match self.source { - Sources::Spigot => todo!(), - Sources::Hangar => todo!(), - Sources::Modrinth => ModrinthData::get_link(name, self, game_version).await, - Sources::CurseForge => todo!(), - } - } -} diff --git a/src/controller/mod.rs b/src/controller/mod.rs deleted file mode 100644 index 70f01df..0000000 --- a/src/controller/mod.rs +++ /dev/null @@ -1,112 +0,0 @@ -use std::{future::Future, pin::Pin, sync::Arc, time::Duration}; - -use async_watcher::{notify::RecursiveMode, AsyncDebouncer}; -use log::{error, info, trace}; -use tokio::time::sleep; -use tokio_util::sync::CancellationToken; - -use crate::{config::Config, downloader::Downloader, errors::error::Result, lock::locker::Lock}; - -const CONFIG_PATH: &str = "./config.toml"; - -pub struct Controller { - config: Config, - lock: Lock, -} - -impl Controller { - pub fn init() -> Pin + Send>> { - Box::pin(async move { - let mut controller = Self::new().await.unwrap(); - - info!("Start removing useless things"); - if let Err(e) = remove_zombies(&mut controller.lock, &controller.config).await { - error!("{:?}", e); - } - let token = Arc::new(CancellationToken::new()); - let token_clone = token.clone(); - - let checker = tokio::spawn(async move { - run(&controller.config, &mut controller.lock, &token).await; - }); - let finder = tokio::spawn(async move { - watch_config_changes(&token_clone).await; - }); - let (_, _) = tokio::try_join!(checker, finder).unwrap(); - }) - } - - async fn new() -> Result { - // Load Config file - let config = match Config::load_config(CONFIG_PATH).await { - Ok(config) => config, - Err(e) => { - log::error!("Failed to load config: {}", e); - log::warn!("Loading default config"); - Config::default() - } - }; - - // Load lock - let lock = { - let mut lock = Lock::default(); - if let Err(e) = lock.load(&config.additions.path_to_lock).await { - error!("{}", e); - lock.create(&config.additions.path_to_lock).await?; - lock.load(&config.additions.path_to_lock).await?; - } - lock - }; - - Ok(Self { config, lock }) - } -} - -/// Итерируем Lock и находим то чего нет в Config. -/// Нет, удаляем в Lock. -async fn remove_zombies(lock: &mut Lock, config: &Config) -> Result<()> { - trace!("Start fn: remove_zombies"); - lock.remove_if_not_exist_plugin(config).await?; - lock.remove_if_not_exist_core(config).await -} - -async fn run(config: &Config, lock: &mut Lock, token: &CancellationToken) { - // let sleep_cooldown = self.config.lock().await.additions.time_to_await; - let cooldown = 600f32; - loop { - info!("Start checking and download"); - info!("Init downloader"); - if let Err(e) = Downloader::init(config, lock).check_and_download().await { - error!("{:?}", e); - } - - // Sleep for 5 minutes - tokio::select! { - _ = sleep(Duration::from_secs_f32(cooldown)) => {}, - _ = token.cancelled() => break, - }; - } -} - -/// Load downloader module. -/// Always check config file. -/// Use `token` for canceling minecraft task -pub async fn watch_config_changes(token: &CancellationToken) { - trace!("Start Watch Config"); - // initialize the debouncer - let (mut tx, mut rx) = AsyncDebouncer::new_with_channel(Duration::from_millis(200), None) - .await - .unwrap(); - info!("Get debouncer"); - // register path to watch - tx.watcher() - .watch(CONFIG_PATH.as_ref(), RecursiveMode::NonRecursive) - .unwrap(); - info!("Fill debouncer"); - // wait for events - while let Some(event) = rx.recv().await { - trace!("event: {:?}", event); - token.cancel(); - Controller::init().await - } -} diff --git a/src/downloader/mod.rs b/src/downloader/mod.rs deleted file mode 100644 index b75c37a..0000000 --- a/src/downloader/mod.rs +++ /dev/null @@ -1,214 +0,0 @@ -pub mod hash; - -use crate::config::Config; -use crate::errors::error::Result; -use crate::errors::error::{CompareHashError, Error}; -use crate::lock::locker::{ExistState, Lock}; - -use log::{debug, info}; -use std::fs::File; -use std::io::Write; -use std::path::Path; - -use self::hash::ChooseHash; - -#[derive(Debug)] -pub struct Downloader<'config, 'lock> { - config: &'config Config, - lock: &'lock mut Lock, -} - -impl<'config, 'lock> Downloader<'config, 'lock> { - pub fn init(config: &'config Config, lock: &'lock mut Lock) -> Self { - Self { config, lock } - } - - ///Check and download plugins, mods, core - pub async fn check_and_download(&mut self) -> Result<()> { - info!("Start check fn"); - self.core_reqwest().await?; - self.plugin_reqwest().await - } - - /// Make reqwest to check version and download core. - async fn core_reqwest(&mut self) -> Result<()> { - //Find version to download - let (link, hash, version) = self.config.core.get_link().await?; - let core_name = self.config.core.provider.get_name().await; - debug!("Find {} link: {}, hash: {}", core_name, &link, &hash); - info!("Start to download {}!", core_name); - //Need to update or download? - match self.lock.exist_core(&self.config.core, &version).await { - ExistState::Exist => { - if self.config.core.freeze().await { - return Ok(()); - } - info!("Core exist"); - self.core_force_update(core_name, link, hash, version).await - } - ExistState::DifferentVersion | ExistState::DifferentBuild => { - if self.config.core.freeze().await { - return Ok(()); - } - info!("Core have different or build version, Download!"); - self.download_core(core_name, link, hash, version).await - } - ExistState::None => { - info!("No one core find, Download!"); - self.download_core(core_name, link, hash, version).await - } - } - } - - async fn core_force_update( - &mut self, - core_name: &str, - link: String, - hash: ChooseHash, - version: String, - ) -> Result<()> { - if self.config.core.force_update { - info!("Force update core!"); - return self.download_core(core_name, link, hash, version).await; - } - info!("Core doesn't need to download"); - Ok(()) - } - /// download core - async fn download_core( - &mut self, - name: &str, - link: String, - hash: ChooseHash, - build: String, - ) -> Result<()> { - // download - get_file(link, hash, &self.config.additions.path_to_core, name).await?; - let path = format!("{}/{}.jar", self.config.additions.path_to_core, name); - self.lock - .core_edit(self.config.core.clone(), path, build) - .await; - //save lock - self.lock.save(&self.config.additions.path_to_lock).await?; - Ok(()) - } - - ///////Plugin Section - - /// Make reqwest to check version and download [`Plugin`]. - async fn plugin_reqwest(&mut self) -> Result<()> { - if self.config.plugins.is_empty() { - return Ok(()); - }; - for (name, plugin) in self - .config - .plugins - .iter() - .map(|(name, plugin)| (name.to_lowercase().replace('_', "-"), plugin)) - { - if plugin.freeze().await { - continue; - } - let (link, hash, version) = plugin - .get_link(&name, self.config.core.version.as_deref()) - .await?; - - // Check exist plugin. - match self.lock.exist_plugin(&name, &version).await { - ExistState::Exist => { - if plugin.freeze().await { - return Ok(()); - } - // Download force update - if plugin.force_update { - info!("Plugin: {}. Force download!", name); - download_plugin( - self.lock, - &name, - version, - &self.config.additions.path_to_plugins, - &self.config.additions.path_to_lock, - link, - hash, - ) - .await? - } - info!("Plugin: {}. Does't need to update", name); - } - ExistState::DifferentVersion | ExistState::DifferentBuild => { - if plugin.freeze().await { - return Ok(()); - } - info!("Plugin: {}. Need tp update", name); - download_plugin( - self.lock, - &name, - version, - &self.config.additions.path_to_plugins, - &self.config.additions.path_to_lock, - link, - hash, - ) - .await? - } - ExistState::None => { - info!("No one plugin: {} find, Download!", name); - download_plugin( - self.lock, - &name, - version, - &self.config.additions.path_to_plugins, - &self.config.additions.path_to_lock, - link, - hash, - ) - .await? - } - } - } - Ok(()) - } -} - -/// download plugin -async fn download_plugin( - lock: &mut Lock, - name: &str, - version: String, - path_plugin: &str, - path_lock: &str, - link: String, - hash: ChooseHash, -) -> Result<()> { - //This downloaded plugin replace current plugin. - //download plugin - get_file(link, hash, path_plugin, name).await?; - //push to lock - lock.plugin_add(name.to_owned(), version, path_plugin).await; - //save lock - lock.save(path_lock).await?; - Ok(()) -} - -/// Get and write file by path -async fn get_file(link: String, hash: ChooseHash, download_dir: &str, name: &str) -> Result<()> { - let response = reqwest::get(link).await.unwrap(); - let content = response.bytes().await?; - - // Check hash - if hash.calculate_hash(&*content).await { - info!("Hash same"); - let mut name = name.to_owned(); - name.push_str(".jar"); - let file_name = Path::new(&name); // Name of file - debug!("File name: {:#?}", &file_name); - let file_path = Path::new(download_dir).join(file_name); // Where to download with file name - debug!("File path: {:#?}", &file_path); - let mut file = File::create(&file_path)?; // Create the file - info!("delete curent core"); - file.write_all(&content)?; //write - Ok(()) - } else { - Err(Error::CompareHash(CompareHashError::None)) - } -} diff --git a/src/errors/error.rs b/src/errors/error.rs index 8cdba2f..9cf4698 100644 --- a/src/errors/error.rs +++ b/src/errors/error.rs @@ -1,8 +1,9 @@ use thiserror::Error; -#[allow(dead_code)] #[derive(Error, Debug)] pub enum CompareHashError { + #[error("Хэш не совпадает")] + HashNotCompare(), #[error("Конвертация Sha1 проведена не успешно : {0}")] SHA1(std::io::Error), #[error("Конвертация Sha256 проведена не успешно : {0}")] @@ -43,7 +44,7 @@ macro_rules! not_found { #[macro_export] macro_rules! not_found_path { - ($arg:tt) => { + ($arg:expr) => { Err(Error::NotFound(format!( "No path like: ->{}<-, exist", $arg diff --git a/src/lock/core.rs b/src/lock/core.rs new file mode 100644 index 0000000..5289a61 --- /dev/null +++ b/src/lock/core.rs @@ -0,0 +1,23 @@ +use serde::{Deserialize, Serialize}; + +use crate::settings::core::{Core, Provider}; + +#[derive(Deserialize, Serialize, Debug, Default, PartialEq, Clone)] +pub struct CoreMeta { + // Ядро + provider: Provider, + // Версия ядра + version: String, + // Версия билда ядра + build: Option, +} + +impl From for CoreMeta { + fn from(value: Core) -> Self { + Self { + provider: value.provider().clone(), + version: value.version().to_owned(), + build: value.build().cloned(), + } + } +} diff --git a/src/lock/ext.rs b/src/lock/ext.rs new file mode 100644 index 0000000..c957c37 --- /dev/null +++ b/src/lock/ext.rs @@ -0,0 +1,17 @@ +use serde::{Deserialize, Serialize}; + +use crate::settings::extensions::plugin::Plugin; + +#[derive(Debug, PartialEq, Serialize, Deserialize, Default)] +pub struct ExtensionMeta { + version: Option, + path: String, +} +impl ExtensionMeta { + fn from_plugin(value: Plugin, path: &str) -> Self { + Self { + version: value.version().cloned(), + path: path.to_owned(), + } + } +} diff --git a/src/lock/locker.rs b/src/lock/locker.rs deleted file mode 100644 index 202bb3d..0000000 --- a/src/lock/locker.rs +++ /dev/null @@ -1,263 +0,0 @@ -use std::{ - collections::HashMap, - ffi::OsStr, - path::{Path, PathBuf}, -}; - -use log::{debug, error, info, trace, warn}; -use serde::{Deserialize, Serialize}; - -use crate::{ - config::{ - core::{Core, Provider}, - Config, - }, - errors::error::{Error, Result}, - not_found, not_found_path, -}; - -use tokio::{ - fs::{self, File}, - io::AsyncWriteExt, -}; - -#[derive(Debug, PartialEq, Serialize, Deserialize, Default)] -#[serde(rename_all = "camelCase")] -pub struct Lock { - core: CoreMetaData, - plugins: HashMap, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize, Default)] -struct CoreMetaData { - name: Provider, - version: Option, - build: Option, - path: String, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize, Default)] -struct ExtensionMetaData { - version: String, - path: String, -} - -impl Lock { - /// Load lock from the specified file path - pub async fn load(&mut self, path: &str) -> Result<()> { - if !self.check_path(path).await { - return not_found_path!(path); - } - info!("Starting to load lock from file: {}", path); - - // Read the file contents - let toml = fs::read_to_string(&path).await?; - info!("Lock file loaded successfully."); - - info!("Deserializing lock file contents..."); - // Deserialize the file contents into Lock struct - let lock: Lock = toml::from_str(&toml).unwrap_or_else(|e| { - error!("Parse error: {}", e); - warn!("Load default Lock!"); - Lock::default() - }); - info!("Lock file deserialized successfully."); - *self = lock; - info!("Lock reload successfully"); - Ok(()) - } - - /// Create lock file - pub async fn create(&self, path: &str) -> Result<()> { - if !self.check_path(path).await { - return not_found_path!(path); - } - info!("Creating lock file at path: {}", path); - - // Serialize the Lock struct to TOML - let toml_content = toml::to_string_pretty(&self)?; - - // Open or create the lock file - let mut file = File::create(&path).await?; - info!("Lock file created."); - - // Write the serialized TOML content to the file - file.write_all(toml_content.as_bytes()).await?; - info!("Lock file content written successfully."); - - Ok(()) - } - - /// Re parsing file and load - pub async fn _reload(&mut self, path: &str) -> Result<()> { - if !self.check_path(path).await { - return not_found_path!(path); - } - info!("Reloading lock file from path: {}", path); - // Read the file contents - let toml_content = fs::read_to_string(&path).await?; - info!("Lock file reloaded successfully."); - - info!("Deserializing lock file contents..."); - // Deserialize the file contents into Lock struct using serde_toml - let lock: Lock = toml::from_str(&toml_content)?; - info!("Lock file deserialized successfully."); - *self = lock; - info!("Lock reload successfully"); - Ok(()) - } - - /// Check if file exists in the system - pub async fn check_path(&self, path: &str) -> bool { - info!("Checking if lock file exists at path: {}", path); - - // Check if the lock file exists - let exists = Path::new(&path).exists(); - info!("Lock file exists: {}", exists); - - exists - } - - /// Save lock - pub async fn save(&self, path: &str) -> Result<()> { - if !self.check_path(path).await { - return not_found_path!(path); - } - info!("Saving lock to file: {}", path); - // Serialize the Lock struct to TOML - let toml_content = toml::to_string_pretty(&self)?; - - // Open or create the lock file - let mut file = File::create(&path).await?; - info!("Lock file created."); - - // info!("Flush lock"); - // file.flush().await?; - - file.write_all(toml_content.as_bytes()).await?; - info!("Lock file content written successfully."); - - Ok(()) - } - - ///Exist this item? - pub async fn exist_plugin(&self, name: &str, version: &str) -> ExistState { - if self.plugins.contains_key(name) { - return ExistState::Exist; - } - if self.plugins.contains_key(name) - && self - .plugins - .get(name) - .map_or(false, |x| x.version == version) - { - return ExistState::DifferentVersion; - } - - ExistState::None - } - - pub async fn exist_core(&self, core: &Core, build: &str) -> ExistState { - if self.core.name == core.provider - && self.core.version == core.version - && self.core.build == Some(build.to_owned()) - { - return ExistState::Exist; - } - if self.core.version == core.version { - return ExistState::DifferentVersion; - } - if self.core.build == core.build { - return ExistState::DifferentBuild; - } - ExistState::None - } - - /// Delete all core items from meta_data - /// cause only one core can exist in one time - pub async fn _delete_core(&mut self) -> Result<()> { - delete_file_by_path(&self.core.path).await - } - ///Delete plugin - pub async fn _delete_plugin(&mut self, name: &str) -> Result<()> { - match self.plugins.remove(name) { - Some(e) => delete_file_by_path(&e.path).await, - None => not_found!(name), - } - } - - pub async fn remove_if_not_exist_plugin(&mut self, config: &Config) -> Result<()> { - trace!("Start fn: remove_if_not_exist_plugin"); - // Create list of keys to delete - let mut keys_to_remove: Vec = Vec::new(); - for i in self.plugins.keys() { - if !config.plugins.contains_key(i) { - keys_to_remove.push(i.to_owned()); - } - } - debug!("List of keys to remove: {:#?}", &keys_to_remove); - // Remove the plugins from self.plugins using the collected keys - for i in keys_to_remove.iter() { - let i = self.plugins.remove(i).unwrap(); - delete_file_by_path(&i.path).await?; - } - self.save(&config.additions.path_to_lock).await - } - - pub async fn remove_if_not_exist_core(&mut self, config: &Config) -> Result<()> { - trace!("Start fn: remove_if_not_exist_core"); - if self.core.name != config.core.provider { - debug!("Delete core: {:#?}", &self.core.name); - delete_file_by_path(&self.core.path).await?; - self.core = CoreMetaData::default(); - } - Ok(()) - } - - /// Converting [`Core`] to [`CoreMetaData`] and change values of core in [`Lock`] - /// - /// Need to clone [`Core`] - pub async fn core_edit(&mut self, core: Core, path: String, build: String) { - self.core = CoreMetaData { - name: core.provider, - version: core.version, - build: Some(build), - path, - } - } - - /// Push key: String, value: Version from plugin - /// Path where plugin exist - pub async fn plugin_add(&mut self, name: String, version: String, path_to_dir: &str) { - let path = format!("{}/{}.jar", path_to_dir, &name); - debug!("FN Plugin_add: path: {}", &path); - let extension = ExtensionMetaData { version, path }; - debug!("FN Plugin_add: Extension: {:#?}", &extension); - self.plugins.insert(name, extension); - debug!("FN Plugin_add: self.plugins: {:#?}", &self.plugins); - } -} - -async fn _delete_file(name: &str, download_dir: &str) -> Result<()> { - let file_name = format!("{}.jar", name); - let file_path = PathBuf::from(download_dir).join(file_name); - debug!("file_path: {:#?}", file_path); - fs::remove_file(&file_path).await.map_err(|e| e.into()) -} - -async fn delete_file_by_path(path: &str) -> Result<()> { - info!("DELETE by path: {path}"); - if path.is_empty() { - Ok(()) - } else { - let path = OsStr::new(path); - debug!("file_path: {:#?}", path); - fs::remove_file(path).await.map_err(|e| e.into()) - } -} -pub enum ExistState { - Exist, - DifferentVersion, - DifferentBuild, - None, -} diff --git a/src/lock/mod.rs b/src/lock/mod.rs index e111b82..d8f273f 100644 --- a/src/lock/mod.rs +++ b/src/lock/mod.rs @@ -1 +1,31 @@ -pub mod locker; +mod core; +mod ext; + +use serde::{Deserialize, Serialize}; + +use self::core::CoreMeta; +use self::ext::ExtensionMeta; +use crate::{ + settings::core::Core, + tr::{load::Load, save::Save}, +}; +use std::collections::HashMap; + +#[derive(Default, Serialize, Deserialize)] +pub struct Lock { + core: CoreMeta, + plugins: HashMap, + // mods: HashMap, +} +impl Lock { + fn update_core(&mut self, core: Core) { + self.core = core.into(); + } +} + +impl Save for Lock { + const PATH: &'static str = "./lock.toml"; +} +impl Load for Lock { + const PATH: &'static str = "./lock.toml"; +} diff --git a/src/main.rs b/src/main.rs index e819786..64f041f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,36 @@ -mod config; -mod controller; -mod downloader; -mod errors; -mod lock; +pub mod errors; +pub mod lock; +pub mod models; +pub mod query; +pub mod settings; +pub mod tr; + +use crate::errors::error::Result; +use crate::lock::Lock; +use settings::Settings; +use std::sync::Arc; +use tokio::sync::Mutex; +use tr::{load::Load, save::Save}; #[tokio::main] -async fn main() { - pretty_env_logger::formatted_builder() - .filter_level(log::LevelFilter::Trace) - .init(); - controller::Controller::init().await +async fn main() -> Result<()> { + // let lock = Lock::default(); + // let mut query = Query::default(); + + // for (name, plugin) in settings.plugins().items().iter() { + // let game_version = settings.core().version(); + // let a = plugin.get_link(name, game_version).await?; + // query.query_mut().insert(name.to_string(), a.into()); + // } + // let settings = Arc::new(Mutex::new(Settings::default())); + // let lock = Arc::new(Mutex::new(Lock::default())); + // let plugins = Plugins::new(path, items); + // settings.get_mut().plugins_mut() + // lock.lock().await.save().await?; + // settings.lock().await.save().await?; + + let load_settings = Settings::load().await?; + println!("{:#?}", load_settings); + load_settings.save().await?; + Ok(()) } diff --git a/src/config/models/cores/folia.rs b/src/models/cores/folia.rs similarity index 100% rename from src/config/models/cores/folia.rs rename to src/models/cores/folia.rs diff --git a/src/config/models/cores/mod.rs b/src/models/cores/mod.rs similarity index 100% rename from src/config/models/cores/mod.rs rename to src/models/cores/mod.rs diff --git a/src/config/models/cores/paper.rs b/src/models/cores/paper.rs similarity index 69% rename from src/config/models/cores/paper.rs rename to src/models/cores/paper.rs index 43f471e..703feca 100644 --- a/src/config/models/cores/paper.rs +++ b/src/models/cores/paper.rs @@ -1,11 +1,10 @@ -use log::{debug, info}; use serde::{Deserialize, Serialize}; use crate::{ - config::{core::Core, models::model::ModelCore}, - downloader::hash::ChooseHash, errors::error::{Error, Result}, not_found_build_error, not_found_version_error, + settings::core::Core, + tr::{hash::ChooseHash, model::core::ModelCore}, }; pub struct Paper(); @@ -44,32 +43,30 @@ pub struct Application { } impl ModelCore for T { + type Link = String; + type Version = String; //find build and push link async fn get_link(core: &Core) -> Result<(String, ChooseHash, String)> { - debug!("Start Get link"); let core_name = Self::CORE_NAME; //get data from core - let build = core.build.as_deref(); - let version = core.version.as_deref(); + let build = core.build(); + let version = core.version(); //find link and version - let version = Self::find_version(version).await?; + let version = find_version(version, core_name).await?; let verlink = format!( "https://api.papermc.io/v2/projects/{}/versions/{}", core_name, version ); - info!("Get BuildList"); let build_list: BuildList = reqwest::get(verlink).await?.json().await?; let build_list = build_list.builds.as_slice(); match build { Some(e) => { let build: u16 = e.parse().unwrap(); if build_list.contains(&build) { - info!("Find build, download"); let buildlink = format!( "https://api.papermc.io/v2/projects/{}/versions/{}/builds/{}", core_name, version, build ); - info!("Get Url"); let url: Url = reqwest::get(&buildlink).await?.json().await?; Ok(( format!("{}/downloads/{}", buildlink, url.downloads.application.name), @@ -81,9 +78,7 @@ impl ModelCore for T { } } None => { - info!("Download latest build"); let lastbuild = build_list.last().unwrap(); - info!("Get Url"); let buildlink = format!( "https://api.papermc.io/v2/projects/{}/versions/{}/builds/{}", core_name, version, lastbuild @@ -97,25 +92,26 @@ impl ModelCore for T { } } } +} - //Find version in version list, if exist give out version or give error - async fn find_version(version: Option<&str>) -> Result { - debug!("Start find Version"); - let link = format!("https://api.papermc.io/v2/projects/{}", Self::CORE_NAME); - let verlist: VersionList = reqwest::get(link).await?.json().await?; - let verlist = verlist.versions; - match version { - Some(ver) => { - if verlist.contains(&ver.to_owned()) { - Ok(ver.to_owned()) - } else { - not_found_version_error!(ver) - } +//Find version in version list, if exist give out version or give error +async fn find_version(version: &str, core_name: &str) -> Result { + let link = format!("https://api.papermc.io/v2/projects/{}", core_name); + let version_list = { + let version_list: VersionList = reqwest::get(link).await?.json().await?; + version_list.versions + }; + match version { + "Latest" => match version_list.last() { + Some(e) => Ok(e.to_owned()), + None => not_found_version_error!("Latest"), + }, + _ => { + if version_list.contains(&version.to_string()) { + Ok(version.to_owned()) + } else { + not_found_version_error!(version) } - None => match verlist.last() { - Some(e) => Ok(e.to_owned()), - None => not_found_version_error!("Latest"), - }, } } } diff --git a/src/config/models/cores/purpur.rs b/src/models/cores/purpur.rs similarity index 65% rename from src/config/models/cores/purpur.rs rename to src/models/cores/purpur.rs index d7b3802..9e4dea9 100644 --- a/src/config/models/cores/purpur.rs +++ b/src/models/cores/purpur.rs @@ -1,11 +1,10 @@ -use log::{info, trace}; use serde::{Deserialize, Serialize}; use crate::{ - config::{core::Core, models::model::ModelCore}, - downloader::hash::ChooseHash, errors::error::{Error, Result}, not_found_build_error, not_found_version_error, + settings::core::Core, + tr::{hash::ChooseHash, model::core::ModelCore}, }; pub struct Purpur {} @@ -38,15 +37,17 @@ pub struct FileHash { const MAIN_LINK: &str = "https://api.purpurmc.org/v2/purpur"; impl ModelCore for Purpur { + type Link = String; + + type Version = String; + //find build and push link async fn get_link(core: &Core) -> Result<(String, ChooseHash, String)> { - let build = core.build.as_deref(); - let version = core.version.as_deref(); - trace!("Find version started!"); - let version = Self::find_version(version).await?; + let build = core.build(); + let version = core.version(); + let version = find_version(version).await?; //Version string let verlink = format!("{}/{}", MAIN_LINK, version); - info!("Get BuildList"); let build_list: BuildList = reqwest::get(verlink).await?.json().await?; let build_list_latest: &str = build_list.builds.latest.as_ref(); let build_list = build_list.builds.all; @@ -54,9 +55,7 @@ impl ModelCore for Purpur { match build { Some(build) => { if build_list.contains(&build.to_owned()) { - info!("Find build, download"); let build_link = format!("{}/{}/{}", MAIN_LINK, version, build); - info!("Get Url"); let file_hash: FileHash = reqwest::get(&build_link).await?.json().await?; Ok(( format!("{}/download", build_link), @@ -68,8 +67,6 @@ impl ModelCore for Purpur { } } None => { - info!("Download latest build"); - info!("Get Url"); let build_link = format!("{}/{}/{}", MAIN_LINK, version, build_list_latest); let file_hash: FileHash = reqwest::get(&build_link).await?.json().await?; Ok(( @@ -80,24 +77,25 @@ impl ModelCore for Purpur { } } } +} - //Find version in version list, if exist give out version or give error - async fn find_version(version: Option<&str>) -> Result { - let verlist: VersionList = reqwest::get(MAIN_LINK).await?.json().await?; - let verlist: &[String] = verlist.versions.as_ref(); - match version { - Some(ver) => { - trace!("have ver"); - if verlist.contains(&ver.to_owned()) { - Ok(ver.to_owned()) - } else { - not_found_version_error!(ver) - } +//Find version in version list, if exist give out version or give error +async fn find_version(version: &str) -> Result { + let version_list = { + let version_list: VersionList = reqwest::get(MAIN_LINK).await?.json().await?; + version_list.versions + }; + match version { + "Latest" => match version_list.last() { + Some(e) => Ok(e.to_owned()), + None => not_found_version_error!("Latest"), + }, + _ => { + if version_list.contains(&version.to_string()) { + Ok(version.to_owned()) + } else { + not_found_version_error!(version) } - None => match verlist.last() { - Some(e) => Ok(e.to_string()), - None => not_found_version_error!("Latest"), - }, } } } diff --git a/src/config/models/cores/vanilla.rs b/src/models/cores/vanilla.rs similarity index 71% rename from src/config/models/cores/vanilla.rs rename to src/models/cores/vanilla.rs index 562db43..3c13a15 100644 --- a/src/config/models/cores/vanilla.rs +++ b/src/models/cores/vanilla.rs @@ -1,13 +1,9 @@ use crate::{ - config::{core::Core, models::model::ModelCore}, - downloader::hash::ChooseHash, errors::error::{Error, Result}, not_found_version_error, + settings::core::Core, + tr::{hash::ChooseHash, model::core::ModelCore}, }; -use log::debug; -use log::info; -use log::trace; -use log::warn; use serde::Deserialize; use serde::Serialize; @@ -52,7 +48,7 @@ pub enum TypeOfVersion { impl Default for TypeOfVersion { fn default() -> Self { - warn!("Use default fn of TypeOfVersion"); + // warn!("Use default fn of TypeOfVersion"); TypeOfVersion::Release } } @@ -76,50 +72,49 @@ pub struct Server { } impl ModelCore for Vanilla { + type Link = OuterLink; + type Version = VersionID; /// Making request to mojang api and find the link to download minecraft.jar async fn get_link(core: &Core) -> Result<(OuterLink, ChooseHash, VersionID)> { - let version = core.version.as_deref(); - debug!("Start find fn with version: {:#?}", version); + let version = core.version(); + // debug!("Start find fn with version: {:#?}", version); let link = find_version(version).await?; - trace!("get link: {}", &link.0); - trace!("get link: {}", &link.0); + // trace!("get link: {}", &link.0); let response = reqwest::get(link.0).await?; - trace!("get response, status of request: {}", &response.status()); + // trace!("get response, status of request: {}", &response.status()); let download_section: DownloadSection = response.json().await?; - debug!("Find jar to download!"); - debug!("Check body: {:#?}", &download_section.downloads.server); + // debug!("Find jar to download!"); + // debug!("Check body: {:#?}", &download_section.downloads.server); Ok(( download_section.downloads.server.url, ChooseHash::SHA1(download_section.downloads.server.sha1), link.1, )) } - - ///Return `url` for get a json which contain links of all versions - async fn find_version(_version: Option<&str>) -> Result { - todo!() - } } ///Return `url` which get a json that contain links of all versions -async fn find_version(version: Option<&str>) -> Result<(String, String)> { +async fn find_version(version: &str) -> Result<(String, String)> { const LINK: &str = "https://launchermeta.mojang.com/mc/game/version_manifest.json"; - trace!("Start find version of core!"); + // trace!("Start find version of core!"); let response = reqwest::get(LINK).await?; let vanilla: Vanilla = response.json().await?; - let local_version: &str = match &version { - Some(e) => e, - None => &vanilla.latest.release, + let local_version = { + if version == "Latest" { + vanilla.latest.release + } else { + version.to_string() + } }; - info!("Need to find: {}", &local_version); + // info!("Need to find: {}", &local_version); // Use a temporary variable to hold the found version and URL let found_version_and_url = vanilla .versions .iter() - .find(|x| x.version.contains(local_version)) + .find(|x| x.version.contains(&local_version)) .map(|x| { - info!("find version: {}", &x.version); + // info!("find version: {}", &x.version); let c = x.version.clone(); (c, x.url.clone()) }); diff --git a/src/config/models/cores/velocity.rs b/src/models/cores/velocity.rs similarity index 100% rename from src/config/models/cores/velocity.rs rename to src/models/cores/velocity.rs diff --git a/src/config/models/cores/waterfall.rs b/src/models/cores/waterfall.rs similarity index 100% rename from src/config/models/cores/waterfall.rs rename to src/models/cores/waterfall.rs diff --git a/src/config/models/extensions/mod.rs b/src/models/extensions/mod.rs similarity index 100% rename from src/config/models/extensions/mod.rs rename to src/models/extensions/mod.rs diff --git a/src/config/models/extensions/modrinth.rs b/src/models/extensions/modrinth.rs similarity index 77% rename from src/config/models/extensions/modrinth.rs rename to src/models/extensions/modrinth.rs index a165d2d..7d5a8bd 100644 --- a/src/config/models/extensions/modrinth.rs +++ b/src/models/extensions/modrinth.rs @@ -1,11 +1,11 @@ -use log::info; use serde::Deserialize; use serde::Serialize; -use crate::config::models::model::ModelExtensions; -use crate::downloader::hash::ChooseHash; use crate::errors::error::{Error, Result}; use crate::not_found_plugin_error; +use crate::settings::extensions::plugin::Plugin; +use crate::tr::hash::ChooseHash; +use crate::tr::model::extension::ModelExtensions; ///# Example ///we have cdn like this: `https://cdn.modrinth.com/data/PROJECT_ID/versions/ID/NAME-LOADER-VERSION.jar` @@ -22,43 +22,44 @@ pub struct ModrinthData { } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct File { +struct File { pub hashes: Hashes, pub url: String, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct Hashes { +struct Hashes { pub sha1: String, pub sha512: String, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct Dependency { +struct Dependency { pub project_id: String, pub dependency_type: String, } impl ModelExtensions for ModrinthData { + type Ext = Plugin; + type Link = String; + type Version = String; async fn get_link( + ext: &Self::Ext, name: &str, - plugin: &crate::config::plugins::Plugin, - game_version: Option<&str>, - ) -> Result<(String, crate::downloader::hash::ChooseHash, String)> { + game_version: &str, + ) -> Result<(Self::Link, ChooseHash, Self::Version)> { let loader = "fabric"; let link: String = { // TODO: Make normal params! match game_version { - Some(game_version) => { - let channel = plugin.channel.get_str().await; - let link = format!("https://api.modrinth.com/v2/project/{}/version?game_versions=[\"{}\"]&loaders=[\"{}\"]&featured=true&version_type={}", name, game_version, loader, channel); - info!("Modrinth link: {}", &link); + "Latest" => { + let channel = ext.channel().get_str().await; + let link = format!("https://api.modrinth.com/v2/project/{}/version?&loaders=[\"{}\"]&featured=true&version_type={}", name, loader, channel); link } - None => { - let channel = plugin.channel.get_str().await; - let link = format!("https://api.modrinth.com/v2/project/{}/version?&loaders=[\"{}\"]&featured=true&version_type={}", name, loader, channel); - info!("Modrinth link: {}", &link); + _ => { + let channel = ext.channel().get_str().await; + let link = format!("https://api.modrinth.com/v2/project/{}/version?game_versions=[\"{}\"]&loaders=[\"{}\"]&featured=true&version_type={}", name, game_version, loader, channel); link } } diff --git a/src/config/models/mod.rs b/src/models/mod.rs similarity index 70% rename from src/config/models/mod.rs rename to src/models/mod.rs index 0562acf..69f8edd 100644 --- a/src/config/models/mod.rs +++ b/src/models/mod.rs @@ -1,3 +1,2 @@ pub mod cores; pub mod extensions; -pub mod model; diff --git a/src/config/models/model.rs b/src/models/model.rs similarity index 100% rename from src/config/models/model.rs rename to src/models/model.rs diff --git a/src/networkmanager/controller.rs b/src/networkmanager/controller.rs deleted file mode 100644 index 0d9cb08..0000000 --- a/src/networkmanager/controller.rs +++ /dev/null @@ -1,14 +0,0 @@ -//config/lock/show - show lock [get] -///// -//config/core/change - change mod. Push MetaData -//config/extension/change?name="" - change extension. Push MetaData -///// -//config/change - push config and change it. [put] -///// -//config/core/check - check core -//config/extension/check?name="" - check extension -///// -//config/check - check all -//config/show - push all configuration -///// -//config/extension/delete?name="" - delete any plugin, mod. \ No newline at end of file diff --git a/src/networkmanager/mod.rs b/src/networkmanager/mod.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/query.rs b/src/query.rs new file mode 100644 index 0000000..32b9184 --- /dev/null +++ b/src/query.rs @@ -0,0 +1,51 @@ +use std::collections::HashMap; + +use crate::tr::hash::ChooseHash; + +#[derive(Default, PartialEq)] +pub struct Query { + query: HashMap, +} +impl Query { + /// Check Data and add it if is't same + async fn push(&mut self, name: String, data: QueryData) { + match self.query.get_mut(&name) { + Some(e) => { + if data != *e { + *e = data; + } + } + None => { + self.query.insert(name, data); + } + } + } + + pub fn query(&self) -> &HashMap { + &self.query + } + + pub fn query_mut(&mut self) -> &mut HashMap { + &mut self.query + } + + pub fn set_query(&mut self, query: HashMap) { + self.query = query; + } +} +#[derive(PartialEq)] +pub struct QueryData { + link: String, + hash: ChooseHash, + build: String, +} + +impl From<(String, ChooseHash, String)> for QueryData { + fn from(value: (String, ChooseHash, String)) -> Self { + Self { + link: value.0, + hash: value.1, + build: value.2, + } + } +} diff --git a/src/settings/additions.rs b/src/settings/additions.rs new file mode 100644 index 0000000..f6a6606 --- /dev/null +++ b/src/settings/additions.rs @@ -0,0 +1,12 @@ +use serde::{Deserialize, Serialize}; + + +#[derive(Deserialize, Serialize, Debug, Default, PartialEq)] +pub struct Additions { + // git link + #[serde(default)] + config_plugins_from: Option, + // git key + #[serde(default)] + key: Option, +} \ No newline at end of file diff --git a/src/settings/core.rs b/src/settings/core.rs new file mode 100644 index 0000000..9f6bcb9 --- /dev/null +++ b/src/settings/core.rs @@ -0,0 +1,85 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize, Debug, Default, PartialEq, Clone)] +#[serde(rename_all = "PascalCase")] +pub struct Core { + // Ядро + #[serde(default)] + provider: Provider, + // Версия ядра + #[serde(default = "version")] + version: String, + // Версия билда ядра + #[serde(default)] + build: Option, + // Приостановить обновление + #[serde(default)] + freeze: bool, + // Нужно обновить + #[serde(default)] + force_update: bool, +} + +fn version() -> String { + // warn!("We use default core path!"); + "Latest".to_string() +} + +impl Core { + pub fn provider(&self) -> &Provider { + &self.provider + } + + pub fn version(&self) -> &str { + self.version.as_ref() + } + + pub fn build(&self) -> Option<&String> { + self.build.as_ref() + } + + pub fn freeze(&self) -> bool { + self.freeze + } + + pub fn force_update(&self) -> bool { + self.force_update + } + + pub fn set_provider(&mut self, provider: Provider) { + self.provider = provider; + } + + pub fn set_version(&mut self, version: String) { + self.version = version; + } + + pub fn set_build(&mut self, build: Option) { + self.build = build; + } + + pub fn set_freeze(&mut self, freeze: bool) { + self.freeze = freeze; + } + + pub fn set_force_update(&mut self, force_update: bool) { + self.force_update = force_update; + } +} + +#[derive(Deserialize, Serialize, Debug, Default, PartialEq, Clone)] +#[serde(rename_all = "lowercase")] +pub enum Provider { + #[default] + Vanilla, // done + Paper, // done + Folia, // done + Purpur, // in work, good api + Fabric, // in work, api with out hash + //https://meta.fabricmc.net/v2/versions/game <- version check /v2/versions/intermediary give only stable + // or https://meta.fabricmc.net/v1/versions/game/1.14.4. Если нет версии, ответ пуст. + Forge, //no api + NeoForge, //worst api + Waterfall, // done + Velocity, // done +} diff --git a/src/settings/extensions/mod.rs b/src/settings/extensions/mod.rs new file mode 100644 index 0000000..90e1e05 --- /dev/null +++ b/src/settings/extensions/mod.rs @@ -0,0 +1,4 @@ +pub mod mode; +pub mod mods; +pub mod plugin; +pub mod plugins; diff --git a/src/settings/extensions/mode.rs b/src/settings/extensions/mode.rs new file mode 100644 index 0000000..1b4694c --- /dev/null +++ b/src/settings/extensions/mode.rs @@ -0,0 +1,4 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize, Debug, Default, PartialEq)] +pub struct Mode {} diff --git a/src/settings/extensions/mods.rs b/src/settings/extensions/mods.rs new file mode 100644 index 0000000..6cd5f76 --- /dev/null +++ b/src/settings/extensions/mods.rs @@ -0,0 +1,8 @@ +use std::collections::HashMap; + +use serde::{Deserialize, Serialize}; + +use super::mode::Mode; + +#[derive(Deserialize, Serialize, Debug, Default, PartialEq)] +pub struct Mods (HashMap); diff --git a/src/settings/extensions/plugin.rs b/src/settings/extensions/plugin.rs new file mode 100644 index 0000000..6480ef8 --- /dev/null +++ b/src/settings/extensions/plugin.rs @@ -0,0 +1,80 @@ +use serde::{Deserialize, Serialize}; + +use crate::errors::error::Result; +use crate::models::extensions::modrinth::ModrinthData; +use crate::tr::hash::ChooseHash; +use crate::tr::model::extension::ModelExtensions; + +#[derive(Deserialize, Serialize, Debug, PartialEq, Default)] +pub struct Plugin { + // Откуда качаем + #[serde(default)] + source: Sources, + // Версия + #[serde(default)] + version: Option, + // Стабильная, Альфа, Бета + #[serde(default)] + channel: Channels, + // Приостановить обновление + #[serde(default)] + freeze: bool, + // Нужно обновить + #[serde(default)] + force_update: bool, +} + +impl Plugin { + pub fn source(&self) -> &Sources { + &self.source + } + + pub fn version(&self) -> Option<&String> { + self.version.as_ref() + } + + pub fn channel(&self) -> &Channels { + &self.channel + } + + pub fn freeze(&self) -> bool { + self.freeze + } + + pub fn force_update(&self) -> bool { + self.force_update + } + pub fn get_link<'a>( + &'a self, + name: &'a str, + game_version: &'a str, + ) -> impl std::future::Future> + Send + 'a { + async move { + match self.source { + Sources::Spigot => todo!(), + Sources::Hangar => todo!(), + Sources::Modrinth => ModrinthData::get_link(self, name, game_version).await, + Sources::CurseForge => todo!(), + } + } + } +} + +#[derive(Deserialize, Serialize, Debug, Default, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum Sources { + Spigot, // bad api + Hangar, // ? + #[default] + Modrinth, // Favorite + CurseForge, // ? +} + +#[derive(Deserialize, Serialize, Debug, Default, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum Channels { + #[default] + Release, + Beta, + Alpha, +} diff --git a/src/settings/extensions/plugins.rs b/src/settings/extensions/plugins.rs new file mode 100644 index 0000000..8ee29f1 --- /dev/null +++ b/src/settings/extensions/plugins.rs @@ -0,0 +1,36 @@ +use std::collections::HashMap; + +use serde::{Deserialize, Serialize}; + +use crate::tr::{download::Download, save::Save}; + +use super::plugin::{Channels, Plugin}; + +#[derive(Deserialize, Serialize, Debug, Default, PartialEq)] +pub struct Plugins(HashMap); + + +impl Plugins { + pub fn new(items: HashMap) -> Self { + Self(items) + } + + pub fn items(&self) -> &HashMap { + &self.0 + } +} + +impl Channels { + pub async fn get_str(&self) -> &'static str { + match self { + Channels::Release => "release", + Channels::Beta => "beta", + Channels::Alpha => "alpha", + } + } +} + +impl Download for Plugin {} +impl Save for Plugin { + const PATH: &'static str = "./mods/"; +} diff --git a/src/settings/mod.rs b/src/settings/mod.rs new file mode 100644 index 0000000..84662ce --- /dev/null +++ b/src/settings/mod.rs @@ -0,0 +1,67 @@ +pub mod core; +pub mod extensions; +pub mod additions; + +use serde::{Deserialize, Serialize}; + +use crate::tr::{load::Load, save::Save}; + +use self::{ + additions::Additions, core::Core, extensions::{mods::Mods, plugins::Plugins} +}; +#[derive(Deserialize, Serialize, Debug, Default, PartialEq)] +pub struct Settings { + #[serde(default)] + core: Core, + #[serde(default)] + mods: Option, + #[serde(default)] + plugins: Option, + #[serde(default)] + addtions: Option, +} + +impl Settings { + pub fn core(&self) -> &Core { + &self.core + } + + pub fn mods(&self) -> Option<&Mods> { + self.mods.as_ref() + } + + pub fn plugins(&self) -> Option<&Plugins> { + self.plugins.as_ref() + } + + pub fn core_mut(&mut self) -> &mut Core { + &mut self.core + } + + pub fn mods_mut(&mut self) -> &mut Option { + &mut self.mods + } + + pub fn plugins_mut(&mut self) -> &mut Option { + &mut self.plugins + } + + pub fn set_core(&mut self, core: Core) { + self.core = core; + } + + pub fn set_mods(&mut self, mods: Option) { + self.mods = mods; + } + + pub fn set_plugins(&mut self, plugins: Option) { + self.plugins = plugins; + } +} + +impl Save for Settings { + const PATH: &'static str = "./settings.toml"; +} +impl Load for Settings { + const PATH: &'static str = "./settings.toml"; +} diff --git a/src/tr/download.rs b/src/tr/download.rs new file mode 100644 index 0000000..1fddee7 --- /dev/null +++ b/src/tr/download.rs @@ -0,0 +1,19 @@ +use bytes::Bytes; + +use crate::errors::error::Result; + +use super::hash::ChooseHash; +pub trait Download { + fn get_file( + &self, + link: String, + hash: ChooseHash, + ) -> impl std::future::Future> + Send { + async move { + let response = reqwest::get(link).await?; + let content = response.bytes().await?; + hash.calculate_hash(&*content).await?; + Ok(content) + } + } +} diff --git a/src/downloader/hash.rs b/src/tr/hash.rs similarity index 69% rename from src/downloader/hash.rs rename to src/tr/hash.rs index 2f4bb03..21ea6d4 100644 --- a/src/downloader/hash.rs +++ b/src/tr/hash.rs @@ -1,5 +1,8 @@ +use crate::errors::error::CompareHashError; +use crate::errors::error::{Error, Result}; use md5::Md5; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use sha1::Digest as Digest1; use sha1::Sha1; use sha2::Digest as Digest256; @@ -15,7 +18,10 @@ pub enum ChooseHash { } impl ChooseHash { - pub async fn calculate_hash(&self, mut reader: impl tokio::io::AsyncRead + Unpin) -> bool { + pub async fn calculate_hash( + &self, + mut reader: impl tokio::io::AsyncRead + Unpin, + ) -> Result<()> { match self { ChooseHash::SHA1(e) => { let mut hashed = ::new(); @@ -27,7 +33,11 @@ impl ChooseHash { hashed.update(&buffer[..n]); } let result = hashed.finalize(); - e.eq(&format!("{:x}", result)) + if e.eq(&format!("{:x}", result)) { + Ok(()) + } else { + Err(Error::CompareHash(CompareHashError::HashNotCompare())) + } } ChooseHash::SHA256(e) => { let mut hashed = ::new(); @@ -39,7 +49,11 @@ impl ChooseHash { hashed.update(&buffer[..n]); } let result = hashed.finalize(); - e.eq(&format!("{:x}", result)) + if e.eq(&format!("{:x}", result)) { + Ok(()) + } else { + Err(Error::CompareHash(CompareHashError::HashNotCompare())) + } } ChooseHash::MD5(e) => { let mut hashed = ::new(); @@ -51,9 +65,13 @@ impl ChooseHash { hashed.update(&buffer[..n]); } let result = hashed.finalize(); - e.eq(&format!("{:x}", result)) + if e.eq(&format!("{:x}", result)) { + Ok(()) + } else { + Err(Error::CompareHash(CompareHashError::HashNotCompare())) + } } - ChooseHash::None => true, + ChooseHash::None => Ok(()), } } } diff --git a/src/tr/load.rs b/src/tr/load.rs new file mode 100644 index 0000000..52a83eb --- /dev/null +++ b/src/tr/load.rs @@ -0,0 +1,20 @@ +use crate::errors::error::Result; +use serde::Deserialize; +use tokio::fs; +/// Загружаем с диска нужную нам структуру +pub trait Load { + const PATH: &'static str; + fn load() -> impl std::future::Future> + Send + where + for<'de> Self: Deserialize<'de>, + { + async move { + // Читаем с диска + let file = fs::read_to_string(Self::PATH).await?; + // Преобразуем в структуру + let item: Self = toml::from_str(&file)?; + // Выдача результата + Ok(item) + } + } +} diff --git a/src/tr/mod.rs b/src/tr/mod.rs new file mode 100644 index 0000000..421c002 --- /dev/null +++ b/src/tr/mod.rs @@ -0,0 +1,5 @@ +pub mod download; +pub mod hash; +pub mod load; +pub mod model; +pub mod save; diff --git a/src/tr/model/core.rs b/src/tr/model/core.rs new file mode 100644 index 0000000..2ce9485 --- /dev/null +++ b/src/tr/model/core.rs @@ -0,0 +1,11 @@ +use crate::errors::error::Result; +use crate::settings::core::Core; +use crate::tr::hash::ChooseHash; + +pub trait ModelCore { + type Link; + type Version; + fn get_link( + core: &Core, + ) -> impl std::future::Future> + Send; +} diff --git a/src/tr/model/extension.rs b/src/tr/model/extension.rs new file mode 100644 index 0000000..a6d8b06 --- /dev/null +++ b/src/tr/model/extension.rs @@ -0,0 +1,13 @@ +use crate::errors::error::Result; +use crate::tr::hash::ChooseHash; + +pub trait ModelExtensions { + type Ext; + type Link; + type Version; + fn get_link( + ext: &Self::Ext, + name: &str, + game_version: &str, + ) -> impl std::future::Future> + Send; +} diff --git a/src/tr/model/mod.rs b/src/tr/model/mod.rs new file mode 100644 index 0000000..26d3be5 --- /dev/null +++ b/src/tr/model/mod.rs @@ -0,0 +1,2 @@ +pub mod core; +pub mod extension; diff --git a/src/tr/save.rs b/src/tr/save.rs new file mode 100644 index 0000000..fb82ee7 --- /dev/null +++ b/src/tr/save.rs @@ -0,0 +1,61 @@ +use crate::errors::error::{Error, Result}; +use crate::not_found_path; +use bytes::Bytes; +use std::path::Path; +use tokio::fs::File; +use tokio::io::AsyncWriteExt; + +/// Сохраняем структуру на диск +pub trait Save { + const PATH: &'static str; + fn save(&self) -> impl std::future::Future> + Send + where + Self: serde::ser::Serialize + Sync, + { + async move { + { + let os_path = Path::new(Self::PATH); + // Проверить путь на исправность + if !os_path.exists() { + return not_found_path!(Self::PATH); + } + // Сериализуем в понятный человеку томл + let toml_content = toml::to_string_pretty(&self)?; + + // Откроем для записи + let mut file = File::create(os_path).await?; + + // Запишем файл + file.write_all(toml_content.as_bytes()).await?; + + Ok(()) + } + } + } + fn save_bytes( + &self, + bytes: Bytes, + name: &str, + ) -> impl std::future::Future> + Send { + async move { + { + // Конвертируем &str в Path + let path_to_dir = Path::new(Self::PATH); + // Проверить путь на исправность + if !path_to_dir.exists() { + return not_found_path!(Self::PATH); + } + // Добавляем имя к пути + let path_to_file = path_to_dir.join(name); + + // Откроем для записи + let mut file = File::create(path_to_file).await?; + + // Запишем файл + file.write_all(&bytes).await?; + + Ok(()) + } + } + } +}