690 lines
16 KiB
C#
690 lines
16 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace ICSharpCode.SharpZipLib.Tar
|
|
{
|
|
// Token: 0x02000034 RID: 52
|
|
public class TarArchive : IDisposable
|
|
{
|
|
// Token: 0x14000001 RID: 1
|
|
// (add) Token: 0x0600017C RID: 380 RVA: 0x000099AD File Offset: 0x000089AD
|
|
// (remove) Token: 0x0600017D RID: 381 RVA: 0x000099C6 File Offset: 0x000089C6
|
|
public event ProgressMessageHandler ProgressMessageEvent;
|
|
|
|
// Token: 0x0600017E RID: 382 RVA: 0x000099E0 File Offset: 0x000089E0
|
|
protected virtual void OnProgressMessageEvent(TarEntry entry, string message)
|
|
{
|
|
ProgressMessageHandler progressMessageEvent = this.ProgressMessageEvent;
|
|
if (progressMessageEvent != null)
|
|
{
|
|
progressMessageEvent(this, entry, message);
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600017F RID: 383 RVA: 0x00009A00 File Offset: 0x00008A00
|
|
protected TarArchive()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000180 RID: 384 RVA: 0x00009A1E File Offset: 0x00008A1E
|
|
protected TarArchive(TarInputStream stream)
|
|
{
|
|
if (stream == null)
|
|
{
|
|
throw new ArgumentNullException("stream");
|
|
}
|
|
this.tarIn = stream;
|
|
}
|
|
|
|
// Token: 0x06000181 RID: 385 RVA: 0x00009A51 File Offset: 0x00008A51
|
|
protected TarArchive(TarOutputStream stream)
|
|
{
|
|
if (stream == null)
|
|
{
|
|
throw new ArgumentNullException("stream");
|
|
}
|
|
this.tarOut = stream;
|
|
}
|
|
|
|
// Token: 0x06000182 RID: 386 RVA: 0x00009A84 File Offset: 0x00008A84
|
|
public static TarArchive CreateInputTarArchive(Stream inputStream)
|
|
{
|
|
if (inputStream == null)
|
|
{
|
|
throw new ArgumentNullException("inputStream");
|
|
}
|
|
TarInputStream tarInputStream = inputStream as TarInputStream;
|
|
TarArchive tarArchive;
|
|
if (tarInputStream != null)
|
|
{
|
|
tarArchive = new TarArchive(tarInputStream);
|
|
}
|
|
else
|
|
{
|
|
tarArchive = TarArchive.CreateInputTarArchive(inputStream, 20);
|
|
}
|
|
return tarArchive;
|
|
}
|
|
|
|
// Token: 0x06000183 RID: 387 RVA: 0x00009ABC File Offset: 0x00008ABC
|
|
public static TarArchive CreateInputTarArchive(Stream inputStream, int blockFactor)
|
|
{
|
|
if (inputStream == null)
|
|
{
|
|
throw new ArgumentNullException("inputStream");
|
|
}
|
|
if (inputStream is TarInputStream)
|
|
{
|
|
throw new ArgumentException("TarInputStream not valid");
|
|
}
|
|
return new TarArchive(new TarInputStream(inputStream, blockFactor));
|
|
}
|
|
|
|
// Token: 0x06000184 RID: 388 RVA: 0x00009AEC File Offset: 0x00008AEC
|
|
public static TarArchive CreateOutputTarArchive(Stream outputStream)
|
|
{
|
|
if (outputStream == null)
|
|
{
|
|
throw new ArgumentNullException("outputStream");
|
|
}
|
|
TarOutputStream tarOutputStream = outputStream as TarOutputStream;
|
|
TarArchive tarArchive;
|
|
if (tarOutputStream != null)
|
|
{
|
|
tarArchive = new TarArchive(tarOutputStream);
|
|
}
|
|
else
|
|
{
|
|
tarArchive = TarArchive.CreateOutputTarArchive(outputStream, 20);
|
|
}
|
|
return tarArchive;
|
|
}
|
|
|
|
// Token: 0x06000185 RID: 389 RVA: 0x00009B24 File Offset: 0x00008B24
|
|
public static TarArchive CreateOutputTarArchive(Stream outputStream, int blockFactor)
|
|
{
|
|
if (outputStream == null)
|
|
{
|
|
throw new ArgumentNullException("outputStream");
|
|
}
|
|
if (outputStream is TarOutputStream)
|
|
{
|
|
throw new ArgumentException("TarOutputStream is not valid");
|
|
}
|
|
return new TarArchive(new TarOutputStream(outputStream, blockFactor));
|
|
}
|
|
|
|
// Token: 0x06000186 RID: 390 RVA: 0x00009B53 File Offset: 0x00008B53
|
|
public void SetKeepOldFiles(bool keepExistingFiles)
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
this.keepOldFiles = keepExistingFiles;
|
|
}
|
|
|
|
// Token: 0x17000049 RID: 73
|
|
// (get) Token: 0x06000187 RID: 391 RVA: 0x00009B6F File Offset: 0x00008B6F
|
|
// (set) Token: 0x06000188 RID: 392 RVA: 0x00009B8A File Offset: 0x00008B8A
|
|
public bool AsciiTranslate
|
|
{
|
|
get
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
return this.asciiTranslate;
|
|
}
|
|
set
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
this.asciiTranslate = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000189 RID: 393 RVA: 0x00009BA6 File Offset: 0x00008BA6
|
|
[Obsolete("Use the AsciiTranslate property")]
|
|
public void SetAsciiTranslation(bool translateAsciiFiles)
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
this.asciiTranslate = translateAsciiFiles;
|
|
}
|
|
|
|
// Token: 0x1700004A RID: 74
|
|
// (get) Token: 0x0600018A RID: 394 RVA: 0x00009BC2 File Offset: 0x00008BC2
|
|
// (set) Token: 0x0600018B RID: 395 RVA: 0x00009BDD File Offset: 0x00008BDD
|
|
public string PathPrefix
|
|
{
|
|
get
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
return this.pathPrefix;
|
|
}
|
|
set
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
this.pathPrefix = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700004B RID: 75
|
|
// (get) Token: 0x0600018C RID: 396 RVA: 0x00009BF9 File Offset: 0x00008BF9
|
|
// (set) Token: 0x0600018D RID: 397 RVA: 0x00009C14 File Offset: 0x00008C14
|
|
public string RootPath
|
|
{
|
|
get
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
return this.rootPath;
|
|
}
|
|
set
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
this.rootPath = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600018E RID: 398 RVA: 0x00009C30 File Offset: 0x00008C30
|
|
public void SetUserInfo(int userId, string userName, int groupId, string groupName)
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
this.userId = userId;
|
|
this.userName = userName;
|
|
this.groupId = groupId;
|
|
this.groupName = groupName;
|
|
this.applyUserInfoOverrides = true;
|
|
}
|
|
|
|
// Token: 0x1700004C RID: 76
|
|
// (get) Token: 0x0600018F RID: 399 RVA: 0x00009C69 File Offset: 0x00008C69
|
|
// (set) Token: 0x06000190 RID: 400 RVA: 0x00009C84 File Offset: 0x00008C84
|
|
public bool ApplyUserInfoOverrides
|
|
{
|
|
get
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
return this.applyUserInfoOverrides;
|
|
}
|
|
set
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
this.applyUserInfoOverrides = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700004D RID: 77
|
|
// (get) Token: 0x06000191 RID: 401 RVA: 0x00009CA0 File Offset: 0x00008CA0
|
|
public int UserId
|
|
{
|
|
get
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
return this.userId;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700004E RID: 78
|
|
// (get) Token: 0x06000192 RID: 402 RVA: 0x00009CBB File Offset: 0x00008CBB
|
|
public string UserName
|
|
{
|
|
get
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
return this.userName;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700004F RID: 79
|
|
// (get) Token: 0x06000193 RID: 403 RVA: 0x00009CD6 File Offset: 0x00008CD6
|
|
public int GroupId
|
|
{
|
|
get
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
return this.groupId;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000050 RID: 80
|
|
// (get) Token: 0x06000194 RID: 404 RVA: 0x00009CF1 File Offset: 0x00008CF1
|
|
public string GroupName
|
|
{
|
|
get
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
return this.groupName;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000051 RID: 81
|
|
// (get) Token: 0x06000195 RID: 405 RVA: 0x00009D0C File Offset: 0x00008D0C
|
|
public int RecordSize
|
|
{
|
|
get
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
if (this.tarIn != null)
|
|
{
|
|
return this.tarIn.RecordSize;
|
|
}
|
|
if (this.tarOut != null)
|
|
{
|
|
return this.tarOut.RecordSize;
|
|
}
|
|
return 10240;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000052 RID: 82
|
|
// (set) Token: 0x06000196 RID: 406 RVA: 0x00009D59 File Offset: 0x00008D59
|
|
public bool IsStreamOwner
|
|
{
|
|
set
|
|
{
|
|
if (this.tarIn != null)
|
|
{
|
|
this.tarIn.IsStreamOwner = value;
|
|
return;
|
|
}
|
|
this.tarOut.IsStreamOwner = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000197 RID: 407 RVA: 0x00009D7C File Offset: 0x00008D7C
|
|
[Obsolete("Use Close instead")]
|
|
public void CloseArchive()
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
// Token: 0x06000198 RID: 408 RVA: 0x00009D84 File Offset: 0x00008D84
|
|
public void ListContents()
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
for (;;)
|
|
{
|
|
TarEntry nextEntry = this.tarIn.GetNextEntry();
|
|
if (nextEntry == null)
|
|
{
|
|
break;
|
|
}
|
|
this.OnProgressMessageEvent(nextEntry, null);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000199 RID: 409 RVA: 0x00009DC0 File Offset: 0x00008DC0
|
|
public void ExtractContents(string destinationDirectory)
|
|
{
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
for (;;)
|
|
{
|
|
TarEntry nextEntry = this.tarIn.GetNextEntry();
|
|
if (nextEntry == null)
|
|
{
|
|
break;
|
|
}
|
|
this.ExtractEntry(destinationDirectory, nextEntry);
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600019A RID: 410 RVA: 0x00009DFC File Offset: 0x00008DFC
|
|
private void ExtractEntry(string destDir, TarEntry entry)
|
|
{
|
|
this.OnProgressMessageEvent(entry, null);
|
|
string text = entry.Name;
|
|
if (Path.IsPathRooted(text))
|
|
{
|
|
text = text.Substring(Path.GetPathRoot(text).Length);
|
|
}
|
|
text = text.Replace('/', Path.DirectorySeparatorChar);
|
|
string text2 = Path.Combine(destDir, text);
|
|
if (entry.IsDirectory)
|
|
{
|
|
TarArchive.EnsureDirectoryExists(text2);
|
|
return;
|
|
}
|
|
string directoryName = Path.GetDirectoryName(text2);
|
|
TarArchive.EnsureDirectoryExists(directoryName);
|
|
bool flag = true;
|
|
FileInfo fileInfo = new FileInfo(text2);
|
|
if (fileInfo.Exists)
|
|
{
|
|
if (this.keepOldFiles)
|
|
{
|
|
this.OnProgressMessageEvent(entry, "Destination file already exists");
|
|
flag = false;
|
|
}
|
|
else if ((fileInfo.Attributes & FileAttributes.ReadOnly) != (FileAttributes)0)
|
|
{
|
|
this.OnProgressMessageEvent(entry, "Destination file already exists, and is read-only");
|
|
flag = false;
|
|
}
|
|
}
|
|
if (flag)
|
|
{
|
|
bool flag2 = false;
|
|
Stream stream = File.Create(text2);
|
|
if (this.asciiTranslate)
|
|
{
|
|
flag2 = !TarArchive.IsBinary(text2);
|
|
}
|
|
StreamWriter streamWriter = null;
|
|
if (flag2)
|
|
{
|
|
streamWriter = new StreamWriter(stream);
|
|
}
|
|
byte[] array = new byte[32768];
|
|
for (;;)
|
|
{
|
|
int num = this.tarIn.Read(array, 0, array.Length);
|
|
if (num <= 0)
|
|
{
|
|
break;
|
|
}
|
|
if (flag2)
|
|
{
|
|
int num2 = 0;
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
if (array[i] == 10)
|
|
{
|
|
string @string = Encoding.ASCII.GetString(array, num2, i - num2);
|
|
streamWriter.WriteLine(@string);
|
|
num2 = i + 1;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
stream.Write(array, 0, num);
|
|
}
|
|
}
|
|
if (flag2)
|
|
{
|
|
streamWriter.Close();
|
|
return;
|
|
}
|
|
stream.Close();
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600019B RID: 411 RVA: 0x00009F6C File Offset: 0x00008F6C
|
|
public void WriteEntry(TarEntry sourceEntry, bool recurse)
|
|
{
|
|
if (sourceEntry == null)
|
|
{
|
|
throw new ArgumentNullException("sourceEntry");
|
|
}
|
|
if (this.isDisposed)
|
|
{
|
|
throw new ObjectDisposedException("TarArchive");
|
|
}
|
|
try
|
|
{
|
|
if (recurse)
|
|
{
|
|
TarHeader.SetValueDefaults(sourceEntry.UserId, sourceEntry.UserName, sourceEntry.GroupId, sourceEntry.GroupName);
|
|
}
|
|
this.WriteEntryCore(sourceEntry, recurse);
|
|
}
|
|
finally
|
|
{
|
|
if (recurse)
|
|
{
|
|
TarHeader.RestoreSetValues();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600019C RID: 412 RVA: 0x00009FE0 File Offset: 0x00008FE0
|
|
private void WriteEntryCore(TarEntry sourceEntry, bool recurse)
|
|
{
|
|
string text = null;
|
|
string text2 = sourceEntry.File;
|
|
TarEntry tarEntry = (TarEntry)sourceEntry.Clone();
|
|
if (this.applyUserInfoOverrides)
|
|
{
|
|
tarEntry.GroupId = this.groupId;
|
|
tarEntry.GroupName = this.groupName;
|
|
tarEntry.UserId = this.userId;
|
|
tarEntry.UserName = this.userName;
|
|
}
|
|
this.OnProgressMessageEvent(tarEntry, null);
|
|
if (this.asciiTranslate && !tarEntry.IsDirectory && !TarArchive.IsBinary(text2))
|
|
{
|
|
text = Path.GetTempFileName();
|
|
using (StreamReader streamReader = File.OpenText(text2))
|
|
{
|
|
using (Stream stream = File.Create(text))
|
|
{
|
|
for (;;)
|
|
{
|
|
string text3 = streamReader.ReadLine();
|
|
if (text3 == null)
|
|
{
|
|
break;
|
|
}
|
|
byte[] bytes = Encoding.ASCII.GetBytes(text3);
|
|
stream.Write(bytes, 0, bytes.Length);
|
|
stream.WriteByte(10);
|
|
}
|
|
stream.Flush();
|
|
}
|
|
}
|
|
tarEntry.Size = new FileInfo(text).Length;
|
|
text2 = text;
|
|
}
|
|
string text4 = null;
|
|
if (this.rootPath != null && tarEntry.Name.StartsWith(this.rootPath))
|
|
{
|
|
text4 = tarEntry.Name.Substring(this.rootPath.Length + 1);
|
|
}
|
|
if (this.pathPrefix != null)
|
|
{
|
|
text4 = ((text4 == null) ? (this.pathPrefix + "/" + tarEntry.Name) : (this.pathPrefix + "/" + text4));
|
|
}
|
|
if (text4 != null)
|
|
{
|
|
tarEntry.Name = text4;
|
|
}
|
|
this.tarOut.PutNextEntry(tarEntry);
|
|
if (tarEntry.IsDirectory)
|
|
{
|
|
if (recurse)
|
|
{
|
|
TarEntry[] directoryEntries = tarEntry.GetDirectoryEntries();
|
|
for (int i = 0; i < directoryEntries.Length; i++)
|
|
{
|
|
this.WriteEntryCore(directoryEntries[i], recurse);
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
using (Stream stream2 = File.OpenRead(text2))
|
|
{
|
|
byte[] array = new byte[32768];
|
|
for (;;)
|
|
{
|
|
int num = stream2.Read(array, 0, array.Length);
|
|
if (num <= 0)
|
|
{
|
|
break;
|
|
}
|
|
this.tarOut.Write(array, 0, num);
|
|
}
|
|
}
|
|
if (text != null && text.Length > 0)
|
|
{
|
|
File.Delete(text);
|
|
}
|
|
this.tarOut.CloseEntry();
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600019D RID: 413 RVA: 0x0000A228 File Offset: 0x00009228
|
|
public void Dispose()
|
|
{
|
|
this.Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
// Token: 0x0600019E RID: 414 RVA: 0x0000A238 File Offset: 0x00009238
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!this.isDisposed)
|
|
{
|
|
this.isDisposed = true;
|
|
if (disposing)
|
|
{
|
|
if (this.tarOut != null)
|
|
{
|
|
this.tarOut.Flush();
|
|
this.tarOut.Close();
|
|
}
|
|
if (this.tarIn != null)
|
|
{
|
|
this.tarIn.Close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600019F RID: 415 RVA: 0x0000A288 File Offset: 0x00009288
|
|
public virtual void Close()
|
|
{
|
|
this.Dispose(true);
|
|
}
|
|
|
|
// Token: 0x060001A0 RID: 416 RVA: 0x0000A294 File Offset: 0x00009294
|
|
~TarArchive()
|
|
{
|
|
this.Dispose(false);
|
|
}
|
|
|
|
// Token: 0x060001A1 RID: 417 RVA: 0x0000A2C4 File Offset: 0x000092C4
|
|
private static void EnsureDirectoryExists(string directoryName)
|
|
{
|
|
if (!Directory.Exists(directoryName))
|
|
{
|
|
try
|
|
{
|
|
Directory.CreateDirectory(directoryName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new TarException("Exception creating directory '" + directoryName + "', " + ex.Message, ex);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x060001A2 RID: 418 RVA: 0x0000A310 File Offset: 0x00009310
|
|
private static bool IsBinary(string filename)
|
|
{
|
|
using (FileStream fileStream = File.OpenRead(filename))
|
|
{
|
|
int num = Math.Min(4096, (int)fileStream.Length);
|
|
byte[] array = new byte[num];
|
|
int num2 = fileStream.Read(array, 0, num);
|
|
for (int i = 0; i < num2; i++)
|
|
{
|
|
byte b = array[i];
|
|
if (b < 8 || (b > 13 && b < 32) || b == 255)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Token: 0x040000E1 RID: 225
|
|
private bool keepOldFiles;
|
|
|
|
// Token: 0x040000E2 RID: 226
|
|
private bool asciiTranslate;
|
|
|
|
// Token: 0x040000E3 RID: 227
|
|
private int userId;
|
|
|
|
// Token: 0x040000E4 RID: 228
|
|
private string userName = string.Empty;
|
|
|
|
// Token: 0x040000E5 RID: 229
|
|
private int groupId;
|
|
|
|
// Token: 0x040000E6 RID: 230
|
|
private string groupName = string.Empty;
|
|
|
|
// Token: 0x040000E7 RID: 231
|
|
private string rootPath;
|
|
|
|
// Token: 0x040000E8 RID: 232
|
|
private string pathPrefix;
|
|
|
|
// Token: 0x040000E9 RID: 233
|
|
private bool applyUserInfoOverrides;
|
|
|
|
// Token: 0x040000EA RID: 234
|
|
private TarInputStream tarIn;
|
|
|
|
// Token: 0x040000EB RID: 235
|
|
private TarOutputStream tarOut;
|
|
|
|
// Token: 0x040000EC RID: 236
|
|
private bool isDisposed;
|
|
}
|
|
}
|