Skip to content

Commit

Permalink
Specify FileStream mode (Fixes #52)
Browse files Browse the repository at this point in the history
  • Loading branch information
RupertAvery committed Oct 12, 2023
1 parent 4ed89e1 commit 6915b3e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion PSXPackager.Common/Cue/CueFileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class CueFileWriter

public static void Write(CueFile cueFile, string file)
{
using (var stream = new FileStream(file, FileMode.Create))
using (var stream = new FileStream(file, FileMode.Create, FileAccess.Write))
{
using (var writer = new StreamWriter(stream))
{
Expand Down
6 changes: 3 additions & 3 deletions PSXPackager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace PSXPackager
public static class Results
{
public const int OK = 0;
public const int INVALID_INPUT = -1;
public const int CANCELLED = -2;
public const int ERROR = -3;
public const int ERROR = 1;
public const int CANCELLED = 2;
public const int INVALID_INPUT = 3;
}

class Program
Expand Down
2 changes: 1 addition & 1 deletion Popstation.Database/GameDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static string FindGameId(string srcIso)
var regex = new Regex("(SCUS|SLUS|SLES|SCES|SCED|SLPS|SLPM|SCPS|SLED|SLPS|SIPS|ESPM|PBPX)[_-](\\d{3})\\.(\\d{2})", RegexOptions.IgnoreCase);
var bootRegex = new Regex("BOOT\\s*=\\s*cdrom:\\\\?(?:.*?\\\\)?(.*?);1");

using (var stream = new FileStream(srcIso, FileMode.Open))
using (var stream = new FileStream(srcIso, FileMode.Open, FileAccess.Read))
{
var cdReader = new CDReader(stream, false, 2352);

Expand Down
10 changes: 6 additions & 4 deletions Popstation/Processing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public bool ProcessFile(
if (FileExtensionHelper.IsCue(file))
{
var (outfile, srcToc) = ProcessCue(file, options.TempPath);

result = ConvertIso(originalFile, outfile, srcToc, options, cancellationToken);
}
else if (FileExtensionHelper.IsM3u(file))
Expand Down Expand Up @@ -255,7 +256,7 @@ static MergedBin MergeBins(string file, CueFile cueFilex, string tempPath)

mergedBin.CueFile.FileEntries.Add(mcueFile);

using (var joinedFile = new FileStream(mergedBin.Path, FileMode.Create))
using (var joinedFile = new FileStream(mergedBin.Path, FileMode.Create, FileAccess.Write))
{
foreach (var cueFileEntry in cueFilex.FileEntries)
{
Expand All @@ -265,7 +266,7 @@ static MergedBin MergeBins(string file, CueFile cueFilex, string tempPath)
binPath = Path.Combine(cueFilePath, cueFileEntry.FileName);
}

using (var srcStream = new FileStream(binPath, FileMode.Open))
using (var srcStream = new FileStream(binPath, FileMode.Open, FileAccess.Read))
{
srcStream.CopyTo(joinedFile);

Expand Down Expand Up @@ -448,6 +449,7 @@ private bool ConvertIsos(
GenerateResourceFolders(processOptions, options, game);
return true;
}

SetResources(processOptions, options, game);

for (var i = 0; i < srcIsos.Length; i++)
Expand Down Expand Up @@ -534,11 +536,11 @@ private static string GetActualFileName(string path)
// Enumerate all files in the directory, using the file name as a pattern
// This will list all case variants of the filename even on file systems that
// are case sensitive
var foundFiles = Directory.EnumerateFiles(directory, pattern).ToList();
var foundFiles = Directory.EnumerateFiles(directory, pattern, new EnumerationOptions() { MatchCasing = MatchCasing.CaseInsensitive }).ToList();

if (foundFiles.Any())
{
if (foundFiles.Count() > 1)
if (foundFiles.Count > 1)
{
// More than two files with the same name but different case spelling found
throw new Exception("Ambiguous File reference for " + path);
Expand Down

0 comments on commit 6915b3e

Please sign in to comment.