Exemple #1
0
 static void Prefix(ref SGBarracksMWCustomizationPopup __instance, ref PortraitSettings portraitSettingsData)
 {
     try {
         if (portraitSettingsData == null)
         {
             if (!string.IsNullOrEmpty(__instance.pilot.pilotDef.Description.Icon))
             {
                 foreach (string path in CommanderPortraitLoader.jsonSearchablePaths)
                 {
                     string filePath = path + __instance.pilot.pilotDef.Description.Icon + ".json";
                     if (File.Exists(filePath))
                     {
                         portraitSettingsData = new PortraitSettings();
                         using (StreamReader r = new StreamReader(filePath))
                         {
                             string json = r.ReadToEnd();
                             portraitSettingsData.FromJSON(json);
                             break;
                         }
                     }
                 }
             }
         }
     } catch (Exception e) {
         Logger.LogError(e);
     }
 }
Exemple #2
0
        public static void Postfix(ref VersionManifest __result)
        {
            try
            {
                string        filePath = $"{ CommanderPortraitLoader.ModDirectory}/PortraitJsons/";
                DirectoryInfo d1       = new DirectoryInfo(filePath);
                FileInfo[]    f1       = d1.GetFiles("*.json");

                PortraitSettings preset = new PortraitSettings();
                foreach (FileInfo info in f1)
                {
                    using (StreamReader r = new StreamReader(info.FullName))
                    {
                        string json = r.ReadToEnd();
                        preset.FromJSON(json);
                    }
                    __result.AddOrUpdate(preset.Description.Id, info.FullName, "PortraitSettings", DateTime.Now, null, false);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }