|
1 | 1 | package tools.sctrade.companion.domain.gamelog;
|
2 | 2 |
|
| 3 | +import java.nio.file.Path; |
| 4 | +import java.util.ArrayList; |
3 | 5 | import java.util.Optional;
|
4 | 6 | import org.slf4j.Logger;
|
5 | 7 | import org.slf4j.LoggerFactory;
|
6 | 8 | import tools.sctrade.companion.domain.setting.Setting;
|
7 | 9 | import tools.sctrade.companion.domain.setting.SettingRepository;
|
8 | 10 |
|
9 |
| -public class GameLogService { |
10 |
| - private static final String GAME_LOG = "\\Game.log"; |
| 11 | +public class GameLogPathSubject extends FilePathSubject { |
| 12 | + static final String GAME_LOG_FILE = "Game.log"; |
11 | 13 |
|
12 |
| - private final Logger logger = LoggerFactory.getLogger(GameLogService.class); |
| 14 | + private final Logger logger = LoggerFactory.getLogger(GameLogPathSubject.class); |
13 | 15 |
|
14 | 16 | private SettingRepository settings;
|
15 | 17 |
|
16 |
| - public GameLogService(SettingRepository settings) { |
| 18 | + public GameLogPathSubject(SettingRepository settings) { |
| 19 | + super(); |
17 | 20 | this.settings = settings;
|
| 21 | + this.observers = new ArrayList<>(); |
| 22 | + setState(); |
18 | 23 | }
|
19 | 24 |
|
20 |
| - public void updateStarCitizenLivePath(String starCitizenLivePath) { |
| 25 | + public void setStarCitizenLivePath(String starCitizenLivePath) { |
21 | 26 | if (starCitizenLivePath == null || starCitizenLivePath.strip().isEmpty()) {
|
22 | 27 | logger.warn("Star Citizen LIVE path is empty");
|
23 | 28 | return;
|
24 | 29 | }
|
25 | 30 |
|
26 | 31 | starCitizenLivePath = starCitizenLivePath.strip();
|
27 | 32 | settings.set(Setting.STAR_CITIZEN_LIVE_PATH, starCitizenLivePath.replace("\\", "\\\\"));
|
| 33 | + setState(); |
28 | 34 | }
|
29 | 35 |
|
30 | 36 | public Optional<String> getStarCitizenLivePath() {
|
31 | 37 | return Optional.ofNullable(settings.get(Setting.STAR_CITIZEN_LIVE_PATH).toString());
|
32 | 38 | }
|
33 | 39 |
|
| 40 | + @Override |
| 41 | + protected void setState() { |
| 42 | + if (getStarCitizenLivePath().isEmpty()) { |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + filePath = Path.of(getStarCitizenLivePath().get(), GAME_LOG_FILE); |
| 47 | + notifyObservers(); |
| 48 | + } |
34 | 49 | }
|
0 commit comments