diff --git a/lib/util/game_launcher.dart b/lib/util/game_launcher.dart index bdcdd53..7f334a6 100644 --- a/lib/util/game_launcher.dart +++ b/lib/util/game_launcher.dart @@ -3,6 +3,8 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'game_loader.dart'; + String customSteamPath = ""; Future launchGame(BuildContext context, String trainerPath, int appId, VoidCallback stopCircleIndicator, bool isCustomTrainer) async { @@ -39,13 +41,8 @@ Future _launchGame(BuildContext context, String trainerPath, int appId, Vo throw Exception(AppLocalizations.of(context)!.trainerPathNotFound(trainerPath)); } if (Platform.isLinux) { - String home = Platform.environment['HOME']!; - String defaultPath = "$home/.local/share/Steam"; - String steamPath = customSteamPath.isEmpty ? defaultPath : customSteamPath; - if (!await dirExist('$steamPath/steamapps')) { - if (!context.mounted) return; - throw Exception(AppLocalizations.of(context)!.steamPathNotFound(defaultPath, steamPath)); - } + if (!context.mounted) return; + String steamPath = await getSteamPath(context, appId); String gamePath = '$steamPath/steamapps/compatdata/$appId'; if (isCustomTrainer || !await dirExist(gamePath)) { int? nonSteamGameId = _getAppIdFromPS(); diff --git a/lib/util/game_loader.dart b/lib/util/game_loader.dart index 412116c..ec5da4e 100644 --- a/lib/util/game_loader.dart +++ b/lib/util/game_loader.dart @@ -37,3 +37,25 @@ Future> getLocalGames(BuildContext context) async { final games = server.getBatchGames(appIds); return games; } + +Future getSteamPath(BuildContext context, int appId) async { + String defaultPath = "${Platform.environment['HOME']!}/.local/share/Steam"; + String steamPath = customSteamPath.isEmpty ? defaultPath : customSteamPath; + if (!await dirExist('$steamPath/steamapps')) { + if (!context.mounted) return ""; + throw Exception(AppLocalizations.of(context)!.steamPathNotFound(defaultPath, steamPath)); + } + + final libraryFile = File('$steamPath/steamapps/libraryfolders.vdf'); + if (!await libraryFile.exists()) { + return steamPath; + } + + Map decoded = vdf.decode(await libraryFile.readAsString()); + for (var location in (decoded["libraryfolders"] as Map).values) { + if ((location["apps"] as Map).containsKey(appId.toString())) { + return location["path"]; + } + } + return steamPath; +} diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index b7c93a8..b07f80a 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -8,7 +8,7 @@ import Foundation import package_info_plus import path_provider_foundation import screen_retriever -import sqflite +import sqflite_darwin import url_launcher_macos import window_manager diff --git a/macos/Podfile.lock b/macos/Podfile.lock index 6913cfb..d92bf10 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -7,7 +7,7 @@ PODS: - FlutterMacOS - screen_retriever (0.0.1): - FlutterMacOS - - sqflite (0.0.3): + - sqflite_darwin (0.0.4): - Flutter - FlutterMacOS - url_launcher_macos (0.0.1): @@ -20,7 +20,7 @@ DEPENDENCIES: - package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`) - path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`) - screen_retriever (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos`) - - sqflite (from `Flutter/ephemeral/.symlinks/plugins/sqflite/darwin`) + - sqflite_darwin (from `Flutter/ephemeral/.symlinks/plugins/sqflite_darwin/darwin`) - url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`) - window_manager (from `Flutter/ephemeral/.symlinks/plugins/window_manager/macos`) @@ -33,8 +33,8 @@ EXTERNAL SOURCES: :path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin screen_retriever: :path: Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos - sqflite: - :path: Flutter/ephemeral/.symlinks/plugins/sqflite/darwin + sqflite_darwin: + :path: Flutter/ephemeral/.symlinks/plugins/sqflite_darwin/darwin url_launcher_macos: :path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos window_manager: @@ -45,8 +45,8 @@ SPEC CHECKSUMS: package_info_plus: fa739dd842b393193c5ca93c26798dff6e3d0e0c path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46 screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38 - sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec - url_launcher_macos: 5f437abeda8c85500ceb03f5c1938a8c5a705399 + sqflite_darwin: a553b1fd6fe66f53bbb0fe5b4f5bab93f08d7a13 + url_launcher_macos: c82c93949963e55b228a30115bd219499a6fe404 window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8 PODFILE CHECKSUM: e6941affa76272697b93766f7a7df72c8e5d2cb8 diff --git a/pubspec.lock b/pubspec.lock index 97c7f85..395de53 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -151,10 +151,10 @@ packages: dependency: transitive description: name: flutter_plugin_android_lifecycle - sha256: "9ee02950848f61c4129af3d6ec84a1cfc0e47931abc746b03e7a3bc3e8ff6eda" + sha256: "9b78450b89f059e96c9ebb355fa6b3df1d6b330436e0b885fb49594c41721398" url: "https://pub.dev" source: hosted - version: "2.0.22" + version: "2.0.23" flutter_test: dependency: "direct dev" description: flutter @@ -289,10 +289,10 @@ packages: dependency: transitive description: name: path_provider_android - sha256: "6f01f8e37ec30b07bc424b4deabac37cacb1bc7e2e515ad74486039918a37eb7" + sha256: c464428172cb986b758c6d1724c603097febb8fb855aa265aeecc9280c294d4a url: "https://pub.dev" source: hosted - version: "2.2.10" + version: "2.2.12" path_provider_foundation: dependency: transitive description: @@ -382,18 +382,42 @@ packages: dependency: transitive description: name: sqflite - sha256: ff5a2436ef8ebdfda748fbfe957f9981524cb5ff11e7bafa8c42771840e8a788 + sha256: "79a297dc3cc137e758c6a4baf83342b039e5a6d2436fcdf3f96a00adaaf2ad62" url: "https://pub.dev" source: hosted - version: "2.3.3+2" + version: "2.4.0" + sqflite_android: + dependency: transitive + description: + name: sqflite_android + sha256: "11821baf1d1bd3d71150d9b0d4c2e22cf680858c71add2113c919ca55cf9dc56" + url: "https://pub.dev" + source: hosted + version: "2.4.0-1" sqflite_common: dependency: transitive description: name: sqflite_common - sha256: "2d8e607db72e9cb7748c9c6e739e2c9618320a5517de693d5a24609c4671b1a4" + sha256: "4468b24876d673418a7b7147e5a08a715b4998a7ae69227acafaab762e0e5490" + url: "https://pub.dev" + source: hosted + version: "2.5.4+5" + sqflite_darwin: + dependency: transitive + description: + name: sqflite_darwin + sha256: "5e325c925cbd63f27e0e538aed018a40852325e590b5d83165181e492d272f9b" url: "https://pub.dev" source: hosted - version: "2.5.4+4" + version: "2.4.1-0" + sqflite_platform_interface: + dependency: transitive + description: + name: sqflite_platform_interface + sha256: b62ab81e1284341783222aefbbb44f984ebf4663d672ae10408c9a8ddab4bfb6 + url: "https://pub.dev" + source: hosted + version: "2.4.0-0" stack_trace: dependency: transitive description: @@ -462,10 +486,10 @@ packages: dependency: transitive description: name: url_launcher_android - sha256: e35a698ac302dd68e41f73250bd9517fe3ab5fa4f18fe4647a0872db61bacbab + sha256: "8fc3bae0b68c02c47c5c86fa8bfa74471d42687b0eded01b78de87872db745e2" url: "https://pub.dev" source: hosted - version: "6.3.10" + version: "6.3.12" url_launcher_ios: dependency: transitive description: @@ -558,10 +582,10 @@ packages: dependency: transitive description: name: win32 - sha256: "68d1e89a91ed61ad9c370f9f8b6effed9ae5e0ede22a270bdfa6daf79fc2290a" + sha256: "4d45dc9069dba4619dc0ebd93c7cec5e66d8482cb625a370ac806dcc8165f2ec" url: "https://pub.dev" source: hosted - version: "5.5.4" + version: "5.5.5" window_manager: dependency: "direct main" description: @@ -574,10 +598,10 @@ packages: dependency: transitive description: name: xdg_directories - sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d + sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15" url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.1.0" sdks: dart: ">=3.5.0 <4.0.0" flutter: ">=3.24.0"