public SimulationHost(string empyrionPath) { this.EmpyrionBasePath = new DirectoryInfo(empyrionPath); this.IApplication = new ApplicationSimulator(); this.IApplication.EmpyrionRootDirectory = this.EmpyrionBasePath.FullName; PlayfieldSimulator playfield = this.IApplication.CreatePlayfield("Planet", "Temperate", 1); playfield.GeneratePoIs(30); this.IApplication.LocalPlayer = playfield.Players[playfield.SpawnTestPlayer(UnityEngine.Vector3.zero)]; this.IModApi = new ModApiSimulator(); this.IModApi.Application = this.IApplication; this.IModApi.ClientPlayfield = playfield; this.ModGameAPI = new ModGameApiSimulator(); foreach (string dir in Directory.GetDirectories(Path.Combine(this.EmpyrionBasePath.FullName, @"Content\Mods"))) { ModDetails mod = new ModDetails(dir); this.Mods[mod.ShortName] = mod; } }
private void SaveYaml(string yamlPath) { try { log.InfoFormat("Saving YAML file: {0}", yamlPath); var tags = new List <string>(); foreach (var tag in ModTags) { if (tag.Selected) { tags.AddIfMissing(tag.Title); } } if (!string.IsNullOrWhiteSpace(AdditionalTags)) { foreach (var tag in AdditionalTags.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { tags.AddIfMissing(tag.Trim()); } } ModDetails details = new ModDetails() { Author = ModAuthor, Title = ModTitle, Notes = ModNotes, PreviewPath = ModPreview, Files = ModFiles.ToList(), Tags = tags }; details.SaveYamlFile(yamlPath); } catch (Exception ex) { log.Error(string.Format("Error saving YAML file {0}", yamlPath), ex); } }
private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (!IsDragging) { if (popup.IsOpen) { popup.IsOpen = false; } return; } //get the target item var targetItem = (ModDetail)ModDetailsGrid.SelectedItem; if (targetItem == null || !ReferenceEquals(DraggedItem, targetItem)) { //get target index var targetIndex = ModDetails.IndexOf(targetItem); //move source at the target's location ModDetails.Move(DraggedItem, targetIndex); //select the dropped item ModDetailsGrid.SelectedItem = DraggedItem; } //reset ResetDragDrop(); }
private async Task LoadModsFromList() { var modIdList = ModDetails.Select(m => m.ModId).ToList(); var response = await GetModDetails(modIdList); var modDetails = ModDetailList.GetModDetails(response, Path.Combine(_profile.InstallDirectory, Config.Default.ServerModsRelativePath), modIdList); UpdateModDetailsList(modDetails); ModDetailsChanged = true; }
private void SaveSelection() { this.FullSelect(); this.m_SelctedMods.Clear(); foreach (DataGridViewRow _CurrentRow in dgrvMods.SelectedRows) { ModDetails _CurrentMod = (DataObjects.ModDetails)_CurrentRow.DataBoundItem; this.m_SelctedMods.Add(_CurrentMod); } }
private void dgrvMods_SelectionChanged(object sender, EventArgs e) { foreach (DataGridViewCell _CurrentCell in dgrvMods.SelectedCells) { ModDetails _CurrentMod = (DataObjects.ModDetails)_CurrentCell.OwningRow.DataBoundItem; this.txbxModDetails.Text = _CurrentMod.Details; return; } this.txbxModDetails.Text = null; }
private void clbSimulationMods_SelectedIndexChanged(object sender, EventArgs e) { ModDetails mod = this.clbSimulationMods.SelectedItem as ModDetails; if (mod == null) { this.lblSimulationModDetails.Text = ""; } else { this.lblSimulationModDetails.Text = mod.ToString(); } }
private async void SaveMods_Click(object sender, RoutedEventArgs e) { var cursor = this.Cursor; try { Application.Current.Dispatcher.Invoke(() => this.Cursor = System.Windows.Input.Cursors.Wait); await Task.Delay(500); string mapString; string totalConversionString; string modIdString; // check if there are any unknown mod types. if (ModDetails.AnyUnknownModTypes) { if (MessageBox.Show(_globalizer.GetResourceString("ModDetails_Save_UnknownLabel"), _globalizer.GetResourceString("ModDetails_Save_UnknownTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } } if (ModDetails.GetModStrings(out mapString, out totalConversionString, out modIdString)) { if (mapString != null) { _profile.ServerMap = mapString; } else if (_profile.ServerMap.Contains('/')) { _profile.ServerMap = string.Empty; } _profile.TotalConversionModId = totalConversionString ?? string.Empty; _profile.ServerModIds = modIdString ?? string.Empty; } await LoadModsFromProfile(); OnSavePerformed(); } catch (Exception ex) { MessageBox.Show(ex.Message, _globalizer.GetResourceString("ModDetails_Save_FailedTitle"), MessageBoxButton.OK, MessageBoxImage.Error); } finally { Application.Current.Dispatcher.Invoke(() => this.Cursor = cursor); } }
private void PurgeModsFromServerFolder(out int folderCount, out int fileCount) { folderCount = 0; fileCount = 0; // build a list of mods to be processed var modIdList = ModDetails.Select(m => m.ModId).ToList(); var modDirectory = new DirectoryInfo(Path.Combine(_profile.InstallDirectory, Config.Default.ServerModsRelativePath)); if (Directory.Exists(modDirectory.FullName)) { foreach (var directory in modDirectory.GetDirectories()) { var modId = directory.Name; if (ModUtils.IsOfficialMod(modId)) { continue; } if (modIdList.Contains(modId)) { continue; } directory.Delete(true); folderCount++; } foreach (var file in modDirectory.GetFiles("*.mod")) { var modId = Path.GetFileNameWithoutExtension(file.Name); if (ModUtils.IsOfficialMod(modId)) { continue; } if (modIdList.Contains(modId)) { continue; } file.Delete(); fileCount++; } } }
private async Task LoadModsFromList() { // build a list of mods to be processed var modIdList = new List <string>(); modIdList.AddRange(ModDetails.Select(m => m.ModId)); modIdList = ModUtils.ValidateModList(modIdList); var response = await Task.Run(() => SteamUtils.GetSteamModDetails(modIdList)); var workshopFiles = WorkshopFiles; var modsRootFolder = Path.Combine(_profile.InstallDirectory, Config.Default.ServerModsRelativePath); var modDetails = ModDetailList.GetModDetails(modIdList, modsRootFolder, workshopFiles, response); UpdateModDetailsList(modDetails); ModDetailsStatusMessage = modDetails.Count > 0 && response?.publishedfiledetails == null?_globalizer.GetResourceString("ModDetails_ModDetailFetchFailed_Label") : string.Empty; ModDetailsChanged = true; }
private void LoadYaml(string yamlPath) { try { log.InfoFormat("Loading YAML file: {0}", yamlPath); string yamlContents = File.ReadAllText(yamlPath); var details = ModDetails.LoadFromYaml(yamlContents); Clear(); ModAuthor = details.Author; ModTitle = details.Title; ModNotes = details.Notes; ModPreview = details.PreviewPath; string preview = TroveMod.GetOverridePath(details.PreviewPath, PrimaryLocationPath); if (!string.IsNullOrWhiteSpace(preview) && File.Exists(preview) && (preview.EndsWith(".png", StringComparison.OrdinalIgnoreCase) || preview.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase))) { PreviewImage = preview; } foreach (string file in details.Files) { ModFiles.Add(file); } foreach (string tag in details.Tags) { var modTag = ModTags.FirstOrDefault(t => t.Title.Equals(tag, StringComparison.OrdinalIgnoreCase)); if (modTag != null) { modTag.Selected = true; } else { AdditionalTags = string.IsNullOrWhiteSpace(AdditionalTags) ? tag : string.Format("{0}, {1}", AdditionalTags, tag); } } } catch (Exception ex) { log.Error(string.Format("Error loading YAML file {0}", yamlPath), ex); } }
private void LoadPreview(object Args) { object[] ArgsArray = (object[])Args; bool Spacewar = (bool)ArgsArray[0]; ulong ID = (ulong)ArgsArray[1]; ModDetails[] Response = GetModsDetails(ID); ModDetails Details = Response is null ? default : Response[0]; Dispatcher.Invoke(() => { if (Details.Status == 1) { (Spacewar ? PreviewS : PreviewA).Source = string.IsNullOrEmpty(Details.PreviewURL) ? new BitmapImage() : new BitmapImage(new Uri(Details.PreviewURL)); (Spacewar ? NameS : NameA).Text = Details.Name; if (Spacewar && Details.AppID != 480) { (Spacewar ? ErrorS : ErrorA).Visibility = Visibility.Visible; (Spacewar ? ErrorS : ErrorA).Text = LocString(LocCode.MIPvNotASpacewarMod); } else if (!Spacewar && Details.AppID != 346110) { (Spacewar ? ErrorS : ErrorA).Visibility = Visibility.Visible; (Spacewar ? ErrorS : ErrorA).Text = LocString(LocCode.MIPvNotAnARKMod); } else { (Spacewar ? ErrorS : ErrorA).Visibility = Visibility.Collapsed; } } else { (Spacewar ? PreviewS : PreviewA).Source = new BitmapImage(); (Spacewar ? NameS : NameA).Text = string.Empty; (Spacewar ? ErrorS : ErrorA).Visibility = Visibility.Visible; (Spacewar ? ErrorS : ErrorA).Text = Details.Status == 0 ? LocString(LocCode.MIPvFailed) : LocString(LocCode.MIPvNoMod); } }); }
private async void SaveMods_Click(object sender, RoutedEventArgs e) { var cursor = this.Cursor; try { Application.Current.Dispatcher.Invoke(() => this.Cursor = System.Windows.Input.Cursors.Wait); await Task.Delay(500); string mapString; string totalConversionString; string modIdString; // check if there are any unknown mod types. if (ModDetails.AnyUnknownModTypes) { if (MessageBox.Show(_globalizer.GetResourceString("ModDetails_Save_UnknownLabel"), _globalizer.GetResourceString("ModDetails_Save_UnknownTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } } if (ModDetails.GetModStrings(out mapString, out totalConversionString, out modIdString)) { if (mapString != null) { _profile.ServerMap = mapString; } else if (_profile.ServerMap.Contains('/')) { _profile.ServerMap = string.Empty; } // check if a total conversion mod was found in the mod list if (string.IsNullOrWhiteSpace(totalConversionString)) { // total conversion mod not found, was it previously set to an official mod? if (!ModUtils.IsOfficialMod(_profile.TotalConversionModId)) { // total conversion was not previoulsly set to an official mod, clear total conversion mod id _profile.TotalConversionModId = string.Empty; } } else { // total conversion mod found, set the found mod id _profile.TotalConversionModId = totalConversionString; } _profile.ServerModIds = modIdString ?? string.Empty; } await LoadModsFromProfile(); OnSavePerformed(); } catch (Exception ex) { MessageBox.Show(ex.Message, _globalizer.GetResourceString("ModDetails_Save_FailedTitle"), MessageBoxButton.OK, MessageBoxImage.Error); } finally { Application.Current.Dispatcher.Invoke(() => this.Cursor = cursor); } }
private void RemoveAllMods_Click(object sender, RoutedEventArgs e) { ModDetails.Clear(); }
private void RemoveMod_Click(object sender, RoutedEventArgs e) { var mod = ((ModDetail)((Button)e.Source).DataContext); ModDetails.Remove(mod); }
private async void Change(object Sender, RoutedEventArgs Args) { if (Game.IsRunning) { SetStatus(LocString(LocCode.CantChangeSIDGameRunning), DarkRed); return; } NewID.IsReadOnly = OldID.IsReadOnly = true; ulong OID = ulong.Parse(OldID.Text), NID = ulong.Parse(NewID.Text); Mod Mod = Mods.Find(M => M.ID == OID); if (Mod is null) { SetStatus(LocString(LocCode.OIDNotFound), DarkRed); NewID.IsReadOnly = OldID.IsReadOnly = false; return; } if (!(Mods.Find(M => M.ID == NID) is null)) { SetStatus(LocString(LocCode.NIDAlrInUse), DarkRed); NewID.IsReadOnly = OldID.IsReadOnly = false; return; } SetStatus(LocString(LocCode.SIDChangerRequesting), YellowBrush); ModDetails[] Response = await GetModsDetailsAsync(NID); ModDetails Details = (Response?.Length ?? 0) == 0 ? default : Response[0]; if (Details.Status != 1 || Details.AppID != 480) { SetStatus(LocString(LocCode.SIDChangerReqFailed + Details.Status), DarkRed); NewID.IsReadOnly = OldID.IsReadOnly = false; return; } string OldPath = Mod.Path, OldModFilePath = Mod.ModFilePath, OldModsPath = Mod.ModsPath; Mod.Path = Mod.Path.Replace(OID.ToString(), NID.ToString()); Mod.ModFilePath = $"{Mod.ModsPath = $@"{Game.Path}\ShooterGame\Content\Mods\{Mod.ID = NID}"}.mod"; Move(OldPath, Mod.Path); if (FileExists(OldModFilePath)) { File.Move(OldModFilePath, Mod.ModFilePath); } if (Exists(OldModsPath)) { Move(OldModsPath, Mod.ModsPath); } if (!(Mod.ImageFile is null)) { Mod.ImageFile = Mod.ImageFile.Replace(OID.ToString(), NID.ToString()); } Mod.Details = Details; if (await TryDeployAsync()) { await SteamAPI.UnsubscribeModAsync(OID); if ((Mod.IsSubscribed = (await SteamAPI.SubscribeModAsync(NID)) ? (bool?)true : null) is null) { Message.Show("Info", LocString(LocCode.FailedToSub)); Execute($"{SteamWorkshop}{NID}"); } } else { Mod.IsSubscribed = null; Message.Show("Info", LocString(LocCode.FailedToSub)); Execute($"{SteamWorkshop}{NID}"); } NewID.IsReadOnly = OldID.IsReadOnly = false; SetStatus(LocString(LocCode.SIDChangerSuccess), DarkGreen); }
private async void InstallCancel(object Sender, RoutedEventArgs Args) { if (IsInstalling) { InstallCancelButton.IsEnabled = false; Downloader.Pause(); SetStatus(LocString(LocCode.Cancelling), YellowBrush); } else if (ARKID.Text.Length == 0) { SetStatus(LocString(LocCode.MIEnterARKID), DarkRed); } else { ulong ID = ulong.Parse(ARKID.Text); if (Workshop.ContainsKey(ID)) { if (!(Mods.Find(Mod => Mod.ID == Workshop[ID])?.IsInstalled ?? false) && ShowOptions("Info", LocString(LocCode.MIARKdictedPrompt))) { ulong ARKDictedID = Workshop[ID]; SetStatus(LocString(LocCode.MIRequestingDetails), YellowBrush); ModDetails[] Response = await GetModsDetailsAsync(ARKDictedID); ModDetails Details = (Response?.Length ?? 0) == 0 ? default : Response[0]; string Name = Details.Status == 1 ? Details.Name : LocString(LocCode.MIDefaultModName); SetStatus(string.Format(LocString(LocCode.MISubscribing), Name), YellowBrush); bool Subscribed = false; if (await TryDeployAsync()) { if (await SteamAPI.SubscribeModAsync(ARKDictedID)) { Subscribed = true; } } if (Subscribed) { SetStatus(LocString(LocCode.MIWaitingForSteam), YellowBrush); if (await SteamAPI.TrackDownloadProgressAsync(ARKDictedID, ProgressBar, SetStatus)) { string ModFolder = $@"{WorkshopPath}\{ARKDictedID}"; SetStatus(LocString(LocCode.MIWaitingModCopy), YellowBrush); int TimeoutCounter = 60; while (!Exists($@"{ModFolder}\mod.info") && --TimeoutCounter != 0) { await Delay(1000); } if (TimeoutCounter == 0) { SetStatus(LocString(LocCode.MIModCopyTimeout), DarkRed); } else { SetStatus(LocString(LocCode.CInstallingMod), YellowBrush); Mod Mod = Mods.Find(ListMod => ListMod.ID == ARKDictedID); if (!(Mod is null)) { Mods.Remove(Mod); } Mod = new Mod(ModFolder, null) { IsSubscribed = true, Details = Details }; await Run(() => Mod.Install(ProgressBar.Progress, ProgressBar)); Mods.Add(Mod); SetStatus(string.Format(LocString(LocCode.MISuccess), Name), DarkGreen); } } } else { Show("Info", LocString(LocCode.FailedToSub)); Execute($"{SteamWorkshop}{ARKDictedID}"); SetStatus(string.Format(LocString(LocCode.MISubSuccess), Name), DarkGreen); } FinishHandler(); return; } } if (SpacewarID.Text.Length == 0) { SetStatus(LocString(LocCode.MIEnterSpacewarID), DarkRed); } else if (Mods.Find(Mod => Mod.ID == ulong.Parse(SpacewarID.Text))?.IsInstalled ?? false) { SetStatus(LocString(LocCode.MIIDInUse), DarkRed); } else { IsInstalling = true; SpacewarID.IsReadOnly = ARKID.IsReadOnly = true; SelectIDButton.IsEnabled = BackButton.IsEnabled = false; ((VectorImage)InstallCancelButton.Template.FindName("Icon", InstallCancelButton)).Source = "Pause"; ARKModID = ID; SpacewarModID = ulong.Parse(SpacewarID.Text); SetStatus(LocString(LocCode.MIRequestingDetails), YellowBrush); string Message = null; ModDetails[] Details = await GetModsDetailsAsync(ARKModID, SpacewarModID); if ((Details?.Length ?? 0) < 2) { Message = LocString(LocCode.MIRequestFailed); } else if (Details[0].Status == 2) { Message = LocString(LocCode.MINoARKMod); } else if (Details[0].AppID != 346110U) { Message = LocString(LocCode.MINotAnARKMod); } else if (Details[1].Status == 2) { Message = LocString(LocCode.MINoSpacewarMod); } else if (Details[1].AppID != 480U) { Message = LocString(LocCode.MINotASpacewarMod); } if (Message is null) { ARKModDetails = Details[0]; SpacewarModDetails = Details[1]; new Thread(DownloadJob).Start(); } else { SetStatus(Message, DarkRed); Downloader.FilesUpToDate = 0; FinishHandler(); } } } }