Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Fix: Wrong path joining in yuzu filesystem (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
89pleasure committed Jun 11, 2023
1 parent 7081531 commit ffc8688
Showing 1 changed file with 16 additions and 34 deletions.
50 changes: 16 additions & 34 deletions lib/src/service/filesystem/emulator/yuzu_filesystem.dart
Expand Up @@ -6,8 +6,7 @@ import 'package:modmopet/src/service/logger.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';

class YuzuFilesystem extends EmulatorFilesystem
implements EmulatorFilesystemInterface {
class YuzuFilesystem extends EmulatorFilesystem implements EmulatorFilesystemInterface {
YuzuFilesystem._();
static final instance = YuzuFilesystem._();
static const String emulatorId = 'yuzu';
Expand All @@ -32,22 +31,19 @@ class YuzuFilesystem extends EmulatorFilesystem

@override
Future<Directory> defaultEmulatorAppDirectory() async {
Directory applicationSupportDirectory =
(await getApplicationSupportDirectory()).parent;
return Directory(
path.join(applicationSupportDirectory.path, applicationFolderName));
Directory applicationSupportDirectory = (await getApplicationSupportDirectory()).parent;
return Directory(path.join(applicationSupportDirectory.path, applicationFolderName));
}

/// Gets the directory of a potentially installed mod
@override
Future<Directory> getModDirectory(
Emulator emulator, String gameTitleId, String identfier) async {
Future<Directory> getModDirectory(Emulator emulator, String gameTitleId, String identifier) async {
final modFolderBasename = mmPrefix + identifier;
final modDirectory = Directory(path.joinAll([
emulator.path!,
modsDirectoryBasename,
gameTitleId,
mmPrefix,
identfier
modFolderBasename,
]));

return modDirectory;
Expand All @@ -62,11 +58,7 @@ class YuzuFilesystem extends EmulatorFilesystem
final Directory emulatorAppDirectory = Directory(emulator.path!);
if (await emulatorAppDirectory.exists()) {
final Directory modDirectory = Directory(
emulatorAppDirectory.path +
Platform.pathSeparator +
identifierDirectory +
Platform.pathSeparator +
gameTitleId,
emulatorAppDirectory.path + Platform.pathSeparator + identifierDirectory + Platform.pathSeparator + gameTitleId,
);

if (await modDirectory.exists()) {
Expand All @@ -80,17 +72,14 @@ class YuzuFilesystem extends EmulatorFilesystem

// Yuzu does not support game metadata yet
@override
Future<GameMeta?> getGameMetadata(
Emulator emulator, String gameTitleId) async {
Future<GameMeta?> getGameMetadata(Emulator emulator, String gameTitleId) async {
return null;
}

@override
Future<Directory> getGameDirectory(
Emulator emulator, String gameTitleId) async {
Future<Directory> getGameDirectory(Emulator emulator, String gameTitleId) async {
final Directory emulatorAppDirectory = Directory(emulator.path!);
final gameDirectory = Directory(path.joinAll(
[emulatorAppDirectory.path, gamesDirectoryBasename, gameTitleId]));
final gameDirectory = Directory(path.joinAll([emulatorAppDirectory.path, gamesDirectoryBasename, gameTitleId]));

return gameDirectory;
}
Expand All @@ -105,43 +94,36 @@ class YuzuFilesystem extends EmulatorFilesystem
}

@override
Future<Stream<FileSystemEntity>> getGamesDirectoryList(
Emulator emulator) async {
Future<Stream<FileSystemEntity>> getGamesDirectoryList(Emulator emulator) async {
final Directory? emulatorAppDirectory = await _getDirectory(emulator.path!);

if (emulatorAppDirectory == null) {
return const Stream<FileSystemEntity>.empty();
}

String gameListPath =
path.join(emulatorAppDirectory.path, gamesDirectoryBasename);
String gameListPath = path.join(emulatorAppDirectory.path, gamesDirectoryBasename);
Directory? gameListDirectory = await _getDirectory(gameListPath);

if (gameListDirectory == null) {
for (String alternativePath
in gamesAlternativePaths[Platform.operatingSystem]!) {
for (String alternativePath in gamesAlternativePaths[Platform.operatingSystem]!) {
gameListDirectory = await _getDirectory(alternativePath);
if (gameListDirectory != null) {
break;
}
}
}

return gameListDirectory != null
? gameListDirectory.list()
: const Stream<FileSystemEntity>.empty();
return gameListDirectory != null ? gameListDirectory.list() : const Stream<FileSystemEntity>.empty();
}

@override
Future<bool> isIdentifiedByDirectoryStructure(
String emulatorDirectoryPath) async {
Future<bool> isIdentifiedByDirectoryStructure(String emulatorDirectoryPath) async {
final Directory emulatorDirectory = Directory(emulatorDirectoryPath);
await for (var element in emulatorDirectory.list()) {
if (element is Directory) {
final directory = path.basename(element.path);
if (directory == identifierDirectory) {
LoggerService.instance
.log('Yuzu application folder found at: $emulatorDirectoryPath');
LoggerService.instance.log('Yuzu application folder found at: $emulatorDirectoryPath');
return true;
}
}
Expand Down

0 comments on commit ffc8688

Please sign in to comment.