163 lines
4.0 KiB
C#
163 lines
4.0 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace ICSharpCode.SharpZipLib.Zip
|
|
{
|
|
// Token: 0x02000078 RID: 120
|
|
public class DiskArchiveStorage : BaseArchiveStorage
|
|
{
|
|
// Token: 0x06000491 RID: 1169 RVA: 0x00016948 File Offset: 0x00015948
|
|
public DiskArchiveStorage(ZipFile file, FileUpdateMode updateMode)
|
|
: base(updateMode)
|
|
{
|
|
if (file.Name == null)
|
|
{
|
|
throw new ZipException("Cant handle non file archives");
|
|
}
|
|
this.fileName_ = file.Name;
|
|
}
|
|
|
|
// Token: 0x06000492 RID: 1170 RVA: 0x00016970 File Offset: 0x00015970
|
|
public DiskArchiveStorage(ZipFile file)
|
|
: this(file, FileUpdateMode.Safe)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000493 RID: 1171 RVA: 0x0001697C File Offset: 0x0001597C
|
|
public override Stream GetTemporaryOutput()
|
|
{
|
|
if (this.temporaryName_ != null)
|
|
{
|
|
this.temporaryName_ = DiskArchiveStorage.GetTempFileName(this.temporaryName_, true);
|
|
this.temporaryStream_ = File.Open(this.temporaryName_, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
|
|
}
|
|
else
|
|
{
|
|
this.temporaryName_ = Path.GetTempFileName();
|
|
this.temporaryStream_ = File.Open(this.temporaryName_, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
|
|
}
|
|
return this.temporaryStream_;
|
|
}
|
|
|
|
// Token: 0x06000494 RID: 1172 RVA: 0x000169E0 File Offset: 0x000159E0
|
|
public override Stream ConvertTemporaryToFinal()
|
|
{
|
|
if (this.temporaryStream_ == null)
|
|
{
|
|
throw new ZipException("No temporary stream has been created");
|
|
}
|
|
Stream stream = null;
|
|
string tempFileName = DiskArchiveStorage.GetTempFileName(this.fileName_, false);
|
|
bool flag = false;
|
|
try
|
|
{
|
|
this.temporaryStream_.Close();
|
|
File.Move(this.fileName_, tempFileName);
|
|
File.Move(this.temporaryName_, this.fileName_);
|
|
flag = true;
|
|
File.Delete(tempFileName);
|
|
stream = File.Open(this.fileName_, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
stream = null;
|
|
if (!flag)
|
|
{
|
|
File.Move(tempFileName, this.fileName_);
|
|
File.Delete(this.temporaryName_);
|
|
}
|
|
throw;
|
|
}
|
|
return stream;
|
|
}
|
|
|
|
// Token: 0x06000495 RID: 1173 RVA: 0x00016A84 File Offset: 0x00015A84
|
|
public override Stream MakeTemporaryCopy(Stream stream)
|
|
{
|
|
stream.Close();
|
|
this.temporaryName_ = DiskArchiveStorage.GetTempFileName(this.fileName_, true);
|
|
File.Copy(this.fileName_, this.temporaryName_, true);
|
|
this.temporaryStream_ = new FileStream(this.temporaryName_, FileMode.Open, FileAccess.ReadWrite);
|
|
return this.temporaryStream_;
|
|
}
|
|
|
|
// Token: 0x06000496 RID: 1174 RVA: 0x00016AD4 File Offset: 0x00015AD4
|
|
public override Stream OpenForDirectUpdate(Stream stream)
|
|
{
|
|
Stream stream2;
|
|
if (stream == null || !stream.CanWrite)
|
|
{
|
|
if (stream != null)
|
|
{
|
|
stream.Close();
|
|
}
|
|
stream2 = new FileStream(this.fileName_, FileMode.Open, FileAccess.ReadWrite);
|
|
}
|
|
else
|
|
{
|
|
stream2 = stream;
|
|
}
|
|
return stream2;
|
|
}
|
|
|
|
// Token: 0x06000497 RID: 1175 RVA: 0x00016B08 File Offset: 0x00015B08
|
|
public override void Dispose()
|
|
{
|
|
if (this.temporaryStream_ != null)
|
|
{
|
|
this.temporaryStream_.Close();
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000498 RID: 1176 RVA: 0x00016B20 File Offset: 0x00015B20
|
|
private static string GetTempFileName(string original, bool makeTempFile)
|
|
{
|
|
string text = null;
|
|
if (original == null)
|
|
{
|
|
text = Path.GetTempFileName();
|
|
}
|
|
else
|
|
{
|
|
int num = 0;
|
|
int num2 = DateTime.Now.Second;
|
|
while (text == null)
|
|
{
|
|
num++;
|
|
string text2 = string.Format("{0}.{1}{2}.tmp", original, num2, num);
|
|
if (!File.Exists(text2))
|
|
{
|
|
if (makeTempFile)
|
|
{
|
|
try
|
|
{
|
|
using (File.Create(text2))
|
|
{
|
|
}
|
|
text = text2;
|
|
continue;
|
|
}
|
|
catch
|
|
{
|
|
num2 = DateTime.Now.Second;
|
|
continue;
|
|
}
|
|
}
|
|
text = text2;
|
|
}
|
|
}
|
|
}
|
|
return text;
|
|
}
|
|
|
|
// Token: 0x0400030A RID: 778
|
|
private Stream temporaryStream_;
|
|
|
|
// Token: 0x0400030B RID: 779
|
|
private string fileName_;
|
|
|
|
// Token: 0x0400030C RID: 780
|
|
private string temporaryName_;
|
|
}
|
|
}
|