This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Теперь не нужно передавать инстанс обьекта через аргументы функции
- Loading branch information
Showing
19 changed files
with
203 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,89 @@ | ||
mod config; | ||
mod defunct; | ||
pub mod dictionary; | ||
mod downloader; | ||
mod manager; | ||
mod model; | ||
|
||
use std::{fs::File, io::Write}; | ||
|
||
use config::ConfigMessages; | ||
use defunct::DefunctMessages; | ||
use downloader::DownloaderMessages; | ||
use log::{error, warn}; | ||
use manager::ManagerMessages; | ||
use model::ModelMessages; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::tr::load::Load; | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct MessageDictionary { | ||
intro: String, | ||
downloader: DownloaderMessages, | ||
manager: ManagerMessages, | ||
config: ConfigMessages, | ||
model: ModelMessages, | ||
defunct: DefunctMessages, | ||
} | ||
|
||
impl Default for MessageDictionary { | ||
fn default() -> Self { | ||
Self { | ||
intro: "MDM ready to work!".into(), | ||
downloader: DownloaderMessages::default(), | ||
manager: ManagerMessages::default(), | ||
config: ConfigMessages::default(), | ||
model: ModelMessages::default(), | ||
defunct: DefunctMessages::default(), | ||
} | ||
} | ||
} | ||
impl MessageDictionary { | ||
pub fn get_dict() -> crate::errors::error::Result<Self> { | ||
'_default_language_scope: { | ||
let path = <MessageDictionary as Load>::PATH; | ||
if File::open(path).is_err() { | ||
let default = MessageDictionary::default(); | ||
warn!("Create default language file"); | ||
let mut file = File::create(path)?; | ||
let toml_default = toml::to_string_pretty(&default)?; | ||
file.write_all(toml_default.as_bytes())?; | ||
} | ||
} | ||
match MessageDictionary::load_sync() { | ||
Ok(e) => Ok(e), | ||
Err(e) => { | ||
error!("MessageDictionary: {}", e); | ||
warn!("Load default Dictionary"); | ||
Ok(MessageDictionary::default()) | ||
} | ||
} | ||
} | ||
|
||
pub fn intro(&self) -> &str { | ||
&self.intro | ||
} | ||
|
||
pub fn downloader(&self) -> &DownloaderMessages { | ||
&self.downloader | ||
} | ||
|
||
pub fn config(&self) -> &ConfigMessages { | ||
&self.config | ||
} | ||
pub fn manager(&self) -> &ManagerMessages { | ||
&self.manager | ||
} | ||
|
||
pub fn model(&self) -> &ModelMessages { | ||
&self.model | ||
} | ||
|
||
pub fn defunct(&self) -> &DefunctMessages { | ||
&self.defunct | ||
} | ||
} | ||
|
||
impl Load for MessageDictionary { | ||
const PATH: &'static str = "dictionary.toml"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.