Compare commits
No commits in common. "c240f977730102bb8f7a4918fc98becbb54aa746" and "bacaef22c6ade91a15614dc28bee53ca21a5344e" have entirely different histories.
c240f97773
...
bacaef22c6
@ -3,22 +3,22 @@ import 'package:minecraft_server_installer/main/adapter/gateway/installation_fil
|
|||||||
import 'package:minecraft_server_installer/main/application/repository/installation_repository.dart';
|
import 'package:minecraft_server_installer/main/application/repository/installation_repository.dart';
|
||||||
|
|
||||||
class InstallationRepositoryImpl implements InstallationRepository {
|
class InstallationRepositoryImpl implements InstallationRepository {
|
||||||
final InstallationApiService _installationApiService;
|
final InstallationApiService _apiService;
|
||||||
final InstallationFileStorage _installationFileStorage;
|
final InstallationFileStorage _fileStorage;
|
||||||
|
|
||||||
InstallationRepositoryImpl(this._installationApiService, this._installationFileStorage);
|
InstallationRepositoryImpl(this._apiService, this._fileStorage);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> downloadFile(Uri url, String path, {DownloadProgressCallback? onProgressChanged}) async {
|
Future<void> downloadFile(Uri url, String path, {DownloadProgressCallback? onProgressChanged}) async {
|
||||||
final fileBytes = await _installationApiService.fetchRemoteFile(url, onProgressChanged: onProgressChanged);
|
final fileBytes = await _apiService.fetchRemoteFile(url, onProgressChanged: onProgressChanged);
|
||||||
await _installationFileStorage.saveFile(fileBytes, path);
|
await _fileStorage.saveFile(fileBytes, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> writeFile(String path, String content) => _installationFileStorage.writeFile(path, content);
|
Future<void> writeFile(String path, String content) => _fileStorage.writeFile(path, content);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> grantFileExecutePermission(String path) {
|
Future<void> grantFileExecutePermission(String path) {
|
||||||
return _installationFileStorage.grantFileExecutePermission(path);
|
return _fileStorage.grantFileExecutePermission(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:minecraft_server_installer/properties/domain/entity/server_properties.dart';
|
|
||||||
import 'package:minecraft_server_installer/properties/domain/enum/difficulty.dart';
|
|
||||||
import 'package:minecraft_server_installer/properties/domain/enum/game_mode.dart';
|
|
||||||
|
|
||||||
class ServerPropertiesDto with EquatableMixin {
|
|
||||||
final int serverPort;
|
|
||||||
final int maxPlayers;
|
|
||||||
final int spawnProtection;
|
|
||||||
final int viewDistance;
|
|
||||||
final bool pvp;
|
|
||||||
final String gameMode;
|
|
||||||
final String difficulty;
|
|
||||||
final bool enableCommandBlock;
|
|
||||||
final bool onlineMode;
|
|
||||||
final String motd;
|
|
||||||
|
|
||||||
const ServerPropertiesDto({
|
|
||||||
required this.serverPort,
|
|
||||||
required this.maxPlayers,
|
|
||||||
required this.spawnProtection,
|
|
||||||
required this.viewDistance,
|
|
||||||
required this.pvp,
|
|
||||||
required this.gameMode,
|
|
||||||
required this.difficulty,
|
|
||||||
required this.enableCommandBlock,
|
|
||||||
required this.onlineMode,
|
|
||||||
required this.motd,
|
|
||||||
});
|
|
||||||
|
|
||||||
ServerPropertiesDto.fromEntity(ServerProperties serverProperties)
|
|
||||||
: serverPort = serverProperties.serverPort,
|
|
||||||
maxPlayers = serverProperties.maxPlayers,
|
|
||||||
spawnProtection = serverProperties.spawnProtection,
|
|
||||||
viewDistance = serverProperties.viewDistance,
|
|
||||||
pvp = serverProperties.pvp,
|
|
||||||
gameMode = serverProperties.gameMode.value,
|
|
||||||
difficulty = serverProperties.difficulty.value,
|
|
||||||
enableCommandBlock = serverProperties.enableCommandBlock,
|
|
||||||
onlineMode = serverProperties.onlineMode,
|
|
||||||
motd = serverProperties.motd;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [
|
|
||||||
serverPort,
|
|
||||||
maxPlayers,
|
|
||||||
spawnProtection,
|
|
||||||
viewDistance,
|
|
||||||
pvp,
|
|
||||||
gameMode,
|
|
||||||
difficulty,
|
|
||||||
enableCommandBlock,
|
|
||||||
onlineMode,
|
|
||||||
motd,
|
|
||||||
];
|
|
||||||
|
|
||||||
Map<String, String> toStringMap() => {
|
|
||||||
'server-port': serverPort.toString(),
|
|
||||||
'max-players': maxPlayers.toString(),
|
|
||||||
'spawn-protection': spawnProtection.toString(),
|
|
||||||
'view-distance': viewDistance.toString(),
|
|
||||||
'pvp': pvp.toString(),
|
|
||||||
'gamemode': gameMode,
|
|
||||||
'difficulty': difficulty,
|
|
||||||
'enable-command-block': enableCommandBlock.toString(),
|
|
||||||
'online-mode': onlineMode.toString(),
|
|
||||||
'motd': motd,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
extension _GameModeExtension on GameMode {
|
|
||||||
String get value {
|
|
||||||
switch (this) {
|
|
||||||
case GameMode.survival:
|
|
||||||
return 'survival';
|
|
||||||
case GameMode.creative:
|
|
||||||
return 'creative';
|
|
||||||
case GameMode.adventure:
|
|
||||||
return 'adventure';
|
|
||||||
case GameMode.spectator:
|
|
||||||
return 'spectator';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension _DifficultyExtension on Difficulty {
|
|
||||||
String get value {
|
|
||||||
switch (this) {
|
|
||||||
case Difficulty.peaceful:
|
|
||||||
return 'peaceful';
|
|
||||||
case Difficulty.easy:
|
|
||||||
return 'easy';
|
|
||||||
case Difficulty.normal:
|
|
||||||
return 'normal';
|
|
||||||
case Difficulty.hard:
|
|
||||||
return 'hard';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
import 'package:minecraft_server_installer/properties/adapter/gateway/server_properties_dto.dart';
|
|
||||||
|
|
||||||
abstract interface class ServerPropertiesFileStorage {
|
|
||||||
Future<void> writeServerProperties(ServerPropertiesDto serverPropertiesDto, String directoryPath);
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
import 'package:minecraft_server_installer/properties/adapter/gateway/server_properties_dto.dart';
|
|
||||||
import 'package:minecraft_server_installer/properties/adapter/gateway/server_properties_file_storage.dart';
|
|
||||||
import 'package:minecraft_server_installer/properties/application/repository/server_properties_repository.dart';
|
|
||||||
import 'package:minecraft_server_installer/properties/domain/entity/server_properties.dart';
|
|
||||||
|
|
||||||
class ServerPropertiesRepositoryImpl implements ServerPropertiesRepository {
|
|
||||||
final ServerPropertiesFileStorage _serverPropertiesFileStorage;
|
|
||||||
|
|
||||||
ServerPropertiesRepositoryImpl(this._serverPropertiesFileStorage);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> writeServerProperties(ServerProperties serverProperties, String directoryPath) =>
|
|
||||||
_serverPropertiesFileStorage.writeServerProperties(
|
|
||||||
ServerPropertiesDto.fromEntity(serverProperties),
|
|
||||||
directoryPath,
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
import 'package:minecraft_server_installer/properties/domain/entity/server_properties.dart';
|
|
||||||
|
|
||||||
abstract interface class ServerPropertiesRepository {
|
|
||||||
Future<void> writeServerProperties(ServerProperties serverProperties, String directoryPath);
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
import 'package:minecraft_server_installer/properties/application/repository/server_properties_repository.dart';
|
|
||||||
import 'package:minecraft_server_installer/properties/domain/entity/server_properties.dart';
|
|
||||||
|
|
||||||
class WriteServerPropertiesUseCase {
|
|
||||||
final ServerPropertiesRepository _serverPropertiesRepository;
|
|
||||||
|
|
||||||
WriteServerPropertiesUseCase(this._serverPropertiesRepository);
|
|
||||||
|
|
||||||
Future<void> call(ServerProperties serverProperties, String directoryPath) =>
|
|
||||||
_serverPropertiesRepository.writeServerProperties(serverProperties, directoryPath);
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:minecraft_server_installer/properties/domain/enum/difficulty.dart';
|
|
||||||
import 'package:minecraft_server_installer/properties/domain/enum/game_mode.dart';
|
|
||||||
|
|
||||||
class ServerProperties with EquatableMixin {
|
|
||||||
final int serverPort;
|
|
||||||
final int maxPlayers;
|
|
||||||
final int spawnProtection;
|
|
||||||
final int viewDistance;
|
|
||||||
final bool pvp;
|
|
||||||
final GameMode gameMode;
|
|
||||||
final Difficulty difficulty;
|
|
||||||
final bool enableCommandBlock;
|
|
||||||
final bool onlineMode;
|
|
||||||
final String motd;
|
|
||||||
|
|
||||||
const ServerProperties({
|
|
||||||
required this.serverPort,
|
|
||||||
required this.maxPlayers,
|
|
||||||
required this.spawnProtection,
|
|
||||||
required this.viewDistance,
|
|
||||||
required this.pvp,
|
|
||||||
required this.gameMode,
|
|
||||||
required this.difficulty,
|
|
||||||
required this.enableCommandBlock,
|
|
||||||
required this.onlineMode,
|
|
||||||
required this.motd,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [
|
|
||||||
serverPort,
|
|
||||||
maxPlayers,
|
|
||||||
spawnProtection,
|
|
||||||
viewDistance,
|
|
||||||
pvp,
|
|
||||||
gameMode,
|
|
||||||
difficulty,
|
|
||||||
enableCommandBlock,
|
|
||||||
onlineMode,
|
|
||||||
motd,
|
|
||||||
];
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
enum Difficulty {
|
|
||||||
peaceful,
|
|
||||||
easy,
|
|
||||||
normal,
|
|
||||||
hard,
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
enum GameMode {
|
|
||||||
survival,
|
|
||||||
creative,
|
|
||||||
adventure,
|
|
||||||
spectator,
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:minecraft_server_installer/properties/adapter/gateway/server_properties_dto.dart';
|
|
||||||
import 'package:minecraft_server_installer/properties/adapter/gateway/server_properties_file_storage.dart';
|
|
||||||
|
|
||||||
class ServerPropertiesFileStorageImpl implements ServerPropertiesFileStorage {
|
|
||||||
@override
|
|
||||||
Future<void> writeServerProperties(ServerPropertiesDto serverPropertiesDto, String directoryPath) async {
|
|
||||||
File file = File('$directoryPath/server.properties');
|
|
||||||
await file.create(recursive: true);
|
|
||||||
|
|
||||||
final propertiesMap = serverPropertiesDto.toStringMap();
|
|
||||||
await file.writeAsString(propertiesMap.entries.map((e) => '${e.key}=${e.value}').join('\n'));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user