Replaced all File.OpenWrite calls /w .Open(FileMode.Create)

File.OpenWrite is equivalent to FileMode.OpenOrCreate, which caused errors when replacing a file that was larger previously
This commit is contained in:
Justin Swanson 2020-01-18 14:52:09 -06:00
parent 3bac5d2f00
commit 5db84a6ee6
15 changed files with 21 additions and 25 deletions

View File

@ -3,6 +3,7 @@
* Progress ring displays when downloading modlist images
* GUI releases memory of download modlists better when navigating around
* Fixed phrasing after failed installations to say "failed".
* Fixed download bug that was marking some modlists as corrupted if they were replacing older versions.
#### Version - 1.0 beta 15 - 1/6/2020
* Don't delete the download folder when deleting empty folders during an update

View File

@ -110,7 +110,7 @@ namespace Compression.BSA.Test
Directory.CreateDirectory(Path.GetDirectoryName(absName));
using (var fs = File.OpenWrite(absName))
using (var fs = File.Open(absName, FileMode.Create))
{
file.CopyDataTo(fs);
}

View File

@ -51,7 +51,7 @@ namespace Compression.BSA
public void Build(string filename)
{
SortEntries();
using (var fs = File.OpenWrite(filename))
using (var fs = File.Open(filename, FileMode.Create))
using (var bw = new BinaryWriter(fs))
{
bw.Write(Encoding.ASCII.GetBytes(_state.HeaderMagic));

View File

@ -90,9 +90,7 @@ namespace Compression.BSA
public void Build(string outputName)
{
RegenFolderRecords();
if (File.Exists(outputName)) File.Delete(outputName);
using (var fs = File.OpenWrite(outputName))
using (var fs = File.Open(outputName, FileMode.Create))
using (var wtr = new BinaryWriter(fs))
{
wtr.Write(_fileId);

View File

@ -27,10 +27,7 @@ namespace Wabbajack.Common
private static void ExtractResource(string from, string to)
{
if (File.Exists(to))
File.Delete(to);
using (var ous = File.OpenWrite(to))
using (var ous = File.Open(to, System.IO.FileMode.Create))
using (var ins = new GZipInputStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(from)))
{
ins.CopyTo(ous);
@ -144,7 +141,7 @@ namespace Wabbajack.Common
if (!Directory.Exists(parent))
Directory.CreateDirectory(parent);
using (var fs = File.OpenWrite(outPath))
using (var fs = File.Open(outPath, System.IO.FileMode.Create))
{
f.CopyDataTo(fs);
}

View File

@ -417,7 +417,7 @@ namespace Wabbajack.Common
/*
public static void ToBSON<T>(this T obj, string filename)
{
using (var fo = File.OpenWrite(filename))
using (var fo = File.Open(filename, System.IO.FileMode.Create))
using (var br = new BsonDataWriter(fo))
{
fo.SetLength(0);
@ -518,7 +518,7 @@ namespace Wabbajack.Common
public static void BZip2ExtractToFile(this Stream src, string dest)
{
using (var os = File.OpenWrite(dest))
using (var os = File.Open(dest, System.IO.FileMode.Create))
{
os.SetLength(0);
using (var bz = new BZip2InputStream(src))
@ -828,7 +828,7 @@ namespace Wabbajack.Common
{
var tmpName = Path.Combine("patch_cache", Guid.NewGuid() + ".tmp");
using (var f = File.OpenWrite(tmpName))
using (var f = File.Open(tmpName, System.IO.FileMode.Create))
{
Status("Creating Patch");
BSDiff.Create(a, b, f);
@ -947,7 +947,7 @@ namespace Wabbajack.Common
long size = 0;
byte[] buffer = new byte[1024 * 8];
random.NextBytes(buffer);
using (var fs = File.OpenWrite(file))
using (var fs = File.Open(file, System.IO.FileMode.Create))
{
while (DateTime.Now < startTime + new TimeSpan(0, 0, seconds))
{

View File

@ -179,7 +179,7 @@ namespace Wabbajack.Lib
}
}
using (var fs = File.OpenWrite($"{ModList.Name}.md"))
using (var fs = File.Open($"{ModList.Name}.md", System.IO.FileMode.Create))
{
fs.SetLength(0);
using (var reporter = new ReportBuilder(fs, ModListOutputFolder))

View File

@ -214,7 +214,7 @@ namespace Wabbajack.Lib
File.Delete(toFile);
// Patch it
using (var outStream = File.OpenWrite(toFile))
using (var outStream = File.Open(toFile, FileMode.Create))
{
BSDiff.Apply(oldData, () => new MemoryStream(patchData), outStream);
}

View File

@ -59,7 +59,7 @@ namespace Wabbajack.Lib.Downloaders
public override async Task<bool> Download(Archive a, string destination)
{
var stream = await ResolveDownloadStream();
using (var file = File.OpenWrite(destination))
using (var file = File.Open(destination, FileMode.Create))
{
stream.CopyTo(file);
}

View File

@ -65,7 +65,7 @@ namespace Wabbajack.Lib.Downloaders
public override async Task<bool> Download(Archive a, string destination)
{
using(var src = File.OpenRead(SourcePath))
using (var dest = File.OpenWrite(destination))
using (var dest = File.Open(destination, System.IO.FileMode.Create))
{
var size = new FileInfo(SourcePath).Length;
src.CopyToWithStatus(size, dest, "Copying from Game folder");

View File

@ -84,7 +84,7 @@ namespace Wabbajack.Lib.Downloaders
Directory.CreateDirectory(parent.FullName);
}
using (var fs = download ? File.OpenWrite(destination) : null)
using (var fs = download ? File.Open(destination, FileMode.Create) : null)
{
var client = Client ?? new HttpClient();
client.DefaultRequestHeaders.Add("User-Agent", Consts.UserAgent);
@ -103,11 +103,11 @@ namespace Wabbajack.Lib.Downloaders
Utils.Status($"Starting Download {a?.Name ?? Url}", 0);
var response = await client.GetAsync(Url, HttpCompletionOption.ResponseHeadersRead);
TOP:
TOP:
if (!response.IsSuccessStatusCode)
throw new HttpException((int)response.StatusCode, response.ReasonPhrase);
Stream stream;
try
{

View File

@ -23,7 +23,7 @@ namespace Wabbajack.Lib.LibCefHelpers
{
if (File.Exists("cefsharp.7z") && File.Exists("libcef.dll")) return;
using (var fs = File.OpenWrite("cefsharp.7z"))
using (var fs = File.Open("cefsharp.7z", System.IO.FileMode.Create))
using (var rs = Assembly.GetExecutingAssembly().GetManifestResourceStream("Wabbajack.Lib.LibCefHelpers.cefsharp.7z"))
{
rs.CopyTo(fs);

View File

@ -259,7 +259,7 @@ namespace Wabbajack.Lib
var patchData = LoadBytesFromPath(directive.SourceDataID);
var toFile = Path.Combine(OutputFolder, directive.To);
Status($"Patching {filename}");
using (var output = File.OpenWrite(toFile))
using (var output = File.Open(toFile, FileMode.Create))
using (var input = File.OpenRead(gameFile))
{
BSDiff.Apply(input, () => new MemoryStream(patchData), output);

View File

@ -175,7 +175,7 @@ namespace Wabbajack.Lib
var patch_data = installer.LoadBytesFromPath(m.PatchID);
using (var fs = File.OpenWrite(Path.Combine(installer.OutputFolder, m.To)))
using (var fs = File.Open(Path.Combine(installer.OutputFolder, m.To), FileMode.Create))
BSDiff.Apply(new MemoryStream(src_data), () => new MemoryStream(patch_data), fs);
});
}

View File

@ -148,7 +148,7 @@ namespace Wabbajack.VirtualFileSystem
public async Task WriteToFile(string filename)
{
using (var fs = File.OpenWrite(filename))
using (var fs = File.Open(filename, FileMode.Create))
using (var bw = new BinaryWriter(fs, Encoding.UTF8, true))
{
fs.SetLength(0);