Browse Source

Furthered work on the updater, almost works, but due to the lack of I18N.dll and I18N.West.dll it actually just can't work

gonna go build mono now... *sigh*
refactor
Anairkoen Schno 6 years ago
parent
commit
b7d356c2c2
10 changed files with 204 additions and 31 deletions
  1. +1
    -1
      IPA.Tests/updater_test.json
  2. +4
    -0
      IPA/IPA.csproj
  3. +8
    -0
      IllusionInjector/IllusionInjector.csproj
  4. +1
    -0
      IllusionInjector/PluginManager.cs
  5. +4
    -1
      IllusionInjector/Properties/AssemblyInfo.cs
  6. +2
    -2
      IllusionInjector/Updating/ModsaberML/ApiEndpoint.cs
  7. +98
    -26
      IllusionInjector/Updating/ModsaberML/Updater.cs
  8. +61
    -0
      IllusionInjector/Utilities/BlockingStream.cs
  9. +24
    -0
      IllusionInjector/Utilities/SteamCheck.cs
  10. +1
    -1
      IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache

+ 1
- 1
IPA.Tests/updater_test.json View File

@ -8,7 +8,7 @@
"description": "",
"type": "mod",
"published": "2018-08-02T03:12:18.805Z",
"gameVersion": "0.11.1",
"gameVersion": "0.11.2",
"gameVersionID": "5b626bb15d243a0008b8886e",
"oldVersions": [],
"dependsOn": [],


+ 4
- 0
IPA/IPA.csproj View File

@ -98,4 +98,8 @@
</ItemGroup>
<Copy SourceFiles="@(Dlls)" DestinationFolder="$(OutputPath)IPA\Data\Managed" />
</Target>
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>

+ 8
- 0
IllusionInjector/IllusionInjector.csproj View File

@ -13,6 +13,8 @@
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -72,7 +74,9 @@
<Compile Include="Updating\ModsaberML\Updater.cs" />
<Compile Include="Updating\Old\ModUpdater.cs" />
<Compile Include="Updating\Old\UpdateScript.cs" />
<Compile Include="Utilities\BlockingStream.cs" />
<Compile Include="Utilities\SimpleJson.cs" />
<Compile Include="Utilities\SteamCheck.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IllusionPlugin\IllusionPlugin.csproj">
@ -85,6 +89,10 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">


+ 1
- 0
IllusionInjector/PluginManager.cs View File

@ -10,6 +10,7 @@ using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace IllusionInjector
{


+ 4
- 1
IllusionInjector/Properties/AssemblyInfo.cs View File

@ -1,4 +1,5 @@
using System.Reflection;
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -34,3 +35,5 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguage("en")]

+ 2
- 2
IllusionInjector/Updating/ModsaberML/ApiEndpoint.cs View File

@ -25,8 +25,8 @@ namespace IllusionInjector.Updating.ModsaberML
public string Title;
public Version GameVersion;
public string Author;
public string SteamFile;
public string OculusFile;
public string SteamFile = null;
public string OculusFile = null;
public static Mod DecodeJSON(JSONObject obj)
{


+ 98
- 26
IllusionInjector/Updating/ModsaberML/Updater.cs View File

@ -1,4 +1,6 @@
using SimpleJSON;
using IllusionInjector.Utilities;
using Ionic.Zip;
using SimpleJSON;
using System;
using System.Collections;
using System.Collections.Generic;
@ -6,6 +8,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
@ -15,12 +18,24 @@ namespace IllusionInjector.Updating.ModsaberML
{
class Updater : MonoBehaviour
{
public Updater instance;
public static Updater instance;
public void Awake()
{
instance = this;
CheckForUpdates();
try
{
if (instance != null)
Destroy(this);
else
{
instance = this;
CheckForUpdates();
}
}
catch (Exception e)
{
Logger.log.Error(e);
}
}
public void CheckForUpdates()
@ -28,13 +43,17 @@ namespace IllusionInjector.Updating.ModsaberML
StartCoroutine(CheckForUpdatesCoroutine());
}
private Regex commentRegex = new Regex(@"(?: \/\/.+)?$", RegexOptions.Compiled | RegexOptions.Multiline);
private Dictionary<Uri, UpdateScript> cachedRequests = new Dictionary<Uri, UpdateScript>();
private struct UpdateStruct
{
public PluginManager.BSPluginMeta plugin;
public ApiEndpoint.Mod externInfo;
}
IEnumerator CheckForUpdatesCoroutine()
{
Logger.log.Info("Checking for mod updates...");
var toUpdate = new List<PluginManager.BSPluginMeta>();
var toUpdate = new List<UpdateStruct>();
var modList = new List<ApiEndpoint.Mod>();
using (var request = UnityWebRequest.Get(ApiEndpoint.ApiBase+ApiEndpoint.GetApprovedEndpoint))
@ -105,7 +124,11 @@ namespace IllusionInjector.Updating.ModsaberML
if (modRegistry.GameVersion == GameVersion)
{
Logger.log.Debug($"Queueing update...");
toUpdate.Add(plugin);
toUpdate.Add(new UpdateStruct
{
plugin = plugin,
externInfo = modRegistry
});
}
else
{
@ -124,44 +147,93 @@ namespace IllusionInjector.Updating.ModsaberML
Logger.log.Debug($"Created temp download dirtectory {tempDirectory}");
foreach (var item in toUpdate)
{
StartCoroutine(DownloadPluginCoroutine(tempDirectory, item));
StartCoroutine(UpdateModCoroutine(tempDirectory, item));
}
}
class StreamDownloadHandler : DownloadHandlerScript
{
public MemoryStream Stream { get; set; }
protected void ReceiveContentLength(long contentLength)
{
Stream.Capacity = (int)contentLength;
Logger.log.Debug($"Got content length: {contentLength}");
}
protected void OnContentComplete()
{
Logger.log.Debug("Download complete");
}
protected bool ReceiveData(byte[] data, long dataLength)
{
Stream.Write(data, 0, (int)dataLength);
return true;
}
}
IEnumerator DownloadPluginCoroutine(string tempdir, PluginManager.BSPluginMeta item)
IEnumerator UpdateModCoroutine(string tempdir, UpdateStruct item)
{
async Task DownloadPluginAsync(MemoryStream stream)
{ // embedded because i don't think unity likes it in the top level
yield return null;
/*var file = Path.Combine(tempdir, item. + ".dll");
Logger.log.Debug($"Getting ZIP file for {item.plugin.Plugin.Name}");
//var stream = await httpClient.GetStreamAsync(url);
using (var zipFile = new ZipInputStream(new BlockingStream(stream)))
{
Logger.log.Debug("Streams opened");
ZipEntry entry;
while ((entry = zipFile.GetNextEntry()) != null)
{
Logger.log.Debug(entry?.FileName);
}
}
Logger.log.Debug("Downloader exited");
}
string url;
if (SteamCheck.IsAvailable || item.externInfo.OculusFile == null)
url = item.externInfo.SteamFile;
else
url = item.externInfo.OculusFile;
using (var req = UnityWebRequest.Get(item.DownloadUri))
Logger.log.Debug($"URL = {url}");
using (var req = UnityWebRequest.Get(url))
using (var memStream = new MemoryStream())
{
req.downloadHandler = new DownloadHandlerFile(file);
req.downloadHandler = new StreamDownloadHandler
{
Stream = memStream
};
var downloadTask = Task.Run(async () =>
{ // use slightly more multithreaded approach than coroutines
await DownloadPluginAsync(memStream);
});
Logger.log.Debug("Sending request");
yield return req.SendWebRequest();
if (req.isNetworkError)
{
Logger.log.Error($"Network error while trying to download update for {item.Plugin.Plugin.Name}");
Logger.log.Error("Network error while trying to update mod");
Logger.log.Error(req.error);
yield break;
}
if (req.isHttpError)
{
Logger.log.Error($"Server returned an error code while trying to download update for {item.Plugin.Plugin.Name}");
Logger.log.Error($"Server returned an error code while trying to update mod");
Logger.log.Error(req.error);
yield break;
}
}
var pluginDir = Path.GetDirectoryName(item.Plugin.Filename);
var newFile = Path.Combine(pluginDir, item.Name + ".dll");
File.Delete(item.Plugin.Filename);
if (File.Exists(newFile))
File.Delete(newFile);
File.Move(file, newFile);
downloadTask.Wait(); // wait for the damn thing to finish
}
Logger.log.Info($"{item.Plugin.Plugin.Name} updated to {item.NewVersion}");*/
yield return null;
}
}
}

+ 61
- 0
IllusionInjector/Utilities/BlockingStream.cs View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IllusionInjector.Utilities
{
class BlockingStream : Stream
{
public BlockingStream(Stream bstr)
{
BaseStream = bstr;
}
public Stream BaseStream { get; set; }
public override bool CanRead => BaseStream.CanRead;
public override bool CanSeek => BaseStream.CanSeek;
public override bool CanWrite => BaseStream.CanWrite;
public override long Length => BaseStream.Length;
public override long Position { get => BaseStream.Position; set => BaseStream.Position = value; }
public override void Flush()
{
BaseStream.Flush();
}
public override int Read(byte[] buffer, int offset, int count)
{
var read = 0;
do
{
read += BaseStream.Read(buffer, read, count-read);
}
while (read < count);
return count;
}
public override long Seek(long offset, SeekOrigin origin)
{
return BaseStream.Seek(offset, origin);
}
public override void SetLength(long value)
{
BaseStream.SetLength(value);
}
public override void Write(byte[] buffer, int offset, int count)
{
BaseStream.Write(buffer, offset, count);
}
}
}

+ 24
- 0
IllusionInjector/Utilities/SteamCheck.cs View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IllusionInjector.Utilities
{
public static class SteamCheck
{
public static Type SteamVRCamera;
public static Type SteamVRExternalCamera;
public static Type SteamVRFade;
public static bool IsAvailable => FindSteamVRAsset();
private static bool FindSteamVRAsset()
{
SteamVRCamera = Type.GetType("SteamVR_Camera", false);
SteamVRExternalCamera = Type.GetType("SteamVR_ExternalCamera", false);
SteamVRFade = Type.GetType("SteamVR_Fade", false);
return SteamVRCamera != null && SteamVRExternalCamera != null && SteamVRFade != null;
}
}
}

+ 1
- 1
IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache View File

@ -1 +1 @@
4b98b2d3f93866107d7a8621254570f2cc16296c
2d99fb420e28a48fb98f5e9b833e87f1bbb2108f

Loading…
Cancel
Save