private static bool TryGetModpack(StartGameOptions options, out Modpack modpack) { if (options.ModpackId.HasValue) { if (_modpacks.TryGetValue(options.ModpackId.Value, out modpack)) { return(true); } else { Log.Warning($"Modpack with ID {options.ModpackId.Value} does not exist, no modpack enabled"); return(false); } } if (!string.IsNullOrEmpty(options.ModpackName)) { foreach (var pack in Modpacks) { if (pack.DisplayName == options.ModpackName) { modpack = pack; return(true); } } Log.Warning($"Modpack with name {options.ModpackName} does not exist, no modpack enabled"); modpack = null; return(false); } modpack = null; return(false); }
public static void SaveBinarySettings(Modpack modpack) { if (updateCount > 0) { return; } }
public ModpackSynchronizer(Repository repository, Modpack modpack, DirectoryInfo modpackDirectory, Printer printer) { Repository = repository; Modpack = modpack; ModpackDirectory = modpackDirectory; Printer = printer; }
public void Synchronize(Repository repository, Modpack modpack) { if (CurrentConfig == null) { LoadConfiguration(); } DirectoryInfo directory = CurrentConfig.GetModpackDirectory(modpack.ID); if (directory == null) { Printer.PrintLine("Please select modpack directory:", VerboseLevel.REGULAR); directory = PromptModpackDirectory(modpack); if (directory == null || !directory.Exists) { Printer.PrintLine("Modpack directory invalid!", VerboseLevel.IMPORTANT); return; } CurrentConfig.SetModpackDirectory(new ModpackPath() { ModpackID = modpack.ID, Path = directory.FullName }); SaveConfiguration(); } ModpackSynchronizer synchronizer = new ModpackSynchronizer(repository, modpack, directory, Printer); synchronizer.Synchronize(); }
public ModpackViewModel(Modpack modpack) { Modpack = modpack; Size = ByteSize.FromBytes( Modpack.Mods .SelectMany(m => m.Mod.Files) .Select(f => f.Value.Length) .Aggregate((sum, a) => sum + a)).Humanize("G03"); }
private void ModpackListBoxDropHandler(object sender, DragEventArgs e) { ListBox listBox = sender as ListBox; if (listBox == null) { return; } ListBoxItem item = GetItem(listBox, e.GetPosition); if (item != null) { if (e.Data.GetDataPresent(typeof(List <Mod>))) { var mods = (List <Mod>)e.Data.GetData(typeof(List <Mod>)); Modpack parent = (Modpack)listBox.ItemContainerGenerator.ItemFromContainer(item); foreach (Mod mod in mods) { if (!parent.Contains(mod)) { var reference = new ModReference(mod, parent); parent.Mods.Add(reference); } } ModpackTemplateList.Instance.Update(MainViewModel.Instance.Modpacks); ModpackTemplateList.Instance.Save(); } else if (e.Data.GetDataPresent(typeof(List <Modpack>))) { var modpacks = (List <Modpack>)e.Data.GetData(typeof(List <Modpack>)); Modpack parent = (Modpack)listBox.ItemContainerGenerator.ItemFromContainer(item); foreach (Modpack modpack in modpacks) { if (modpack != parent && !parent.Contains(modpack) && !modpack.Contains(parent, true)) { var reference = new ModpackReference(modpack, parent); reference.ParentView = parent.ModsView; parent.Mods.Add(reference); } } ModpackTemplateList.Instance.Update(MainViewModel.Instance.Modpacks); ModpackTemplateList.Instance.Save(); } } else { if (e.Data.GetDataPresent(typeof(List <Mod>))) { var model = (MainViewModel)ViewModel; var mods = (List <Mod>)e.Data.GetData(typeof(List <Mod>)); model.CreateNewModpack(mods); } } }
public static bool DeleteModpack(Modpack modpack) { bool result = _modpacks.RemoveValue(modpack); if (result) { SaveModpacks(); } return(result); }
public static async Task <bool> DeleteModpackAsync(Modpack modpack) { bool result = _modpacks.RemoveValue(modpack); if (result) { await SaveModpacksAsync(); } return(result); }
private void StartModpackInstall() { Task.Factory.StartNew(() => { Modpack.InstallModpack(new Progress <InstallModpackProgress>(installProgress => { ConsoleOut += installProgress.UpdateString + "\n"; })); }); }
public ModpackExportTemplate(Modpack modpack, int[] modIds, int[] modpackIds) { Uid = globalUid; globalUid++; Modpack = modpack; Name = modpack.Name; ModIds = modIds; ModpackIds = modpackIds; }
public static Modpack CreateModpack() { var id = GetNextModpackId(); var name = (App.Current?.Locales?.GetResource("DefaultModpackName") as string) ?? "New Modpack"; var modpack = new Modpack { DisplayName = name }; _modpacks.Add(id, modpack); return(modpack); }
/// <summary> /// Creates a modpack from one or more modpacks, mods, or scripts /// </summary> /// <remarks> /// Sample usage: BuildModpack Mods/Mod1 Mods/Mod2 --disabled Mods/Mod3 --id "SkyEditor.Modpack" --name="My Modpack" --save-to modpack.zip /// This will create a modpack called "My Modpack" with 3 mods. Mod2 will be disabled by default. /// </remarks> private static async Task BuildModpack(Queue <string> arguments, ConsoleContext context) { var builder = new ModpackBuilder(); while (arguments.TryDequeue(out var arg)) { var modpackMetadataType = builder.Metadata.GetType(); if (arg == "--save-to") { var filename = arguments.Dequeue(); await builder.Build(filename); if (context.VerboseLogging) { Console.WriteLine("Saved modpack to " + filename); } return; } else if (arg.StartsWith("--")) { var parts = arg.TrimStart('-').Split('=', 2); var propertyName = parts[0]; var propertyValue = parts[1]; var property = modpackMetadataType.GetProperties().FirstOrDefault(p => string.Equals(p.Name, propertyName, StringComparison.OrdinalIgnoreCase)); if (property == null) { Console.Error.Write($"Warning: Unable to find property '{propertyName}' in modpack metadata. Skipping argument '{arg}'"); continue; } property.SetValue(builder.Metadata, Convert.ChangeType(propertyValue, property.PropertyType)); } else if (File.Exists(arg) || Directory.Exists(arg)) { var enabled = true; if (arguments.TryPeek(out var nextArg) && nextArg == "--disabled") { arguments.Dequeue(); enabled = false; } var modpack = new Modpack(arg, context.FileSystem); foreach (var mod in modpack.Mods ?? Enumerable.Empty <Mod>()) { builder.AddMod(mod, enabled); } } else { throw new InvalidOperationException($"Unrecognized argument in modpack builder: '{arg}'"); } } Console.Error.Write("Reached end of arguments without saving modpack."); }
void PrintModpackInfo(Modpack modpack) { string prefix = "> "; Printer.PrintLine(prefix + $"Modpack '{modpack.Name}'"); Printer.PrintLine(prefix + $"ID: {modpack.ID}"); Printer.PrintLine(prefix + $"Addons count: {modpack.Addons?.Length}"); Printer.PrintLine(prefix + $"Source: {modpack.Source}"); Printer.PrintLine(prefix + $" Server IP: {modpack.IP}"); Printer.PrintLine(prefix + $" Server port: {modpack.Port}"); Printer.PrintLine(prefix + $" Server password: {modpack.Password}"); }
public static int GetModpackId(Modpack modpack) { foreach (var kvp in _modpacks) { if (kvp.Value == modpack) { return(kvp.Key); } } return(-1); }
public Server(string name, string gameVersion, string serverURL, string outputFile, Dictionary <string, string> vMProperties, Dictionary <string, string> properties, IList <string> bannedIPS, IList <Ban> bans, IList <Op> ops, Modpack modpack) { Name = name; GameVersion = gameVersion; ServerURL = serverURL; OutputFile = outputFile; VMProperties = vMProperties; Properties = properties; BannedIPS = bannedIPS; Bans = bans; Ops = ops; Modpack = modpack; }
private static void Load() { var fileBrowser = new OpenFileDialog() { Title = "Choose an Automaton Modpack", InitialDirectory = "Downloads", Filter = "Modpack Files (*.zip;*.auto)|*.zip;*.auto", }; if (fileBrowser.ShowDialog() == DialogResult.OK) { Task.Factory.StartNew(() => { Modpack.LoadModpack(fileBrowser.FileName); }); } }
private static async Task <Modpack> CreateModpack(DirectoryInfo directory, Action <FileSignature, Uri> fileAction) { var modpack = new Modpack { Name = directory.Name, Mods = new List <ModEntry>() }; foreach (var modFolder in directory.EnumerateDirectories()) { var mod = await CreateMod(modFolder, fileAction); modpack.Mods.Add(new ModEntry { Mod = mod }); } return(modpack); }
public static int GetModpackId(Modpack modpack) { if (modpack is null) { throw new ArgumentNullException(nameof(modpack)); } foreach (var kvp in _modpacks) { if (kvp.Value == modpack) { return(kvp.Key); } } return(-1); }
public static void Main(string[] args) { InDebug = false; #if DEBUG InDebug = true; #endif Modpack modpack = DeserializeModpack(args[0]); string ModpackPath = $"{Environment.GetEnvironmentVariable("AppData") + "\\.minecraft\\mods"}\\{modpack.GameVersion}"; if (InDebug) { ModpackPath = $".\\{modpack.GameVersion}"; } DownloadManager manager = new DownloadManager(ModpackPath, modpack.GameVersion); Console.WriteLine("Downloading to " + ModpackPath); Console.WriteLine("Starting Downloads! Some of these mods might be large, so it could be awhile."); manager.DownloadMods(modpack?.Joint); manager.DownloadMods(modpack?.Client); }
void CheckAddonDirectory(Addon addon, DirectoryInfo directory, Modpack modpack) { Directory.CreateDirectory(directory.FullName); HashSet <FileInfo> allFiles = new HashSet <FileInfo>( directory.GetFiles("*", SearchOption.AllDirectories), new FileSystemInfoEqualityComparer()); List <AddonFile> filesToDownload = new List <AddonFile>(); foreach (var f in addon.Files) { string fPath = Path.Combine(ModpackDirectory.FullName, f.Path); FileInfo fi = new FileInfo(fPath); if (fi.Exists) { //long writeTime = ((DateTimeOffset)fi.LastWriteTimeUtc).ToUnixTimeSeconds(); if (fi.Length != f.Size /* || writeTime != f.LastChange*/) { Printer?.PrintLine($"\tSize differs: {fi.Length}/{f.Size} B ({f.Path})", VerboseLevel.REGULAR); filesToDownload.Add(f); } allFiles.Remove(fi); } else { Printer?.PrintLine($"\tFile not found: {f.Path}", VerboseLevel.REGULAR); filesToDownload.Add(f); } } if (filesToDownload.Count > 0) { ConcurrentAddonDownloader downloader = new ConcurrentAddonDownloader(Printer); downloader.DownloadFiles(filesToDownload, modpack.Source, ModpackDirectory).GetAwaiter().GetResult(); } foreach (var f in allFiles) { Printer?.PrintLine($"\tRedundant file: {f.FullName} - Deleting!", VerboseLevel.REGULAR); f.Delete(); } DeleteEmptyDirectories(directory); }
public async Task DownloadMissingFiles(Modpack modpack) { Log.Information("Gathering files to download for {modpack}", modpack.Name); foreach (var mod in modpack.Mods) { foreach (var fh in mod.Mod.Files) { var fileSignature = fh.Value; var(available, stream) = await LocalStorageService.WriteIfMissingOrInvalid(fileSignature); Log.Debug("Check {fh}, Exists: {exists}", fileSignature.Hash, available); if (!available) { DownloadService.Add(new Download(GetDownloadUri(fileSignature), stream, fileSignature.ToString())); } } } }
//--------------------------------------------------------------- Deprecated ------------------------------------------------------------------------------------ private static void AddModpacksRecursive(Modpack modpack, ICollection <ModpackExportTemplate> templateCollection, bool includeVersionInfo) { var template = ModpackExportTemplate.FromModpack(modpack, includeVersionInfo); if (!templateCollection.Contains(template)) { templateCollection.Add(template); } foreach (var reference in modpack.Mods) { ModpackReference modpackReference = reference as ModpackReference; if (modpackReference != null) { Modpack subModpack = modpackReference.Modpack; AddModpacksRecursive(subModpack, templateCollection, includeVersionInfo); } } }
DirectoryInfo PromptModpackDirectory(Modpack modpack) { using (var dialog = new CommonOpenFileDialog() { Title = $"'{modpack.Name}' modpack directory", IsFolderPicker = true, EnsureFileExists = true, Multiselect = false }) { var result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { return(new DirectoryInfo(dialog.FileName)); } return(null); } }
string CreateStartupParameters(Modpack modpack) { DirectoryInfo modpackDirectory = CurrentConfig.GetModpackDirectory(modpack.ID); if (modpackDirectory == null || string.IsNullOrWhiteSpace(modpackDirectory.FullName)) { Printer.PrintLine("Could not find modpack directory!", VerboseLevel.IMPORTANT); return(null); } StringBuilder sb = new StringBuilder(); sb.Append("-connect=").Append(modpack.IP).Append(" "); sb.Append("-port=").Append(modpack.Port).Append(" "); sb.Append("-password="******" "); string mods = string.Join(';', modpack.Addons.Select(a => $"\"{Path.Combine(modpackDirectory.FullName, a)}\"")); sb.Append("-mod=").Append(mods); return(sb.ToString()); }
/// <summary> /// Initializes the NXMWorker pipe listener. /// </summary> private void InitializeDownloadHandle() { if (NoMissingMods) { return; } var nexusProtocol = new NexusProtocol(); // Start capturing piped messages from the NXMWorker, handle any progress reports. nexusProtocol.StartRecievingProtocolValues(new Progress <CaptureProtocolValuesProgress>(async x => { var matchingMods = MissingMods.Where(y => y.NexusModId == x.ModId); if (!matchingMods.Any()) { return; } var matchingMod = matchingMods.First(); if (matchingMod != null) { WindowNotificationControls.MoveToFront(); // Start downloading the mod file. await NexusMod.DownloadModFile(matchingMod, x.FileId, new Progress <DownloadModFileProgress>(downloadProgress => { MissingMods[MissingMods.IndexOf(matchingMod)].CurrentDownloadPercentage = downloadProgress.CurrentDownloadPercentage; if (downloadProgress.IsDownloadComplete) { Modpack.UpdateModArchivePaths(matchingMod, downloadProgress.DownloadLocation); MissingMods.Remove(matchingMod); NoMissingMods = MissingMods.Count == 0; } })); } })); }
private static async Task ApplyMod(string modPath, ConsoleContext context) { if (context.Rom == null) { throw new InvalidOperationException("Mod argument must follow a ROM argument"); } using var modpack = new Modpack(modPath, context.FileSystem); if (context.Rom is IRtdxRom rtdx) { await modpack.Apply <IRtdxRom>(rtdx); } else if (context.Rom is IPsmdRom psmd) { await modpack.Apply <IPsmdRom>(psmd); } else { throw new ArgumentException("Unsupported ROM type: " + context.Rom.GetType().Name); } }
private async Task OpenModpack() { var dialog = new OpenFileDialog { Filters = new List<FileDialogFilter> { new FileDialogFilter { Name = "Mod Files", Extensions = new List<string> { "zip" }}, new FileDialogFilter { Name = "C# Files", Extensions = new List<string> { "csx" }}, new FileDialogFilter { Name = "Lua Files", Extensions = new List<string> { "lua" }}, } }; var paths = await dialog.ShowAsync(Application.Current.GetMainWindowOrThrow()); var firstPath = paths.FirstOrDefault(); if (!string.IsNullOrEmpty(firstPath)) { var modpack = new Modpack(firstPath, PhysicalFileSystem.Instance); await modpack.Apply<IRtdxRom>(viewModel.Model); viewModel.ReloadFromModel(); await CustomizeRom(); } }
private void ModpackListBoxPreviewMouseUpHandler(object sender, MouseButtonEventArgs e) { if (e.ChangedButton != MouseButton.Left) { return; } if (modpacksListBoxDeselectionOmitted) { ListBox listBox = sender as ListBox; if (listBox == null) { return; } ListBoxItem item = GetItem(listBox, e.GetPosition); if (item != null && item.IsSelected) { Modpack selectedModpack = (Modpack)listBox.ItemContainerGenerator.ItemFromContainer(item); if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { listBox.SelectedItems.Remove(selectedModpack); } else { for (int i = listBox.SelectedItems.Count - 1; i >= 0; i--) { Modpack modpack = (Modpack)listBox.SelectedItems[i]; if (modpack != selectedModpack) { listBox.SelectedItems.Remove(modpack); } } } } modpacksListBoxDeselectionOmitted = false; } }
public static ModpackExportTemplate FromModpack(Modpack modpack, bool includeVersionInfo) { var mods = new List <ModExportTemplate>(); var modpacks = new List <string>(); foreach (var reference in modpack.Mods) { ModReference modReference = reference as ModReference; ModpackReference modpackReference = reference as ModpackReference; if (modReference != null) { mods.Add(ModExportTemplate.FromMod(modReference.Mod, includeVersionInfo)); } else if (modpackReference != null) { modpacks.Add(modpackReference.Modpack.Name); } } return(new ModpackExportTemplate(modpack.Name, mods.ToArray(), modpacks.ToArray())); }
public void StartArmaWithModpack(Modpack modpack) { if (CurrentConfig == null) { LoadConfiguration(); } if (string.IsNullOrWhiteSpace(CurrentConfig.Arma3Executable)) { Printer.PrintLine("Please select Arma 3 executable:", VerboseLevel.REGULAR); FileInfo execFile = PromptArmaExecutable(); if (execFile == null || !execFile.Exists) { Printer.PrintLine("Invalid Arma 3 executable file!"); return; } CurrentConfig.Arma3Executable = execFile.FullName; SaveConfiguration(); } string parameters = CreateStartupParameters(modpack); Process.Start(new ProcessStartInfo(CurrentConfig.Arma3Executable, parameters)); }