Can install loose files as well

This commit is contained in:
Timothy Baldridge 2019-07-22 22:27:26 -06:00
parent efd61c4b39
commit dffe2a68de
9 changed files with 136 additions and 13 deletions

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,5 +12,16 @@ namespace Wabbajack.Common
{ {
public static string GameFolderFilesDir = "Game Folder Files"; public static string GameFolderFilesDir = "Game Folder Files";
public static string ModPackMagic = "Celebration!, Cheese for Everyone!"; public static string ModPackMagic = "Celebration!, Cheese for Everyone!";
public static HashSet<string> SupportedArchives = new HashSet<string>() { ".zip", ".rar", ".7z", ".7zip" };
public static String UserAgent {
get
{
var platformType = Environment.Is64BitOperatingSystem ? "x64" : "x86";
var headerString = $"Wabbajack/{Assembly.GetEntryAssembly().GetName().Version} ({Environment.OSVersion.VersionString}; {platformType}) {RuntimeInformation.FrameworkDescription}";
return headerString;
}
}
} }
} }

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -43,6 +44,16 @@ namespace Wabbajack.Common
return Convert.ToBase64String(data); return Convert.ToBase64String(data);
} }
/// <summary>
/// Returns data from a base64 stream
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static byte[] FromBase64(this string data)
{
return Convert.FromBase64String(data);
}
/// <summary> /// <summary>
/// Executes the action for every item in coll /// Executes the action for every item in coll
/// </summary> /// </summary>
@ -74,6 +85,11 @@ namespace Wabbajack.Common
{ {
return JsonConvert.DeserializeObject<T>(File.ReadAllText(filename)); return JsonConvert.DeserializeObject<T>(File.ReadAllText(filename));
} }
public static T FromJSON<T>(this Stream data)
{
var s = Encoding.UTF8.GetString(data.ReadAll());
return JsonConvert.DeserializeObject<T>(s);
}
public static bool FileExists(this string filename) public static bool FileExists(this string filename)
{ {
@ -183,5 +199,25 @@ namespace Wabbajack.Common
return; return;
} }
public static HttpResponseMessage GetSync(this HttpClient client, string url)
{
var result = client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
result.Wait();
return result.Result;
}
public static string GetStringSync(this HttpClient client, string url)
{
var result = client.GetStringAsync(url);
result.Wait();
return result.Result;
}
public static Stream GetStreamSync(this HttpClient client, string url)
{
var result = client.GetStreamAsync(url);
result.Wait();
return result.Result;
}
} }
} }

View File

@ -73,7 +73,7 @@ namespace Wabbajack
Dirty = false; Dirty = false;
} }
} }
Thread.Sleep(250); Thread.Sleep(1000);
} }
} }

View File

@ -15,7 +15,7 @@ namespace Wabbajack
{ {
public class Compiler public class Compiler
{ {
public static HashSet<string> SupportedArchives = new HashSet<string>() { ".zip", ".rar", ".7z", ".7zip" };
public string MO2Folder; public string MO2Folder;
@ -39,7 +39,7 @@ namespace Wabbajack
{ {
get get
{ {
return Path.Combine(MO2Folder, MO2Profile); return Path.Combine(MO2Folder, "profiles", MO2Profile);
} }
} }
@ -47,6 +47,7 @@ namespace Wabbajack
public List<Directive> InstallDirectives { get; private set; } public List<Directive> InstallDirectives { get; private set; }
public List<Archive> SelectedArchives { get; private set; } public List<Archive> SelectedArchives { get; private set; }
public List<RawSourceFile> AllFiles { get; private set; } public List<RawSourceFile> AllFiles { get; private set; }
public ModList ModList { get; private set; }
public List<IndexedArchive> IndexedArchives; public List<IndexedArchive> IndexedArchives;
@ -86,7 +87,7 @@ namespace Wabbajack
public void LoadArchives() public void LoadArchives()
{ {
IndexedArchives = Directory.EnumerateFiles(MO2DownloadsFolder) IndexedArchives = Directory.EnumerateFiles(MO2DownloadsFolder)
.Where(file => SupportedArchives.Contains(Path.GetExtension(file))) .Where(file => Consts.SupportedArchives.Contains(Path.GetExtension(file)))
.PMap(file => LoadArchive(file)); .PMap(file => LoadArchive(file));
} }
@ -171,11 +172,31 @@ namespace Wabbajack
GatherArchives(); GatherArchives();
BuildPatches(); BuildPatches();
ModList = new ModList()
{
Archives = SelectedArchives,
Directives = InstallDirectives
};
PatchExecutable(); PatchExecutable();
ResetMembers();
Info("Done Building Modpack"); Info("Done Building Modpack");
} }
/// <summary>
/// Clear references to lists that hold a lot of data.
/// </summary>
private void ResetMembers()
{
AllFiles = null;
IndexedArchives = null;
InstallDirectives = null;
SelectedArchives = null;
}
/// <summary> /// <summary>
/// Fills in the Patch fields in files that require them /// Fills in the Patch fields in files that require them
@ -320,6 +341,7 @@ namespace Wabbajack
IgnoreStartsWith("nxmhandler."), IgnoreStartsWith("nxmhandler."),
IgnoreEndsWith(".pyc"), IgnoreEndsWith(".pyc"),
IgnoreOtherProfiles(), IgnoreOtherProfiles(),
IgnoreDisabledMods(),
IncludeThisProfile(), IncludeThisProfile(),
// Ignore the ModOrganizer.ini file it contains info created by MO2 on startup // Ignore the ModOrganizer.ini file it contains info created by MO2 on startup
IgnoreStartsWith("ModOrganizer.ini"), IgnoreStartsWith("ModOrganizer.ini"),
@ -334,6 +356,24 @@ namespace Wabbajack
}; };
} }
private Func<RawSourceFile, Directive> IgnoreDisabledMods()
{
var disabled_mods = File.ReadAllLines(Path.Combine(MO2ProfileDir, "modlist.txt"))
.Where(line => line.StartsWith("-") && !line.EndsWith("_separator"))
.Select(line => Path.Combine("mods", line.Substring(1)))
.ToList();
return source =>
{
if (disabled_mods.FirstOrDefault(mod => source.Path.StartsWith(mod)) != null)
{
var r = source.EvolveTo<IgnoredDirectly>();
r.Reason = "Disabled Mod";
return r;
}
return null;
};
}
private Func<RawSourceFile, Directive> IncludePatches() private Func<RawSourceFile, Directive> IncludePatches()
{ {
var indexed = (from archive in IndexedArchives var indexed = (from archive in IndexedArchives
@ -514,7 +554,7 @@ namespace Wabbajack
internal void PatchExecutable() internal void PatchExecutable()
{ {
var data = JsonConvert.SerializeObject(InstallDirectives).BZip2String(); var data = JsonConvert.SerializeObject(ModList).BZip2String();
var executable = Assembly.GetExecutingAssembly().Location; var executable = Assembly.GetExecutingAssembly().Location;
var out_path = Path.Combine(Path.GetDirectoryName(executable), MO2Profile + ".exe"); var out_path = Path.Combine(Path.GetDirectoryName(executable), MO2Profile + ".exe");
Info("Patching Executable {0}", Path.GetFileName(out_path)); Info("Patching Executable {0}", Path.GetFileName(out_path));

View File

@ -78,10 +78,26 @@ namespace Wabbajack
} }
BuildFolderStructure(); BuildFolderStructure();
InstallArchives(); InstallArchives();
InstallIncludedFiles();
Info("Installation complete! You may exit the program."); Info("Installation complete! You may exit the program.");
} }
private void InstallIncludedFiles()
{
Info("Writing inline files");
ModList.Directives
.OfType<InlineFile>()
.PMap(directive =>
{
Status("Writing included file {0}", directive.To);
var out_path = Path.Combine(Outputfolder, directive.To);
if (File.Exists(out_path)) File.Delete(out_path);
File.WriteAllBytes(out_path, directive.SourceData.FromBase64());
});
}
private void BuildFolderStructure() private void BuildFolderStructure()
{ {
Info("Building Folder Structure"); Info("Building Folder Structure");

View File

@ -18,15 +18,23 @@
<TextBlock Text=":"></TextBlock> <TextBlock Text=":"></TextBlock>
<TextBlock Text="YAHSED GUIDE"></TextBlock> <TextBlock Text="YAHSED GUIDE"></TextBlock>
</StackPanel> </StackPanel>
<ListBox Grid.Row ="1" ItemsSource="{Binding Status}"> <ListBox Grid.Row ="1" ItemsSource="{Binding Status}" Width="Auto" HorizontalAlignment="Stretch">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <Grid HorizontalAlignment="Stretch">
<TextBlock Text="CPU "></TextBlock> <Grid.ColumnDefinitions>
<TextBlock Text="{Binding ID}"></TextBlock> <ColumnDefinition Width="Auto"></ColumnDefinition>
<TextBlock Text=" - "></TextBlock> <ColumnDefinition Width="Auto"></ColumnDefinition>
<TextBlock Text="{Binding Msg}"></TextBlock> <ColumnDefinition Width="Auto"></ColumnDefinition>
</StackPanel> <ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto" ></ColumnDefinition>
</Grid.ColumnDefinitions>
<ProgressBar Minimum="0" Maximum="100" Value="{Binding Progress, Mode=OneTime}" Width="100" Grid.Column="0"></ProgressBar>
<TextBlock Text=" CPU " Grid.Column="1"></TextBlock>
<TextBlock Text="{Binding ID}" Grid.Column="2"></TextBlock>
<TextBlock Text=" - " Grid.Column="3"></TextBlock>
<TextBlock Text="{Binding Msg}" Grid.Column="4"></TextBlock>
</Grid>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>

View File

@ -34,6 +34,10 @@ namespace Wabbajack
compiler.LoadArchives(); compiler.LoadArchives();
compiler.MO2Profile = "Lexy's Legacy of The Dragonborn Special Edition"; compiler.MO2Profile = "Lexy's Legacy of The Dragonborn Special Edition";
compiler.Compile(); compiler.Compile();
var installer = new Installer(compiler.ModList, "c:\\tmp\\install\\", msg => context.LogMsg(msg));
installer.Install();
}).Start(); }).Start();

View File

@ -55,6 +55,9 @@
<Reference Include="System.Xaml"> <Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework> <RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="websocket-sharp, Version=1.0.4.0, Culture=neutral, PublicKeyToken=5660b08a1845a91e, processorArchitecture=MSIL">
<HintPath>..\packages\WebSocketSharpFork.1.0.4.0\lib\net35\websocket-sharp.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
@ -75,12 +78,14 @@
<Compile Include="AppState.cs" /> <Compile Include="AppState.cs" />
<Compile Include="AutoScrollBehavior.cs" /> <Compile Include="AutoScrollBehavior.cs" />
<Compile Include="Compiler.cs" /> <Compile Include="Compiler.cs" />
<Compile Include="Installer.cs" />
<Compile Include="MainWindow.xaml.cs"> <Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="NexusAPI.cs" />
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>

View File

@ -3,4 +3,5 @@
<package id="Costura.Fody" version="4.0.0" targetFramework="net472" /> <package id="Costura.Fody" version="4.0.0" targetFramework="net472" />
<package id="Fody" version="5.1.1" targetFramework="net472" developmentDependency="true" /> <package id="Fody" version="5.1.1" targetFramework="net472" developmentDependency="true" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net472" /> <package id="Newtonsoft.Json" version="12.0.2" targetFramework="net472" />
<package id="WebSocketSharpFork" version="1.0.4.0" targetFramework="net472" />
</packages> </packages>