Skip to content
This repository was archived by the owner on May 26, 2024. It is now read-only.

Commit d1b1299

Browse files
committed
add Frosty config generator
1 parent ba011f4 commit d1b1299

4 files changed

Lines changed: 45 additions & 19 deletions

File tree

lib/screens/walk_through/walk_through.dart

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import 'package:kyber_mod_manager/utils/dll_injector.dart';
1111
import 'package:kyber_mod_manager/utils/helpers/path_helper.dart';
1212
import 'package:kyber_mod_manager/utils/helpers/system_tray_helper.dart';
1313
import 'package:kyber_mod_manager/utils/services/api_service.dart';
14+
import 'package:kyber_mod_manager/utils/services/frosty_profile_service.dart';
1415
import 'package:kyber_mod_manager/utils/services/frosty_service.dart';
1516
import 'package:kyber_mod_manager/utils/services/mod_installer_service.dart';
1617
import 'package:kyber_mod_manager/utils/services/mod_service.dart';
1718
import 'package:kyber_mod_manager/utils/services/notification_service.dart';
1819
import 'package:kyber_mod_manager/utils/types/freezed/github_asset.dart';
19-
import 'package:kyber_mod_manager/utils/types/frosty_config.dart';
2020
import 'package:path/path.dart' show join;
2121
import 'package:path_provider/path_provider.dart';
2222

@@ -137,18 +137,17 @@ class _WalkThroughState extends State<WalkThrough> {
137137
if (index == 5) {
138138
return Container(
139139
alignment: Alignment.center,
140-
child: Row(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [
141-
const SizedBox(
140+
child: Row(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: const [
141+
SizedBox(
142142
height: 20,
143143
width: 20,
144144
child: ProgressRing(),
145145
),
146-
const SizedBox(width: 10),
146+
SizedBox(width: 20),
147147
Text(
148-
firstInstall
149-
? "Please close Frosty after it loaded into the menu."
150-
: 'click on "Scan for games" once Frosty starts and, after it loads into the menu, close it.',
151-
style: const TextStyle(fontSize: 18),
148+
"Please close Frosty after it loaded into the menu",
149+
textAlign: TextAlign.center,
150+
style: TextStyle(fontSize: 18),
152151
),
153152
]),
154153
);
@@ -257,11 +256,16 @@ class _WalkThroughState extends State<WalkThrough> {
257256

258257
box.put('frostyPath', _directory!.path);
259258
String? configPath = await FrostyService.getFrostyConfigPath();
260-
box.put('frostyConfigPath', configPath);
261-
FrostyConfig config = await FrostyService.getFrostyConfig();
262-
setState(() {
263-
firstInstall = config.games.keys.contains('starwarsbattlefrontii');
264-
});
259+
var config;
260+
if (configPath != null && File(configPath).existsSync()) {
261+
box.put('frostyConfigPath', configPath);
262+
config = await FrostyService.getFrostyConfig();
263+
} else {
264+
await FrostyProfileService.createFrostyConfig();
265+
}
266+
// setState(() {
267+
// firstInstall = config?.games.keys.contains('starwarsbattlefrontii') ?? true;
268+
// });
265269
await FrostyService.startFrosty(launch: false, frostyPath: _directory!.path);
266270

267271
setState(() {
@@ -299,13 +303,13 @@ class _WalkThroughState extends State<WalkThrough> {
299303
actions: [
300304
Button(
301305
child: index == 3 ? const Text('Cancel') : Text(translate('server_browser.prev_page')),
302-
onPressed: index == 0 || disabled
306+
onPressed: index < 2 || disabled
303307
? null
304308
: () {
305309
if (index == 3) {
306310
PathHelper.cancelDownload();
307311
}
308-
setState(() => index == 3 ? index = 1 : index);
312+
setState(() => index == 3 ? index = 1 : index--);
309313
},
310314
),
311315
if (index == 1)

lib/utils/services/api_service.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class ApiService {
2222
final response = await get(
2323
Uri.parse('$BACKEND_API_BASE_URL/frosty/versions'),
2424
);
25-
print('$BACKEND_API_BASE_URL/frosty/versions');
2625
return List<String>.from(json.decode(response.body));
2726
} catch (e) {
2827
print(e);

lib/utils/services/frosty_profile_service.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:io';
22

33
import 'package:fluent_ui/fluent_ui.dart';
44
import 'package:flutter/foundation.dart';
5+
import 'package:kyber_mod_manager/main.dart';
56
import 'package:kyber_mod_manager/utils/helpers/origin_helper.dart';
67
import 'package:kyber_mod_manager/utils/services/frosty_service.dart';
78
import 'package:kyber_mod_manager/utils/services/mod_service.dart';
@@ -31,6 +32,28 @@ class FrostyProfileService {
3132
}
3233
}
3334

35+
static Future<void> createFrostyConfig() async {
36+
String path = applicationDocumentsDirectory.replaceAll(r'Roaming\Kyber Mod Manager', r'Local\Frosty');
37+
if (!Directory(path).existsSync()) {
38+
Directory(path).createSync(recursive: true);
39+
}
40+
File file = File('$path\\manager_config.json');
41+
if (file.existsSync()) {
42+
return;
43+
}
44+
await file.create();
45+
FrostyConfig config = FrostyConfig.fromJson({'Games': {}, 'GlobalOptions': Map<String, dynamic>.from({})});
46+
config.globalOptions.defaultProfile = 'starwarsbattlefrontii';
47+
config.globalOptions.useDefaultProfile = true;
48+
config.games['starwarsbattlefrontii'] = Game(
49+
gamePath: OriginHelper.getBattlefrontPath(),
50+
bookmarkDb: "[Asset Bookmarks]|[Legacy Bookmarks]",
51+
options: Options(),
52+
packs: {'Default': '', 'KyberModManager': ''},
53+
);
54+
await FrostyService.saveFrostyConfig(config, file.path);
55+
}
56+
3457
static loadFrostyPack(String name, [Function? onProgress]) async {
3558
Logger.root.info('Loading Frosty pack: $name');
3659
String bf2path = OriginHelper.getBattlefrontPath();

lib/utils/services/frosty_service.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FrostyService {
2424
static Future<FrostyConfig> getFrostyConfig() async {
2525
String? filePath = await getFrostyConfigPath();
2626
if (filePath == null) {
27-
return FrostyConfig.fromJson({});
27+
return FrostyConfig.fromJson({'Games': [], 'GlobalOptions': Map<String, dynamic>.from({})});
2828
}
2929
File file = File(filePath);
3030
FrostyConfig config = FrostyConfig.fromJson(
@@ -33,8 +33,8 @@ class FrostyService {
3333
return config;
3434
}
3535

36-
static Future<void> saveFrostyConfig(FrostyConfig config) async {
37-
String? filePath = await getFrostyConfigPath();
36+
static Future<void> saveFrostyConfig(FrostyConfig config, [String? path]) async {
37+
String? filePath = path ?? await getFrostyConfigPath();
3838
if (filePath == null) {
3939
return;
4040
}

0 commit comments

Comments
 (0)