Elin Decompiled Documentation EA 23.356.1 Nightly
Loading...
Searching...
No Matches
ModManager.cs File Reference

Go to the source code of this file.

Classes

class  ModManager
 
class  ModManager.WorkshopDownload
 

Functions

 [instance initializer]
 
 ... (HitESCtocancel)"$"Fetched
 

Variables

 $ {arg}
 
$ Initializingmods
 
$ Fetchingsubscriptions
 
$ ownloading ={item.IsDownloading}
 
mods...$ Installed ={item.IsInstalled}
 
mods...$ $ Update ={item.IsNeedsUpdate}
 

Function Documentation

◆ ...()

DownloadSubscriptions.... ( HitESCtocancel  )

Definition at line 865 of file ModManager.cs.

866{
867 float now = Time.realtimeSinceStartup;
868 List<WorkshopDownload> queue = (from p in packages
869 where p.item is WorkshopItem workshopItem && (!p.installed || workshopItem.IsNeedsUpdate)
870 select new WorkshopDownload(p, now)).ToList();
871 if (queue.Count == 0)
872 {
873 yield break;
874 }
875 WaitForEndOfFrame awaiter = new WaitForEndOfFrame();
876 Text status = _loading.Log($"Downloading {queue.Count} mods...");
877 Dictionary<ulong, EResult> results = new Dictionary<ulong, EResult>();
878 int total = queue.Count;
879 int completed = 0;
880 float lastActivity = now;
881 float nextStatus = 0f;
882 UserGeneratedContent.Client.EventItemDownloaded.AddListener(OnItemDownloaded);
883 try
884 {
885 while (queue.Count > 0)
886 {
887 now = Time.realtimeSinceStartup;
888 for (int num = queue.Count - 1; num >= 0; num--)
889 {
890 WorkshopDownload workshopDownload = queue[num];
891 WorkshopItem item = workshopDownload.item;
892 ulong publishedFileId = item.FileId.m_PublishedFileId;
893 string path = null;
894 string reason = null;
895 bool flag = false;
896 EResult value;
897 if (!workshopDownload.package.downloadStarted)
898 {
899 workshopDownload.package.downloadStarted = true;
900 workshopDownload.lastChange = now;
901 if (item.DownloadItem(highPriority: true))
902 {
903 Debug.Log("Start downloading: " + workshopDownload.Title + " | " + $"Installed={item.IsInstalled}, " + $"Update={item.IsNeedsUpdate}, " + $"Downloading={item.IsDownloading}, " + $"Pending={item.IsDownloadPending}");
904 continue;
905 }
906 reason = "cannot start the download";
907 }
908 else if (results.TryGetValue(publishedFileId, out value) && value != EResult.k_EResultOK)
909 {
910 reason = $"download failed ({value})";
911 }
912 else if (IsItemReady(item, out path))
913 {
914 flag = true;
915 }
916 else
917 {
918 if (item.IsDownloadPending)
919 {
920 workshopDownload.lastChange = now;
921 continue;
922 }
923 if (item.IsDownloading)
924 {
925 float downloadCompletion = item.DownloadCompletion;
926 if (downloadCompletion > workshopDownload.progress)
927 {
928 workshopDownload.progress = downloadCompletion;
929 float lastChange;
930 lastActivity = (lastChange = now);
931 workshopDownload.lastChange = lastChange;
932 }
933 continue;
934 }
935 if (!(now - workshopDownload.lastChange > 20f))
936 {
937 continue;
938 }
939 reason = "cannot start the download";
940 }
941 queue.RemoveAt(num);
942 lastActivity = now;
943 if (flag)
944 {
945 completed++;
946 InstallWorkshopPackage(workshopDownload, path);
947 }
948 else
949 {
950 FailWorkshopPackage(workshopDownload, reason);
951 }
952 }
953 if (queue.Count == 0)
954 {
955 break;
956 }
957 if (IsCancelRequested())
958 {
959 AbortDownloads(queue, "cancelled");
960 break;
961 }
962 if (now - lastActivity > 90f)
963 {
964 AbortDownloads(queue, "not responding");
965 break;
966 }
967 if (now >= nextStatus)
968 {
969 nextStatus = now + 0.5f;
970 WorkshopDownload workshopDownload2 = queue.Find((WorkshopDownload d) => d.item.IsDownloading) ?? queue[0];
971 SetStatus(status, $"Downloading mods {completed}/{total}: " + $"{workshopDownload2.Title} {Mathf.FloorToInt(workshopDownload2.progress * 100f)}%...(Hit ESC to cancel)");
972 }
973 yield return awaiter;
974 }
975 }
976 finally
977 {
978 UserGeneratedContent.Client.EventItemDownloaded.RemoveListener(OnItemDownloaded);
979 }
980 SetStatus(status, $"Downloaded {completed}/{total} mods");
981 packages.RemoveAll((BaseModPackage p) => p.item is WorkshopItem && !p.installed);
982 void OnItemDownloaded(DownloadItemResult_t result)
983 {
984 results[result.m_nPublishedFileId.m_PublishedFileId] = result.m_eResult;
985 }
986 }
987
988 public void LoadCachedWorkshopPackages()
989 {
990 HashSet<string> hashSet = packages.Select((BaseModPackage p) => p.dirInfo.FullName).ToHashSet(StringComparer.OrdinalIgnoreCase);
991 DirectoryInfo[] directories = dirWorkshop.GetDirectories();
992 foreach (DirectoryInfo directoryInfo in directories)
993 {
994 ulong result;
995 bool flag = ulong.TryParse(directoryInfo.Name, out result);
996 if ((!flag || !_blockedItems.Contains(result)) && (_subscribedItems == null || (flag && _subscribedItems.Contains(result))) && !hashSet.Contains(new DirectoryInfo(directoryInfo.FullName.NormalizePath()).FullName))
997 {
998 ModPackage modPackage = AddPackage(directoryInfo);
999 if (flag)
1000 {
1001 modPackage.workshopId = directoryInfo.Name;
1002 }
1003 }
1004 }
1005 }
1006
1007 private void InstallWorkshopPackage(WorkshopDownload download, string path)
1008 {
1009 BaseModPackage package = download.package;
1010 package.installed = true;
1011 package.dirInfo = new DirectoryInfo(path.NormalizePath());
1012 if (package is ModPackage modPackage)
1013 {
1014 modPackage.Mapping = new FileMapping(package.dirInfo);
1015 }
1016 Debug.Log("Downloaded: " + download.Title + " -> " + package.dirInfo.FullName);
1017 }
1018
1019 private void FailWorkshopPackage(WorkshopDownload download, string reason)
1020 {
1021 if (download.isUpdate)
1022 {
1023 Debug.LogWarning("Workshop update failed: " + download.Title + ", " + reason);
1024 return;
1025 }
1026 _missingContent++;
1027 Debug.LogWarning("Workshop download failed: " + download.Title + ", " + reason);
1028 }
1029
1030 private void AbortDownloads(List<WorkshopDownload> queue, string reason)
1031 {
1032 foreach (WorkshopDownload item in queue)
1033 {
1034 FailWorkshopPackage(item, reason);
1035 }
1036 queue.Clear();
1037 }
1038
1039 private static bool IsItemReady(WorkshopItem item, out string path)
1040 {
1041 path = null;
1042 if (!item.IsInstalled || item.IsNeedsUpdate || item.IsDownloading || item.IsDownloadPending)
1043 {
1044 return false;
1045 }
1046 if (UserGeneratedContent.Client.GetItemInstallInfo(item.FileId, out var _, out path, out var _) && !path.IsEmpty())
1047 {
1048 return Directory.Exists(path);
1049 }
1050 return false;
1051 }
1052
1053 private static bool IsCancelRequested()
1054 {
1055 return UnityEngine.Input.GetKey(KeyCode.Escape);
1056 }
1057
1058 private static void SetStatus(Text status, string message)
1059 {
1060 if ((bool)status)
1061 {
1062 status.text = message;
1063 }
1064 }
1065
1066 public override void ParseExtra(DirectoryInfo dir, BaseModPackage package)
1067 {
1068 ModPackage modPackage = (ModPackage)package;
1069 switch (dir.Name.ToLower())
1070 {
1071 case "talktext":
1072 modPackage.ParseTalkText(dir);
1073 break;
1074 case "map":
1075 if (!package.builtin)
1076 {
1077 modPackage.ParseMap(dir);
1078 }
1079 break;
1080 case "map piece":
1081 if (!package.builtin)
1082 {
1083 modPackage.ParseMapPiece(dir);
1084 }
1085 break;
1086 case "texture replace":
1087 replaceFiles.AddRange(modPackage.ParseTextureReplace(dir));
1088 break;
1089 case "texture":
1090 modPackage.ParseTexture(dir);
1091 break;
1092 case "portrait":
1093 modPackage.ParsePortrait(dir);
1094 break;
1095 case "langmod":
1096 modPackage.ParseLangMod(dir);
1097 break;
1098 case "sound":
1099 modPackage.ParseSound(dir);
1100 break;
1101 case "lang":
1102 modPackage.AddOrUpdateLang(dir);
1103 break;
1104 }
1105 }
1106}
$
Definition: ModManager.cs:106
DirectoryInfo dirInfo
IReadOnlyList< FileInfo > ParseTalkText(DirectoryInfo dir)
Definition: ModPackage.cs:32
void ParseLangMod(DirectoryInfo dir)
Definition: ModPackage.cs:167
IReadOnlyList< FileInfo > ParseTexture(DirectoryInfo dir)
Definition: ModPackage.cs:109
void AddOrUpdateLang(DirectoryInfo dir)
Definition: ModPackage.cs:376
IReadOnlyList< FileInfo > ParseMapPiece(DirectoryInfo dir, bool addToList=true)
Definition: ModPackage.cs:71
IReadOnlyList< FileInfo > ParseTextureReplace(DirectoryInfo dir)
Definition: ModPackage.cs:92
IReadOnlyList< FileInfo > ParsePortrait(DirectoryInfo dir)
Definition: ModPackage.cs:129
IReadOnlyList< FileInfo > ParseMap(DirectoryInfo dir, bool addToList=true)
Definition: ModPackage.cs:50
IReadOnlyList< FileInfo > ParseSound(DirectoryInfo dir)
Definition: ModPackage.cs:182

◆ [instance initializer]()

SaveLoadOrder.[instance initializer]

Definition at line 106 of file ModManager.cs.

Variable Documentation

◆ $

◆ Fetchingsubscriptions

$ Fetchingsubscriptions

Definition at line 865 of file ModManager.cs.

◆ Initializingmods

$ Initializingmods

Definition at line 536 of file ModManager.cs.

◆ Installed

mods...$ Installed ={item.IsInstalled}

Definition at line 988 of file ModManager.cs.

Referenced by Zone.SpawnAltar().

◆ ownloading

mods $ $ $ ownloading ={item.IsDownloading}

Definition at line 988 of file ModManager.cs.

◆ Update

mods...$ $ Update ={item.IsNeedsUpdate}

Definition at line 988 of file ModManager.cs.

Referenced by PointTarget.CycleTarget().