25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.4KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. namespace NScript.Filmscript
  5. {
  6. public class FilmscriptInstaller : Install.IInstallable
  7. {
  8. public string Name { get; } = "filmscript.dll";
  9. public void Install()
  10. {
  11. List<Gitea.Release> releases = Gitea.ReleaseUtility.GetReleases("NGnius", "filmscript-rs");
  12. GamecraftModdingAPI.Utility.Logging.Log($"Downloading {Name}");
  13. #if DEBUG
  14. var r = Gitea.ReleaseUtility.FindRelease(releases, prerelease: true)?? throw new Exception("Failed to find valid release candidate");
  15. #else
  16. var r = Gitea.ReleaseUtility.FindRelease(releases)?? throw new Exception("Failed to find valid release candidate");
  17. #endif
  18. var a = Gitea.ReleaseUtility.FindAsset(r, Name)?? throw new Exception($"Failed to find valid asset candidate for {Name}");
  19. var download = Gitea.ReleaseUtility.DownloadAsset(a);
  20. File.WriteAllBytes(NScript.Install.InstallTools.NativeDllFilepath(Name), download);
  21. }
  22. public bool IsInstalled()
  23. {
  24. // NOTE: Mono will only try to load a native DLL once, so trying to call a non-existent DLL
  25. // will prevent it from being loaded later, even if it's downloaded between now and then.
  26. return NScript.Install.InstallTools.NativeDllExists(Name);
  27. }
  28. }
  29. }