Skip to content

Commit

Permalink
feat: restructure project and hopefull fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
LeagueRaINi committed Nov 10, 2022
1 parent 9897e4b commit 7c3d105
Show file tree
Hide file tree
Showing 14 changed files with 565 additions and 233 deletions.
File renamed without changes
28 changes: 18 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
[package]
name = "aida64_keygen"
version = "0.1.1"
authors = ["LeagueRaINi"]
edition = "2021"
[workspace]

[dependencies]
rand = "0.7"
chrono = "0.4"
strum = "0.24"
strum_macros = "0.24"
members = [
"aida64-keys-cli",
"aida64-keys-gui",

"aida64-keys-lib",
]

[profile.release]
opt-level = 3
debug = false
rpath = false
debug-assertions = false
panic = 'abort'
incremental = false
overflow-checks = false
lto = true
codegen-units = 1
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
# **This is for educational purposes only!**
- this project contains methods for generating and verifying aida64 keys

![preview](https://github.com/LeagueRaINi/Aida64-Keygen/blob/master/resources/preview.gif)

**Thanks to:**
- approved for helping reverse some of this
- wildbook & veykril for helping me a lot converting this to rust
- moonshadow565 for explaining and simplifying some of the methods
- moonshadow565 for explaining and simplifying some of the methods
12 changes: 12 additions & 0 deletions aida64-keys-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "aida64-keys-cli"
version = "0.1.0"
authors = ["LeagueRaINi"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aida64-keys-lib = { path = "../aida64-keys-lib" }

strum = "0.24"
1 change: 1 addition & 0 deletions aida64-keys-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
![preview](../.github/resources/preview.gif)
8 changes: 8 additions & 0 deletions aida64-keys-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use aida64_keys_lib::{KeyEdition, License};
use strum::IntoEnumIterator;

fn main() {
for edition in KeyEdition::iter() {
println!("{:?} -> {edition}", License::new(edition).generate_string(true));
}
}
17 changes: 17 additions & 0 deletions aida64-keys-gui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "aida64-keys-gui"
version = "0.1.0"
authors = ["LeagueRaINi"]
edition = "2021"

[dependencies]
aida64-keys-lib = { path = "../aida64-keys-lib" }

egui-datepicker = { git = "https://github.com/LeagueRaINi/egui-datepicker", branch = "month-control-button" }

rand = "0.7"
chrono = "0.4"
eframe = "0.17"
strum = "0.24"
strum_macros = "0.24"
clipboard = "0.5"
1 change: 1 addition & 0 deletions aida64-keys-gui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Under Construction :construction:
167 changes: 167 additions & 0 deletions aida64-keys-gui/src/app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
use chrono::{Date, Duration, TimeZone, Utc};
use clipboard::{ClipboardContext, ClipboardProvider};
use eframe::{egui, epi};
use egui_datepicker::DatePicker;
use std::ops::{Add, Sub};
use strum::IntoEnumIterator;

use aida64_keys_lib::{KeyEdition, License};

pub struct App {
keys: Vec<String>,
key_amount: i32,
key_seats: i32,
key_edition: KeyEdition,
key_purchase: Date<Utc>,
key_expire: Date<Utc>,
key_expire_never: bool,
key_maintenance_expire: Date<Utc>,

clipboard: Option<ClipboardContext>,
}

impl Default for App {
fn default() -> Self {
Self {
keys: Vec::new(),
key_seats: 1,
key_amount: 1,
key_edition: KeyEdition::Extreme,
key_purchase: Utc::today(),
key_expire: Utc::today().add(Duration::days(1)),
key_expire_never: true,
key_maintenance_expire: Utc::today() + Duration::days(3658),

clipboard: ClipboardProvider::new().ok(),
}
}
}

impl epi::App for App {
fn name(&self) -> &str {
"Aida64 Key Generator"
}

fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.columns(2, |columns| {
columns[0].group(|ui| {
let available_size = ui.available_size();

ui.set_max_size(available_size);
ui.set_min_size(available_size);

ui.horizontal(|ui| {
if ui.button("Generate").clicked() {
self.keys.clear();

(0..self.key_amount).for_each(|_| {
let mut license = License::new(self.key_edition)
.with_seats(self.key_seats)
.with_purchase_date(self.key_purchase)
.with_maintenance_expiry(Duration::days(
self.key_maintenance_expire
.sub(self.key_purchase)
.num_days(),
));

if !self.key_expire_never {
println!("{:?}", self.key_expire);

license = license.with_license_expiry(Some(self.key_expire));
}

// TODO!: currently not dedupping
self.keys.push(license.generate_string(true));
});
}

ui.add(egui::DragValue::new(&mut self.key_amount).clamp_range(1..=1000));
});

ui.separator();
ui.horizontal(|ui| {
ui.add(egui::DragValue::new(&mut self.key_seats).clamp_range(1..=797));
ui.label("Seats");
});

egui::ComboBox::new("edition_combobox", "Edition")
.selected_text(self.key_edition.to_string())
.show_ui(ui, |ui| {
for edition in KeyEdition::iter() {
ui.selectable_value(
&mut self.key_edition,
edition,
edition.to_string(),
);
}
});

ui.horizontal(|ui| {
ui.add(
DatePicker::new("license_purchase_date", &mut self.key_purchase)
.min_date(Utc.ymd(2004, 1, 1))
.max_date(Utc.ymd(2099, 12, 31)),
);
ui.label("Purchase Date");
});

let min_date = self.key_purchase + Duration::days(1);
let max_date = self.key_purchase + Duration::days(3658);

self.key_expire = self.key_expire.clamp(min_date, max_date);
self.key_maintenance_expire =
self.key_maintenance_expire.clamp(min_date, max_date);

ui.horizontal(|ui| {
ui.add_enabled_ui(!self.key_expire_never, |ui| {
ui.add(
DatePicker::new("license_expire_date", &mut self.key_expire)
.min_date(min_date)
.max_date(max_date),
);
});

ui.label("Expire Date");
ui.checkbox(&mut self.key_expire_never, "No Expiry");
});

ui.horizontal(|ui| {
ui.add(
DatePicker::new(
"maintenance_expire_date",
&mut self.key_maintenance_expire,
)
.min_date(min_date)
.max_date(max_date),
);
ui.label("Maintenance Expire Date");
});
});

columns[1].group(|ui| {
let available_size = ui.available_size();

ui.set_max_size(available_size);
ui.set_min_size(available_size);

egui::ScrollArea::new([false, true]).show(ui, |ui| {
for key in &self.keys {
if ui
.selectable_label(
false,
egui::RichText::new(key).text_style(egui::TextStyle::Monospace),
)
.clicked()
{
if let Some(clipboard) = &mut self.clipboard {
let _ = clipboard.set_contents(key.to_string());
}
}
}
});
});
});
});
}
}
15 changes: 15 additions & 0 deletions aida64-keys-gui/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

mod app;

use crate::app::App;

fn main() {
let options = eframe::NativeOptions {
drag_and_drop_support: false,
resizable: false,
initial_window_size: Some(eframe::egui::Vec2::new(520.0, 300.0)),
..Default::default()
};
eframe::run_native(Box::new(App::default()), options);
}
12 changes: 12 additions & 0 deletions aida64-keys-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "aida64-keys-lib"
version = "0.1.0"
authors = ["LeagueRaINi"]
edition = "2021"

[dependencies]
rand = "0.7"
chrono = "0.4"
strum = "0.24"
strum_macros = "0.24"
thiserror = "1.0"
1 change: 1 addition & 0 deletions aida64-keys-lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Under Construction :construction:
Loading

0 comments on commit 7c3d105

Please sign in to comment.