Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
xXxTheDarkprogramerxXx committed May 14, 2019
0 parents commit 18b933e
Show file tree
Hide file tree
Showing 60 changed files with 10,684 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
Binary file added .vs/PS2_Tools/v14/.suo
Binary file not shown.
28 changes: 28 additions & 0 deletions PS2_Tools.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PS2_Tools", "PS2_Tools\PS2_Tools.csproj", "{C15D7496-EB98-46A7-A9F6-FDC3C54A7858}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tester", "Tester\Tester.csproj", "{8EE5E84C-529B-443C-ACBF-FFA9CA55BD00}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C15D7496-EB98-46A7-A9F6-FDC3C54A7858}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C15D7496-EB98-46A7-A9F6-FDC3C54A7858}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C15D7496-EB98-46A7-A9F6-FDC3C54A7858}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C15D7496-EB98-46A7-A9F6-FDC3C54A7858}.Release|Any CPU.Build.0 = Release|Any CPU
{8EE5E84C-529B-443C-ACBF-FFA9CA55BD00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8EE5E84C-529B-443C-ACBF-FFA9CA55BD00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8EE5E84C-529B-443C-ACBF-FFA9CA55BD00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8EE5E84C-529B-443C-ACBF-FFA9CA55BD00}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
62 changes: 62 additions & 0 deletions PS2_Tools/BinCue/BinChunk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace PS2_Tools.BinCue
{

public class BinChunk
{
public const int SectorLength = 2352;
public static bool Verbose;
private const string CueExtension = ".cue";

static string outFileNameBase;
static string cueFileName;

public void Convert_To_ISO(string file,string outfile)
{
string cueFileName = file;
string outFileNameBase = outfile;

//Track.TruncatePsx = true;

CueFile cueFile;

try
{
cueFileName = Path.ChangeExtension(cueFileName, CueExtension);
cueFile = new CueFile(cueFileName);
}
catch (Exception e)
{
throw new ApplicationException($"Could not read CUE {cueFileName}:\n{e.Message}");
}

Stream binStream;
try
{
binStream = File.OpenRead(cueFile.BinFileName);
}
catch (Exception e)
{
throw new ApplicationException($"Could not open BIN {cueFile.BinFileName}: {e.Message}");
}

Console.WriteLine(Environment.NewLine + "Writing tracks:");
foreach (Track curTrack in cueFile.TrackList)
{
// Include track number when more than 1 track.
string outFileName;
if (cueFile.TrackList.Count > 1)
outFileName =
$"{outFileNameBase}{curTrack.TrackNumber:00}.{curTrack.FileExtension.ToString().ToLower()}";
else
outFileName = $"{outFileNameBase}.{curTrack.FileExtension.ToString().ToLower()}";
curTrack.Write(binStream, outFileName);
}
}
}
}
80 changes: 80 additions & 0 deletions PS2_Tools/BinCue/CueFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PS2_Tools.BinCue
{
public class CueFile
{
public readonly ArrayList TrackList = new ArrayList();
public readonly string BinFileName;
private readonly string cueFilePath;

public CueFile(string cueFilePath)
{
this.cueFilePath = cueFilePath;
Console.WriteLine("Reading the CUE file:");
string cueLines;
using (TextReader cueReader = new StreamReader(cueFilePath))
{
BinFileName = GetBinFileName(cueReader.ReadLine());
cueLines = cueReader.ReadToEnd();
}

Regex trackRegex = new Regex(@"track\s+?(\d+?)\s+?(\S+?)[\s$]+?index\s+?\d+?\s+?(\S*)",
RegexOptions.IgnoreCase | RegexOptions.Multiline);
var matches = trackRegex.Matches(cueLines);

if (matches.Count == 0)
throw new ApplicationException("No tracks was found.");

Track track = null;
Track prevTrack = null;
foreach (Match trackMatch in matches)
{
track = new Track(
trackMatch.Groups[1].Value,
trackMatch.Groups[2].Value,
trackMatch.Groups[3].Value);

if (BinChunk.Verbose)
Console.WriteLine(" (StartSector {0} ofs {1})", track.StartSector, track.StartPosition);

if (prevTrack != null)
{
prevTrack.Stop = track.StartPosition - 1;
prevTrack.StopSector = track.StartSector;
}
TrackList.Add(track);
prevTrack = track;
}

if (track == null) return;
track.Stop = GetBinFileLength();
track.StopSector = track.Stop / BinChunk.SectorLength;
TrackList[TrackList.Count - 1] = track;
}

private long GetBinFileLength()
{
var fileInfo = new FileInfo(BinFileName);
return fileInfo.Length;
}

private string GetBinFileName(string cueFirstLine)
{
Regex binRegex = new Regex(@"file\s+?""(.*?)""", RegexOptions.IgnoreCase | RegexOptions.Multiline);
Match match = binRegex.Match(cueFirstLine);
string res = match.Groups[1].Value;
var cueDirectory = Path.GetDirectoryName(cueFilePath);
res = Path.Combine(cueDirectory, Path.GetFileName(res));
if (!File.Exists(res))
res = Path.Combine(cueDirectory, Path.GetFileNameWithoutExtension(cueFilePath) + ".bin");
return res;
}
}
}
Loading

0 comments on commit 18b933e

Please sign in to comment.