-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathutils.rs
More file actions
161 lines (146 loc) · 5.19 KB
/
Copy pathutils.rs
File metadata and controls
161 lines (146 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
use aes::Aes128;
use aes::cipher::Array;
use aes::cipher::{BlockCipherEncrypt, KeyInit};
use iced::Theme;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
pub fn get_devices_path() -> PathBuf {
let data_dir = std::env::var("XDG_DATA_HOME")
.unwrap_or_else(|_| format!("{}/.local/share", std::env::var("HOME").unwrap_or_default()));
PathBuf::from(data_dir)
.join("librepods")
.join("devices.json")
}
pub fn get_preferences_path() -> PathBuf {
let config_dir = std::env::var("XDG_CONFIG_HOME")
.unwrap_or_else(|_| format!("{}/.config", std::env::var("HOME").unwrap_or_default()));
PathBuf::from(config_dir)
.join("librepods")
.join("preferences.json")
}
pub fn get_app_settings_path() -> PathBuf {
let home = std::env::var("HOME").unwrap_or_default();
let config_dir = std::env::var("XDG_CONFIG_HOME")
.unwrap_or_else(|_| format!("{}/.config", home));
let data_dir = std::env::var("XDG_DATA_HOME")
.unwrap_or_else(|_| format!("{}/.local/share", home));
let new_path = PathBuf::from(&config_dir)
.join("librepods")
.join("app_settings.json");
let old_path = PathBuf::from(&data_dir)
.join("app_settings.json");
// create new path if needed
if !new_path.exists() {
if let Some(parent) = new_path.parent() {
let _ = std::fs::create_dir_all(parent);
}
}
// migrate if needed
if old_path.exists() {
if std::fs::copy(&old_path, &new_path).is_ok() {
let _ = std::fs::remove_file(&old_path);
}
}
new_path
}
fn e(key: &[u8; 16], data: &[u8; 16]) -> [u8; 16] {
let mut swapped_key = *key;
swapped_key.reverse();
let mut swapped_data = *data;
swapped_data.reverse();
let cipher = Aes128::new(&Array::from(swapped_key));
let mut block = Array::from(swapped_data);
cipher.encrypt_block(&mut block);
let mut result: [u8; 16] = block.into();
result.reverse();
result
}
pub fn ah(k: &[u8; 16], r: &[u8; 3]) -> [u8; 3] {
let mut r_padded = [0u8; 16];
r_padded[..3].copy_from_slice(r);
let encrypted = e(k, &r_padded);
let mut hash = [0u8; 3];
hash.copy_from_slice(&encrypted[..3]);
hash
}
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub enum MyTheme {
Light,
Dark,
Dracula,
Nord,
SolarizedLight,
SolarizedDark,
GruvboxLight,
GruvboxDark,
CatppuccinLatte,
CatppuccinFrappe,
CatppuccinMacchiato,
CatppuccinMocha,
TokyoNight,
TokyoNightStorm,
TokyoNightLight,
KanagawaWave,
KanagawaDragon,
KanagawaLotus,
Moonfly,
Nightfly,
Oxocarbon,
Ferra,
}
impl std::fmt::Display for MyTheme {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Light => "Light",
Self::Dark => "Dark",
Self::Dracula => "Dracula",
Self::Nord => "Nord",
Self::SolarizedLight => "Solarized Light",
Self::SolarizedDark => "Solarized Dark",
Self::GruvboxLight => "Gruvbox Light",
Self::GruvboxDark => "Gruvbox Dark",
Self::CatppuccinLatte => "Catppuccin Latte",
Self::CatppuccinFrappe => "Catppuccin Frappé",
Self::CatppuccinMacchiato => "Catppuccin Macchiato",
Self::CatppuccinMocha => "Catppuccin Mocha",
Self::TokyoNight => "Tokyo Night",
Self::TokyoNightStorm => "Tokyo Night Storm",
Self::TokyoNightLight => "Tokyo Night Light",
Self::KanagawaWave => "Kanagawa Wave",
Self::KanagawaDragon => "Kanagawa Dragon",
Self::KanagawaLotus => "Kanagawa Lotus",
Self::Moonfly => "Moonfly",
Self::Nightfly => "Nightfly",
Self::Oxocarbon => "Oxocarbon",
Self::Ferra => "Ferra",
})
}
}
impl From<MyTheme> for Theme {
fn from(my_theme: MyTheme) -> Self {
match my_theme {
MyTheme::Light => Theme::Light,
MyTheme::Dark => Theme::Dark,
MyTheme::Dracula => Theme::Dracula,
MyTheme::Nord => Theme::Nord,
MyTheme::SolarizedLight => Theme::SolarizedLight,
MyTheme::SolarizedDark => Theme::SolarizedDark,
MyTheme::GruvboxLight => Theme::GruvboxLight,
MyTheme::GruvboxDark => Theme::GruvboxDark,
MyTheme::CatppuccinLatte => Theme::CatppuccinLatte,
MyTheme::CatppuccinFrappe => Theme::CatppuccinFrappe,
MyTheme::CatppuccinMacchiato => Theme::CatppuccinMacchiato,
MyTheme::CatppuccinMocha => Theme::CatppuccinMocha,
MyTheme::TokyoNight => Theme::TokyoNight,
MyTheme::TokyoNightStorm => Theme::TokyoNightStorm,
MyTheme::TokyoNightLight => Theme::TokyoNightLight,
MyTheme::KanagawaWave => Theme::KanagawaWave,
MyTheme::KanagawaDragon => Theme::KanagawaDragon,
MyTheme::KanagawaLotus => Theme::KanagawaLotus,
MyTheme::Moonfly => Theme::Moonfly,
MyTheme::Nightfly => Theme::Nightfly,
MyTheme::Oxocarbon => Theme::Oxocarbon,
MyTheme::Ferra => Theme::Ferra,
}
}
}