Skip to content

Commit

Permalink
Advanced Support (#172)
Browse files Browse the repository at this point in the history
* Who doesn't like drives?

* Add another TODO

* Use built in stuff, it's quicker

* More special handling for floppies, easier this time

* Fix broken test

* Set active drive priority, String -> string

* Track reason for no scanning

* Update DIC version and release notes
  • Loading branch information
mnadareski authored Nov 17, 2019
1 parent 24b08dd commit fbc9d04
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 97 deletions.
6 changes: 6 additions & 0 deletions CHANGELIST.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 1.15 (2019-11-16)

- Updated to DIC version 20191116
- Support non-optical, non-floppy stuff better
- Update protection scanning and fix some things

### 1.14 (2019-10-01)

- Updated to DIC version 20191001
Expand Down
15 changes: 15 additions & 0 deletions DICUI.Library/Data/Enumerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ public enum DICFlag
VideoNowColor,
}

/// <summary>
/// Drive type for dumping
/// </summary>
public enum InternalDriveType
{
Optical,
Floppy,
HardDisk,
Removable,
}

/// <summary>
/// Dump status for Redump
/// </summary>
Expand Down Expand Up @@ -419,6 +430,10 @@ public enum MediaType
// Unsorted Formats
Cartridge,
CED,
CompactFlash,
MMC,
SDCard,
FlashDrive,
}

/// <summary>
Expand Down
26 changes: 26 additions & 0 deletions DICUI.Library/Utilities/Converters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using IMAPI2;
using DICUI.Data;
using Newtonsoft.Json;
Expand All @@ -10,6 +11,26 @@ public static class Converters
{
#region Cross-enumeration conversions

/// <summary>
/// Convert drive type to internal version, if possible
/// </summary>
/// <param name="driveType">DriveType value to check</param>
/// <returns>InternalDriveType, if possible, null on error</returns>
public static InternalDriveType? ToInternalDriveType(this DriveType driveType)
{
switch(driveType)
{
case DriveType.CDRom:
return InternalDriveType.Optical;
case DriveType.Fixed:
return InternalDriveType.HardDisk;
case DriveType.Removable:
return InternalDriveType.Removable;
default:
return null;
}
}

/// <summary>
/// Get the most common known system for a given MediaType
/// </summary>
Expand Down Expand Up @@ -452,6 +473,11 @@ public static string Extension(this MediaType? type)
case MediaType.CDROM:
case MediaType.GDROM:
case MediaType.Cartridge:
case MediaType.HardDisk:
case MediaType.CompactFlash:
case MediaType.MMC:
case MediaType.SDCard:
case MediaType.FlashDrive:
return ".bin";
case MediaType.DVD:
case MediaType.HDDVD:
Expand Down
61 changes: 36 additions & 25 deletions DICUI.Library/Utilities/Drive.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
namespace DICUI.Utilities
using System.IO;
using DICUI.Data;

namespace DICUI.Utilities
{
/// <summary>
/// Represents information for a single drive
/// </summary>
public class Drive
{
/// <summary>
/// Windows drive letter
/// Represents drive type
/// </summary>
public char Letter { get; private set; }
public InternalDriveType? InternalDriveType { get; set; }

/// <summary>
/// Represents if it is a floppy drive
/// DriveInfo object representing the drive, if possible
/// </summary>
public bool IsFloppy { get; private set; }
public DriveInfo DriveInfo { get; private set; }

/// <summary>
/// Media label as read by Windows
/// Windows drive letter
/// </summary>
public string VolumeLabel { get; private set; }
public char Letter { get { return DriveInfo?.Name[0] ?? '\0'; } }

/// <summary>
/// Represents if Windows has marked the drive as active
/// Media label as read by Windows
/// </summary>
public bool MarkedActive { get; private set; }

private Drive(char letter, string volumeLabel, bool isFloppy, bool markedActive)
public string VolumeLabel
{
this.Letter = letter;
this.IsFloppy = isFloppy;
this.VolumeLabel = volumeLabel;
this.MarkedActive = markedActive;
get
{
if (DriveInfo.IsReady)
{
if (string.IsNullOrWhiteSpace(DriveInfo.VolumeLabel))
return "track";
else
return DriveInfo.VolumeLabel;
}
else
{
return Template.DiscNotDetected;
}
}
}

/// <summary>
/// Create a new Floppy drive instance
/// Drive partition format
/// </summary>
/// <param name="letter">Drive letter to use</param>
/// <returns>Drive object for a Floppy drive</returns>
public static Drive Floppy(char letter) => new Drive(letter, null, true, true);
public string DriveFormat { get { return DriveInfo.DriveFormat; } }

/// <summary>
/// Create a new Optical drive instance
/// Represents if Windows has marked the drive as active
/// </summary>
/// <param name="letter">Drive letter to use</param>
/// <param name="volumeLabel">Media label, if it exists</param>
/// <param name="active">True if the drive is marked active, false otherwise</param>
/// <returns>Drive object for an Optical drive</returns>
public static Drive Optical(char letter, string volumeLabel, bool active) => new Drive(letter, volumeLabel, false, active);
public bool MarkedActive { get { return DriveInfo.IsReady; } }

public Drive(InternalDriveType? driveType, DriveInfo driveInfo)
{
this.InternalDriveType = driveType;
this.DriveInfo = driveInfo;
}
}
}
31 changes: 18 additions & 13 deletions DICUI.Library/Utilities/DumpEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ public async void EjectDisc()

CancelDumping();

// Validate we're not trying to eject a floppy disk
if (Drive.IsFloppy)
// Validate we're not trying to eject a non-optical
if (Drive.InternalDriveType != InternalDriveType.Optical)
return;

Process childProcess;
Expand Down Expand Up @@ -467,7 +467,10 @@ public Result VerifyAndSaveDumpOutput(IProgress<Result> progress, Func<Submissio
/// <returns>True if the configuration is valid, false otherwise</returns>
internal bool ParametersValid()
{
return DICParameters.IsValid() && !(Drive.IsFloppy ^ Type == MediaType.FloppyDisk);
return DICParameters.IsValid()
&& !(Drive.InternalDriveType == InternalDriveType.Floppy ^ Type == MediaType.FloppyDisk)
&& !(Drive.InternalDriveType == InternalDriveType.HardDisk ^ Type == MediaType.HardDisk)
&& !(Drive.InternalDriveType == InternalDriveType.Removable ^ (Type == MediaType.CompactFlash || Type == MediaType.SDCard || Type == MediaType.FlashDrive));
}

#endregion
Expand Down Expand Up @@ -676,7 +679,7 @@ private SubmissionInfo ExtractOutputInformation(IProgress<Result> progress)
layerbreak = (info.SizeAndChecksums.Size > 25025314816 ? "25025314816" : null);

// If we have a single-layer disc
if (String.IsNullOrWhiteSpace(layerbreak))
if (string.IsNullOrWhiteSpace(layerbreak))
{
info.CommonDiscInfo.MasteringRingFirstLayerDataSide = (AddPlaceholders ? Template.RequiredIfExistsValue : "");
info.CommonDiscInfo.MasteringSIDCodeFirstLayerDataSide = (AddPlaceholders ? Template.RequiredIfExistsValue : "");
Expand Down Expand Up @@ -733,7 +736,7 @@ private SubmissionInfo ExtractOutputInformation(IProgress<Result> progress)
info.VersionAndEditions.Version = umdversion ?? "";
info.SizeAndChecksums.Size = umdsize;

if (!String.IsNullOrWhiteSpace(umdlayer))
if (!string.IsNullOrWhiteSpace(umdlayer))
info.SizeAndChecksums.Layerbreak = Int64.Parse(umdlayer ?? "-1");
}

Expand Down Expand Up @@ -1237,6 +1240,8 @@ private Result IsValidForDump()
if (!File.Exists(DICPath))
return Result.Failure("Error! Could not find DiscImageCreator!");

// TODO: Ensure output path not the same as input drive OR DIC/DICUI location

return Result.Success();
}

Expand Down Expand Up @@ -1459,17 +1464,17 @@ private string GetDVDProtection(string cssKey, string disc)

// Now we format everything we can
string protection = "";
if (!String.IsNullOrEmpty(region))
if (!string.IsNullOrEmpty(region))
protection += $"Region: {region}\n";
if (!String.IsNullOrEmpty(rceProtection))
if (!string.IsNullOrEmpty(rceProtection))
protection += $"RCE Protection: {rceProtection}\n";
if (!String.IsNullOrEmpty(copyrightProtectionSystemType))
if (!string.IsNullOrEmpty(copyrightProtectionSystemType))
protection += $"Copyright Protection System Type: {copyrightProtectionSystemType}\n";
if (!String.IsNullOrEmpty(encryptedDiscKey))
if (!string.IsNullOrEmpty(encryptedDiscKey))
protection += $"Encrypted Disc Key: {encryptedDiscKey}\n";
if (!String.IsNullOrEmpty(playerKey))
if (!string.IsNullOrEmpty(playerKey))
protection += $"Player Key: {playerKey}\n";
if (!String.IsNullOrEmpty(decryptedDiscKey))
if (!string.IsNullOrEmpty(decryptedDiscKey))
protection += $"Decrypted Disc Key: {decryptedDiscKey}\n";

return protection;
Expand Down Expand Up @@ -1897,7 +1902,7 @@ private bool GetSegaCDBuildInfo(string segaHeader, out string serial, out string
serial = null; date = null;

// If the input header is null, we can't do a thing
if (String.IsNullOrWhiteSpace(segaHeader))
if (string.IsNullOrWhiteSpace(segaHeader))
return false;

// Now read it in cutting it into lines for easier parsing
Expand Down Expand Up @@ -1980,7 +1985,7 @@ private bool GetSaturnBuildInfo(string segaHeader, out string serial, out string
serial = null; version = null; date = null;

// If the input header is null, we can't do a thing
if (String.IsNullOrWhiteSpace(segaHeader))
if (string.IsNullOrWhiteSpace(segaHeader))
return false;

// Now read it in cutting it into lines for easier parsing
Expand Down
18 changes: 10 additions & 8 deletions DICUI.Library/Utilities/Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,10 @@ public string GenerateParameters()
}

// Force Unit Access
if (Command == DICCommand.BluRay
if (Command == DICCommand.Audio
|| Command == DICCommand.BluRay
|| Command == DICCommand.CompactDisc
|| Command == DICCommand.Data
|| Command == DICCommand.DigitalVideoDisc
|| Command == DICCommand.Swap
|| Command == DICCommand.XBOX)
Expand Down Expand Up @@ -700,7 +702,7 @@ public bool IsValid()
private bool ValidateAndSetParameters(string parameters)
{
// The string has to be valid by itself first
if (String.IsNullOrWhiteSpace(parameters))
if (string.IsNullOrWhiteSpace(parameters))
return false;

// Now split the string into parts for easier validation
Expand Down Expand Up @@ -1209,12 +1211,12 @@ private bool ValidateAndSetParameters(string parameters)

case DICFlagStrings.ForceUnitAccess:
if (parts[0] != DICCommandStrings.Audio
&& parts[0] != DICCommandStrings.BluRay
&& parts[0] != DICCommandStrings.CompactDisc
&& parts[0] != DICCommandStrings.DigitalVideoDisc
&& parts[0] != DICCommandStrings.Data
&& parts[0] != DICCommandStrings.GDROM
&& parts[0] != DICCommandStrings.XBOX)
&& parts[0] != DICCommandStrings.BluRay
&& parts[0] != DICCommandStrings.CompactDisc
&& parts[0] != DICCommandStrings.DigitalVideoDisc
&& parts[0] != DICCommandStrings.Data
&& parts[0] != DICCommandStrings.GDROM
&& parts[0] != DICCommandStrings.XBOX)
return false;
else if (!DoesExist(parts, i + 1))
{
Expand Down
Loading

0 comments on commit fbc9d04

Please sign in to comment.