Skip to content

Commit

Permalink
use /proc/mounts to search for the disc mount on linux by default
Browse files Browse the repository at this point in the history
instead of trying hardcoded paths that may differ from distro to distro
also try to fix free space check
  • Loading branch information
13xforever committed Jan 13, 2022
1 parent ac676b4 commit 2d4884a
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Ps3DiscDumper/Dumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Ps3DiscDumper
{
public class Dumper: IDisposable
{
public const string Version = "3.2.0";
public const string Version = "3.2.1";

private static readonly HashSet<char> InvalidChars = new(Path.GetInvalidFileNameChars());
private static readonly char[] MultilineSplit = {'\r', '\n'};
Expand Down Expand Up @@ -193,11 +193,12 @@ public void DetectDisc(string inDir = "", Func<Dumper, string> outputDirFormatte
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if (string.IsNullOrEmpty(inDir))
inDir = "/media";
discSfbPath = IOEx.GetFilepaths(inDir, "PS3_DISC.SFB", 2).FirstOrDefault();
var mountList = inDir is { Length: > 0 }
? new[] { inDir }
: DriveInfo.GetDrives().Where(d => d.DriveType == DriveType.CDRom).Select(d => d.RootDirectory.FullName);
discSfbPath = mountList.SelectMany(mp => IOEx.GetFilepaths(mp, "PS3_DISC.SFB", 2)) .FirstOrDefault();
if (!string.IsNullOrEmpty(discSfbPath))
input = Path.GetDirectoryName(discSfbPath);
input = Path.GetDirectoryName(discSfbPath)!;
}
else
throw new NotImplementedException("Current OS is not supported");
Expand Down Expand Up @@ -235,7 +236,7 @@ public void DetectDisc(string inDir = "", Func<Dumper, string> outputDirFormatte
var separators = new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };
var pathParts = path.Split(separators, StringSplitOptions.RemoveEmptyEntries).Select(p => p.TrimEnd('.'));
OutputDir = string.Join(Path.DirectorySeparatorChar, pathParts);
Log.Debug($"Output: {OutputDir}");
Log.Debug($"Dump folder name: {OutputDir}");
}

public async Task FindDiscKeyAsync(string discKeyCachePath)
Expand Down Expand Up @@ -420,8 +421,11 @@ public async Task DumpAsync(string output)
var validators = GetValidationInfo();
if (!string.IsNullOrEmpty(dumpPath))
{
var root = Path.GetPathRoot(Path.GetFullPath(output));
var drive = DriveInfo.GetDrives().FirstOrDefault(d => d?.RootDirectory.FullName.StartsWith(root) ?? false);
var fullOutputPath = Path.GetFullPath(output);
var drive = DriveInfo.GetDrives()
.OrderByDescending(d => d.RootDirectory.FullName.Length)
.ThenBy(d => d.RootDirectory.FullName, StringComparer.Ordinal)
.FirstOrDefault(d => fullOutputPath.StartsWith(d.RootDirectory.FullName));
if (drive != null)
{
var spaceAvailable = drive.AvailableFreeSpace;
Expand All @@ -437,6 +441,7 @@ public async Task DumpAsync(string output)
foreach (var file in filesystemStructure)
Log.Trace($"0x{file.StartSector:x8}: {file.TargetFileName} ({file.Length}, {file.FileInfo.CreationTimeUtc:u})");
var outputPathBase = Path.Combine(output, OutputDir);
Log.Debug($"Output path: {outputPathBase}");
if (!Directory.Exists(outputPathBase))
Directory.CreateDirectory(outputPathBase);

Expand Down

0 comments on commit 2d4884a

Please sign in to comment.