From 0895aac99b2ea6b0bbaca1da6f5f34d145102699 Mon Sep 17 00:00:00 2001 From: Filipe Rodrigues Date: Sun, 3 May 2020 10:55:54 +0100 Subject: [PATCH] Moved `panic.rs` to be shared among all binaries. Moved `init_logger` to `logger.rs`. Added a `card-editor` binary based on imgui (Abandoned). --- Cargo.lock | 886 ++++++++++++++++++++++++++++++++++- Cargo.toml | 22 + src/card-editor/cli.rs | 41 ++ src/card-editor/main.rs | 282 +++++++++++ src/extractor/main.rs | 28 +- src/logger.rs | 27 ++ src/{extractor => }/panic.rs | 0 src/patcher/main.rs | 28 +- src/patcher/panic.rs | 31 -- 9 files changed, 1245 insertions(+), 100 deletions(-) create mode 100644 src/card-editor/cli.rs create mode 100644 src/card-editor/main.rs create mode 100644 src/logger.rs rename src/{extractor => }/panic.rs (100%) delete mode 100644 src/patcher/panic.rs diff --git a/Cargo.lock b/Cargo.lock index 388d5d3..2c58cb7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,25 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "andrew" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7f09f89872c2b6b29e319377b1fbe91c6f5947df19a25596e121cf19a7b35e" +dependencies = [ + "bitflags", + "line_drawing", + "rusttype 0.7.9", + "walkdir", + "xdg", + "xml-rs", +] + +[[package]] +name = "android_glue" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407" + [[package]] name = "ansi_term" version = "0.11.0" @@ -9,6 +29,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "approx" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3" +dependencies = [ + "num-traits", +] + [[package]] name = "arrayref" version = "0.3.6" @@ -47,6 +76,28 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +[[package]] +name = "backtrace" +version = "0.3.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e692897359247cc6bb902933361652380af0f1b7651ae5c5013407f30e109e" +dependencies = [ + "backtrace-sys", + "cfg-if", + "libc", + "rustc-demangle", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fbebbe1c9d1f383a9cc7e8ccdb471b91c8d024ee9c2ca5b5346121fe8b4399" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "base64" version = "0.11.0" @@ -70,18 +121,40 @@ dependencies = [ "constant_time_eq", ] +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + [[package]] name = "byteorder" version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +[[package]] +name = "cc" +version = "1.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d" + [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "cgl" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55e7ec0b74fe5897894cbc207092c577e87c52f8a59e8ca8d97ef37551f60a49" +dependencies = [ + "gleam", + "libc", +] + [[package]] name = "chrono" version = "0.4.11" @@ -102,18 +175,70 @@ dependencies = [ "ansi_term", "atty", "bitflags", - "strsim", + "strsim 0.8.0", "textwrap", "unicode-width", "vec_map", ] +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "cocoa" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1706996401131526e36b3b49f0c4d912639ce110996f3ca144d78946727bce54" +dependencies = [ + "bitflags", + "block", + "core-foundation", + "core-graphics", + "foreign-types", + "libc", + "objc", +] + [[package]] name = "constant_time_eq" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[package]] +name = "core-foundation" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" + +[[package]] +name = "core-graphics" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56790968ab1c8a1202a102e6de05fc6e1ec87da99e4e93e9a7d13efbfc1e95a9" +dependencies = [ + "bitflags", + "core-foundation", + "foreign-types", + "libc", +] + [[package]] name = "crossbeam-utils" version = "0.7.2" @@ -142,16 +267,27 @@ dependencies = [ name = "dcb-tools" version = "0.1.0" dependencies = [ + "ascii", "clap", "dcb", "derive_more", "err-backtrace", "err-ext", "err-panic", + "float-ord", + "gfx", + "gfx_device_gl", + "gfx_window_glutin", + "glutin", + "imgui", + "imgui-gfx-renderer", + "imgui-winit-support", + "itertools", "log", "serde_yaml", "simplelog", "string-err", + "strsim 0.10.0", ] [[package]] @@ -160,8 +296,8 @@ version = "0.99.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2323f3f47db9a0e77ce7a300605d8d2098597fc451ed1a97bb1f6411bb550a7" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.10", + "quote 1.0.3", "syn", ] @@ -187,12 +323,42 @@ dependencies = [ "winapi", ] +[[package]] +name = "dlib" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e51249a9d823a4cb79e3eca6dcd756153e8ed0157b6c04775d04bf1b13b76a" +dependencies = [ + "libloading", +] + +[[package]] +name = "downcast-rs" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ba6eb47c2131e784a38b726eb54c1e1484904f013e576a25354d0124161af6" + +[[package]] +name = "draw_state" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33cf9537e2d06891448799b96d5a8c8083e0e90522a7fdabe6ebf4f41d79d651" +dependencies = [ + "bitflags", +] + [[package]] name = "dtoa" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3" +[[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" + [[package]] name = "err-backtrace" version = "0.1.0" @@ -206,8 +372,8 @@ name = "err-impl" version = "0.1.0" dependencies = [ "proc-macro-error", - "proc-macro2", - "quote", + "proc-macro2 1.0.10", + "quote 1.0.3", "syn", "synstructure", ] @@ -219,6 +385,27 @@ dependencies = [ "string-err", ] +[[package]] +name = "float-ord" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bad48618fdb549078c333a7a8528acb57af271d0433bdecd523eb620628364e" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "getrandom" version = "0.1.14" @@ -230,6 +417,161 @@ dependencies = [ "wasi", ] +[[package]] +name = "gfx" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01de46f9508a5c259aef105f0bff760ceddca832ea9c87ce03d1923e22ee155b" +dependencies = [ + "draw_state", + "gfx_core", + "log", +] + +[[package]] +name = "gfx_core" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75fbddaef2e12b4995900539d7209d947b988a3d87ee8737484d049b526e5441" +dependencies = [ + "bitflags", + "draw_state", + "log", +] + +[[package]] +name = "gfx_device_gl" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109c385fa380c18888633aa27d1e16cbae518469702a2f69dcb5f52d5378bebc" +dependencies = [ + "gfx_core", + "gfx_gl", + "log", +] + +[[package]] +name = "gfx_gl" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2d38164670920cfb7491bc0cf6f49f0554bd1c44cdbedc6c78d2bf91691ff5e" +dependencies = [ + "gl_generator 0.14.0", +] + +[[package]] +name = "gfx_window_glutin" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "310ff66f08b5a55854b18fea2f48bdbb75c94458207ba574c9723be78e97a646" +dependencies = [ + "gfx_core", + "gfx_device_gl", + "glutin", +] + +[[package]] +name = "gl_generator" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca98bbde17256e02d17336a6bdb5a50f7d0ccacee502e191d3e3d0ec2f96f84a" +dependencies = [ + "khronos_api", + "log", + "xml-rs", +] + +[[package]] +name = "gl_generator" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" +dependencies = [ + "khronos_api", + "log", + "xml-rs", +] + +[[package]] +name = "gleam" +version = "0.6.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cae10d7c99d0e77b4766e850a60898a17c1abaf01075531f1066f03dc7dc5fc5" +dependencies = [ + "gl_generator 0.13.1", +] + +[[package]] +name = "glutin" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5371b35b309dace06be1b81b5f6adb1c9de578b7dbe1e74bf7e4ef762cf6febd" +dependencies = [ + "android_glue", + "cgl", + "cocoa", + "core-foundation", + "core-graphics", + "glutin_egl_sys", + "glutin_emscripten_sys", + "glutin_gles2_sys", + "glutin_glx_sys", + "glutin_wgl_sys", + "lazy_static", + "libloading", + "objc", + "osmesa-sys", + "parking_lot 0.9.0", + "wayland-client", + "winapi", + "winit", +] + +[[package]] +name = "glutin_egl_sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "772edef3b28b8ad41e4ea202748e65eefe8e5ffd1f4535f1219793dbb20b3d4c" +dependencies = [ + "gl_generator 0.13.1", + "winapi", +] + +[[package]] +name = "glutin_emscripten_sys" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80de4146df76e8a6c32b03007bc764ff3249dcaeb4f675d68a06caf1bac363f1" + +[[package]] +name = "glutin_gles2_sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e853d96bebcb8e53e445225c3009758c6f5960d44f2543245f6f07b567dae0" +dependencies = [ + "gl_generator 0.13.1", + "objc", +] + +[[package]] +name = "glutin_glx_sys" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c243de74d6cf5ea100c788826d2fb9319de315485dd4b310811a663b3809c3" +dependencies = [ + "gl_generator 0.13.1", + "x11-dl", +] + +[[package]] +name = "glutin_wgl_sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a93dba7ee3a0feeac0f437141ff25e71ce2066bcf1a706acab1559ffff94eb6a" +dependencies = [ + "gl_generator 0.13.1", +] + [[package]] name = "hermit-abi" version = "0.1.10" @@ -239,6 +581,64 @@ dependencies = [ "libc", ] +[[package]] +name = "imgui" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a2d28cee2982d4dab4dd954c23be339ab1f98be4ff5a13ecd8fbfb47cdfa23a" +dependencies = [ + "bitflags", + "gfx", + "imgui-sys", + "lazy_static", + "parking_lot 0.10.2", +] + +[[package]] +name = "imgui-gfx-renderer" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "506eae7244a06bc18273634d1c30e070bdf592f5e7fb1f6871d062ad17a4b2ec" +dependencies = [ + "gfx", + "imgui", + "winapi", +] + +[[package]] +name = "imgui-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21a8693e0f66ecd2ec10e2f0ed4dc4519071495f350e6d8ddaf3e70351229257" +dependencies = [ + "cc", +] + +[[package]] +name = "imgui-winit-support" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5685c7d17aee9555377f9c4f7b6fac96899a7015f6b41950c613a3df034aff08" +dependencies = [ + "imgui", + "winit", +] + +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + +[[package]] +name = "khronos_api" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" + [[package]] name = "lazy_static" version = "1.4.0" @@ -251,12 +651,40 @@ version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" +[[package]] +name = "libloading" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" +dependencies = [ + "cc", + "winapi", +] + +[[package]] +name = "line_drawing" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc7ad3d82c845bdb5dde34ffdcc7a5fb4d2996e1e1ee0f19c33bc80e15196b9" +dependencies = [ + "num-traits", +] + [[package]] name = "linked-hash-map" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" +[[package]] +name = "lock_api" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.8" @@ -266,6 +694,44 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + +[[package]] +name = "memmap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "nix" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "void", +] + [[package]] name = "num-integer" version = "0.1.42" @@ -285,6 +751,95 @@ dependencies = [ "autocfg", ] +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + +[[package]] +name = "ordered-float" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" +dependencies = [ + "num-traits", +] + +[[package]] +name = "osmesa-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b" +dependencies = [ + "shared_library", +] + +[[package]] +name = "parking_lot" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" +dependencies = [ + "lock_api", + "parking_lot_core 0.6.2", + "rustc_version", +] + +[[package]] +name = "parking_lot" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" +dependencies = [ + "lock_api", + "parking_lot_core 0.7.2", +] + +[[package]] +name = "parking_lot_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" +dependencies = [ + "cfg-if", + "cloudabi", + "libc", + "redox_syscall", + "rustc_version", + "smallvec 0.6.13", + "winapi", +] + +[[package]] +name = "parking_lot_core" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" +dependencies = [ + "cfg-if", + "cloudabi", + "libc", + "redox_syscall", + "smallvec 1.4.0", + "winapi", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pkg-config" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" + [[package]] name = "proc-macro-error" version = "1.0.2" @@ -292,8 +847,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678" dependencies = [ "proc-macro-error-attr", - "proc-macro2", - "quote", + "proc-macro2 1.0.10", + "quote 1.0.3", "syn", "version_check", ] @@ -304,20 +859,38 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.10", + "quote 1.0.3", "syn", "syn-mid", "version_check", ] +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + [[package]] name = "proc-macro2" version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3" dependencies = [ - "unicode-xid", + "unicode-xid 0.2.0", +] + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", ] [[package]] @@ -326,7 +899,16 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.10", +] + +[[package]] +name = "raw-window-handle" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a441a7a6c80ad6473bd4b74ec1c9a4c951794285bf941c2126f607c72e48211" +dependencies = [ + "libc", ] [[package]] @@ -358,6 +940,71 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "rusttype" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "310942406a39981bed7e12b09182a221a29e0990f3e7e0c971f131922ed135d5" +dependencies = [ + "rusttype 0.8.3", +] + +[[package]] +name = "rusttype" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f61411055101f7b60ecf1041d87fb74205fb20b0c7a723f07ef39174cf6b4c0" +dependencies = [ + "approx", + "ordered-float", + "stb_truetype", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "serde" version = "1.0.106" @@ -373,8 +1020,8 @@ version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.10", + "quote 1.0.3", "syn", ] @@ -390,6 +1037,16 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "shared_library" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" +dependencies = [ + "lazy_static", + "libc", +] + [[package]] name = "simplelog" version = "0.7.5" @@ -401,6 +1058,47 @@ dependencies = [ "term", ] +[[package]] +name = "smallvec" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" +dependencies = [ + "maybe-uninit", +] + +[[package]] +name = "smallvec" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" + +[[package]] +name = "smithay-client-toolkit" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ccb8c57049b2a34d2cc2b203fa785020ba0129d31920ef0d317430adaf748fa" +dependencies = [ + "andrew", + "bitflags", + "dlib", + "lazy_static", + "memmap", + "nix", + "wayland-client", + "wayland-commons", + "wayland-protocols", +] + +[[package]] +name = "stb_truetype" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f77b6b07e862c66a9f3e62a07588fee67cd90a9135a2b942409f195507b4fb51" +dependencies = [ + "byteorder", +] + [[package]] name = "string-err" version = "0.1.1" @@ -413,15 +1111,21 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03" dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", + "proc-macro2 1.0.10", + "quote 1.0.3", + "unicode-xid 0.2.0", ] [[package]] @@ -430,8 +1134,8 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.10", + "quote 1.0.3", "syn", ] @@ -441,10 +1145,10 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.10", + "quote 1.0.3", "syn", - "unicode-xid", + "unicode-xid 0.2.0", ] [[package]] @@ -483,6 +1187,12 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + [[package]] name = "unicode-xid" version = "0.2.0" @@ -501,12 +1211,88 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "walkdir" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wayland-client" +version = "0.21.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49963e5f9eeaf637bfcd1b9f0701c99fd5cd05225eb51035550d4272806f2713" +dependencies = [ + "bitflags", + "downcast-rs", + "libc", + "nix", + "wayland-commons", + "wayland-scanner", + "wayland-sys", +] + +[[package]] +name = "wayland-commons" +version = "0.21.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c08896768b667e1df195d88a62a53a2d1351a1ed96188be79c196b35bb32ec" +dependencies = [ + "nix", + "wayland-sys", +] + +[[package]] +name = "wayland-protocols" +version = "0.21.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4afde2ea2a428eee6d7d2c8584fdbe8b82eee8b6c353e129a434cd6e07f42145" +dependencies = [ + "bitflags", + "wayland-client", + "wayland-commons", + "wayland-scanner", + "wayland-sys", +] + +[[package]] +name = "wayland-scanner" +version = "0.21.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf3828c568714507315ee425a9529edc4a4aa9901409e373e9e0027e7622b79e" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "xml-rs", +] + +[[package]] +name = "wayland-sys" +version = "0.21.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520ab0fd578017a0ee2206623ba9ef4afe5e8f23ca7b42f6acfba2f4e66b1628" +dependencies = [ + "dlib", + "lazy_static", +] + [[package]] name = "winapi" version = "0.3.8" @@ -523,12 +1309,70 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +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 = "winit" +version = "0.19.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e96eb4bb472fa43e718e8fa4aef82f86cd9deac9483a1e1529230babdb394a8" +dependencies = [ + "android_glue", + "backtrace", + "bitflags", + "cocoa", + "core-foundation", + "core-graphics", + "lazy_static", + "libc", + "log", + "objc", + "parking_lot 0.9.0", + "percent-encoding", + "raw-window-handle", + "smithay-client-toolkit", + "wayland-client", + "winapi", + "x11-dl", +] + +[[package]] +name = "x11-dl" +version = "2.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf981e3a5b3301209754218f962052d4d9ee97e478f4d26d4a6eced34c1fef8" +dependencies = [ + "lazy_static", + "libc", + "maybe-uninit", + "pkg-config", +] + +[[package]] +name = "xdg" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" + +[[package]] +name = "xml-rs" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a" + [[package]] name = "yaml-rust" version = "0.4.3" diff --git a/Cargo.toml b/Cargo.toml index 027aab7..f5dc41e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,22 @@ path = "src/extractor/main.rs" name = "patcher" path = "src/patcher/main.rs" +[[bin]] +name = "card-editor" +path = "src/card-editor/main.rs" + [dependencies] # Dcb dcb = { path = "../dcb" } +# Text +ascii = "1.0" +strsim = "0.10" + +# Helpers +float-ord = "0.2" +itertools = "0.9" + # Cmd clap = "2.33" @@ -33,6 +45,16 @@ derive_more = "0.99" # Serde serde_yaml = "0.8" +# Window / Ui +gfx = "0.18" +gfx_device_gl = "0.16" +gfx_window_glutin = "0.31" +glutin = "0.21" +#image = "0.23" +imgui = "0.3" +imgui-gfx-renderer = "0.3" +imgui-winit-support = { version = "0.3", default-features = false, features = ["winit-19"] } + # Build dependencies in release mode [profile.dev.package."*"] opt-level = 2 diff --git a/src/card-editor/cli.rs b/src/card-editor/cli.rs new file mode 100644 index 0000000..cebe9e7 --- /dev/null +++ b/src/card-editor/cli.rs @@ -0,0 +1,41 @@ +//! Cli manager for the extractor + +// Filesystem +use std::path::{Path, PathBuf}; + +// Clap +use clap::{App as ClapApp, Arg as ClapArg}; + +/// Data from the command line +#[derive(PartialEq, Clone, Debug)] +pub struct CliData { + /// The data directory + pub data_dir: PathBuf, +} + +impl CliData { + /// Constructs all of the cli data given and returns it + pub fn new() -> Self { + // Get all matches from cli + let matches = ClapApp::new("Dcb Card Editor") + .version("0.0") + .author("Filipe [...] <[...]@gmail.com>") + .about("Edits card data from Digimon Digital Card Battle extracted files") + .arg( + ClapArg::with_name("INPUT") + .help("Sets the Data directory to use") + .short("i") + .long("input") + .index(1) + .takes_value(true) + .required(true), + ) + .get_matches(); + + // Get the data dir as either an input or the current directory + let data_dir = matches.value_of("INPUT").map_or_else(|| Path::new("."), Path::new).to_path_buf(); + + // Return the cli data + Self { data_dir } + } +} diff --git a/src/card-editor/main.rs b/src/card-editor/main.rs new file mode 100644 index 0000000..302c531 --- /dev/null +++ b/src/card-editor/main.rs @@ -0,0 +1,282 @@ +//! Data patches +//! +//! # Details +//! Patches data to the game file from several other files. +//! +//! # Syntax +//! The executable may be called as `./patcher ` +//! +//! Use the command `./patcher --help` for more information. +//! +//! # Data patched +//! Currently only the following is patched: +//! - Card table + +// Features +#![feature(box_syntax, backtrace, panic_info_message, bool_to_option)] +// Lints +#![warn(clippy::restriction, clippy::pedantic, clippy::nursery)] +#![allow( + clippy::implicit_return, // We prefer implicit returns where possible + clippy::module_name_repetitions, // This happens often due to separating things into modules finely + clippy::wildcard_enum_match_arm, // We only use wildcards when we truly only care about some variants + clippy::result_expect_used, + clippy::option_expect_used, // We use expect when there is no alternative. + clippy::used_underscore_binding, // Useful for macros and such + clippy::integer_arithmetic, + clippy::float_arithmetic, // We need to use numbers my guy + clippy::as_conversions, + clippy::cast_sign_loss, + clippy::cast_possible_wrap, + clippy::cast_possible_truncation, // Needed for converting between stuff + clippy::items_after_statements, +)] + +// Modules +mod cli; +#[path = "../logger.rs"] +mod logger; +#[path = "../panic.rs"] +mod panic; + +// Gfx / GLutin +use gfx::Device; +use glutin::{Event, WindowEvent}; + +// Imgui +use imgui::{Context, FontConfig, FontGlyphRanges, FontSource, ImString}; +use imgui_gfx_renderer::{Renderer, Shaders}; +use imgui_winit_support::{HiDpiMode, WinitPlatform}; + +// Errors +use err_backtrace::ErrBacktraceExt; +use err_ext::ResultExt; +use err_panic::ErrorExtPanic; + +// Itertools +use itertools::Itertools; + +// Dcb +use dcb::game::{card::Table as CardTable, deck::Table as DeckTable}; + +#[allow(clippy::too_many_lines)] // TODO: Fix +fn main() { + // Initialize the logger and set the panic handler + logger::init(); + std::panic::set_hook(box panic::log_handler); + + // Get all data from cli + let cli::CliData { data_dir } = cli::CliData::new(); + + // Load all data files + let cards_table_file = std::fs::File::open(data_dir.join("cards.yaml")).panic_err_msg("Unable to open `cards.yaml`"); + let decks_table_file = std::fs::File::open(data_dir.join("decks.yaml")).panic_err_msg("Unable to open `decks.yaml`"); + + // Parse everything from yaml + let mut cards_table: CardTable = serde_yaml::from_reader(cards_table_file).panic_err_msg("Unable to parse `cards.yaml`"); + let decks_table: DeckTable = serde_yaml::from_reader(decks_table_file).panic_err_msg("Unable to parse `decks.yaml`"); + + // Create a new window + let mut events_loop = glutin::EventsLoop::new(); + let builder = glutin::WindowBuilder::new() + .with_title("Dcb Card Editor") + .with_dimensions(glutin::dpi::LogicalSize::new(1024.0, 768.0)); + let context = glutin::ContextBuilder::new().with_vsync(true); + let (windowed_context, mut device, mut factory, mut main_color, mut main_depth) = + gfx_window_glutin::init::(builder, context, &events_loop) + .panic_err_msg("Failed to initialize graphics"); + let mut encoder: gfx::Encoder<_, _> = factory.create_command_buffer().into(); + let shaders = { + let version = device.get_info().shading_language; + if version.is_embedded { + if version.major >= 3 { + Shaders::GlSlEs300 + } else { + Shaders::GlSlEs100 + } + } else if version.major >= 4 { + Shaders::GlSl400 + } else if version.major >= 3 { + if version.minor >= 2 { + Shaders::GlSl150 + } else { + Shaders::GlSl130 + } + } else { + Shaders::GlSl110 + } + }; + + // Create a new context for `imgui` + let mut imgui_context = Context::create(); + let mut platform = WinitPlatform::init(&mut imgui_context); + + // Add our font to imgui + let hidpi_factor = platform.hidpi_factor(); + let font_size = (13.0 * hidpi_factor) as f32; + imgui_context.fonts().add_font(&[ + FontSource::DefaultFontData { + config: Some(FontConfig { + size_pixels: font_size, + ..FontConfig::default() + }), + }, + FontSource::TtfData { + data: include_bytes!("../../resources/OpenSans-Regular.ttf"), + size_pixels: font_size, + config: Some(FontConfig { + rasterizer_multiply: 1.75, + glyph_ranges: FontGlyphRanges::japanese(), + ..FontConfig::default() + }), + }, + ]); + imgui_context.io_mut().font_global_scale = (1.0 / hidpi_factor) as f32; + + // Fix `sRGB` on style colors + let style = imgui_context.style_mut(); + #[allow(clippy::indexing_slicing)] // False positive, this is a `[f32; 4]` + for color in style.colors.iter_mut() { + color[0] = color[0].powf(2.2); + color[1] = color[1].powf(2.2); + color[2] = color[2].powf(2.2); + color[3] = 1.0 - (1.0 - color[3]).powf(2.2); + } + + // Attach the window to the platform + let mut renderer = Renderer::init(&mut imgui_context, &mut factory, shaders).panic_err_msg("Unable to initialize renderer"); + platform.attach_window(imgui_context.io_mut(), windowed_context.window(), HiDpiMode::Rounded); + + let mut last_frame = std::time::Instant::now(); + let mut run = true; + + // Get all digimon names as `ImString`s + let mut digimon_names: Vec<_> = cards_table.digimons.iter().map(|digimon| ImString::new(digimon.name.clone())).collect(); + let mut digimon_filter_idx = 0; + let mut digimon_filter_search = ImString::new(""); + + while run { + // Check for events + events_loop.poll_events(|event| { + platform.handle_event(imgui_context.io_mut(), windowed_context.window(), &event); + + if let Event::WindowEvent { event, .. } = event { + match event { + WindowEvent::Resized(_) => { + gfx_window_glutin::update_views(&windowed_context, &mut main_color, &mut main_depth); + }, + WindowEvent::CloseRequested => run = false, + _ => (), + } + } + }); + + // Prepare and execute ui frame + let io = imgui_context.io_mut(); + platform + .prepare_frame(io, windowed_context.window()) + .ignore_with_err(|err| log::warn!("Unable to prepare frame: {}", err)); + last_frame = io.update_delta_time(last_frame); + let ui = imgui_context.frame(); + { + ui.text("Digimon: "); + + ui.input_text(imgui::im_str!("Digimon Filter"), &mut digimon_filter_search) + .resize_buffer(true) + .build(); + + let digimon_filters: Vec<_> = digimon_names + .iter() + .enumerate() + .map(|(idx, string)| { + ( + float_ord::FloatOrd(1.0 - strsim::jaro(string.to_str(), digimon_filter_search.to_str())), + string, + idx, + ) + }) + .sorted() + .collect(); + + let digimon_filter_names: Vec<_> = digimon_filters + .iter() + .filter_map(|(value, string, _)| (digimon_filter_search.is_empty() || value.0 < 0.5).then_some(string)) + .collect(); + + ui.list_box( + imgui::im_str!("Digimon List"), + &mut digimon_filter_idx, + digimon_filter_names.as_slice(), + 4, + ); + + ui.separator(); + + /* + if let Some((_, _, idx)) = digimon_filters.get(digimon_filter_idx as usize) { + let idx = *idx; + std::mem::drop(digimon_filters); + if let Some(digimon_name_buffer) = digimon_names.get_mut(idx) { + if ui.input_text(imgui::im_str!("Name"), digimon_name_buffer).resize_buffer(true).build() { + if let Some(digimon) = cards_table.digimons.get_mut(idx) { + match ascii::AsciiString::from_ascii(digimon_name_buffer.to_string()) { + Ok(name) => { + digimon.name = name; + }, + Err(err) => { + ui.text(format!("Unable to set digimon name:\n{}", err.err_backtrace())); + }, + } + } + } + } + } + */ + + //if let Some(digimon_name) = digimon_names.iter_mut().enumerate().find(|(_, name)| name == ) + + /* + if let Some((idx, digimon)) = cards_table.digimons.iter_mut().enumerate().find(|(_, digimon)| { + digimon_filter_names + .get(digimon_filter_idx as usize) + .map_or(false, |&name| name.to_str() == digimon.name) + }) { + let mut name_buffer = ImString::new(digimon.name.clone()); + if ui.input_text(imgui::im_str!("Name"), &mut name_buffer).resize_buffer(true).build() { + match ascii::AsciiString::from_ascii(name_buffer.to_string()) { + Ok(name) => { + digimon.name = name; + if let Some(name) = digimon_names.get_mut(idx) { + *name = name_buffer.clone(); + } + }, + Err(err) => { + ui.text(format!("Unable to set digimon name:\n{}", err.err_backtrace())); + }, + } + } + } + */ + } + + // Clear, render everything and flush it out + encoder.clear(&main_color, [0.2, 0.2, 0.2, 1.0]); + platform.prepare_render(&ui, windowed_context.window()); + renderer + .render(&mut factory, &mut encoder, &mut main_color, ui.render()) + .ignore_with_err(|err| log::warn!("Unable to render: {}", err.err_backtrace())); + encoder.flush(&mut device); + windowed_context + .swap_buffers() + .ignore_with_err(|err| log::warn!("Unable to swap buffers: {}", err.err_backtrace())); + device.cleanup(); + } + + // Convert everything back to yaml + let cards_table_yaml = serde_yaml::to_string(&cards_table).panic_err_msg("Unable to serialize cards table to yaml"); + let decks_table_yaml = serde_yaml::to_string(&decks_table).panic_err_msg("Unable to serialize decks table to yaml"); + + // Ouput all data to devices + std::fs::write(&data_dir.join("cards.yaml"), cards_table_yaml).panic_err_msg("Unable to write cards table to file"); + std::fs::write(&data_dir.join("decks.yaml"), decks_table_yaml).panic_err_msg("Unable to write decks table to file"); +} diff --git a/src/extractor/main.rs b/src/extractor/main.rs index e998570..cbb5f7a 100644 --- a/src/extractor/main.rs +++ b/src/extractor/main.rs @@ -28,6 +28,9 @@ // Modules mod cli; +#[path = "../logger.rs"] +mod logger; +#[path = "../panic.rs"] mod panic; // Exports @@ -40,12 +43,11 @@ use dcb::{ }; // Errors -use err_ext::ResultExt; use err_panic::ErrorExtPanic; fn main() { // Initialize the logger and set the panic handler - init_logger(); + logger::init(); std::panic::set_hook(box panic::log_handler); // Get all data from cli @@ -68,25 +70,3 @@ fn main() { std::fs::write(&output_dir.join("cards.yaml"), cards_table_yaml).panic_err_msg("Unable to write cards table to file"); std::fs::write(&output_dir.join("decks.yaml"), decks_table_yaml).panic_err_msg("Unable to write decks table to file"); } - -/// Initializes the global logger -fn init_logger() { - use log::LevelFilter::{Info, Trace}; - use simplelog::{CombinedLogger, Config, SharedLogger, TermLogger, TerminalMode, WriteLogger}; - use std::convert::identity; - /// The type of logger required to pass to `CombinedLogger::init` - type BoxedLogger = Box; - - // All loggers to try and initialize - let loggers: Vec> = vec![ - TermLogger::new(Info, Config::default(), TerminalMode::Mixed).map(|logger| BoxedLogger::from(logger)), - std::fs::File::create("latest.log") - .ok() - .map(|file| WriteLogger::new(Trace, Config::default(), file)) - .map(|logger| BoxedLogger::from(logger)), - ]; - - // Filter all logger that actually work and initialize them - CombinedLogger::init(loggers.into_iter().filter_map(identity).collect()) - .ignore_with_err(|_| log::warn!("Logger was already initialized at the start of the program")); -} diff --git a/src/logger.rs b/src/logger.rs new file mode 100644 index 0000000..be7bff5 --- /dev/null +++ b/src/logger.rs @@ -0,0 +1,27 @@ +//! Logger initialization + +// Log +use log::LevelFilter; +use simplelog::{CombinedLogger, Config, SharedLogger, TermLogger, TerminalMode, WriteLogger}; + +// Error +use err_ext::ResultExt; + +/// The type of logger required to pass to `CombinedLogger::init` +type BoxedLogger = Box; + +/// Initializes the global logger +pub fn init() { + // All loggers to try and initialize + let loggers: Vec> = vec![ + TermLogger::new(LevelFilter::Warn, Config::default(), TerminalMode::Mixed).map(|logger| BoxedLogger::from(logger)), + std::fs::File::create("latest.log") + .ok() + .map(|file| WriteLogger::new(LevelFilter::Trace, Config::default(), file)) + .map(|logger| BoxedLogger::from(logger)), + ]; + + // Filter all logger that actually work and initialize them + CombinedLogger::init(loggers.into_iter().filter_map(std::convert::identity).collect()) + .ignore_with_err(|_| log::warn!("Logger was already initialized at the start of the program")); +} diff --git a/src/extractor/panic.rs b/src/panic.rs similarity index 100% rename from src/extractor/panic.rs rename to src/panic.rs diff --git a/src/patcher/main.rs b/src/patcher/main.rs index 4429111..09db450 100644 --- a/src/patcher/main.rs +++ b/src/patcher/main.rs @@ -27,6 +27,9 @@ // Modules mod cli; +#[path = "../logger.rs"] +mod logger; +#[path = "../panic.rs"] mod panic; // Exports @@ -39,12 +42,11 @@ use dcb::{ }; // Errors -use err_ext::ResultExt; use err_panic::ErrorExtPanic; fn main() { // Initialize the logger and set the panic handler - init_logger(); + logger::init(); std::panic::set_hook(box panic::log_handler); // Get all data from cli @@ -70,25 +72,3 @@ fn main() { cards_table.serialize(&mut game_file).panic_err_msg("Unable to serialize cards table"); decks_table.serialize(&mut game_file).panic_err_msg("Unable to serialize decks table"); } - -/// Initializes the global logger -fn init_logger() { - use log::LevelFilter::{Info, Trace}; - use simplelog::{CombinedLogger, Config, SharedLogger, TermLogger, TerminalMode, WriteLogger}; - use std::convert::identity; - /// The type of logger required to pass to `CombinedLogger::init` - type BoxedLogger = Box; - - // All loggers to try and initialize - let loggers: Vec> = vec![ - TermLogger::new(Info, Config::default(), TerminalMode::Mixed).map(|logger| BoxedLogger::from(logger)), - std::fs::File::create("latest.log") - .ok() - .map(|file| WriteLogger::new(Trace, Config::default(), file)) - .map(|logger| BoxedLogger::from(logger)), - ]; - - // Filter all logger that actually work and initialize them - CombinedLogger::init(loggers.into_iter().filter_map(identity).collect()) - .ignore_with_err(|_| log::warn!("Logger was already initialized at the start of the program")); -} diff --git a/src/patcher/panic.rs b/src/patcher/panic.rs deleted file mode 100644 index 10657ef..0000000 --- a/src/patcher/panic.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! Panic handlers for this application - -// Std -use std::{ - backtrace::{Backtrace, BacktraceStatus}, - error::Error, -}; -// Error backtrace -use err_backtrace::ErrBacktraceExt; - -/// Panic handler based on logging to the current initialization -pub fn log_handler(info: &std::panic::PanicInfo) { - // Log that this thread has panicked - log::error!("Thread \"{}\" panicked", std::thread::current().name().unwrap_or("[Unknown]")); - - // Log any message that came with the panic - log::info!("Panic message: {}", info.message().unwrap_or(&format_args!("None"))); - - // Print an error backtrace if we found any - if let Some(err) = info.payload().downcast_ref::>() { - log::info!("Error backtrace:\n{}", err.err_backtrace()); - } - - // And print a backtrace of where this panic occured. - let backtrace = Backtrace::force_capture(); - if backtrace.status() == BacktraceStatus::Captured { - log::info!("Backtrace:\n{}", backtrace); - } else { - log::info!("Unable to get backtrace: {}", backtrace); - } -}