mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
#2194 Set Archives to Hidden in MO2
If meta exists, check if file is valid or not and depending on that make a new one or append to the existing one. If no file exists create one. The tag added is `removed=true`
This commit is contained in:
parent
a76c80e42b
commit
1c813650e9
@ -148,6 +148,8 @@ public class StandardInstaller : AInstaller<StandardInstaller>
|
||||
|
||||
SetScreenSizeInPrefs();
|
||||
|
||||
SetDownloadMetasToHideInMO2(token);
|
||||
|
||||
await ExtractedModlistFolder!.DisposeAsync();
|
||||
await _wjClient.SendMetric(MetricNames.FinishInstall, ModList.Name);
|
||||
|
||||
@ -270,6 +272,50 @@ public class StandardInstaller : AInstaller<StandardInstaller>
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetDownloadMetasToHideInMO2(CancellationToken token)
|
||||
{
|
||||
_logger.LogInformation("Updating Metas To Hide");
|
||||
await _configuration.Downloads.EnumerateFiles()
|
||||
.PDoAll(async download =>
|
||||
{
|
||||
if (download == default) return;
|
||||
if (download.Extension == Ext.Meta) return;
|
||||
|
||||
var linesToWriteNewFile = new HashSet<string>( );
|
||||
linesToWriteNewFile.Add("[General]");
|
||||
linesToWriteNewFile.Add("removed=true");
|
||||
|
||||
var lineToWriteAppendFile = new HashSet<string> {"removed=true"};
|
||||
|
||||
var metaFile = download.WithExtension(Ext.Meta);
|
||||
if (metaFile.FileExists())
|
||||
{
|
||||
try
|
||||
{
|
||||
var parsed = metaFile.LoadIniFile();
|
||||
if (parsed["General"] != null)
|
||||
{
|
||||
_logger.LogInformation("Updating {FileName}", metaFile.FileName);
|
||||
|
||||
await metaFile.WriteAllLinesAsync(lineToWriteAppendFile,FileMode.Append,token);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogInformation("Re-Generating corrupted {FileName}", metaFile.FileName);
|
||||
|
||||
await metaFile.WriteAllLinesAsync(linesToWriteNewFile,FileMode.Create,token);
|
||||
}
|
||||
}
|
||||
else //Generate new metas to hide files without metas.
|
||||
{
|
||||
_logger.LogInformation("Generating {FileName}", metaFile.FileName);
|
||||
|
||||
await metaFile.WriteAllLinesAsync(linesToWriteNewFile,FileMode.Create,token);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task BuildBSAs(CancellationToken token)
|
||||
{
|
||||
var bsas = ModList.Directives.OfType<CreateBSA>().ToList();
|
||||
|
@ -166,6 +166,15 @@ public static class AbsolutePathExtensions
|
||||
await sw.DisposeAsync();
|
||||
}
|
||||
|
||||
public static async Task WriteAllLinesAsync(this AbsolutePath file, IEnumerable<string> src,
|
||||
FileMode fileMode, CancellationToken token)
|
||||
{
|
||||
await using var dest = file.Open(fileMode, FileAccess.Write, FileShare.None);
|
||||
await using var sw = new StreamWriter(dest, Encoding.UTF8);
|
||||
foreach (var line in src) await sw.WriteLineAsync(line);
|
||||
await sw.DisposeAsync();
|
||||
}
|
||||
|
||||
public static async ValueTask WriteAllBytesAsync(this AbsolutePath file, Memory<byte> data,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user