public FileBrowserView(FileInfoBase[] fileInfos, Modes mode) { this.mode = mode; this.fileInfos = fileInfos; this.InitializeComponent(); this.SelectButton.Text = mode == Modes.Load ? LocalizationService.GetString("Common_OpenFile") : LocalizationService.GetString("Common_SaveFile"); this.Selector.SearchEnabled = mode == Modes.Load; this.ContentArea.DataContext = this; foreach (FileInfoBase info in fileInfos) { IFileSource[]? sources = info.GetFileSources(); if (sources == null) { continue; } foreach (IFileSource source in sources) { if (this.FileSources.Contains(source)) { continue; } this.FileSources.Add(source); } } this.FileSource = this.GetDefaultFileSource(); this.IsOpen = true; if (this.mode == Modes.Save) { this.FileName = "New " + fileInfos[0].Name; Task.Run(async() => { await Task.Delay(100); await Dispatch.MainThread(); this.FileNameInputBox.Focus(); this.FileNameInputBox.SelectAll(); FocusManager.SetFocusedElement(FocusManager.GetFocusScope(this), this.FileNameInputBox); Keyboard.Focus(this.FileNameInputBox); }); } Task.Run(this.UpdateEntries); Type?optionsType = mode == Modes.Load ? fileInfos[0].LoadOptionsViewType : fileInfos[0].SaveOptionsViewType; if (optionsType != null) { this.OptionsControl = (UserControl?)Activator.CreateInstance(optionsType); } }
private async Task Show(Entry entry, Random rnd) { if (entry.Url == null || entry.Author == null) { return; } await Dispatch.MainThread(); UIElement oldHost = this.isImage1 ? this.Image1Host : this.Image2Host; this.isImage1 = !this.isImage1; UIElement host; Image image; RotateTransform rotate; if (this.isImage1) { this.Image1Path = entry.Url; this.Image1Author = entry.Author; image = this.Image1; host = this.Image1Host; rotate = this.Image1Rotate; } else { this.Image2Path = entry.Url; this.Image2Author = entry.Author; image = this.Image2; host = this.Image2Host; rotate = this.Image2Rotate; } rotate.Angle = -5 + (rnd.NextDouble() * 10.0); while (image.Source != null && !image.Source.CanFreeze) { await Task.Delay(100); } await Dispatch.MainThread(); host.Opacity = 0.0; Storyboard?sb = this.Resources[this.isImage1 ? "StoryboardImage1" : "StoryboardImage2"] as Storyboard; if (sb == null) { throw new System.Exception("Missing gallery storyboard"); } sb.Begin(); await Task.Delay(2000); oldHost.Opacity = 0.0; }
private async Task GetProcess() { Process[] processes = Process.GetProcesses(); Process? proc = null; // Search for ffxiv process if (this.EnableProcess) { foreach (Process process in processes) { if (process.ProcessName.ToLower().Contains("ffxiv_dx11")) { proc = process; } } } // if no process, open the process selector GUI if (proc == null) { await Dispatch.MainThread(); if (App.Current == null) { return; } App.Current.MainWindow.Topmost = false; proc = ProcessSelector.FindProcess(); if (SettingsService.Exists) { App.Current.MainWindow.Topmost = SettingsService.Current.AlwaysOnTop; } await Dispatch.NonUiThread(); } // if still no process, shutdown. if (proc == null) { await Dispatch.MainThread(); App.Current.MainWindow.Close(); App.Current.Shutdown(); return; } this.OpenProcess(proc); await AddressService.Scan(); IsProcessAlive = true; }
private void OnRegenerateSkeletonClicked(object sender, RoutedEventArgs e) { if (this.Skeleton?.File != null && this.Skeleton.File.IsGeneratedParenting) { Task.Run(async() => { await Dispatch.MainThread(); await this.Skeleton.GenerateBones(true); }); } }
public async Task StartServices() { await Dispatch.MainThread(); foreach (IService service in Services) { await service.Start(); } IsStarted = true; }
private async Task Load() { string url = "https://raw.githubusercontent.com/wiki/imchillin/Anamnesis/WidgetHelpHome.md"; WebClient client = new WebClient(); string markdown = await client.DownloadStringTaskAsync(url); await Dispatch.MainThread(); this.MainViewer.Document = Markdown.ToDocument(markdown); }
private async void OnCameraChanged(object?sender, PropertyChangedEventArgs?e) { if (CameraService.Instance == null || CameraService.Instance.Camera == null) { return; } await Dispatch.MainThread(); ////this.camera.Position = CameraService.Instance.CameraPosition.ToMedia3DPoint(); QuaternionRotation3D rot = (QuaternionRotation3D)this.cameraRotaion.Rotation; rot.Quaternion = CameraService.Instance.Camera.Rotation3d; this.cameraRotaion.Rotation = rot; }
private async Task Scan() { bool loaded = true; while (loaded) { await Task.Delay(1000); if (!this.isAutomatic) { continue; } if (!MemoryService.Instance.EnableProcess) { continue; } if (Application.Current == null) { return; } await Dispatch.MainThread(); loaded = this.IsLoaded; if (!loaded) { return; } Process[] processes = Process.GetProcesses(); foreach (Process process in processes) { if (process.ProcessName.ToLower().Contains("ffxiv_dx11")) { await Dispatch.MainThread(); this.Selected = process; this.window?.Close(); return; } } } }
public FileBrowserView(FileInfoBase[] fileInfos, Modes mode) { this.mode = mode; this.fileInfos = fileInfos; this.InitializeComponent(); this.ContentArea.DataContext = this; foreach (FileInfoBase info in fileInfos) { IFileSource[]? sources = info.GetFileSources(); if (sources == null) { continue; } foreach (IFileSource source in sources) { this.FileSources.Add(source); } } this.FileSource = this.GetDefaultFileSource(); this.IsOpen = true; if (this.mode == Modes.Save) { this.FileName = "New " + fileInfos[0].Name; Task.Run(async() => { await Task.Delay(100); await Dispatch.MainThread(); this.FileNameInputBox.Focus(); this.FileNameInputBox.SelectAll(); FocusManager.SetFocusedElement(FocusManager.GetFocusScope(this), this.FileNameInputBox); Keyboard.Focus(this.FileNameInputBox); }); } Task.Run(this.UpdateEntries); }
private async Task UpdateEntries() { if (this.FileSource == null || this.CurrentDir == null) { return; } IEnumerable <IFileSource.IEntry> entries = await this.FileSource.GetEntries(this.CurrentDir, this.IsFlattened, this.fileInfos); await Dispatch.MainThread(); this.Entries.Clear(); foreach (IFileSource.IEntry entry in entries) { this.Entries.Add(new EntryWrapper(entry, this)); } }
private async Task Wait() { while (this.Waiting && GposeService.Instance.IsGpose != this.Destination) { await Task.Delay(500); } this.Waiting = false; while (GposeService.Instance.IsChangingState) { await Task.Delay(250); } this.Result = true; await Dispatch.MainThread(); this.Close?.Invoke(); }
private async Task GenerateBones() { this.Generating = true; await Dispatch.MainThread(); this.Bones.Clear(); if (this.Actor?.ModelObject?.Skeleton?.Skeleton == null) { return; } SkeletonViewModel skeletonVm = this.Actor.ModelObject.Skeleton.Skeleton; ////TemplateSkeleton template = skeletonVm.GetTemplate(this.Actor); await this.Generate(skeletonVm); // Map eyes together if they exist BoneVisual3d?lEye = this.GetBone("EyeLeft"); BoneVisual3d?rEye = this.GetBone("EyeRight"); if (lEye != null && rEye != null) { lEye.LinkedEye = rEye; rEye.LinkedEye = lEye; } foreach (BoneVisual3d bone in this.Bones) { bone.ReadTransform(); } foreach (BoneVisual3d bone in this.Bones) { bone.ReadTransform(); } this.Generating = false; }
private async Task GetProcess() { Process?proc = null; await Dispatch.MainThread(); if (App.Current == null) { return; } App.Current.MainWindow.Topmost = false; proc = ProcessSelector.FindProcess(); if (SettingsService.Exists) { App.Current.MainWindow.Topmost = SettingsService.Current.AlwaysOnTop; } await Dispatch.NonUiThread(); // if still no process, shutdown. if (proc == null) { await Dispatch.MainThread(); App.Current.MainWindow.Close(); App.Current.Shutdown(); return; } this.OpenProcess(proc); await AddressService.Scan(); IsProcessAlive = true; }
public override async Task Initialize() { await base.Initialize(); if (!File.Exists(settingsPath)) { this.FirstTimeUser = true; this.Settings = new Settings(); Save(); } else { this.FirstTimeUser = false; try { await Dispatch.MainThread(); if (Keyboard.IsKeyDown(Key.LeftShift)) { throw new Exception("User Abort"); } string json = File.ReadAllText(settingsPath); this.Settings = SerializerService.Deserialize <Settings>(json); } catch (Exception ex) { Log.Warning(ex, "Failed to load settings"); await GenericDialog.Show("Failed to load Settings. Your settings have been reset.", "Error", MessageBoxButton.OK); this.Settings = new Settings(); Save(); } } this.Settings.PropertyChanged += this.OnSettingsChanged; this.OnSettingsChanged(null, new PropertyChangedEventArgs(null)); }
private async Task WriteSkeletonThread() { while (Application.Current != null && this.Bones != null) { await Dispatch.MainThread(); if (this.CurrentBone != null && PoseService.Instance.IsEnabled) { try { this.CurrentBone.WriteTransform(this); } catch (Exception ex) { Log.Write(Severity.Error, new Exception($"Failed to write bone transform: {this.CurrentBone.BoneName}", ex)); this.ClearSelection(); } } // up to 60 times a second await Task.Delay(16); } }
public static async Task Add <T>() where T : IService, new() { try { if (IsStarted) { throw new Exception("Attempt to add service after services have started"); } IService service = Activator.CreateInstance <T>(); Services.Add(service); await Dispatch.MainThread(); await service.Initialize(); Log.Information($"Initialized service: {typeof(T).Name}"); } catch (Exception ex) { Log.Fatal(ex, $"{typeof(T).Name} Error: {ex.Message}"); } }
public static async Task <bool?> Show(string message, string caption, MessageBoxButton buttons) { await Dispatch.MainThread(); GenericDialog dlg = new GenericDialog(); dlg.Message = message; switch (buttons) { case MessageBoxButton.OK: { dlg.Left = null; dlg.Right = "OK"; break; } case MessageBoxButton.OKCancel: { dlg.Left = "Cancel"; dlg.Right = "OK"; break; } case MessageBoxButton.YesNoCancel: throw new NotImplementedException(); case MessageBoxButton.YesNo: { dlg.Left = "No"; dlg.Right = "Yes"; break; } } return(await ViewService.ShowDialog <GenericDialog, bool?>(caption, dlg)); }
private async void OnTransformPropertyChanged(object?sender, PropertyChangedEventArgs?e) { await Dispatch.MainThread(); this.rootRotation.Quaternion = this.RootRotation.ToMedia3DQuaternion(); }
private static async Task ParentBone(SkeletonVisual3d root, IEnumerable <BoneVisual3d> bones, BoneVisual3d bone) { // Must wait for ffxiv to update at least one frame await Task.Delay(75); await Dispatch.MainThread(); // Get the positions of all bones Dictionary <BoneVisual3d, Vector> initialBonePositions = new Dictionary <BoneVisual3d, Vector>(); foreach (BoneVisual3d otherBone in bones) { otherBone.ReadTransform(); initialBonePositions.Add(otherBone, otherBone.Position); } // rotate the test bone Quaternion oldRot = bone.Rotation; bone.Rotation *= Quaternion.FromEuler(new Vector(0, 90, 0)); bone.WriteTransform(root, false); bone.ViewModel.WriteToMemory(true); // Must wait for ffxiv to update at least one frame await Task.Delay(75); await Dispatch.MainThread(); // See if any bones moved as a result of the test bone rotation foreach (BoneVisual3d otherBone in bones) { if (otherBone == bone) { continue; } otherBone.ReadTransform(); // If this bone has moved, then it is a child of the test bone. if (initialBonePositions[otherBone] != otherBone.Position) { //// If this bone is already a child of the testbones hierarchy, dont move it. if (IsChildOf(otherBone, bone)) { continue; } if (IsChildOf(bone, otherBone)) { Log.Warning("Bone that is parent of test bone was moved."); continue; ////throw new Exception("Bone that is parent of test bone was moved."); } otherBone.Parent = bone; } } // Restore the test bone rotation bone.Rotation = oldRot; bone.WriteTransform(root, false); bone.ViewModel.WriteToMemory(true); // restore all initial bone positions foreach (BoneVisual3d otherBone in bones) { otherBone.ReadTransform(); if (initialBonePositions[otherBone] != otherBone.Position) { otherBone.Position = initialBonePositions[otherBone]; otherBone.WriteTransform(root, false); } } }
public async Task <bool> CheckForUpdates() { if (Directory.Exists(UpdateTempDir)) { Directory.Delete(UpdateTempDir, true); } if (!this.httpClient.DefaultRequestHeaders.Contains("User-Agent")) { this.httpClient.DefaultRequestHeaders.Add("User-Agent", "AutoUpdater"); } try { string url = $"https://api.github.com/repos/{Repository}/releases/latest"; string result = await this.httpClient.GetStringAsync(url); this.currentRelease = JsonSerializer.Deserialize <Release>(result); if (this.currentRelease == null) { throw new Exception("Failed to deserialize json response"); } if (this.currentRelease.Published == null) { throw new Exception("No published timestamp in update json"); } DateTimeOffset published = (DateTimeOffset)this.currentRelease.Published; published = published.ToUniversalTime(); bool update = this.currentRelease.Published != null && published > Version; if (update) { await Dispatch.MainThread(); UpdateDialog dlg = new UpdateDialog(); dlg.Changes = this.currentRelease.Changes; await ViewService.ShowDialog <UpdateDialog, bool?>("Update", dlg); } SettingsService.Current.LastUpdateCheck = DateTimeOffset.Now; SettingsService.Save(); return(update); } catch (HttpRequestException ex) { // 404 errors just mean there are no latest releases. if (ex.StatusCode == HttpStatusCode.NotFound) { SettingsService.Current.LastUpdateCheck = DateTimeOffset.Now; SettingsService.Save(); return(false); } throw; } catch (Exception ex) { Log.Error(ex, "Failed to complete update check"); return(false); } }
private async Task Show(Entry entry, Random rnd) { if (entry.Url == null || entry.Author == null) { return; } bool valid = true; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(entry.Url); request.Method = "HEAD"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode != HttpStatusCode.OK) { Log.Information($"Failed to get image from url: {entry.Url}: {response.StatusCode}"); valid = false; } response.Close(); } catch (Exception ex) { Log.Information($"Failed to get image from url: {entry.Url}: {ex.Message}"); valid = false; } if (!valid) { return; } await Dispatch.MainThread(); UIElement oldHost = this.isImage1 ? this.Image1Host : this.Image2Host; this.isImage1 = !this.isImage1; UIElement host; Image image; RotateTransform rotate; if (this.isImage1) { this.Image1Path = entry.Url; this.Image1Author = entry.Author; image = this.Image1; host = this.Image1Host; rotate = this.Image1Rotate; } else { this.Image2Path = entry.Url; this.Image2Author = entry.Author; image = this.Image2; host = this.Image2Host; rotate = this.Image2Rotate; } rotate.Angle = -5 + (rnd.NextDouble() * 10.0); while (image.Source != null && !image.Source.CanFreeze) { await Task.Delay(100); } await Dispatch.MainThread(); host.Opacity = 0.0; Storyboard?sb = this.Resources[this.isImage1 ? "StoryboardImage1" : "StoryboardImage2"] as Storyboard; if (sb == null) { throw new System.Exception("Missing gallery storyboard"); } sb.SpeedRatio = this.skip ? 10 : 1; sb.Begin(); await Task.Delay(this.skip? 200 : 2000); oldHost.Opacity = 0.0; }
public override async Task Initialize() { await base.Initialize(); if (!File.Exists(VersionFile)) { throw new Exception("No version file found"); } string[] parts = File.ReadAllText(VersionFile).Split(';'); Version = DateTimeOffset.Parse(parts[0].Trim()).ToUniversalTime(); SupportedGameVersion = parts[1].Trim(); // Debug builds should not attempt to update #if DEBUG Version = DateTimeOffset.UtcNow; #endif DateTimeOffset lastCheck = SettingsService.Current.LastUpdateCheck; TimeSpan elapsed = DateTimeOffset.Now - lastCheck; if (elapsed.TotalHours < 6) { Log.Information("Last update check was less than 6 hours ago. Skipping."); return; } if (Directory.Exists(UpdateTempDir)) { Directory.Delete(UpdateTempDir, true); } if (!this.httpClient.DefaultRequestHeaders.Contains("User-Agent")) { this.httpClient.DefaultRequestHeaders.Add("User-Agent", "AutoUpdater"); } try { string url = $"https://api.github.com/repos/{Repository}/releases/latest"; string result = await this.httpClient.GetStringAsync(url); this.currentRelease = JsonSerializer.Deserialize <Release>(result); if (this.currentRelease == null) { throw new Exception("Failed to deserialize json response"); } if (this.currentRelease.Published == null) { throw new Exception("No published timestamp in update json"); } DateTimeOffset published = (DateTimeOffset)this.currentRelease.Published; published = published.ToUniversalTime(); if (this.currentRelease.Published != null && published > Version) { await Dispatch.MainThread(); UpdateDialog dlg = new UpdateDialog(); dlg.Changes = this.currentRelease.Changes; await ViewService.ShowDialog <UpdateDialog, bool?>("Update", dlg); } SettingsService.Current.LastUpdateCheck = DateTimeOffset.Now; SettingsService.Save(); } catch (HttpRequestException ex) { // 404 errors just mean there are no latest releases. if (ex.StatusCode == HttpStatusCode.NotFound) { SettingsService.Current.LastUpdateCheck = DateTimeOffset.Now; SettingsService.Save(); return; } throw; } catch (Exception ex) { Log.Error(ex, "Failed to complete update check"); } }
public override async Task Initialize() { await base.Initialize(); string versionStr; if (!File.Exists(VersionFile)) { throw new Exception("No version file found"); } versionStr = File.ReadAllText(VersionFile); versionStr = versionStr.Split('\r')[0].Trim(); versionStr = versionStr.Trim(); Version = DateTimeOffset.Parse(versionStr); if (Directory.Exists(UpdateTempDir)) { Directory.Delete(UpdateTempDir, true); } if (!this.httpClient.DefaultRequestHeaders.Contains("User-Agent")) { this.httpClient.DefaultRequestHeaders.Add("User-Agent", "AutoUpdater"); } try { string url = $"https://api.github.com/repos/{Repository}/releases/latest"; string result = await this.httpClient.GetStringAsync(url); this.currentRelease = JsonSerializer.Deserialize <Release>(result); if (this.currentRelease == null) { throw new Exception("Failed to deserialize json response"); } if (this.currentRelease.Published != null && this.currentRelease.Published > Version) { await Dispatch.MainThread(); UpdateDialog dlg = new UpdateDialog(); dlg.Changes = this.currentRelease.Changes; await ViewService.ShowDialog <UpdateDialog, bool?>("Update", dlg); } } catch (HttpRequestException ex) { // 404 errors just mean there are no latest releases. if (ex.StatusCode == HttpStatusCode.NotFound) { return; } throw; } catch (Exception ex) { Log.Write(Severity.Error, new Exception("Unable to complete update check", ex)); throw; } }