mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Rename old log files. Don't overwrite downloads with the same name
This commit is contained in:
parent
9ece8bae56
commit
b1eefa6a41
@ -54,11 +54,15 @@ namespace Wabbajack.Common
|
||||
Directory.CreateDirectory(Consts.LocalAppDataPath);
|
||||
|
||||
var programName = Assembly.GetEntryAssembly()?.Location ?? "Wabbajack";
|
||||
LogFile = Path.GetFileNameWithoutExtension(programName) + DateTime.Now.ToString(" yyyy-MM-dd HH_mm_ss") + ".log";
|
||||
LogFile = Path.GetFileNameWithoutExtension(programName) + ".current.log";
|
||||
_startTime = DateTime.Now;
|
||||
|
||||
|
||||
if (LogFile.FileExists())
|
||||
File.Delete(LogFile);
|
||||
{
|
||||
var new_path = Path.GetFileNameWithoutExtension(programName) + (new FileInfo(LogFile)).LastWriteTime.ToString(" yyyy-MM-dd HH_mm_ss") + ".log";
|
||||
File.Move(LogFile, new_path, MoveOptions.ReplaceExisting);
|
||||
}
|
||||
|
||||
var watcher = new FileSystemWatcher(Consts.LocalAppDataPath);
|
||||
AppLocalEvents = Observable.Merge(Observable.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>(h => watcher.Changed += h, h => watcher.Changed -= h).Select(e => (FileEventType.Changed, e.EventArgs)),
|
||||
@ -182,6 +186,18 @@ namespace Wabbajack.Common
|
||||
|
||||
return sha.Hash.ToBase64();
|
||||
}
|
||||
|
||||
public static string StringSHA256Hex(this string s)
|
||||
{
|
||||
var sha = new SHA256Managed();
|
||||
using (var o = new CryptoStream(Stream.Null, sha, CryptoStreamMode.Write))
|
||||
{
|
||||
using var i = new MemoryStream(Encoding.UTF8.GetBytes(s));
|
||||
i.CopyTo(o);
|
||||
}
|
||||
|
||||
return sha.Hash.ToHex();
|
||||
}
|
||||
|
||||
public static string FileHash(this string file, bool nullOnIOError = false)
|
||||
{
|
||||
|
@ -258,20 +258,30 @@ namespace Wabbajack.Lib
|
||||
var outputPath = Path.Combine(DownloadFolder, archive.Name);
|
||||
|
||||
if (download)
|
||||
{
|
||||
if (outputPath.FileExists())
|
||||
File.Delete(outputPath);
|
||||
{
|
||||
var orig_name = Path.GetFileNameWithoutExtension(archive.Name);
|
||||
var ext = Path.GetExtension(archive.Name);
|
||||
var unique_key = archive.State.PrimaryKeyString.StringSHA256Hex();
|
||||
outputPath = Path.Combine(DownloadFolder, orig_name + "_" + unique_key + "_" + ext);
|
||||
if (outputPath.FileExists())
|
||||
File.Delete(outputPath);
|
||||
}
|
||||
}
|
||||
|
||||
return await DownloadArchive(archive, download);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<bool> DownloadArchive(Archive archive, bool download)
|
||||
public async Task<bool> DownloadArchive(Archive archive, bool download, string destination = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = Path.Combine(DownloadFolder, archive.Name);
|
||||
await archive.State.Download(archive, path);
|
||||
path.FileHashCached();
|
||||
if (destination == null)
|
||||
destination = Path.Combine(DownloadFolder, archive.Name);
|
||||
await archive.State.Download(archive, destination);
|
||||
destination.FileHashCached();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -4,6 +4,8 @@ using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Threading;
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Wabbajack.Common;
|
||||
@ -13,6 +15,7 @@ using Wabbajack.Lib.Downloaders;
|
||||
using Wabbajack.Lib.LibCefHelpers;
|
||||
using Wabbajack.Lib.NexusApi;
|
||||
using Wabbajack.Lib.Validation;
|
||||
using Directory = System.IO.Directory;
|
||||
using File = Alphaleonis.Win32.Filesystem.File;
|
||||
using Game = Wabbajack.Common.Game;
|
||||
|
||||
@ -463,8 +466,6 @@ namespace Wabbajack.Test
|
||||
var entries = archive.Entries.Select(e => e.FullName).ToList();
|
||||
CollectionAssert.AreEqual(entries, new List<string> {@"Data\TestCK.esp", @"Data\TestCK.ini"});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,7 +80,6 @@ namespace Wabbajack.Test
|
||||
|
||||
|
||||
var modlist = await CompileAndInstall(profile);
|
||||
|
||||
utils.VerifyAllFiles();
|
||||
|
||||
var loot_folder = Path.Combine(utils.InstallFolder, "LOOT Config Files");
|
||||
|
Loading…
Reference in New Issue
Block a user