Skip to content

Commit f2d0b98

Browse files
committed
move settings into dedicated config file
1 parent e162aa4 commit f2d0b98

File tree

25 files changed

+401
-656
lines changed

25 files changed

+401
-656
lines changed

CHANGELOG.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9-
## [3.0.0-beta.1] - 2021-04-20
9+
## [3.0.0-beta.2] - 2021-04-20
10+
11+
### Removed
1012

11-
BREAKING: Requires DCS 2.7 from now on.
13+
- **BREAKING:** The plugin settings have been removed from the DCS settings screen. DATIS is now configured through a config file at `Saved Games\DCS.openbeta\Config\DATIS.json`, see [Settings](./docs/Settings.md). Existing settings are not automatically migrated. This has been done, because each mission you save contains all your plugin settings. This included the cloud provider access keys set for DATIS. The change has been made to prevent the accidential sharing of those credentials.
14+
15+
## [3.0.0-beta.1] - 2021-04-20
1216

1317
### Added
1418

15-
- Added support for DCS 2.7 cloud presets.
19+
- **BREAKING:** Added support for DCS 2.7 cloud presets. Requires DCS 2.7 from now on.
1620

1721
## [2.2.2] - 2021-04-11
1822

README.md

+7-29
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,27 @@ ATIS stations are not the only report kind this mod supports, all supported repo
2323

2424
The mods uses the Window' built-in TTS by default, but can also either use Google Cloud's TTS, AWS Polly, or a combination of all of them (tip: setup both Google Cloud and Amazon Web Services to have a greater choice of different voices).
2525

26+
## Migrate to 3.x.x
27+
28+
The plugin settings have been removed from the DCS settings screen. DATIS is now configured through a config file at `Saved Games\DCS.openbeta\Config\DATIS.json`, see [Settings](./docs/Settings.md).
29+
This has been done, because each mission you save contains all your plugin settings. This included the cloud provider access keys set for DATIS. The change has been made to prevent the accidential sharing of those credentials.
30+
2631
## Installation
2732

2833
[Build it](#build) yourself and use the content inside the `mod` directory or use the pre-build mod from one of the [releases](https://github.com/rkusa/DATIS/releases).
2934

3035
1. Copy the content (`Mods` and `Scripts` directory) into `Saved Games\DCS.openbeta\`.
31-
2. Optional (not necessary when using Window' built-in TTS): Setup your cloud provider of choice
32-
1. Create your cloud credentials, either
33-
1. Google Cloud: Go to https://console.cloud.google.com/apis/credentials and create an API key and restrict API access to Google Text-to-Speech, or
34-
2. Amazon Web Services: Go to https://console.aws.amazon.com/iam/home#/users and create a new user with `AmazonPollyReadOnlyAccess` permissions
35-
2. Open DCS go to OPTIONS -> SPECIAL -> DCS ATIS, enter your API keys into the respective input fields
36+
2. Optional: Customize your settings, see [Settings](./docs/Settings.md)
3637

3738
Once you start a mission that contains a pattern as described in the next section, DATIS runs automatically.
38-
It thereby expects a SRS server to run locally on the default SRS ports. The port can be changed in the DCS DATIS mod settings page.
39+
It thereby expects a SRS server to run locally on the default SRS ports.
3940

4041
If DATIS isn't working, you might find some helpful information in the log file at `DCS.openbeta\Logs\DATIS.log`.
4142

4243
For information about the free tier of both GCloud and AWS see:
4344
- https://cloud.google.com/text-to-speech/pricing
4445
- https://aws.amazon.com/polly/pricing/
4546

46-
![Settings](./docs/settings.jpg)
47-
48-
While it is easiest to temporariely start DCS with a GUI even on a dedicated server for the sake of changing DATIS settings, they can also be changed by manually updating `Saved Games\DCS.openbeta\Config\options.lua`:
49-
50-
```lua
51-
options = {
52-
-- ...
53-
["plugins"] = {
54-
-- ..
55-
["DATIS"] = {
56-
["awsAccessKey"] = "Your AWS access key",
57-
["awsPrivateKey"] = "Your AWS private key",
58-
["awsRegion"] = "eu-central-1",
59-
["debugLoggingEnabled"] = false,
60-
["defaultVoice"] = "WIN",
61-
["gcloudAccessKey"] = "Your Google Cloud access key",
62-
["srsPort"] = "5002",
63-
},
64-
-- ..
65-
}
66-
}
67-
```
68-
6947
## Setup
7048

7149
### Setup ATIS stations

crates/datis-cmd/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "datis-cmd"
3-
version = "3.0.0-beta.1"
3+
version = "3.0.0-beta.2"
44
authors = ["Markus Ast <m@rkusa.st>"]
55
edition = "2018"
66

crates/datis-cmd/src/main.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::str::FromStr;
22

33
use clap::{App, Arg};
4+
use datis_core::config::{AwsConfig, GcloudConfig};
45
use datis_core::station::{Airfield, Position, Station, Transmitter};
56
use datis_core::tts::TextToSpeechProvider;
67
use datis_core::Datis;
@@ -90,21 +91,27 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
9091
active_rwy_override: None,
9192
}),
9293
};
93-
let mut datis = Datis::new(vec![station])?;
94-
datis.set_port(5002);
94+
let mut config = Default::default();
9595

9696
if let Some(key) = matches.value_of("gcloud_key") {
97-
datis.set_gcloud_key(key);
97+
config.gcloud = Some(GcloudConfig {
98+
key: key.to_string(),
99+
})
98100
}
99101

100102
if let (Some(key), Some(secret), Some(region)) = (
101103
matches.value_of("aws_key"),
102104
matches.value_of("aws_secret"),
103105
matches.value_of("aws_region"),
104106
) {
105-
datis.set_aws_keys(key, secret, region);
107+
config.aws = Some(AwsConfig {
108+
key: key.to_string(),
109+
secret: secret.to_string(),
110+
region: region.to_string(),
111+
})
106112
}
107113

114+
let datis = Datis::new(vec![station], config)?;
108115
datis.start()?;
109116

110117
let (tx, rx) = std::sync::mpsc::channel();

crates/datis-core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "datis-core"
3-
version = "3.0.0-beta.1"
3+
version = "3.0.0-beta.2"
44
authors = ["Markus Ast <m@rkusa.st>"]
55
edition = "2018"
66

crates/datis-core/src/config.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use crate::tts::TextToSpeechProvider;
2+
use serde::{Deserialize, Serialize};
3+
4+
#[derive(Debug, Serialize, Deserialize)]
5+
pub struct Config {
6+
#[serde(default)]
7+
pub default_voice: TextToSpeechProvider,
8+
pub gcloud: Option<GcloudConfig>,
9+
pub aws: Option<AwsConfig>,
10+
#[serde(default = "default_srs_port")]
11+
pub srs_port: u16,
12+
#[serde(default)]
13+
pub debug: bool,
14+
}
15+
16+
#[derive(Debug, Serialize, Deserialize)]
17+
pub struct GcloudConfig {
18+
pub key: String,
19+
}
20+
21+
#[derive(Debug, Serialize, Deserialize)]
22+
pub struct AwsConfig {
23+
pub key: String,
24+
pub secret: String,
25+
pub region: String,
26+
}
27+
28+
impl Default for Config {
29+
fn default() -> Self {
30+
Config {
31+
default_voice: TextToSpeechProvider::default(),
32+
gcloud: None,
33+
aws: None,
34+
srs_port: default_srs_port(),
35+
debug: false,
36+
}
37+
}
38+
}
39+
40+
fn default_srs_port() -> u16 {
41+
5002
42+
}

crates/datis-core/src/export.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::HashMap;
22
use std::fs::File;
3+
use std::path::{Path, PathBuf};
34
use std::sync::Arc;
45
use std::{error, fmt};
56

@@ -9,14 +10,14 @@ use futures::lock::Mutex;
910
pub struct ReportExporter(Arc<Mutex<ReportExporterInner>>);
1011

1112
pub struct ReportExporterInner {
12-
path: String,
13+
path: PathBuf,
1314
reports: HashMap<String, String>,
1415
}
1516

1617
impl ReportExporter {
17-
pub fn new(path: String) -> Self {
18+
pub fn new(path: impl AsRef<Path>) -> Self {
1819
ReportExporter(Arc::new(Mutex::new(ReportExporterInner {
19-
path,
20+
path: path.as_ref().to_path_buf(),
2021
reports: HashMap::new(),
2122
})))
2223
}

crates/datis-core/src/lib.rs

+13-40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[macro_use]
22
extern crate anyhow;
33

4+
pub mod config;
45
pub mod export;
56
pub mod extract;
67
#[cfg(feature = "ipc")]
@@ -12,6 +13,7 @@ pub mod weather;
1213

1314
use std::mem;
1415
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
16+
use std::path::Path;
1517
use std::str::FromStr;
1618
use std::sync::Arc;
1719
use std::time::{Duration, Instant};
@@ -24,6 +26,7 @@ use crate::tts::{
2426
win::{self, WindowsConfig},
2527
TextToSpeechConfig, TextToSpeechProvider,
2628
};
29+
use config::{AwsConfig, Config};
2730
use futures::future::FutureExt;
2831
use futures::select;
2932
use futures::sink::SinkExt;
@@ -36,57 +39,27 @@ use tokio::time::sleep;
3639
pub struct Datis {
3740
stations: Vec<Station>,
3841
exporter: Option<ReportExporter>,
39-
gcloud_key: Option<String>,
40-
aws_config: Option<AwsConfig>,
41-
port: u16,
42+
config: Config,
4243
runtime: Runtime,
4344
started: bool,
4445
shutdown_signals: Vec<oneshot::Sender<()>>,
4546
}
4647

47-
struct AwsConfig {
48-
key: String,
49-
secret: String,
50-
region: String,
51-
}
52-
5348
impl Datis {
54-
pub fn new(stations: Vec<Station>) -> Result<Self, Error> {
49+
pub fn new(stations: Vec<Station>, config: Config) -> Result<Self, Error> {
5550
Ok(Datis {
5651
stations,
5752
exporter: None,
58-
gcloud_key: None,
59-
aws_config: None,
60-
port: 5002,
53+
config,
6154
runtime: runtime::Builder::new_multi_thread().enable_all().build()?,
6255
started: false,
6356
shutdown_signals: Vec::new(),
6457
})
6558
}
6659

67-
pub fn set_port(&mut self, port: u16) {
68-
self.port = port;
69-
}
70-
71-
pub fn set_gcloud_key<S: Into<String>>(&mut self, key: S) {
72-
self.gcloud_key = Some(key.into());
73-
}
74-
75-
pub fn set_aws_keys<K: Into<String>, S: Into<String>, R: Into<String>>(
76-
&mut self,
77-
key: K,
78-
secret: S,
79-
region: R,
80-
) {
81-
self.aws_config = Some(AwsConfig {
82-
key: key.into(),
83-
secret: secret.into(),
84-
region: region.into(),
85-
});
86-
}
87-
88-
pub fn set_log_dir<S: Into<String>>(&mut self, log_dir: S) {
89-
let exporter = ReportExporter::new(log_dir.into() + "atis-reports.json");
60+
pub fn enable_exporter(&mut self, write_dir: impl AsRef<Path>) {
61+
let path = write_dir.as_ref().to_path_buf().join("atis-reports.json");
62+
let exporter = ReportExporter::new(path);
9063
self.exporter = Some(exporter);
9164
}
9265

@@ -100,9 +73,9 @@ impl Datis {
10073
for station in &mut self.stations {
10174
let config = match station.tts {
10275
TextToSpeechProvider::GoogleCloud { voice } => {
103-
if let Some(ref key) = self.gcloud_key {
76+
if let Some(ref config) = self.config.gcloud {
10477
TextToSpeechConfig::GoogleCloud(GoogleCloudConfig {
105-
key: key.clone(),
78+
key: config.key.clone(),
10679
voice,
10780
})
10881
} else {
@@ -118,7 +91,7 @@ impl Datis {
11891
ref key,
11992
ref secret,
12093
ref region,
121-
}) = self.aws_config
94+
}) = self.config.aws
12295
{
12396
TextToSpeechConfig::AmazonWebServices(AmazonWebServicesConfig {
12497
key: key.clone(),
@@ -157,7 +130,7 @@ impl Datis {
157130
self.runtime.spawn(
158131
spawn(
159132
station.clone(),
160-
self.port,
133+
self.config.srs_port,
161134
config,
162135
self.exporter.clone(),
163136
rx,

crates/datis-core/src/tts/aws.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt::Display;
12
use std::str::FromStr;
23

34
use audiopus::{coder::Encoder, Application, Channels, SampleRate};
@@ -109,8 +110,8 @@ impl FromStr for VoiceKind {
109110
}
110111
}
111112

112-
impl ToString for VoiceKind {
113-
fn to_string(&self) -> String {
114-
format!("{:?}", self)
113+
impl Display for VoiceKind {
114+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
115+
write!(f, "{:?}", self)
115116
}
116117
}

crates/datis-core/src/tts/gcloud.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt::Display;
12
use std::io::Cursor;
23
use std::str::FromStr;
34

@@ -188,3 +189,9 @@ impl FromStr for VoiceKind {
188189
serde_json::from_value(json!(s))
189190
}
190191
}
192+
193+
impl Display for VoiceKind {
194+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
195+
f.write_str(&serde_json::to_string(self).unwrap())
196+
}
197+
}

0 commit comments

Comments
 (0)