private void CompileModList() { string[] ModsFolderContents = Directory.GetFiles(ModFolder); foreach (string s in ModsFolderContents) { var fi = new FileInfo(s); if (fi.Extension == ".dll" && !fi.Attributes.HasFlag(FileAttributes.ReparsePoint)) { targetFiles.Add(new ModRelay(s)); } if (AintThisPS(s)) { PubstuntFound = true; } } foreach (ModRelay mr in targetFiles) { Modlist.Items.Add(mr); } for (int i = 0; i < Modlist.Items.Count; i++) { if (Modlist.Items[i] is ModRelay) { ModRelay mr = Modlist.Items[i] as ModRelay; Modlist.SetItemCheckState(i, (mr.enabled) ? CheckState.Checked : CheckState.Unchecked); } } }
private void Modlist_ItemCheck(object sender, ItemCheckEventArgs e) { if (!ReadyForRefresh) { return; } if (Modlist.Items[e.Index] is ModRelay && (Modlist.Items[e.Index] as ModRelay).MyType == ModRelay.ModType.Invalid) { e.NewValue = CheckState.Unchecked; if (inp == null || inp.IsDisposed) { inp = new BlepOutIn.InvalidModPopup(this, (Modlist.Items[e.Index] as ModRelay).AssociatedModData.DisplayedName); } inp.ShowDialog(); } CheckState[] ich = new CheckState[Modlist.Items.Count]; for (int i = 0; i < ich.Length; i++) { ich[i] = Modlist.GetItemCheckState(i); } ich[e.Index] = e.NewValue; Debug.WriteLine("Mod state about to change: " + (Modlist.Items[e.Index] as ModRelay).AssociatedModData.DisplayedName + "; Type: " + (Modlist.Items[e.Index] as ModRelay).MyType.ToString()); ApplyModlist(ich); Debug.WriteLine("Resulting state: " + ((Modlist.Items[e.Index] as ModRelay).enabled ? "ON" : "OFF")); }
/// <summary> /// Adds all mods from <see cref="Donkey.cargo" into current modlist/> /// </summary> private void FillModList() { Modlist.Items.Clear(); Modlist.ItemCheck -= Modlist_ItemCheck; foreach (var mod in Donkey.cargo) { Modlist.Items.Add(mod); Modlist.SetItemChecked(Modlist.Items.Count - 1, mod.Enabled); } Modlist.ItemCheck += Modlist_ItemCheck; }
/// <summary> /// Applies search mask to visible modlist; depending on selected search mode, names and/or tags will be accounted for. /// </summary> /// <param name="mask">Mask contents.</param> private void ApplyMaskToModlist(string mask) { Modlist.Items.Clear(); Modlist.ItemCheck -= Modlist_ItemCheck; foreach (var mod in Donkey.cargo) { if (ModSelectedByMask(mask, mod)) { Modlist.Items.Add(mod); Modlist.SetItemChecked(Modlist.Items.Count - 1, mod.Enabled); } } Modlist.ItemCheck += Modlist_ItemCheck; }
private void ApplyModlist() { Debug.WriteLine("Applying modlist."); Debug.Indent(); for (int i = 0; i < Modlist.Items.Count; i++) { if (Modlist.Items[i] is ModRelay) { ModRelay mr = Modlist.Items[i] as ModRelay; if (Modlist.GetItemChecked(i)) { mr.Enable(); } else { mr.Disable(); } Debug.WriteLine(mr.AssociatedModData.DisplayedName + " : " + ((mr.enabled) ? "ON" : "OFF")); } } Debug.Unindent(); }
private void ApplyMaskToModlist(string mask) { bool oldrst = ReadyForRefresh; ReadyForRefresh = false; Modlist.Items.Clear(); foreach (ModRelay mr in targetFiles) { if (ModSelectedByMask(mask, mr)) { Modlist.Items.Add(mr); } } for (int i = 0; i < Modlist.Items.Count; i++) { if (Modlist.Items[i] is ModRelay) { ModRelay mr = Modlist.Items[i] as ModRelay; Modlist.SetItemCheckState(i, (mr.enabled) ? CheckState.Checked : CheckState.Unchecked); } } ReadyForRefresh = oldrst; }
protected override async Task <int> Run() { if (!File.Exists(Modlist)) { Log($"The file {Modlist} does not exist!"); return(-1); } if (!Directory.Exists(Input)) { Log($"The input directory {Input} does not exist!"); return(-1); } if (!Directory.Exists(Output)) { Log($"The output directory {Output} does not exist, it will be created."); Directory.CreateDirectory(Output); } if (!Modlist.EndsWith(Consts.ModListExtension) && !Modlist.EndsWith("modlist.txt")) { Log($"The file {Modlist} is not a valid modlist file!"); return(-1); } if (Copy && Move) { Log("You can't set both copy and move flags!"); return(-1); } var isModlist = Modlist.EndsWith(Consts.ModListExtension); var list = new List <TransferFile>(); if (isModlist) { ModList modlist; try { modlist = AInstaller.LoadFromFile(Modlist); } catch (Exception e) { Log($"Error while loading the Modlist!\n{e}"); return(1); } if (modlist == null) { Log("The Modlist could not be loaded!"); return(1); } Log($"Modlist contains {modlist.Archives.Count} archives."); modlist.Archives.Do(a => { var inputPath = Path.Combine(Input, a.Name); var outputPath = Path.Combine(Output, a.Name); if (!File.Exists(inputPath)) { Log($"File {inputPath} does not exist, skipping."); return; } Log($"Adding {inputPath} to the transfer list."); list.Add(new TransferFile(inputPath, outputPath)); var metaInputPath = Path.Combine(inputPath, ".meta"); var metaOutputPath = Path.Combine(outputPath, ".meta"); if (File.Exists(metaInputPath)) { Log($"Found meta file {metaInputPath}"); if (IncludeMeta) { Log($"Adding {metaInputPath} to the transfer list."); list.Add(new TransferFile(metaInputPath, metaOutputPath)); } else { Log($"Meta file {metaInputPath} will be ignored."); } } else { Log($"Found no meta file for {inputPath}"); if (IncludeMeta) { if (string.IsNullOrWhiteSpace(a.Meta)) { Log($"Meta for {a.Name} is empty, this should not be possible but whatever."); return; } Log("Adding meta from archive info the transfer list"); list.Add(new TransferFile(a.Meta, metaOutputPath, true)); } else { Log($"Meta will be ignored for {a.Name}"); } } }); } else { if (!Directory.Exists(Mods)) { Log($"Mods directory {Mods} does not exist!"); return(-1); } Log($"Reading modlist.txt from {Modlist}"); string[] modlist = File.ReadAllLines(Modlist); if (modlist == null || modlist.Length == 0) { Log($"Provided modlist.txt file at {Modlist} is empty or could not be read!"); return(-1); } var mods = modlist.Where(s => s.StartsWith("+")).Select(s => s.Substring(1)).ToHashSet(); if (mods.Count == 0) { Log("Counted mods from modlist.txt are 0!"); return(-1); } Log($"Found {mods.Count} mods in modlist.txt"); var downloads = new HashSet <string>(); Directory.EnumerateDirectories(Mods, "*", SearchOption.TopDirectoryOnly) .Where(d => mods.Contains(Path.GetRelativePath(Path.GetDirectoryName(d), d))) .Do(d => { var meta = Path.Combine(d, "meta.ini"); if (!File.Exists(meta)) { Log($"Mod meta file {meta} does not exist, skipping"); return; } string[] ini = File.ReadAllLines(meta); if (ini == null || ini.Length == 0) { Log($"Mod meta file {meta} could not be read or is empty!"); return; } ini.Where(i => !string.IsNullOrWhiteSpace(i) && i.StartsWith("installationFile=")) .Select(i => i.Replace("installationFile=", "")) .Do(i => { Log($"Found installationFile {i}"); downloads.Add(i); }); }); Log($"Found {downloads.Count} installationFiles from mod metas."); Directory.EnumerateFiles(Input, "*", SearchOption.TopDirectoryOnly) .Where(f => downloads.Contains(Path.GetFileNameWithoutExtension(f))) .Do(f => { Log($"Found archive {f}"); var outputPath = Path.Combine(Output, Path.GetFileName(f)); Log($"Adding {f} to the transfer list"); list.Add(new TransferFile(f, outputPath)); var metaInputPath = Path.Combine(f, ".meta"); if (File.Exists(metaInputPath)) { Log($"Found meta file for {f} at {metaInputPath}"); if (IncludeMeta) { var metaOutputPath = Path.Combine(outputPath, ".meta"); Log($"Adding {metaInputPath} to the transfer list."); list.Add(new TransferFile(metaInputPath, metaOutputPath)); } else { Log("Meta file will be ignored"); } } else { Log($"Found no meta file for {f}"); } }); } Log($"Transfer list contains {list.Count} items"); var success = 0; var failed = 0; var skipped = 0; list.Do(f => { if (File.Exists(f.Output)) { if (Overwrite) { Log($"Output file {f.Output} already exists, it will be overwritten"); if (f.IsMeta || Move) { Log($"Deleting file at {f.Output}"); try { File.Delete(f.Output); } catch (Exception e) { Log($"Could not delete file {f.Output}!\n{e}"); failed++; } } } else { Log($"Output file {f.Output} already exists, skipping"); skipped++; return; } } if (f.IsMeta) { Log($"Writing meta data to {f.Output}"); try { File.WriteAllText(f.Output, f.Input, Encoding.UTF8); success++; } catch (Exception e) { Log($"Error while writing meta data to {f.Output}!\n{e}"); failed++; } } else { if (Copy) { Log($"Copying file {f.Input} to {f.Output}"); try { File.Copy(f.Input, f.Output, Overwrite ? CopyOptions.None : CopyOptions.FailIfExists, CopyMoveProgressHandler, null); success++; } catch (Exception e) { Log($"Error while copying file {f.Input} to {f.Output}!\n{e}"); failed++; } } else if (Move) { Log($"Moving file {f.Input} to {f.Output}"); try { File.Move(f.Input, f.Output, Overwrite ? MoveOptions.ReplaceExisting : MoveOptions.None, CopyMoveProgressHandler, null); success++; } catch (Exception e) { Log($"Error while moving file {f.Input} to {f.Output}!\n{e}"); failed++; } } } }); Log($"Skipped transfers: {skipped}"); Log($"Failed transfers: {failed}"); Log($"Successful transfers: {success}"); return(0); }