createProfile method
Creates a new profile with the specified settings.
name
- Name of the profile
versionId
- Minecraft version ID
gameDir
- Optional custom game directory
javaDir
- Optional custom Java directory
javaArgs
- Optional custom Java arguments
icon
- Icon identifier for the profile
skipJreVersionCheck
- Whether to skip Java version checking
type
- Type of profile
Returns the created profile.
Throws an exception if profiles have not been loaded.
Implementation
Future<Profile> createProfile({
required String name,
required String versionId,
String? gameDir,
String? javaDir,
String? javaArgs,
String icon = 'Furnace',
bool skipJreVersionCheck = false,
String type = 'custom',
}) async {
if (_profiles == null) {
throw Exception('Launcher profiles not loaded');
}
final now = DateTime.now().toIso8601String();
final profile = Profile(
created: now,
gameDir: gameDir,
icon: icon,
javaDir: javaDir,
lastUsed: now,
lastVersionId: versionId,
name: name,
skipJreVersionCheck: skipJreVersionCheck,
type: type,
javaArgs: javaArgs,
);
final profileId = _generateProfileId();
final updatedProfiles = Map<String, Profile>.from(_profiles!.profiles);
updatedProfiles[profileId] = profile;
_profiles = LauncherProfiles(
profiles: updatedProfiles,
settings: _profiles!.settings,
version: _profiles!.version,
);
await saveProfiles();
return profile;
}