ask to endorse mods, fixes to broken installers

This commit is contained in:
Timothy Baldridge 2019-08-26 17:02:49 -06:00
parent 3127a00d95
commit d33c1a358d
7 changed files with 71 additions and 4 deletions

View File

@ -89,7 +89,6 @@ namespace Wabbajack.Common
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
};
var p = new Process
@ -98,6 +97,7 @@ namespace Wabbajack.Common
};
p.Start();
ChildProcessTracker.AddProcess(p);
p.PriorityClass = ProcessPriorityClass.BelowNormal;
p.WaitForExit();

View File

@ -321,6 +321,15 @@ namespace Wabbajack.Common
return result.Result;
}
public static Stream PostStreamSync(this HttpClient client, string url, HttpContent content)
{
var result = client.PostAsync(url, content);
result.Wait();
var stream = result.Result.Content.ReadAsStreamAsync();
stream.Wait();
return stream.Result;
}
public static string ExceptionToString(this Exception ex)
{
StringBuilder sb = new StringBuilder();

View File

@ -77,6 +77,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BSDiff.cs" />
<Compile Include="ChildProcessTracker.cs" />
<Compile Include="Consts.cs" />
<Compile Include="DynamicIniData.cs" />
<Compile Include="FileExtractor.cs" />

View File

@ -972,11 +972,12 @@ namespace Wabbajack
{
var result = source.EvolveTo<FromArchive>();
var match = found.Where(f => Path.GetFileName(f.Paths[0]) == Path.GetFileName(source.Path))
var match = found.Where(f => Path.GetFileName(f.Paths[f.Paths.Length - 1]) == Path.GetFileName(source.Path))
.OrderBy(f => f.Paths.Length)
.FirstOrDefault();
if (match == null)
match = found.FirstOrDefault();
match = found.OrderBy(f => f.Paths.Length).FirstOrDefault();
result.ArchiveHashPath = match.MakeRelativePaths();

View File

@ -10,6 +10,7 @@ using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using VFS;
using Wabbajack.Common;
@ -114,6 +115,38 @@ namespace Wabbajack
BuildBSAs();
Info("Installation complete! You may exit the program.");
AskToEndorse();
}
private void AskToEndorse()
{
var mods = ModList.Directives
.OfType<NexusMod>()
.GroupBy(f => (f.GameName, f.ModID))
.Select(mod => mod.First())
.ToArray();
var result = MessageBox.Show(
$"Installation has completed, but you have installed ${mods.Length} from the Nexus, would you like to" +
" endorse these mods to show support to the authors? It will only take a few moments.", "Endorse Mods?",
MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result != MessageBoxResult.Yes) return;
// Shuffle mods so that if we hit a API limit we don't always miss the same mods
var r = new Random();
for (var i = 0; i < mods.Length; i++)
{
var a = r.Next(mods.Length);
var b = r.Next(mods.Length);
var tmp = mods[a];
mods[a] = mods[b];
mods[b] = tmp;
}
mods.PMap(mod => NexusAPI.EndorseMod(mod, NexusAPIKey));
Info("Done! You may now exit the application!");
}
private bool LocateGameFolder()
@ -314,7 +347,7 @@ namespace Wabbajack
vfiles.DoIndexed((idx, file) =>
{
Status($"Installing files", idx * 100 / vfiles.Count);
Utils.Status($"Installing files", idx * 100 / vfiles.Count);
File.Copy(file.FromFile.StagedPath, Path.Combine(Outputfolder, file.To));
});

View File

@ -162,5 +162,25 @@ namespace Wabbajack
}
}
public static EndorsementResponse EndorseMod(NexusMod mod, string apikey)
{
Utils.Status($"Endorsing ${mod.GameName} - ${mod.ModID}");
var url = $"https://api.nexusmods.com/v1/games/{ConvertGameName(mod.GameName)}/mods/{mod.ModID}/endorse.json";
var client = BaseNexusClient(apikey);
var content = new FormUrlEncodedContent(new Dictionary<string, string>() {{"value", "\"\""}});
using (var s = client.PostStreamSync(url, content))
{
return s.FromJSON<EndorsementResponse>();
}
}
}
public class EndorsementResponse
{
public string message;
public string status;
}
}

View File

@ -20,4 +20,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<StartArguments>"c:\Mod Organizer 2" "Nexus SSO Test" "c:\tmp\validate"</StartArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug %28no commandargs%29|x64'">
<StartWorkingDirectory>c:\tmp\vstmp</StartWorkingDirectory>
</PropertyGroup>
</Project>