Skip to content

Commit

Permalink
V1.2.1 (#25)
Browse files Browse the repository at this point in the history
* Add: Basic telemetry

Still have to add the uuid feature; and primary data like the os and variable statuses.

* Add: Advanced telemetry

* Fix: Only show telemetry ID if OS is supported

* Add: Time telemetry

* Add: Cross platform telemetry

* Fix: Clippy compliance

* Add: Application version telemetry

* Add all contribs file

* Add: Updated readme

* docs: add Xanthus58 as a contributor for ideas, code, and 2 more (#22)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* docs: add FlameOrchid as a contributor for code (#23)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* docs: add WolfenXVII as a contributor for test (#24)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
  • Loading branch information
Zephira58 and allcontributors[bot] authored Apr 1, 2023
1 parent 75a5a0c commit b41bd10
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/target
.env
65 changes: 62 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "FileSorterX"
version = "1.2.0"
version = "1.2.1"
edition = "2021"
authors = ["Xanthus58 <Xanthus58@protonmail.com>"]
description = "FileSorterX is an automatic file sorting application that sorts your files into folders based on their file extension. With FileSorterX, you can easily keep your files organized and find what you need quickly."
Expand All @@ -14,6 +14,8 @@ categories = ["command-line-utilities"]
clap = { version = "4.2.1", features = ["derive"] }
self_update = "0.36.0"
rand = "0.8.5"
dotenv_codegen = "0.15.0"
uuid = { version = "1.3.0", features = ["v4", "fast-rng", "macro-diagnostics"] }

[profile.release]
opt-level = 3
Expand Down
152 changes: 148 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
#![allow(unused_must_use)]

use clap::{Parser, Subcommand};
use std::{path::PathBuf, time::SystemTime};
use FileSorterX::{benchmark, create_files, custom_sort, sort_files, update_filesorterx};
use dotenv_codegen::dotenv;
use std::{
env,
path::PathBuf,
process::Command,
time::{Duration, SystemTime},
};
use uuid::*;
use FileSorterX::*;

/*
Made by Xanthus
Expand All @@ -18,6 +25,10 @@ struct Cli {
/// Sorts the files in the current directory
#[command(subcommand)]
command: Option<Commands>,

/// Disables telemetry
#[arg(short, long, default_value_t = false)]
disable_telemetry: bool,
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -83,9 +94,9 @@ enum Commands {
}

fn main() {
let start = SystemTime::now();
let cli = Cli::parse();

let start = SystemTime::now();
match &cli.command {
Some(Commands::Sort {
inputdir,
Expand All @@ -106,6 +117,21 @@ fn main() {
let end = SystemTime::now();
let duration = end.duration_since(start).unwrap();
println!("Time taken: {:?}", duration);

if !cli.disable_telemetry {
collect_telemetry(
inputdir.to_string(),
outputdir.to_string(),
&nesting_level.to_string(),
&use_alt.to_string(),
&verbose.to_string(),
&log.to_string(),
"N/A".to_string(),
"N/A",
"Sort Files",
duration,
);
}
}
Some(Commands::Customsort {
inputdir,
Expand All @@ -114,20 +140,138 @@ fn main() {
verbose,
log,
}) => {
let end = SystemTime::now();
let duration = end.duration_since(start).unwrap();
custom_sort(inputdir, outputdir, extension, *verbose, *log);
if !cli.disable_telemetry {
collect_telemetry(
inputdir.to_string(),
outputdir.to_string(),
"N/A",
"N/A",
&verbose.to_string(),
&log.to_string(),
extension.to_string(),
"N/A",
"Custom Sort",
duration,
);
}
}
Some(Commands::Create { amount }) => {
create_files(amount + 1);
let end = SystemTime::now();
let duration = end.duration_since(start).unwrap();
println!("Time taken: {:?}", duration);

if !cli.disable_telemetry {
collect_telemetry(
"N/A".to_string(),
"N/A".to_string(),
"N/A",
"N/A",
"N/A",
"N/A",
"N/A".to_string(),
amount.to_string().as_str(),
"Create Files",
duration,
);
}
}
Some(Commands::Update { .. }) => {
update_filesorterx().expect("Failed to update FileSorterX");

if !cli.disable_telemetry {
collect_telemetry(
"N/A".to_string(),
"N/A".to_string(),
"N/A",
"N/A",
"N/A",
"N/A",
"N/A".to_string(),
"N/A",
"Update",
Duration::from_secs(0),
);
}
}
Some(Commands::Benchmark { .. }) => {
println!("Time Taken: {:?}", benchmark());
let time = benchmark();
println!("Time Taken: {:?}", time);
if !cli.disable_telemetry {
collect_telemetry(
"N/A".to_string(),
"N/A".to_string(),
"N/A",
"N/A",
"N/A",
"N/A",
"N/A".to_string(),
"N/A",
"Benchmark",
time,
);
}
}
None => println!("No command provided. Use 'filesorterx --help' for more information."),
}
}

fn collect_telemetry(
inputdir: String,
outputdir: String,
nesting_level: &str,
use_alt: &str,
verbose: &str,
log: &str,
extension: String,
amount: &str,
cmd: &str,
time: Duration,
) {
let id = Uuid::new_v4();
let os = env::consts::OS;
let token = dotenv!("TELEMETRY_TOKEN");
let mut command = String::new();

command.push_str("'UUID: ");
command.push_str(&id.to_string());
command.push_str(" | OS: ");
command.push_str(os);
command.push_str(" | Command: ");
command.push_str(cmd);
command.push_str(" | Inputdir: ");
command.push_str(&inputdir);
command.push_str(" | OutputDir: ");
command.push_str(&outputdir);
command.push_str(" | Nesting Level: ");
command.push_str(nesting_level);
command.push_str(" | Use Alt: ");
command.push_str(use_alt);
command.push_str(" | Verbose: ");
command.push_str(verbose);
command.push_str(" | Logging: ");
command.push_str(log);
command.push_str(" | Extension: ");
command.push_str(&extension);
command.push_str(" | Amount: ");
command.push_str(amount);
command.push_str(" | Time Taken: ");
command.push_str(&time.as_secs_f64().to_string());
command.push_str(" | FileSorterX Version: ");
command.push_str(env!("CARGO_PKG_VERSION"));
command.push('\'');

Command::new("curl")
.arg("-A")
.arg(command)
.arg(token)
.arg("-k")
.output()
.expect("Failed to execute command");

println!("Telemetry ID: {}", id);
println!("Pleaes use this ID when reporting any issues.");
}

0 comments on commit b41bd10

Please sign in to comment.