Implemented Salvaging Strategy 3.
All checks were successful
🚀 Pack skyscraper8 / make-zip (push) Successful in 47s

This commit is contained in:
feyris-tan 2026-05-18 21:50:40 +02:00
parent a925a3a416
commit c4c08d1494
3 changed files with 76 additions and 2 deletions

View File

@ -2,7 +2,7 @@
"profiles": { "profiles": {
"skyscraper8": { "skyscraper8": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "\"C:\\Users\\Sascha Schiemann\\Downloads\\65w_fix.ts\"", "commandLineArgs": "salvage strat3 \"Z:\\Persönliches\\Satellitescommunity\\Skyscraper Test Fixture\\105.5E_4169.263_H_5237_(2026-04-24 12.36.13)_dump.ts\"",
"remoteDebugEnabled": false "remoteDebugEnabled": false
}, },
"Container (Dockerfile)": { "Container (Dockerfile)": {

View File

@ -15,6 +15,7 @@ namespace skyscraper8.Skyscraper.IO
private bool _positionSupported; private bool _positionSupported;
private readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name); private readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
private long emulatedPosition; private long emulatedPosition;
private bool canNotReadAnymore;
public UnseekableInputStream(Stream wrappedStream) public UnseekableInputStream(Stream wrappedStream)
{ {
@ -57,6 +58,9 @@ namespace skyscraper8.Skyscraper.IO
emulatedPosition += result; emulatedPosition += result;
} }
if (result == 0 && count > 0)
canNotReadAnymore = true;
return result; return result;
} }
@ -75,7 +79,17 @@ namespace skyscraper8.Skyscraper.IO
throw new NotSupportedException(); throw new NotSupportedException();
} }
public override bool CanRead => _wrappedStream.CanRead; public override bool CanRead
{
get
{
if (canNotReadAnymore)
return false;
return true;
}
}
public override bool CanSeek => false; public override bool CanSeek => false;
public override bool CanWrite => false; public override bool CanWrite => false;

View File

@ -42,6 +42,11 @@ namespace skyscraper8.Skyscraper
if (fi.Exists) if (fi.Exists)
{ {
InputStream = fi.OpenRead(); InputStream = fi.OpenRead();
string filename = fi.Name;
filename = Path.GetFileNameWithoutExtension(filename);
filename = string.Format("{0}_salvaged_{1}_{2}.ts", filename, args[1], DateTime.Now.Ticks);
SalvagedOutput = File.OpenWrite(filename);
} }
else else
{ {
@ -74,6 +79,9 @@ namespace skyscraper8.Skyscraper
InputStream = new UnseekableInputStream(InputStream); InputStream = new UnseekableInputStream(InputStream);
Run(); Run();
SalvagedOutput?.Flush();
SalvagedOutput?.Close();
} }
private void Run() private void Run()
@ -110,12 +118,64 @@ namespace skyscraper8.Skyscraper
case SalvagingStrategy.PatchSyncByte: case SalvagingStrategy.PatchSyncByte:
RunWithPatchingSyncByte(); RunWithPatchingSyncByte();
break; break;
case SalvagingStrategy.SeekForSyncByte:
RunWithSeekForSyncByte();
break;
default: default:
logger.ErrorFormat("I'm sorry, but the strategy \"{0}\" is not yet fully implemented.",Strategy); logger.ErrorFormat("I'm sorry, but the strategy \"{0}\" is not yet fully implemented.",Strategy);
return; return;
} }
} }
private void RunWithSeekForSyncByte()
{
bool synced = false;
while (InputStream.CanRead)
{
Array.Clear(readBuffer);
if (InputStream.Read(readBuffer, 0, 1) != 1)
return;
if (readBuffer[0] != 'G') //wrong sync byte
{
if (synced)
{
logger.WarnFormat("Lost sync at byte {0}", InputStream.Position - 1);
synced = false;
}
continue;
}
if (InputStream.Read(readBuffer, 1, 3) != 3)
{
return;
}
int tsc = readBuffer[3] & 0xc0;
int adaptionField = readBuffer[3] & 0x30;
tsc >>= 6;
adaptionField >>= 4;
if (tsc == 1)
continue;
if (adaptionField == 0)
continue;
if (InputStream.Read(readBuffer, 4, 184) != 184)
{
return;
}
SalvagedOutput?.Write(readBuffer,0,184);
Context.IngestSinglePacket(readBuffer);
synced = true;
}
}
private void RunWithPatchingSyncByte() private void RunWithPatchingSyncByte()
{ {
while (readLength == 188) while (readLength == 188)