Skip to content

Commit

Permalink
feat(gebura): update steam app import logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Feb 20, 2024
1 parent c5300b4 commit 58227dc
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 104 deletions.
27 changes: 21 additions & 6 deletions lib/bloc/gebura/gebura_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
emit(state.copyWith(localLibraryState: S.current.scanningLocalFiles));
final (apps, result) = await scanLocalLibrary();
final folders = await getSteamLibraryFolders();
final imported = _repo.getImportedSteamApps();
final imported = _repo.getImportedSteamAppInsts();
final unImported = apps.where((element) =>
!imported.any((imported) => imported.steamAppID == element.appId));
emit(state.copyWith(
Expand Down Expand Up @@ -408,7 +408,8 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
));
await _repo.setAppLauncherSetting(AppLauncherSetting(
appInstID: instResp.getData().id.id.toInt(),
path: event.path,
path: '',
installPath: event.path,
realPath: '',
processName: '',
sleepTime: 0,
Expand All @@ -429,7 +430,7 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
EventStatus.processing));
var processCount = 0;
var failedCount = 0;
final importedSteamApps = _repo.getImportedSteamApps();
final importedSteamApps = _repo.getImportedSteamAppInsts();
for (final steamAppID in event.steamAppIDs) {
processCount += 1;
emit(GeburaImportSteamAppsState(
Expand Down Expand Up @@ -488,12 +489,26 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
failedCount += 1;
continue;
}
importedSteamApps.add(ImportedSteamApp(
internalID: purchaseResp.getData().id.id.toInt(),
final instResp = await _api.doRequest(
(client) => client.createAppInst,
CreateAppInstRequest(
appInst: AppInst(
appId: createResp.getData().id,
deviceId: _deviceID,
),
),
);
if (instResp.status != ApiStatus.success) {
failedCount += 1;
continue;
}
importedSteamApps.add(ImportedSteamAppInst(
instID: instResp.getData().id.id.toInt(),
appID: createResp.getData().id.id.toInt(),
steamAppID: steamAppID,
));
}
await _repo.setImportedSteamApps(importedSteamApps);
await _repo.setImportedSteamAppInsts(importedSteamApps);
add(GeburaRefreshLibraryEvent());
emit(GeburaImportSteamAppsState(
state.copyWith(
Expand Down
4 changes: 2 additions & 2 deletions lib/bloc/gebura/gebura_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GeburaState {
late String? localLibraryState;
late SteamScanResult? localSteamScanResult;
late List<InstalledSteamApps>? localSteamAppInsts;
late List<ImportedSteamApp>? importedSteamAppInsts;
late List<ImportedSteamAppInst>? importedSteamAppInsts;
late List<String>? localSteamLibraryFolders;

GeburaState({
Expand Down Expand Up @@ -45,7 +45,7 @@ class GeburaState {
String? localLibraryState,
SteamScanResult? localSteamScanResult,
List<InstalledSteamApps>? localSteamAppInsts,
List<ImportedSteamApp>? importedSteamAppInsts,
List<ImportedSteamAppInst>? importedSteamAppInsts,
List<String>? localSteamLibraryFolders,
}) {
return GeburaState(
Expand Down
9 changes: 9 additions & 0 deletions lib/common/steam/local_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class InstalledSteamApps {
final String appId;
final String name;
final String launcherPath;
final String installPath;
final String sizeOnDisk;
final String? iconFilePath;

InstalledSteamApps({
required this.appId,
required this.name,
required this.launcherPath,
required this.installPath,
required this.sizeOnDisk,
this.iconFilePath,
});
Expand All @@ -30,13 +32,15 @@ class InstalledSteamApps {
String? appId,
String? name,
String? launcherPath,
String? installPath,
String? sizeOnDisk,
String? iconFilePath,
}) {
return InstalledSteamApps(
appId: appId ?? this.appId,
name: name ?? this.name,
launcherPath: launcherPath ?? this.launcherPath,
installPath: installPath ?? this.installPath,
sizeOnDisk: sizeOnDisk ?? this.sizeOnDisk,
iconFilePath: iconFilePath ?? this.iconFilePath,
);
Expand Down Expand Up @@ -156,6 +160,10 @@ InstalledSteamApps? _getAppInfo(String path) {
final appId = appState['appid'];
final name = appState['name'];
final launcherPath = appState['LauncherPath'];
final installDir = appState['installdir'];
final installPath = installDir is String
? p.join(p.dirname(path), 'common', installDir)
: '';
final sizeOnDisk = appState['SizeOnDisk'];
if (appId is String && _excludeAppIds.contains(appId)) {
return null;
Expand All @@ -168,6 +176,7 @@ InstalledSteamApps? _getAppInfo(String path) {
appId: appId,
name: name,
launcherPath: launcherPath,
installPath: installPath,
sizeOnDisk: sizeOnDisk,
);
}
Expand Down
14 changes: 8 additions & 6 deletions lib/model/gebura_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ part 'gebura_model.g.dart';
class AppLauncherSetting with _$AppLauncherSetting {
const factory AppLauncherSetting({
required int appInstID,
required String installPath,
required String path,
required bool advancedTracing,
required String processName,
Expand All @@ -31,14 +32,15 @@ class AppRunState with _$AppRunState {
}

@freezed
class ImportedSteamApp with _$ImportedSteamApp {
const factory ImportedSteamApp({
required int internalID,
class ImportedSteamAppInst with _$ImportedSteamAppInst {
const factory ImportedSteamAppInst({
required int instID,
required int appID,
required String steamAppID,
}) = _ImportedSteamApp;
}) = _ImportedSteamAppInst;

factory ImportedSteamApp.fromJson(Map<String, Object?> json) =>
_$ImportedSteamAppFromJson(json);
factory ImportedSteamAppInst.fromJson(Map<String, Object?> json) =>
_$ImportedSteamAppInstFromJson(json);
}

@freezed
Expand Down
Loading

0 comments on commit 58227dc

Please sign in to comment.