feat: create a pre-commented config file if possible

This commit is contained in:
beerpiss 2024-06-27 00:03:07 +07:00
parent 30b00c242e
commit ee849ca846
2 changed files with 36 additions and 47 deletions

View File

@ -1,54 +1,36 @@
[general]
# Set to 'false' to disable the hook
enable = true
# Whether the hook should export your class medals and emblems or not.
# Whether the hook should export class medals (dans) and emblems.
export_class = true
# Whether the hook should export PBs. This should be used as a last resort, if
# you cannot import scores from your network, since this provides less data
# and sends only one pre-joined score per chart. Will only work once every session; you'll
# need to restart the game to do it again.
export_pbs = false
# Whether FAILED should override FULL COMBO and ALL JUSTICE.
# Whether FAILED lamps should override FULL COMBO and ALL JUSTICE.
# Not recommended, but it's an option.
fail_over_lamp = false
# Timeout for web requests, in milliseconds
timeout = 30000
# Timeout for web requests, in milliseconds. If your network connection
# to Tachi is unstable, you might want to bump this up.
timeout = 3000
# Whether the hook should update itself when a new update is found.
auto_update = true
# The directory/folder to store failed imports due to network
# connectivity issues. It will not save any imports rejected
# by Tachi for other reasons.
failed_import_dir = "failed_saekawa_imports"
[cards]
# **DOES NOT WORK FOR WHITELISTING PBS!!**
#
# Access codes that should be whitelisted
# If this is empty, all cards will be whitelisted
# There should be no whitespace between the digits
#
# example: whitelist = ["00001111222233334444"]
whitelist = []
# Tachi API keys go here. You can set a default API key for all
# cards using the `default` key:
# default = "example-api-key"
# You can also set the API key that will be used for a specific access code
# (useful for shared setups):
# "00001111222233334444" = "example-api-key-1"
# "55556666777788889999" = "example-api-key-2"
# The `default` key can also be removed, discarding any scores
# that do not come from the list of access codes configured.
[crypto]
# Since CRYSTAL+, the game employs network encryption. If you do not wish to
# patch out encryption from your game, you will need to fill in these values.
#
# All values are in hex strings.
key = ""
iv = ""
# Salt for deriving hashed API endpoint names. Not necessary on PARADISE LOST
# and older. For CHUNITHM NEW and later versions, this must be set if encryption
# is not patched out, otherwise the hook will be active but doing nothing, since
# it cannot recognize the score upload endpoint.
#
# This must also be a hex string.
salt = ""
# Number of PBKDF2 iterations to hash the endpoint URL. Set to 70 for CHUNITHM SUN
# and newer, and 44 for older versions.
iterations = 70
default = "your-api-key"
[tachi]
# Tachi instance base URL
base_url = "https://kamai.tachi.ac"
# Tachi status endpoint
status = "/api/v1/status"
# Tachi score import endpoint
import = "/ir/direct-manual/import"
# Your Tachi API key
api_key = "your-key-here"
# The base URL of the Tachi instance to submit scores to.
base_url = "https://kamai.tachi.ac/"

View File

@ -1,7 +1,7 @@
mod defaults;
mod migrate;
use std::{collections::HashMap, fs::File, path::PathBuf, str::FromStr};
use std::{collections::HashMap, fs::File, io::Write, path::{Path, PathBuf}, str::FromStr};
use log::{info, warn};
use migrate::OldSaekawaConfig;
@ -37,6 +37,13 @@ pub enum MigrationError {
impl SaekawaConfig {
pub fn load() -> Result<SaekawaConfig, ConfigLoadError> {
if !Path::new("saekawa.toml").exists() {
// We don't really care about the error here, since Confy will autogenerate a
// default configuration file anyways. That one just doesn't have comments.
let _ = File::create_new("saekawa.toml")
.and_then(|mut file| file.write_all(include_bytes!("../../res/saekawa.toml")));
}
let result = confy::load_path::<SaekawaConfig>("saekawa.toml");
match result {