use std::path::PathBuf;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("tdata folder not found: {path}")]
FolderNotFound { path: PathBuf },
#[error("required file not found: {file} in {folder}")]
FileNotFound { file: String, folder: PathBuf },
#[error("key file not found in tdata folder")]
KeyFileNotFound,
#[error("decryption failed: wrong passcode or corrupted data")]
DecryptionFailed,
#[error("tdata is password-protected, passcode required")]
PasscodeRequired,
#[error("invalid passcode")]
InvalidPasscode,
#[error("QDataStream parse error: {message}")]
QDataStreamError { message: String },
#[error("unexpected end of data at offset {offset}")]
UnexpectedEof { offset: u64 },
#[error("invalid UTF-16 string data")]
InvalidUtf16,
#[error("invalid data format: {message}")]
InvalidFormat { message: String },
#[error("no accounts found in tdata")]
NoAccounts,
#[error("account index {index} out of range (max: {max})")]
AccountIndexOutOfRange { index: usize, max: usize },
#[error("checksum mismatch: data may be corrupted")]
ChecksumMismatch,
#[error("unsupported tdata version: {version}")]
UnsupportedVersion { version: u32 },
#[error("failed to extract auth key: {reason}")]
AuthKeyExtractionFailed { reason: String },
}
impl Error {
pub fn qdatastream(msg: impl Into<String>) -> Self {
Self::QDataStreamError {
message: msg.into(),
}
}
pub fn invalid_format(msg: impl Into<String>) -> Self {
Self::InvalidFormat {
message: msg.into(),
}
}
pub fn auth_key_failed(reason: impl Into<String>) -> Self {
Self::AuthKeyExtractionFailed {
reason: reason.into(),
}
}
}