-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add list of custom Proton versions
- Loading branch information
Showing
7 changed files
with
128 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:game_center/steam/steam_data.dart'; | ||
import 'package:path/path.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
import 'package:watcher/watcher.dart'; | ||
|
||
part 'proton_model.g.dart'; | ||
|
||
@riverpod | ||
class ProtonModel extends _$ProtonModel { | ||
late String installLocation; | ||
late List<String> protonVersions; | ||
|
||
Future<List<String>> build({String? install}) async { | ||
// default install location | ||
if (install == null) { | ||
final home = Platform.environment['SNAP_REAL_HOME'] ?? | ||
Platform.environment['HOME']; | ||
if (home == null) { | ||
throw StateError('Home directory not found.'); | ||
} | ||
install = '$home/snap/steam/common'; | ||
} | ||
|
||
installLocation = install; | ||
|
||
// directory isn't created by Steam by default, so ensure it exists | ||
final protonDir = Directory(protonDirectory(installLocation)); | ||
protonDir.create(recursive: true); | ||
|
||
await updateProtonVersions(); | ||
|
||
final fileSystem = FileWatcher(protonDirectory(installLocation)); | ||
fileSystem.events.listen((event) async => await updateProtonVersions()); | ||
|
||
return protonVersions; | ||
} | ||
|
||
Future<void> updateProtonVersions() async { | ||
final protonDir = Directory(protonDirectory(installLocation)); | ||
final fileStream = await protonDir.list().toList(); | ||
protonVersions = fileStream.map((x) => basename(x.path)).toList(); | ||
|
||
state = AsyncData(protonVersions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// Directory within Steam's install path where actual Steam data is found. | ||
const steamDataDir = '.steam/steam'; | ||
|
||
/// Directory where Steam expects 3rd party Proton versions to be. | ||
String protonDirectory(String installLocation) { | ||
return '$installLocation/$steamDataDir/compatibilitytools.d'; | ||
} | ||
|
||
/// Steam's global settings file path. | ||
String steamGlobalConfig(String installLocation) { | ||
return '$installLocation/$steamDataDir/config/config.vdf'; | ||
} | ||
|
||
/// Steam user settings *(not to be confused with the Linux user)* file path. | ||
/// | ||
/// Most users of Steam will only have 1 account per Linux user. However, it is | ||
/// possible to log in to multiple Steam accounts from a single Linux user so a | ||
/// `userID` must be provided. | ||
String steamUserConfig(String installLocation, String userID) { | ||
return '$installLocation/$steamDataDir/userdata/$userID/config/localconfig.vdf'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:game_center/steam/proton_model.dart'; | ||
|
||
import 'test_utils.dart'; | ||
|
||
void main() { | ||
test('build', () async { | ||
final container = createContainer(); | ||
final provider = protonModelProvider(); | ||
container.read(provider.future); | ||
final model = container.read(provider.notifier); | ||
|
||
final directory = Directory(model.installLocation); | ||
expect(await directory.exists(), isTrue); | ||
}); | ||
} |