Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
If file does not exist locally, use latest GitHub release.
Browse files Browse the repository at this point in the history
  • Loading branch information
RequiDev committed Aug 13, 2021
1 parent 42bb121 commit 6fc8671
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions ReModCE.Loader/ReMod.Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Reflection;
using System.Threading.Tasks;
Expand Down Expand Up @@ -33,15 +34,37 @@ public class ReLoader : MelonMod
private Action<int, string> _onSceneWasLoaded;
private Action<int, string> _onSceneWasInitialized;

private List<string> _possiblePaths = new List<string>
private readonly List<string> _possiblePaths = new List<string>
{
"ReModCE.dll",
"Mods/ReModCE.dll"
"Mods/ReModCE.dll",
"https://github.com/RequiDev/ReModCE/releases/latest/download/ReModCE.dll"
};

public override void OnApplicationStart()
{
var bytes = (from path in _possiblePaths where File.Exists(path) select File.ReadAllBytes(path)).FirstOrDefault();
var bytes = new byte[] { };
foreach (var path in _possiblePaths)
{
if (path.StartsWith("http"))
{
try
{
bytes = new WebClient().DownloadData(path);
if (bytes != null)
break;
}
catch (WebException e)
{

}
}
else if (File.Exists(path))
{
bytes = File.ReadAllBytes(path);
break;
}
}

if (bytes == null)
{
Expand Down

0 comments on commit 6fc8671

Please sign in to comment.