Add checks to rename configs if required

This commit is contained in:
Luke D. Jones
2023-01-08 22:00:32 +13:00
parent ab3007d53d
commit 9cc62d63c9
7 changed files with 125 additions and 59 deletions

128
MANUAL.md
View File

@@ -117,60 +117,67 @@ I'm unsure of how many laptops this works on, so please try it.
An Aura config itself is a file with contents:
```json
{
"name": "aura-default",
"aura": [
{
"Breathe": {
"led_type": {
"Key": "W"
},
"start_colour1": [
255,
0,
20
```ron
(
name: "aura-default",
aura: (
effects: [
Breathe((
led: W,
start_colour1: (255, 0, 20),
start_colour2: (20, 255, 0),
speed: Low,
)),
Breathe((
led: A,
start_colour1: (255, 0, 20),
start_colour2: (20, 255, 0),
speed: Low,
)),
Breathe((
led: S,
start_colour1: (255, 0, 20),
start_colour2: (20, 255, 0),
speed: Low,
)),
Breathe((
led: D,
start_colour1: (255, 0, 20),
start_colour2: (20, 255, 0),
speed: Low,
)),
Breathe((
led: F,
start_colour1: (255, 0, 0),
start_colour2: (255, 0, 0),
speed: High,
)),
Static((
led: RCtrl,
colour: (0, 0, 255),
)),
Static((
led: LCtrl,
colour: (0, 0, 255),
)),
Static((
led: Esc,
colour: (0, 0, 255),
)),
DoomFlicker((
led: N9,
start_colour: (0, 0, 255),
max_percentage: 80,
min_percentage: 40,
)),
],
"start_colour2": [
20,
255,
0
],
"speed": "Low"
}
},
{
"Static": {
"led_type": {
"Key": "Esc"
},
"colour": [
0,
0,
255
]
}
},
{
"Flicker": {
"led_type": {
"Key": "N9"
},
"start_colour": [
0,
0,
255
],
"max_percentage": 80,
"min_percentage": 40
}
}
]
}
zoned: false,
),
)
```
If your laptop supports multizone, `"led_type"` can also be `"Zone": <one of the following>`
- `"None"`
If your laptop supports multizone, `"led"` can also be `"Zone": <one of the following>`
- `SingleZone` // Keyboards with only one zone
- `ZonedKbLeft` // keyboard left
- `ZonedKbLeftMid` // keyboard left-middle
- `ZonedKbRightMid` // etc
@@ -182,6 +189,25 @@ If your laptop supports multizone, `"led_type"` can also be `"Zone": <one of the
- `LightbarLeftCorner`
- `LightbarLeft`
Single zone example:
```ron
(
name: "aura-default",
aura: (
effects: [
DoomFlicker((
led: SingleZone,
start_colour: (200, 40, 5),
max_percentage: 80,
min_percentage: 40,
)),
],
zoned: true,
),
)
```
At the moment there are only three effects available as shown in the example. More will come in the future
but this may take me some time.

View File

@@ -31,6 +31,46 @@ where
.unwrap_or_else(|e| panic!("Could not create {:?} {e}", Self::config_dir()));
}
config.push(self.file_name());
let mut do_rename = !config.exists();
let mut cfg_old = config.clone();
// Migrating all configs to .ron format, so we do need to check for older ones
if do_rename {
warn!("Config {cfg_old:?} does not exist, looking for .cfg next");
cfg_old.pop();
let tmp = self.file_name();
let parts: Vec<_> = tmp.split('.').collect();
cfg_old.push(format!("{}.cfg", parts[0]));
}
if do_rename && cfg_old.exists() {
// Now we gotta rename it
warn!("Renaming {cfg_old:?} to {config:?}");
std::fs::rename(&cfg_old, &config).unwrap_or_else(|err| {
error!(
"Could not rename. Please remove {} then restart service: Error {}",
self.file_name(),
err
)
});
do_rename = false;
}
if do_rename && !cfg_old.exists() {
warn!("Config {cfg_old:?} does not exist, looking for .conf next");
cfg_old.pop();
let tmp = self.file_name();
let parts: Vec<_> = tmp.split('.').collect();
cfg_old.push(format!("{}.conf", parts[0]));
}
if do_rename && cfg_old.exists() {
// Now we gotta rename it
warn!("Renaming {cfg_old:?} to {config:?}");
std::fs::rename(&cfg_old, &config).unwrap_or_else(|err| {
error!(
"Could not rename. Please remove {} then restart service: Error {}",
self.file_name(),
err
)
});
}
config
}

View File

@@ -108,7 +108,7 @@ impl StdConfig for ConfigAnime {
}
fn file_name(&self) -> String {
format!("{}.cfg", self.name)
format!("{}.ron", self.name)
}
fn config_dir() -> std::path::PathBuf {
@@ -180,7 +180,7 @@ impl StdConfig for ConfigAura {
}
fn file_name(&self) -> String {
format!("{}.cfg", self.name)
format!("{}.ron", self.name)
}
fn config_dir() -> std::path::PathBuf {
@@ -208,7 +208,7 @@ impl StdConfig for ConfigBase {
}
fn file_name(&self) -> String {
"rog-user.cfg".to_owned()
"rog-user.ron".to_owned()
}
fn config_dir() -> std::path::PathBuf {

View File

@@ -1,7 +1,7 @@
use config_traits::{StdConfig, StdConfigLoad3};
use serde_derive::{Deserialize, Serialize};
const CONFIG_FILE: &str = "asusd.conf";
const CONFIG_FILE: &str = "asusd.ron";
#[derive(Deserialize, Serialize, Default)]
pub struct Config {

View File

@@ -5,7 +5,7 @@ use rog_anime::error::AnimeError;
use rog_anime::{ActionData, ActionLoader, AnimTime, AnimeType, Fade, Vec2};
use serde_derive::{Deserialize, Serialize};
const CONFIG_FILE: &str = "anime.conf";
const CONFIG_FILE: &str = "anime.ron";
#[derive(Deserialize, Serialize)]
pub struct AnimeConfigV341 {

View File

@@ -8,7 +8,7 @@ use rog_platform::hid_raw::HidRaw;
use rog_platform::keyboard_led::KeyboardLed;
use serde_derive::{Deserialize, Serialize};
const CONFIG_FILE: &str = "aura.conf";
const CONFIG_FILE: &str = "aura.ron";
/// Enable/disable LED control in various states such as
/// when the device is awake, suspended, shutting down or

View File

@@ -7,8 +7,8 @@ use serde_derive::{Deserialize, Serialize};
use crate::CONFIG_PATH_BASE;
const CONFIG_FILE: &str = "profile.conf";
const CONFIG_FAN_FILE: &str = "fan_curves.conf";
const CONFIG_FILE: &str = "profile.ron";
const CONFIG_FAN_FILE: &str = "fan_curves.ron";
#[derive(Deserialize, Serialize, Debug)]
pub struct ProfileConfig {