|
5 | 5 | using System.Reflection; |
6 | 6 | using System.IO; |
7 | 7 | using System.Linq; |
| 8 | +using System.Text; |
8 | 9 | using System.Xml; |
9 | 10 | using RimWorld; |
10 | 11 | using UnityEngine; |
@@ -121,6 +122,14 @@ public void DoWindowContents(Rect rect) { |
121 | 122 | Find.WindowStack.Add( |
122 | 123 | new FloatMenu( |
123 | 124 | new List<FloatMenuOption> { |
| 125 | + new FloatMenuOption( |
| 126 | + LanguageKeys.keyed.ModSwitch_Import_OpenFolder.Translate(), |
| 127 | + () => { |
| 128 | + MS_GenFilePaths.EnsureExportFolderExists(); |
| 129 | + |
| 130 | + Process.Start(MS_GenFilePaths.ModSwitchFolderPath); |
| 131 | + } |
| 132 | + ), |
124 | 133 | new FloatMenuOption( |
125 | 134 | LanguageKeys.keyed.ModSwitch_Import_FromFile.Translate(), |
126 | 135 | () => { |
@@ -163,15 +172,9 @@ public void DoWindowContents(Rect rect) { |
163 | 172 | absorbInputAroundWindow = true, |
164 | 173 | closeOnClickedOutside = true, |
165 | 174 | doCloseX = true |
166 | | - })) |
| 175 | + })), |
167 | 176 | })); |
168 | 177 |
|
169 | | - if (list.ButtonTextLabeled("Import/Export location", "Open folder")) { |
170 | | - MS_GenFilePaths.EnsureExportFolderExists(); |
171 | | - |
172 | | - Process.Start(MS_GenFilePaths.ModSwitchFolderPath); |
173 | | - } |
174 | | - |
175 | 178 | #if DEBUG |
176 | 179 | if (list.ButtonTextLabeled("Debug", "ListExisting")) { |
177 | 180 | foreach (var modSet in Sets) { |
@@ -219,28 +222,76 @@ public override void ExposeData() { |
219 | 222 | } |
220 | 223 |
|
221 | 224 | private void ImportFromSave(FileInfo fi) { |
222 | | - Scribe.loader.InitLoadingMetaHeaderOnly(fi.FullName); |
223 | | - try { |
224 | | - ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false); |
225 | | - Scribe.loader.FinalizeLoading(); |
226 | 225 |
|
227 | | - int suffix = 0; |
228 | | - string name = fi.Name; |
229 | | - while (Sets.Any(ms => ms.Name == name)) |
230 | | - name = $"{fi.Name}_{++suffix}"; |
| 226 | + void AddModSet(string name, IEnumerable<ModMetaData> mods) { |
231 | 227 | Sets.Add( |
232 | | - new ModSet(this) { |
| 228 | + new ModSet(this) { |
233 | 229 | Name = name, |
234 | 230 | BuildNumber = new Version(VersionControl.VersionStringWithoutRev(ScribeMetaHeaderUtility.loadedGameVersion)).Build, |
235 | | - Mods = new List<string>(ScribeMetaHeaderUtility.loadedModIdsList) |
| 231 | + Mods = new List<string>(mods.Select(mmd => mmd.FolderName)) |
236 | 232 | }); |
237 | 233 | Mod.WriteSettings(); |
| 234 | + } |
| 235 | + |
| 236 | + |
| 237 | + Scribe.loader.InitLoadingMetaHeaderOnly(fi.FullName); |
| 238 | + try { |
| 239 | + ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false); |
| 240 | + Scribe.loader.FinalizeLoading(); |
| 241 | + |
| 242 | + int suffix = 0; |
| 243 | + string setname = fi.Name; |
| 244 | + while (Sets.Any(ms => ms.Name == setname)) |
| 245 | + setname = $"{fi.Name}_{++suffix}"; |
| 246 | + |
| 247 | + var modsFromSave = ScribeMetaHeaderUtility.loadedModIdsList |
| 248 | + .Zip(ScribeMetaHeaderUtility.loadedModNamesList, (id, name) => new {Id = id, Name = name}) |
| 249 | + .Select((t, idx) => new { Id = t.Id, Name = t.Name, Index = idx}); |
| 250 | + |
| 251 | + |
| 252 | + Log.Message($"Loaded version: '{ScribeMetaHeaderUtility.loadedGameVersion}'"); |
| 253 | + |
| 254 | + var idAccessor = Util.GetVersionSpecificIdMapping(VersionControl.VersionFromString(VersionControl.VersionStringWithoutRev(ScribeMetaHeaderUtility.loadedGameVersion))); |
| 255 | + |
| 256 | + var (resolved, unresolved) = ModConfigUtil.TryResolveModsList( |
| 257 | + modsFromSave, |
| 258 | + idAccessor, |
| 259 | + t => t.Id, |
| 260 | + (mmd, t) => new {Mod = mmd, Index = t.Index }, |
| 261 | + (_, t) => new {Name = t.Name, Id = t.Id}); |
| 262 | + |
| 263 | + var loadableMods = resolved.OrderBy(t => t.Index).Select(t => t.Mod); |
| 264 | + |
| 265 | + StringBuilder sb = new StringBuilder(LanguageKeys.keyed.ModSwitch_MissingMods.Translate(Path.GetFileNameWithoutExtension(fi.Name))); |
| 266 | + sb.AppendLine(); |
| 267 | + sb.AppendLine(); |
| 268 | + foreach (var item in unresolved) |
| 269 | + sb.AppendLine($" - {item.Name} ({item.Id})"); |
| 270 | + |
| 271 | + if (unresolved.Any()) { |
| 272 | + Find.WindowStack.Add( |
| 273 | + new Dialog_MissingMods( |
| 274 | + sb.ToString(), |
| 275 | + () => AddModSet(setname, loadableMods), |
| 276 | + () => { |
| 277 | + // dont know how to open multiple tabs in steam overlay right now - just pop urls to browser ;) |
| 278 | + foreach (var mod in unresolved) { |
| 279 | + string url = Util.BuildWorkshopUrl(mod.Name, mod.Id); |
| 280 | + Process.Start(url); |
| 281 | + } |
| 282 | + }, |
| 283 | + null |
| 284 | + )); |
| 285 | + } |
| 286 | + |
| 287 | + AddModSet(setname, loadableMods); |
238 | 288 | } catch (Exception ex) { |
239 | 289 | Log.Warning(string.Concat("Exception loading ", fi.FullName, ": ", ex)); |
240 | 290 | Scribe.ForceStop(); |
241 | 291 |
|
242 | 292 | } |
243 | 293 | } |
| 294 | + |
244 | 295 |
|
245 | 296 | private void ImportFromExport(FileInfo fi){ |
246 | 297 | if (File.Exists(fi.FullName)) { |
|
0 commit comments