Files
Aaru.VideoNow/DiscImageChef.VideoNow/Program.cs

214 lines
7.1 KiB
C#
Raw Normal View History

2020-03-01 05:40:50 +00:00
// /***************************************************************************
2019-01-29 18:16:23 +00:00
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Program.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : VideoNow analyzing and decoding tools.
//
// --[ Description ] ----------------------------------------------------------
//
// Main program loop.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
using System;
2019-01-29 18:50:07 +00:00
using System.IO;
using System.Linq;
2019-01-29 18:16:23 +00:00
using System.Reflection;
2019-02-10 16:25:24 +00:00
// ReSharper disable LocalizableElement
2019-01-29 18:16:23 +00:00
namespace DiscImageChef.VideoNow
{
2019-02-10 15:39:15 +00:00
internal static class MainClass
2019-01-29 18:16:23 +00:00
{
2019-02-10 15:39:15 +00:00
const int MAX_SIZE = 635040000;
static string assemblyCopyright;
static string assemblyTitle;
static AssemblyInformationalVersionAttribute assemblyVersion;
static readonly byte[] FrameStart =
{
0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81
};
static readonly byte[] SwappedFrameStart =
{
0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3
};
2019-01-29 18:16:23 +00:00
public static void Main(string[] args)
{
object[] attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
2019-02-10 15:39:15 +00:00
assemblyTitle = ((AssemblyTitleAttribute)attributes[0]).Title;
2019-01-29 18:16:23 +00:00
attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
2019-02-10 15:39:15 +00:00
assemblyVersion =
2019-01-29 18:16:23 +00:00
Attribute.GetCustomAttribute(typeof(MainClass).Assembly, typeof(AssemblyInformationalVersionAttribute))
as AssemblyInformationalVersionAttribute;
2019-02-10 15:39:15 +00:00
assemblyCopyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
2019-01-29 18:16:23 +00:00
PrintCopyright();
2019-01-29 18:50:07 +00:00
if(args.Length != 1)
{
2019-02-10 16:25:24 +00:00
Console.WriteLine(Localization.Usage);
2019-02-10 15:39:15 +00:00
2019-01-29 18:50:07 +00:00
return;
}
if(!File.Exists(args[0]))
{
2019-02-10 16:25:24 +00:00
Console.WriteLine(Localization.FileDoesNotExist);
2019-02-10 15:39:15 +00:00
2019-01-29 18:50:07 +00:00
return;
}
FileStream fs;
2019-02-10 15:39:15 +00:00
try
{
fs = File.Open(args[0], FileMode.Open, FileAccess.Read, FileShare.Read);
}
2019-01-29 18:50:07 +00:00
catch
{
2019-02-10 16:25:24 +00:00
Console.WriteLine(Localization.FileCannotBeOpened);
2019-02-10 15:39:15 +00:00
2019-01-29 18:50:07 +00:00
return;
}
2019-02-10 15:39:15 +00:00
if(fs.Length > MAX_SIZE)
2019-01-29 18:50:07 +00:00
{
2019-02-10 16:25:24 +00:00
Console.WriteLine(Localization.FileIsTooBig);
2019-02-10 15:39:15 +00:00
2019-01-29 18:50:07 +00:00
return;
}
2019-02-10 16:25:24 +00:00
Console.WriteLine(Localization.FileName, args[0]);
Console.WriteLine(Localization.SearchingFirstFrame);
2019-01-29 18:50:07 +00:00
2019-03-13 20:36:47 +00:00
long framePosition = 0;
byte[] buffer = new byte[Color.FrameMarker.Length];
byte[] swappedBuffer = new byte[Color.FrameMarker.Length];
bool swapped = false;
bool xp = false;
byte[] startBuffer = new byte[FrameStart.Length];
byte[] xpBuffer = new byte[Xp.FrameMarker.Length];
byte[] xpSwappedBuffer = new byte[Xp.FrameMarker.Length];
while(framePosition < 19760)
2019-01-29 18:50:07 +00:00
{
fs.Position = framePosition;
fs.Read(startBuffer, 0, startBuffer.Length);
if(!startBuffer.SequenceEqual(FrameStart) &&
!startBuffer.SequenceEqual(SwappedFrameStart))
{
framePosition++;
continue;
}
2019-01-29 18:50:07 +00:00
fs.Position = framePosition;
fs.Read(buffer, 0, buffer.Length);
2019-02-10 15:39:15 +00:00
for(int ab = 8; ab < buffer.Length; ab += 10)
buffer[ab] = 0;
2019-01-30 20:35:49 +00:00
2019-03-13 19:26:14 +00:00
if(buffer.SequenceEqual(Color.FrameMarker))
2019-02-10 15:39:15 +00:00
break;
2019-01-29 18:50:07 +00:00
2019-02-10 16:03:10 +00:00
fs.Position = framePosition;
fs.Read(swappedBuffer, 0, swappedBuffer.Length);
for(int ab = 9; ab < swappedBuffer.Length; ab += 10)
swappedBuffer[ab] = 0;
2019-03-13 19:26:14 +00:00
if(swappedBuffer.SequenceEqual(Color.SwappedFrameMarker))
2019-02-10 16:03:10 +00:00
{
swapped = true;
break;
}
2019-03-13 20:36:47 +00:00
fs.Position = framePosition;
fs.Read(xpBuffer, 0, xpBuffer.Length);
for(int i = 0; i < xpBuffer.Length; i++)
xpBuffer[i] &= Xp.FrameMask[i];
if(xpBuffer.SequenceEqual(Xp.FrameMarker))
{
xp = true;
break;
}
2019-01-29 18:50:07 +00:00
2019-03-13 20:36:47 +00:00
fs.Position = framePosition;
fs.Read(xpSwappedBuffer, 0, xpSwappedBuffer.Length);
for(int i = 0; i < xpSwappedBuffer.Length; i++)
xpSwappedBuffer[i] &= Xp.SwappedFrameMask[i];
if(xpSwappedBuffer.SequenceEqual(Xp.SwappedFrameMarker))
{
swapped = true;
xp = true;
2019-01-30 20:35:49 +00:00
2019-03-13 20:36:47 +00:00
break;
}
framePosition++;
}
2019-02-10 16:03:10 +00:00
2019-03-13 20:36:47 +00:00
if(!buffer.SequenceEqual(Color.FrameMarker) &&
!swappedBuffer.SequenceEqual(Color.SwappedFrameMarker) &&
!xpBuffer.SequenceEqual(Xp.FrameMarker) &&
!xpSwappedBuffer.SequenceEqual(Xp.SwappedFrameMarker))
2019-01-29 18:50:07 +00:00
{
2019-02-10 16:25:24 +00:00
Console.WriteLine(Localization.NoFrameFound);
2019-02-10 15:39:15 +00:00
2019-01-29 18:50:07 +00:00
return;
}
2019-02-10 16:25:24 +00:00
Console.WriteLine(Localization.FirstFrameFoundAt, framePosition);
Console.WriteLine(framePosition % 2352 == 0 ? Localization.FirstFrameIsAtSectorBoundary
: Localization.FirstFrameIsNotAtSectorBoundary);
2019-03-13 20:36:47 +00:00
if(xp)
Xp.Decode(args[0], fs, swapped, framePosition);
2019-03-13 20:36:47 +00:00
else
Color.Decode(args[0], fs, swapped, framePosition);
2019-01-30 23:10:55 +00:00
fs.Close();
2019-01-29 18:16:23 +00:00
}
static void PrintCopyright()
{
2019-02-10 15:39:15 +00:00
Console.WriteLine("{0} {1}", assemblyTitle, assemblyVersion?.InformationalVersion);
Console.WriteLine("{0}", assemblyCopyright);
2019-01-29 18:16:23 +00:00
Console.WriteLine();
}
}
}