diff --git a/gameyfin/src/main/frontend/components/general/input/FileTreeView.tsx b/gameyfin/src/main/frontend/components/general/input/FileTreeView.tsx index 35d8f70..102c16c 100644 --- a/gameyfin/src/main/frontend/components/general/input/FileTreeView.tsx +++ b/gameyfin/src/main/frontend/components/general/input/FileTreeView.tsx @@ -57,8 +57,8 @@ export default function FileTreeView({onPathChange}: { onPathChange: (file: stri path = path.replace(`${pathSeparator}${pathSeparator}`, pathSeparator); if (node.parent === null) { - if (hostOSType === OperatingSystemType.WINDOWS) return path ? path : node.name - return path ? `${node.name}${pathSeparator}${path}` : node.name; + if (hostOSType === OperatingSystemType.WINDOWS) return path; + return `${pathSeparator}${path}`; } const parentNode = flattenedFileTree.find(n => n.id === node.parent); diff --git a/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/filesystem/FilesystemService.kt b/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/filesystem/FilesystemService.kt index 6175c94..99517ca 100644 --- a/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/filesystem/FilesystemService.kt +++ b/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/filesystem/FilesystemService.kt @@ -21,27 +21,23 @@ class FilesystemService { */ fun listContents(path: String?): List { if (path == null || path.isEmpty()) { - return FileSystems.getDefault().rootDirectories - .map { - FileDto( - it.root.toString(), - if (it.isDirectory()) FileType.DIRECTORY else FileType.FILE, - it.hashCode() - ) - } + val roots = FileSystems.getDefault().rootDirectories.toList() + + if (roots.size > 1) return roots.map { + FileDto( + it.root.toString(), + if (it.isDirectory()) FileType.DIRECTORY else FileType.FILE, + it.hashCode() + ) + } + + // If there is only one root, return its contents + return safeReadDirectoryContents(roots.first().toString()) } var path = FilenameUtils.separatorsToSystem(path) - if (path.startsWith("\\")) path = path.substring(1) - return try { - Path(path).toFile().listFiles() - .filter { f -> !f.isHidden } - .map { FileDto(it.name, if (it.isDirectory) FileType.DIRECTORY else FileType.FILE, it.hashCode()) } - } catch (_: Exception) { - log.error { "Error listing contents of path $path" } - emptyList() - } + return safeReadDirectoryContents(path) } /** @@ -64,4 +60,15 @@ class FilesystemService { else -> OperatingSystemType.UNKNOWN } } + + private fun safeReadDirectoryContents(path: String): List { + return try { + Path(path).toFile().listFiles() + .filter { !it.isHidden } + .map { FileDto(it.name, if (it.isDirectory) FileType.DIRECTORY else FileType.FILE, it.hashCode()) } + } catch (e: Exception) { + log.error(e) { "Error reading directory contents of $path" } + emptyList() + } + } } \ No newline at end of file