mirror of
https://github.com/beerpiss/saekawa.git
synced 2024-11-13 18:20:51 +01:00
cargo fmt
This commit is contained in:
parent
3c938c7ef3
commit
62764997ce
@ -6,8 +6,8 @@ use serde::{Deserialize, Serialize};
|
||||
use snafu::{prelude::Snafu, ResultExt};
|
||||
|
||||
use crate::{
|
||||
consts::USER_AGENT,
|
||||
config::SaekawaConfig,
|
||||
consts::USER_AGENT,
|
||||
types::tachi::{
|
||||
api::{TachiFailureResponse, TachiResponse},
|
||||
api_returns::{ImportPollStatus, ImportResponse},
|
||||
|
@ -1,71 +1,70 @@
|
||||
mod music;
|
||||
pub mod upsert;
|
||||
|
||||
use serde::{de, Deserialize};
|
||||
|
||||
pub use self::upsert::UpsertUserAllRequest;
|
||||
|
||||
fn deserialize_bool<'de, D>(deserializer: D) -> Result<bool, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
{
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum BooleanishTypes {
|
||||
String(String),
|
||||
Bool(bool),
|
||||
Number(i32),
|
||||
}
|
||||
|
||||
let s: BooleanishTypes = de::Deserialize::deserialize(deserializer)?;
|
||||
|
||||
match s {
|
||||
BooleanishTypes::String(s) => match s.as_str() {
|
||||
"true" => Ok(true),
|
||||
"false" => Ok(false),
|
||||
_ => Err(de::Error::unknown_variant(&s, &["true", "false"])),
|
||||
},
|
||||
BooleanishTypes::Bool(b) => Ok(b),
|
||||
BooleanishTypes::Number(n) => Ok(n > 0),
|
||||
}
|
||||
}
|
||||
|
||||
mod serde_user_play_date {
|
||||
use chrono::NaiveDateTime;
|
||||
use serde::{ser, de};
|
||||
|
||||
const DT_FORMAT: &str = "%Y-%m-%d %H:%M:%S";
|
||||
|
||||
#[derive(Debug)]
|
||||
struct UserPlayDateVisitor;
|
||||
|
||||
pub fn serialize<S>(dt: &NaiveDateTime, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: ser::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&dt.format(DT_FORMAT).to_string())
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<NaiveDateTime, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(UserPlayDateVisitor)
|
||||
}
|
||||
|
||||
impl<'de> de::Visitor<'de> for UserPlayDateVisitor {
|
||||
type Value = NaiveDateTime;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(formatter, "a string in the format of \"{}\"", DT_FORMAT)
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
NaiveDateTime::parse_from_str(v, DT_FORMAT)
|
||||
.map_err(E::custom)
|
||||
}
|
||||
}
|
||||
}
|
||||
mod music;
|
||||
pub mod upsert;
|
||||
|
||||
use serde::{de, Deserialize};
|
||||
|
||||
pub use self::upsert::UpsertUserAllRequest;
|
||||
|
||||
fn deserialize_bool<'de, D>(deserializer: D) -> Result<bool, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
{
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum BooleanishTypes {
|
||||
String(String),
|
||||
Bool(bool),
|
||||
Number(i32),
|
||||
}
|
||||
|
||||
let s: BooleanishTypes = de::Deserialize::deserialize(deserializer)?;
|
||||
|
||||
match s {
|
||||
BooleanishTypes::String(s) => match s.as_str() {
|
||||
"true" => Ok(true),
|
||||
"false" => Ok(false),
|
||||
_ => Err(de::Error::unknown_variant(&s, &["true", "false"])),
|
||||
},
|
||||
BooleanishTypes::Bool(b) => Ok(b),
|
||||
BooleanishTypes::Number(n) => Ok(n > 0),
|
||||
}
|
||||
}
|
||||
|
||||
mod serde_user_play_date {
|
||||
use chrono::NaiveDateTime;
|
||||
use serde::{de, ser};
|
||||
|
||||
const DT_FORMAT: &str = "%Y-%m-%d %H:%M:%S";
|
||||
|
||||
#[derive(Debug)]
|
||||
struct UserPlayDateVisitor;
|
||||
|
||||
pub fn serialize<S>(dt: &NaiveDateTime, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: ser::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&dt.format(DT_FORMAT).to_string())
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<NaiveDateTime, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(UserPlayDateVisitor)
|
||||
}
|
||||
|
||||
impl<'de> de::Visitor<'de> for UserPlayDateVisitor {
|
||||
type Value = NaiveDateTime;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(formatter, "a string in the format of \"{}\"", DT_FORMAT)
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
NaiveDateTime::parse_from_str(v, DT_FORMAT).map_err(E::custom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ pub struct UserData {
|
||||
|
||||
#[serde(
|
||||
default = "default_class_emblem",
|
||||
deserialize_with = "deserialize_option_number_from_string",
|
||||
deserialize_with = "deserialize_option_number_from_string"
|
||||
)]
|
||||
pub class_emblem_base: Option<u32>,
|
||||
|
||||
|
@ -58,7 +58,9 @@ impl UserPlaylog {
|
||||
};
|
||||
|
||||
let jst_offset = FixedOffset::east_opt(9 * 3600).expect("chrono should parse JST timezone");
|
||||
let jst_time = jst_offset.from_local_datetime(&self.user_play_date).unwrap();
|
||||
let jst_time = jst_offset
|
||||
.from_local_datetime(&self.user_play_date)
|
||||
.unwrap();
|
||||
|
||||
Ok(BatchManualScore {
|
||||
score: self.score,
|
||||
|
@ -18,7 +18,8 @@ use winapi::{
|
||||
minwindef::{BOOL, DWORD, HMODULE, LPVOID, PROC},
|
||||
ntdef::{LPCWSTR, LPSTR},
|
||||
winerror::{
|
||||
CERT_E_CHAINING, CERT_E_EXPIRED, CERT_E_UNTRUSTEDROOT, CRYPT_E_SECURITY_SETTINGS, TRUST_E_BAD_DIGEST, TRUST_E_EXPLICIT_DISTRUST, TRUST_E_NOSIGNATURE
|
||||
CERT_E_CHAINING, CERT_E_EXPIRED, CERT_E_UNTRUSTEDROOT, CRYPT_E_SECURITY_SETTINGS,
|
||||
TRUST_E_BAD_DIGEST, TRUST_E_EXPLICIT_DISTRUST, TRUST_E_NOSIGNATURE,
|
||||
},
|
||||
},
|
||||
um::{
|
||||
@ -172,9 +173,7 @@ struct UpdateInformation {
|
||||
/// and the hook should uninject itself so a newer version can load in.
|
||||
#[allow(clippy::result_large_err)]
|
||||
pub fn self_update(module: &LibraryHandle) -> Result<bool, SelfUpdateError> {
|
||||
let agent = ureq::builder()
|
||||
.user_agent(USER_AGENT)
|
||||
.build();
|
||||
let agent = ureq::builder().user_agent(USER_AGENT).build();
|
||||
|
||||
info!("Checking for updates...");
|
||||
let response = agent
|
||||
@ -371,7 +370,10 @@ pub fn self_update(module: &LibraryHandle) -> Result<bool, SelfUpdateError> {
|
||||
let handle = CreateThread(
|
||||
ptr::null_mut(),
|
||||
0,
|
||||
Some(std::mem::transmute::<PROC, unsafe extern "system" fn(*mut winapi::ctypes::c_void) -> u32>(updater_start_address)),
|
||||
Some(std::mem::transmute::<
|
||||
PROC,
|
||||
unsafe extern "system" fn(*mut winapi::ctypes::c_void) -> u32,
|
||||
>(updater_start_address)),
|
||||
heap as *mut _,
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
|
Loading…
Reference in New Issue
Block a user