Skip to content

Commit 6a04aa4

Browse files
committed
updated and fixed code, updated 'logger'
1 parent 443894b commit 6a04aa4

File tree

5 files changed

+48
-37
lines changed

5 files changed

+48
-37
lines changed

src/add_file.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ pub mod add_fn
2222
// START POINT
2323
pub fn start(file_path: &String, unq_name: &String)
2424
{
25-
crate::log::logger::start("ADD ".to_string());
26-
2725
let time_date : [String; 2] = crate::time::time_fn::start();
2826

2927
let save_info : [String; 4] = [
@@ -34,7 +32,12 @@ pub mod add_fn
3432

3533

3634
let create_copy = crate::database::add::start(save_info);
37-
if create_copy == true { create_save(&unq_name, &file_path); }
38-
else { println!(":("); }
35+
if create_copy == true {
36+
create_save(&unq_name, &file_path);
37+
crate::log::logger::start("ADD ".to_string());
38+
} else {
39+
println!(":(");
40+
crate::log::logger::start("ADD -> ERROR".to_string());
41+
}
3942
}
4043
}

src/database/mod.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ pub mod del
104104

105105
match fs::remove_file(save_path) {
106106
Err(error) => println!("{:?}", error.kind()),
107-
Ok(_) => println!("The save was successfully deleted !"),
107+
Ok(_) => {
108+
println!("The save was successfully deleted !");
109+
crate::log::logger::start("DELETE".to_string());
110+
}
108111
}
109112
}
110113

@@ -119,7 +122,10 @@ pub mod del
119122
writeln!(file, "{}", res);
120123
}
121124
}
122-
} else { println!("some error"); }
125+
} else {
126+
println!("Error when deleting. Something went wrong :(");
127+
crate::log::logger::start("DELETE -> ERROR".to_string());
128+
}
123129
}
124130

125131

@@ -131,6 +137,25 @@ pub mod del
131137

132138
pub mod slc
133139
{
140+
// PACKAGES
141+
use std::fs;
142+
use std::io::Write;
143+
144+
pub fn write_content(file_path: &String, file_name: &String)
145+
{
146+
let new_file_name = format!("rustix/saves/{:02}.txt", file_name);
147+
match fs::read_to_string(new_file_name) {
148+
Err(error) => println!("{:?}", error.kind()),
149+
Ok(x) => {
150+
let mut f = fs::File::create(file_path).expect("Unable to create file");
151+
f.write_all(x.as_bytes()).expect("Unable to write data");
152+
153+
println!("To a file {:?} moved saving {:?}", file_path, file_name);
154+
},
155+
}
156+
}
157+
158+
134159
pub fn start(save_name: &String) -> (bool, String)
135160
{
136161
let saves_base = crate::database::get::start().unwrap();

src/delete.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
pub mod delete_fn
22
{
33
// START POINT
4-
pub fn start(save_name: String) {
5-
crate::log::logger::start("DELETE".to_string());
6-
crate::database::del::start(save_name);
7-
}
4+
pub fn start(save_name: String) { crate::database::del::start(save_name); }
85
}

src/initialize.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ pub mod init_fn
2626
// START POINT
2727
pub fn start() {
2828
match fs::create_dir("rustix") {
29-
Err(why) => println!("{:?} !", why.kind()),
29+
Err(why) => {
30+
println!("{:?} !", why.kind());
31+
crate::log::logger::start("INIT -> ERROR".to_string());
32+
}
3033
Ok(_) => {
3134
fs::File::create("rustix/log.txt");
3235
fs::File::create("rustix/init.yml");
3336
fs::File::create("rustix/storage.txt");
3437
fs::create_dir("rustix/saves");
3538
create_yaml();
39+
40+
crate::log::logger::start("INIT ".to_string());
3641
},
3742
}
38-
39-
crate::log::logger::start("INIT ".to_string());
4043
}
4144
}

src/select.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
11
pub mod select_fn
22
{
3-
// PACKAGES
4-
use std::fs;
5-
use std::io::Write;
6-
7-
8-
fn write_content(file_path: &String, file_name: &String)
9-
{
10-
let new_file_name = format!("rustix/saves/{:02}.txt", file_name);
11-
match fs::read_to_string(new_file_name) {
12-
Err(error) => println!("{:?}", error.kind()),
13-
Ok(x) => {
14-
let mut f = fs::File::create(file_path).expect("Unable to create file");
15-
f.write_all(x.as_bytes()).expect("Unable to write data");
16-
17-
println!("To a file {:?} moved saving {:?}", file_path, file_name);
18-
},
19-
}
20-
}
21-
22-
233
// START POINT
244
pub fn start(save_name: String)
255
{
26-
crate::log::logger::start("SELECT".to_string());
27-
286
let save_info : (bool, String) = crate::database::slc::start(&save_name);
297

30-
if save_info.0 == true { write_content(&save_info.1, &save_name); }
31-
else { println!("there is no save with this name !"); }
8+
if save_info.0 == true {
9+
crate::database::slc::write_content(&save_info.1, &save_name);
10+
crate::log::logger::start("SELECT".to_string());
11+
} else {
12+
println!("there is no save with this name !");
13+
crate::log::logger::start("SELECT -> ERROR".to_string());
14+
}
3215
}
3316
}

0 commit comments

Comments
 (0)